From 211a4c5039048c2e3973161f5f755ca6b78e03c9 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Tue, 12 May 2020 01:30:15 +0300 Subject: [PATCH 1/6] feat(theme-shared): add dismissible property to confirmation options #3686 --- .../components/confirmation/confirmation.component.html | 5 ++++- .../packages/theme-shared/src/lib/models/confirmation.ts | 8 +++++++- .../theme-shared/src/lib/services/confirmation.service.ts | 7 +++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html b/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html index 8987cda2f9..47c555a16b 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html +++ b/npm/ng-packs/packages/theme-shared/src/lib/components/confirmation/confirmation.component.html @@ -1,5 +1,8 @@
-
+
diff --git a/npm/ng-packs/packages/theme-shared/src/lib/models/confirmation.ts b/npm/ng-packs/packages/theme-shared/src/lib/models/confirmation.ts index 815fd65c20..18dceb320d 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/models/confirmation.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/models/confirmation.ts @@ -3,13 +3,19 @@ import { Config } from '@abp/ng.core'; export namespace Confirmation { export interface Options { id?: any; - closable?: boolean; + dismissible?: boolean; messageLocalizationParams?: string[]; titleLocalizationParams?: string[]; hideCancelBtn?: boolean; hideYesBtn?: boolean; cancelText?: Config.LocalizationParam; yesText?: Config.LocalizationParam; + + /** + * + * @deprecated To be deleted in v2.9 + */ + closable?: boolean; } export interface DialogData { diff --git a/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts b/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts index 2672a93a2a..70ad0d0e2b 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/services/confirmation.service.ts @@ -68,7 +68,7 @@ export class ConfirmationService { message: Config.LocalizationParam, title: Config.LocalizationParam, severity?: Confirmation.Severity, - options?: Partial, + options = {} as Partial, ): Observable { if (!this.containerComponentRef) this.setContainer(); @@ -78,8 +78,11 @@ export class ConfirmationService { severity: severity || 'neutral', options, }); + this.status$ = new Subject(); - this.listenToEscape(); + const { dismissible = true } = options; + if (dismissible) this.listenToEscape(); + return this.status$; } From 11f836706fb0d34d959fec84a3ec8c4ac79f14d8 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Tue, 12 May 2020 01:31:25 +0300 Subject: [PATCH 2/6] docs: explain dismissible option #3686 --- docs/en/UI/Angular/Confirmation-Service.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/en/UI/Angular/Confirmation-Service.md b/docs/en/UI/Angular/Confirmation-Service.md index 2d1c5c1843..9bc015ced5 100644 --- a/docs/en/UI/Angular/Confirmation-Service.md +++ b/docs/en/UI/Angular/Confirmation-Service.md @@ -53,7 +53,7 @@ this.confirmation - `Confirmation.Status` is an enum and has three properties; - `Confirmation.Status.confirm` is a closing event value that will be emitted when the popup is closed by the confirm button. - `Confirmation.Status.reject` is a closing event value that will be emitted when the popup is closed by the cancel button. - - `Confirmation.Status.dismiss` is a closing event value that will be emitted when the popup is closed by pressing the escape. + - `Confirmation.Status.dismiss` is a closing event value that will be emitted when the popup is closed by pressing the escape or clicking the backdrop. If you are not interested in the confirmation status, you do not have to subscribe to the returned observable: @@ -70,6 +70,7 @@ Options can be passed as the third parameter to `success`, `warn`, `error`, and const options: Partial = { hideCancelBtn: false, hideYesBtn: false, + dismissible: false, cancelText: 'Close', yesText: 'Confirm', messageLocalizationParams: ['Demo'], @@ -83,10 +84,11 @@ this.confirmation.warn( ); ``` -- `hideCancelBtn` option hides the cancellation button when `true`. Default value is `false` -- `hideYesBtn` option hides the confirmation button when `true`. Default value is `false` -- `cancelText` is the text of the cancellation button. A localization key or localization object can be passed. Default value is `AbpUi::Cancel` -- `yesText` is the text of the confirmation button. A localization key or localization object can be passed. Default value is `AbpUi::Yes` +- `hideCancelBtn` option hides the cancellation button when `true`. Default value is `false`. +- `hideYesBtn` option hides the confirmation button when `true`. Default value is `false`. +- `dismissible` option allows dismissing the confirmation overlay by pressing escape or clicking the backdrop. Default value is `true`. +- `cancelText` is the text of the cancellation button. A localization key or localization object can be passed. Default value is `AbpUi::Cancel`. +- `yesText` is the text of the confirmation button. A localization key or localization object can be passed. Default value is `AbpUi::Yes`. - `messageLocalizationParams` is the interpolation parameters for the localization of the message. - `titleLocalizationParams` is the interpolation parameters for the localization of the title. From aa1eeed4e1e2d1182ea4d7295c3129b00ab6fad0 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Tue, 12 May 2020 01:33:15 +0300 Subject: [PATCH 3/6] docs: change a word --- docs/en/UI/Angular/Confirmation-Service.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/UI/Angular/Confirmation-Service.md b/docs/en/UI/Angular/Confirmation-Service.md index 9bc015ced5..16dfa9fd94 100644 --- a/docs/en/UI/Angular/Confirmation-Service.md +++ b/docs/en/UI/Angular/Confirmation-Service.md @@ -86,7 +86,7 @@ this.confirmation.warn( - `hideCancelBtn` option hides the cancellation button when `true`. Default value is `false`. - `hideYesBtn` option hides the confirmation button when `true`. Default value is `false`. -- `dismissible` option allows dismissing the confirmation overlay by pressing escape or clicking the backdrop. Default value is `true`. +- `dismissible` option allows dismissing the confirmation popup by pressing escape or clicking the backdrop. Default value is `true`. - `cancelText` is the text of the cancellation button. A localization key or localization object can be passed. Default value is `AbpUi::Cancel`. - `yesText` is the text of the confirmation button. A localization key or localization object can be passed. Default value is `AbpUi::Yes`. - `messageLocalizationParams` is the interpolation parameters for the localization of the message. From 05c59b6fd346f442605adf6f3db2213909b2b322 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Thu, 14 May 2020 00:36:34 +0300 Subject: [PATCH 4/6] test: fix testing error --- npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts index e823328f73..189a9ab6d9 100644 --- a/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts +++ b/npm/ng-packs/packages/core/src/lib/tests/config.state.spec.ts @@ -306,6 +306,7 @@ describe('ConfigState', () => { const configuration = { setting: { values: { 'Abp.Localization.DefaultLanguage': 'tr;TR' } }, + localization: { currentCulture: {} }, }; const res$ = new ReplaySubject(1); @@ -324,7 +325,7 @@ describe('ConfigState', () => { timer(0).subscribe(() => { expect(patchStateArg).toEqual(configuration); expect(dispatchArg instanceof SetLanguage).toBeTruthy(); - expect(dispatchArg).toEqual({ payload: 'tr' }); + expect(dispatchArg).toEqual({ payload: 'tr', dispatchAppConfiguration: false }); done(); }); }); From 04209199f6bc25a5ecec0545811dbc2cb4001a25 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Thu, 14 May 2020 00:49:24 +0300 Subject: [PATCH 5/6] test: add a dismissible option test to confirmation.service.spec --- .../src/lib/tests/confirmation.service.spec.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/tests/confirmation.service.spec.ts b/npm/ng-packs/packages/theme-shared/src/lib/tests/confirmation.service.spec.ts index e70b88061f..1413e034d7 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/tests/confirmation.service.spec.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/tests/confirmation.service.spec.ts @@ -105,6 +105,14 @@ describe('ConfirmationService', () => { selectConfirmationElement('button#cancel').click(); }); + + test('should not call the listenToEscape method when dismissible is false', () => { + const spy = spyOn(service as any, 'listenToEscape'); + + service.info('', '', { dismissible: false }); + + expect(spy.calls.count()).toBe(0); + }); }); function clearElements(selector = '.confirmation') { From 72e8a686f62344f11c0deb6015cfc0ece4b02b46 Mon Sep 17 00:00:00 2001 From: Arman Ozak Date: Thu, 14 May 2020 10:15:24 +0300 Subject: [PATCH 6/6] test: add else case for listenToEscape call spec --- .../lib/tests/confirmation.service.spec.ts | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/npm/ng-packs/packages/theme-shared/src/lib/tests/confirmation.service.spec.ts b/npm/ng-packs/packages/theme-shared/src/lib/tests/confirmation.service.spec.ts index 1413e034d7..3cbdcbd7de 100644 --- a/npm/ng-packs/packages/theme-shared/src/lib/tests/confirmation.service.spec.ts +++ b/npm/ng-packs/packages/theme-shared/src/lib/tests/confirmation.service.spec.ts @@ -106,13 +106,20 @@ describe('ConfirmationService', () => { selectConfirmationElement('button#cancel').click(); }); - test('should not call the listenToEscape method when dismissible is false', () => { - const spy = spyOn(service as any, 'listenToEscape'); - - service.info('', '', { dismissible: false }); - - expect(spy.calls.count()).toBe(0); - }); + test.each` + dismissible | count + ${true} | ${1} + ${false} | ${0} + `( + 'should call the listenToEscape method $count times when dismissible is $dismissible', + ({ dismissible, count }) => { + const spy = spyOn(service as any, 'listenToEscape'); + + service.info('', '', { dismissible }); + + expect(spy).toHaveBeenCalledTimes(count); + }, + ); }); function clearElements(selector = '.confirmation') {