Browse Source

Fix remember me.

pull/613/head
Sebastian 5 years ago
parent
commit
7b0f27ebb3
  1. 2
      backend/i18n/frontend_en.json
  2. 2
      backend/i18n/source/frontend_en.json
  3. 57
      frontend/app/framework/services/dialog.service.spec.ts
  4. 10
      frontend/app/framework/services/dialog.service.ts

2
backend/i18n/frontend_en.json

@ -297,7 +297,7 @@
"common.queryOperators.ne": "is not equals to", "common.queryOperators.ne": "is not equals to",
"common.queryOperators.startsWith": "starts with", "common.queryOperators.startsWith": "starts with",
"common.refresh": "Refresh", "common.refresh": "Refresh",
"common.remember": "Remember my decision", "common.remember": "Don't ask again",
"common.rename": "Rename", "common.rename": "Rename",
"common.requiredHint": "required", "common.requiredHint": "required",
"common.reset": "Reset", "common.reset": "Reset",

2
backend/i18n/source/frontend_en.json

@ -297,7 +297,7 @@
"common.queryOperators.ne": "is not equals to", "common.queryOperators.ne": "is not equals to",
"common.queryOperators.startsWith": "starts with", "common.queryOperators.startsWith": "starts with",
"common.refresh": "Refresh", "common.refresh": "Refresh",
"common.remember": "Remember my decision", "common.remember": "Don't ask again",
"common.rename": "Rename", "common.rename": "Rename",
"common.requiredHint": "required", "common.requiredHint": "required",
"common.reset": "Reset", "common.reset": "Reset",

57
frontend/app/framework/services/dialog.service.spec.ts

@ -79,10 +79,13 @@ describe('DialogService', () => {
dialog.complete(confirmed); dialog.complete(confirmed);
}); });
dialogService.confirm('MyTitle', 'MyText').subscribe(result => { dialogService.confirm('MyTitle', 'MyText').subscribe({
isNext = result; next: result => {
}, undefined, () => { isNext = result;
isCompleted = true; },
complete: () => {
isCompleted = true;
}
}); });
expect(isCompleted).toBeTruthy(); expect(isCompleted).toBeTruthy();
@ -93,10 +96,10 @@ describe('DialogService', () => {
}); });
[ [
{ confirmed: true, saved: 1 }, { confirmed: true, saved: 1 },
{ confirmed: false, saved: 2 } { confirmed: false, saved: 0 }
].map(({ confirmed, saved }) => { ].map(({ confirmed, saved }) => {
it(`should confirm dialog with '${confirmed}' and remember when remembered`, () => { it(`should confirm dialog with '${confirmed}' and remember when remembered and confirmed`, () => {
const dialogService = new DialogService(localStore.object); const dialogService = new DialogService(localStore.object);
let isCompleted = false; let isCompleted = false;
@ -107,47 +110,53 @@ describe('DialogService', () => {
dialog.complete(confirmed); dialog.complete(confirmed);
}); });
dialogService.confirm('MyTitle', 'MyText', 'MyKey').subscribe(result => { dialogService.confirm('MyTitle', 'MyText', 'MyKey').subscribe({
isNext = result; next: result => {
}, undefined, () => { isNext = result;
isCompleted = true; },
complete: () => {
isCompleted = true;
}
}); });
expect(isCompleted).toBeTruthy(); expect(isCompleted).toBeTruthy();
expect(isNext!).toEqual(confirmed); expect(isNext!).toEqual(confirmed);
localStore.verify(x => x.setInt(`dialogs.confirm.MyKey`, saved), Times.once()); localStore.verify(x => x.setBoolean(`dialogs.confirm.MyKey`, It.isAny()), Times.exactly(saved));
}); });
}); });
[ [
{ confirmed: true, saved: 1 }, { confirmed: true, saved: true, render: 0 },
{ confirmed: false, saved: 2 } { confirmed: false, saved: false, render: 1 }
].map(({ confirmed, saved }) => { ].map(({ confirmed, saved, render }) => {
it(`should confirm dialog with '${confirmed}' from local store when saved`, () => { it(`should confirm dialog with '${confirmed}' from local store when saved`, () => {
const dialogService = new DialogService(localStore.object); const dialogService = new DialogService(localStore.object);
localStore.setup(x => x.getInt(`dialogs.confirm.MyKey`)) localStore.setup(x => x.getBoolean(`dialogs.confirm.MyKey`))
.returns(() => saved); .returns(() => saved);
let requestCount = 0; let requestCount = 0;
let isCompleted = false; let isCompleted = false;
let isNext: boolean; let isNext: boolean | undefined;
dialogService.dialogs.subscribe(_ => { dialogService.dialogs.subscribe(_ => {
requestCount++; requestCount++;
}); });
dialogService.confirm('MyTitle', 'MyText', 'MyKey').subscribe(result => { dialogService.confirm('MyTitle', 'MyText', 'MyKey').subscribe({
isNext = result; next: result => {
}, undefined, () => { isNext = result;
isCompleted = true; },
complete: () => {
isCompleted = true;
}
}); });
expect(isCompleted).toBeTruthy(); expect(isCompleted).toEqual(confirmed);
expect(isNext!).toEqual(confirmed); expect(isNext).toEqual(confirmed ? true : undefined);
expect(requestCount).toEqual(0); expect(requestCount).toEqual(render);
}); });
}); });

10
frontend/app/framework/services/dialog.service.ts

@ -41,18 +41,18 @@ export class DialogRequest {
if (rememberKey) { if (rememberKey) {
this.rememberKey = `dialogs.confirm.${rememberKey}`; this.rememberKey = `dialogs.confirm.${rememberKey}`;
const isConfirmed = this.localStore.getInt(this.rememberKey); const isConfirmed = this.localStore.getBoolean(this.rememberKey);
if (isConfirmed > 0) { if (isConfirmed) {
this.resultStream$.next(isConfirmed === 1); this.resultStream$.next(true);
this.resultStream$.complete(); this.resultStream$.complete();
} }
} }
} }
public complete(confirmed: boolean) { public complete(confirmed: boolean) {
if (this.rememberKey && this.remember) { if (this.rememberKey && this.remember && confirmed) {
this.localStore.setInt(this.rememberKey, confirmed ? 1 : 2); this.localStore.setBoolean(this.rememberKey, true);
} }
this.resultStream$.next(confirmed); this.resultStream$.next(confirmed);

Loading…
Cancel
Save