From d4e1acb4e5dc54ec91e8e4dca134dc66ff75450b Mon Sep 17 00:00:00 2001 From: ewandor Date: Sun, 12 Feb 2023 16:16:49 +0100 Subject: [PATCH] Usiung a type instead of a header in flashmessages --- .../flashmessages.component.html | 17 ++++++++-- .../flashmessages/flashmessages.service.ts | 34 +++++++++++++------ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/front/app/src/app/layout/flashmessages/flashmessages.component.html b/front/app/src/app/layout/flashmessages/flashmessages.component.html index a2f7f2f7..c5e3fbfd 100644 --- a/front/app/src/app/layout/flashmessages/flashmessages.component.html +++ b/front/app/src/app/layout/flashmessages/flashmessages.component.html @@ -1,5 +1,18 @@ {{flashmessage.body}} +> + + + + + + + diff --git a/front/app/src/app/layout/flashmessages/flashmessages.service.ts b/front/app/src/app/layout/flashmessages/flashmessages.service.ts index 59d50c42..ff0e5c8b 100644 --- a/front/app/src/app/layout/flashmessages/flashmessages.service.ts +++ b/front/app/src/app/layout/flashmessages/flashmessages.service.ts @@ -1,20 +1,34 @@ import {Injectable} from "@angular/core"; export interface Flashmessage { - header: string; - body: string; - delay?: number; + body: string; + delay?: number; + type: "Error"|"Success"|"Info"; } @Injectable({ providedIn: 'root' }) export class FlashmessagesService { - toasts: Flashmessage[] = []; + toasts: Flashmessage[] = []; - show(header: string, body: string) { - this.toasts.push({ header, body }); - } + success(body: string) { + this.show("Success", body); + } - remove(toast: Flashmessage) { - this.toasts = this.toasts.filter(t => t != toast); - } + error(body: string) { + this.show("Error", body); + } + + show(type: string, body: string) { + if (type == "Success") { + this.toasts.push({ type, body }); + } else if (type == "Error") { + this.toasts.push({ type, body }); + } else { + this.toasts.push({ type: "Info", body }); + } + } + + remove(toast: Flashmessage) { + this.toasts = this.toasts.filter(t => t != toast); + } } \ No newline at end of file