From d83a424d35ebfca05814498da97acbc160bf1fe4 Mon Sep 17 00:00:00 2001 From: Clemente Raposo Date: Fri, 17 Jan 2025 11:22:59 +0000 Subject: [PATCH] Add support for default text in messages component --- .../app/core/src/lib/common/types/messages.ts | 1 + .../components/message/message.component.html | 2 +- .../lib/services/message/message.service.ts | 37 ++++++++++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/core/app/core/src/lib/common/types/messages.ts b/core/app/core/src/lib/common/types/messages.ts index cf016dab2..f9058d0d9 100644 --- a/core/app/core/src/lib/common/types/messages.ts +++ b/core/app/core/src/lib/common/types/messages.ts @@ -29,6 +29,7 @@ export interface Message { type: MessageTypes; text?: string; labelKey?: string; + defaultText?: string; } export enum MessageTypes { diff --git a/core/app/core/src/lib/components/message/message.component.html b/core/app/core/src/lib/components/message/message.component.html index 82e26b170..0244707f1 100644 --- a/core/app/core/src/lib/components/message/message.component.html +++ b/core/app/core/src/lib/components/message/message.component.html @@ -33,7 +33,7 @@ class="message {{ message.type }} alert-dismissible fade show shadow" [@fade] role="alert"> - {{appStrings[message.labelKey] || message.labelKey || ''}} + {{appStrings[message?.labelKey] || message?.defaultText || message?.labelKey || ''}} {{message.text}} diff --git a/core/app/core/src/lib/services/message/message.service.ts b/core/app/core/src/lib/services/message/message.service.ts index 1a3740eb2..b22878f17 100644 --- a/core/app/core/src/lib/services/message/message.service.ts +++ b/core/app/core/src/lib/services/message/message.service.ts @@ -109,11 +109,17 @@ export class MessageService { }); } - addSuccessMessageByKey(labelKey: string): number { - return this.addMessage({ + addSuccessMessageByKey(labelKey: string, defaultText:string = null): number { + const message = { type: MessageTypes.success, labelKey - }); + } as Message; + + if (defaultText) { + message.defaultText = defaultText; + } + + return this.addMessage(message); } addDangerMessage(text: string): number { @@ -123,11 +129,18 @@ export class MessageService { }); } - addDangerMessageByKey(labelKey: string): number { - return this.addMessage({ + addDangerMessageByKey(labelKey: string, defaultText: string = null): number { + + const message = { type: MessageTypes.danger, labelKey - }); + } as Message; + + if (defaultText) { + message.defaultText = defaultText; + } + + return this.addMessage(message); } addWarningMessage(text: string): number { @@ -137,11 +150,17 @@ export class MessageService { }); } - addWarningMessageByKey(labelKey: string): number { - return this.addMessage({ + addWarningMessageByKey(labelKey: string, defaultText: string = null): number { + const message = { type: MessageTypes.warning, labelKey - }); + } as Message; + + if (defaultText) { + message.defaultText = defaultText; + } + + return this.addMessage(message); } addInfoMessage(text: string): number {