Skip to content

Commit

Permalink
support account handle buttons aliases #175
Browse files Browse the repository at this point in the history
  • Loading branch information
vladimiry committed Nov 21, 2019
1 parent c87fcca commit 72cd1fa
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
16 changes: 9 additions & 7 deletions src/electron-main/api/endpoints-builders/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ export async function buildEndpoints(
ctx: Context,
): Promise<Pick<IpcMainApiEndpoints, "addAccount" | "updateAccount" | "changeAccountOrder" | "removeAccount">> {
return {
async addAccount({type, login, entryUrl, database, credentials, proxy, loginDelayUntilSelected, loginDelaySecondsRange}) {
const account = {
async addAccount({type, login, title, entryUrl, database, credentials, proxy, loginDelayUntilSelected, loginDelaySecondsRange}) {
const account: AccountConfig = {
type,
login,
title,
entryUrl,
database,
credentials,
proxy,
loginDelayUntilSelected,
loginDelaySecondsRange,
} as AccountConfig; // TODO ger rid of "TS as" casting
};
const settings = await ctx.settingsStore.readExisting();

settings.accounts.push(account);
Expand All @@ -32,11 +33,12 @@ export async function buildEndpoints(
return result;
},

async updateAccount({login, entryUrl, database, credentials, proxy, loginDelayUntilSelected, loginDelaySecondsRange}) {
async updateAccount({login, title, entryUrl, database, credentials, proxy, loginDelayUntilSelected, loginDelaySecondsRange}) {
const settings = await ctx.settingsStore.readExisting();
const account = pickAccountStrict(settings.accounts, {login});
const {credentials: existingCredentials} = account;

account.title = title;
account.database = database;

if (typeof entryUrl === "undefined") {
Expand All @@ -62,7 +64,7 @@ export async function buildEndpoints(
account.loginDelayUntilSelected = loginDelayUntilSelected;
account.loginDelaySecondsRange = loginDelaySecondsRange;

return await ctx.settingsStore.write(settings);
return ctx.settingsStore.write(settings);
},

async changeAccountOrder({login, index: moveToIndex}) {
Expand All @@ -82,7 +84,7 @@ export async function buildEndpoints(
settings.accounts.splice(removeIndex, 1);
settings.accounts.splice(moveToIndex, 0, accountToMove);

return await ctx.settingsStore.write(settings);
return ctx.settingsStore.write(settings);
},

async removeAccount({login}) {
Expand All @@ -94,7 +96,7 @@ export async function buildEndpoints(

// TODO remove session, not yet supported by Electron?

return await ctx.settingsStore.write(settings);
return ctx.settingsStore.write(settings);
},
};
}
1 change: 1 addition & 0 deletions src/shared/model/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type AccountType = "protonmail" | "tutanota";
export interface GenericAccountConfig<Type extends AccountType, CredentialFields extends string> {
type: Type;
login: string;
title?: string;
entryUrl: string;
database?: boolean;
credentials: Partial<Record<CredentialFields, string>>;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/model/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ export type AccountConfigCreatePatch<T extends AccountType = AccountType> = Acco

export type AccountConfigUpdatePatch<T extends AccountType = AccountType> = Pick<AccountConfig<T>, "login">
& Partial<Pick<AccountConfig,
"login" | "entryUrl" | "database" | "credentials" | "proxy" | "loginDelayUntilSelected" | "loginDelaySecondsRange">>;
"login" | "title" | "entryUrl" | "database" | "credentials" | "proxy" | "loginDelayUntilSelected" | "loginDelaySecondsRange">>;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
<i class="fa fa-hand-pointer-o" *ngIf="state.account.loginDelayedUntilSelected"></i>
<span *ngIf="state.account.loginDelayedSeconds; let remainingSeconds">{{ remainingSeconds }}</span>
</div>
<div class="ml-2 d-flex flex-grow-1">{{ state.account.accountConfig.login }}</div>
<div class="ml-2 d-flex flex-grow-1">
{{ state.account.accountConfig.title || state.account.accountConfig.login }}
</div>
</a>
<button (click)="toggleViewMode($event)" *ngIf="state.stored" class="btn b-toggle-view" title="Toggle online/database view mode">
<i
Expand Down
15 changes: 14 additions & 1 deletion src/web/browser-window/app/_options/account-edit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,23 @@
<div class="card mb-3">
<div class="card-header" [ngStyle]="advancedBlockCollapsed ? {'border-bottom-width': '0'} : {}">
<button type="button" class="btn btn-link p-0" (click)="advancedBlockCollapsed = !advancedBlockCollapsed">
Advanced
Extended Options
</button>
</div>
<div class="card-body" [collapse]="advancedBlockCollapsed">
<div class="form-group">
<label class="d-block">
Handle button alias
<i
popover="If specified will be displayed in the UI instead of login."
class="fa fa-info-circle text-primary align-self-center"
container="body"
[placement]="'bottom'"
triggers="mouseenter:mouseleave"
></i>
</label>
<input type="text" class="form-control" formControlName="title">
</div>
<div class="form-group">
<label class="d-block pull-left">
Proxy Rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ export class AccountEditComponent implements OnInit, OnDestroy {
];
entryUrlItems: EntryUrlItem[] = [];
controls: Record<keyof Pick<AccountConfig,
| "type" | "login" | "database" | "entryUrl" | "loginDelayUntilSelected" | "loginDelaySecondsRange">
| "type" | "login" | "title" | "database" | "entryUrl" | "loginDelayUntilSelected" | "loginDelaySecondsRange">
| keyof Pick<Required<Required<AccountConfig>["proxy"]>, "proxyRules" | "proxyBypassRules">
| keyof AccountConfigProtonmail["credentials"],
AbstractControl> = {
type: new FormControl(this.typeValues[0].value, Validators.required),
login: new FormControl(null, Validators.required),
title: new FormControl(null),
database: new FormControl(null),
entryUrl: new FormControl(null, Validators.required),
proxyRules: new FormControl(null),
Expand Down Expand Up @@ -109,6 +110,7 @@ export class AccountEditComponent implements OnInit, OnDestroy {

(() => {
controls.type.patchValue(account.type);
controls.title.patchValue(account.title);
controls.database.patchValue(account.database);
controls.entryUrl.patchValue(account.entryUrl);

Expand Down Expand Up @@ -159,6 +161,7 @@ export class AccountEditComponent implements OnInit, OnDestroy {
login: account
? account.login :
controls.login.value,
title: controls.title.value,
entryUrl: controls.entryUrl.value,
database: Boolean(controls.database.value),
credentials: {
Expand Down

0 comments on commit 72cd1fa

Please sign in to comment.