From d315dc83e3dcd96fa64c0630b38c66cfe0b6db09 Mon Sep 17 00:00:00 2001 From: Brandon Wortman Date: Thu, 5 Dec 2024 13:12:49 -0500 Subject: [PATCH] Extend notification service to include the new GfPromptDialogComponent #3955 --- .../notification/interfaces/interfaces.ts | 10 +++++ .../core/notification/notification.service.ts | 39 ++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/apps/client/src/app/core/notification/interfaces/interfaces.ts b/apps/client/src/app/core/notification/interfaces/interfaces.ts index f5a526c92..28971e0ed 100644 --- a/apps/client/src/app/core/notification/interfaces/interfaces.ts +++ b/apps/client/src/app/core/notification/interfaces/interfaces.ts @@ -17,3 +17,13 @@ export interface IConfirmParams { message?: string; title: string; } + +export interface IPromptParams { + confirmFn?: (value: string) => void; + confirmLabel?: string; + defaultValue?: string; + discardFn?: () => void; + discardLabel?: string; + title: string; + valueLabel?: string; +} diff --git a/apps/client/src/app/core/notification/notification.service.ts b/apps/client/src/app/core/notification/notification.service.ts index 189da67f5..48d2d56c5 100644 --- a/apps/client/src/app/core/notification/notification.service.ts +++ b/apps/client/src/app/core/notification/notification.service.ts @@ -7,7 +7,12 @@ import { isFunction } from 'lodash'; import { GfAlertDialogComponent } from './alert-dialog/alert-dialog.component'; import { GfConfirmationDialogComponent } from './confirmation-dialog/confirmation-dialog.component'; import { ConfirmationDialogType } from './confirmation-dialog/confirmation-dialog.type'; -import { IAlertParams, IConfirmParams } from './interfaces/interfaces'; +import { + IAlertParams, + IConfirmParams, + IPromptParams +} from './interfaces/interfaces'; +import { GfPromptDialogComponent } from './prompt-dialog/prompt-dialog.component'; @Injectable() export class NotificationService { @@ -73,6 +78,38 @@ export class NotificationService { }); } + public prompt(aParams: IPromptParams) { + if (!aParams.confirmLabel) { + aParams.confirmLabel = translate('OK'); + } + + if (!aParams.discardLabel) { + aParams.discardLabel = translate('CANCEL'); + } + + const dialog = this.matDialog.open(GfPromptDialogComponent, { + autoFocus: false, + maxWidth: this.dialogMaxWidth, + width: this.dialogWidth + }); + + dialog.componentInstance.initialize({ + confirmLabel: aParams.confirmLabel, + defaultValue: aParams.defaultValue, + discardLabel: aParams.discardLabel, + title: aParams.title, + valueLabel: aParams.valueLabel + }); + + return dialog.afterClosed().subscribe((value) => { + if (value !== undefined && isFunction(aParams.confirmFn)) { + aParams.confirmFn(value); + } else if (value === 'discard' && isFunction(aParams.discardFn)) { + aParams.discardFn(); + } + }); + } + public setDialogMaxWidth(aDialogMaxWidth: string) { this.dialogMaxWidth = aDialogMaxWidth; }