Add support for default text in messages component

This commit is contained in:
Clemente Raposo 2025-01-17 11:22:59 +00:00 committed by c.raposo
parent f795ca4ad0
commit d83a424d35
3 changed files with 30 additions and 10 deletions

View file

@ -29,6 +29,7 @@ export interface Message {
type: MessageTypes;
text?: string;
labelKey?: string;
defaultText?: string;
}
export enum MessageTypes {

View file

@ -33,7 +33,7 @@
class="message {{ message.type }} alert-dismissible fade show shadow"
[@fade]
role="alert">
<ng-container *ngIf="message.labelKey">{{appStrings[message.labelKey] || message.labelKey || ''}}</ng-container>
<ng-container *ngIf="message.labelKey">{{appStrings[message?.labelKey] || message?.defaultText || message?.labelKey || ''}}</ng-container>
<ng-container *ngIf="message.text && !message.labelKey">{{message.text}}</ng-container>
<a (click)="close(message)" type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">&times;</span>

View file

@ -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 {