diff --git a/src/app/app.module.ts b/src/app/app.module.ts index a1f172ab09f5d18169e4826edd76bf949dc24817..da7f30bba0b8103ecf0e070640a4b103fca8d87c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -44,6 +44,7 @@ import { FormulaireService } from "./services/formulaire/formulaire.service"; import { I18nService } from "./services/internationalisation/internationalisation.service"; import { HttpService } from "./services/http/http.service"; import { ApplicationSetupService } from "./services/app-setup/app-setup.service"; +import { NotificationsService } from "./services/notifications/notifications.service"; import { AppComponent } from "./app.component"; import { NgParamInputComponent } from "./components/ngparam-input/ngparam-input.component"; @@ -191,6 +192,7 @@ const appRoutes: Routes = [ FormulaireService, HttpService, I18nService, + NotificationsService, { provide: ErrorStateMatcher, useClass: ImmediateErrorStateMatcher diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 0bbc9aecea7ce9d0b564c2ee16fbe23a260d79a5..5bd1cf92ae8ed5dbbf0f0b6898814dc68e3cb560 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -22,6 +22,7 @@ import { FormulaireParallelStructure } from "../../formulaire/definition/concret import { NgParameter } from "../../formulaire/ngparam"; import { FieldsetContainer } from "../..//formulaire/fieldset-container"; import { ApplicationSetupService } from "../app-setup/app-setup.service"; +import { NotificationsService } from "../notifications/notifications.service"; @Injectable() export class FormulaireService extends Observable { @@ -36,7 +37,9 @@ export class FormulaireService extends Observable { constructor( private i18nService: I18nService, private appSetupService: ApplicationSetupService, - private httpService: HttpService + private httpService: HttpService, + private intlService: I18nService, + private notificationsService: NotificationsService ) { super(); this._formulaires = []; @@ -630,7 +633,13 @@ export class FormulaireService extends Observable { for (const dn of dependingNubs) { if (! visited.includes(dn.uid)) { const form = this.getFormulaireFromNubId(dn.uid); - form.resetResults(visited); + if (form.hasResults) { + form.resetResults(visited); + this.notificationsService.notify( + this.intlService.localizeText("INFO_SNACKBAR_RESULTS_INVALIDATED") + " " + form.calculatorName, + 2000 + ); + } } } } diff --git a/src/app/services/notifications/notifications.service.ts b/src/app/services/notifications/notifications.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..9caf0d7ffb1a7832f671261980764a7e30a29046 --- /dev/null +++ b/src/app/services/notifications/notifications.service.ts @@ -0,0 +1,49 @@ +import { Injectable } from "@angular/core"; +import { MatSnackBar } from "@angular/material"; + +/** + * Displays a notifications queue as consecutive snackbars + */ +@Injectable() +export class NotificationsService { + + /** FIFO queue for notifications */ + private notifications: any[]; + + private isOpen: boolean; + + public constructor( + private snackBar: MatSnackBar + ) { + this.notifications = []; + this.isOpen = false; + } + + /** Push a notification and display it as soon as possible */ + public notify(message: string, duration: number, action: string = "OK") { + this.notifications.push({ + message: message, + duration: duration, + action: action + }); + this.show(); + } + + /** Show all messages in the FIFO queue one after another */ + public show() { + if (! this.isOpen) { + // process next notification + if (this.notifications.length > 0) { + const notif = this.notifications.shift(); + this.isOpen = true; + const ref = this.snackBar.open(notif.message, notif.action, { + duration: notif.duration + }); + ref.afterDismissed().subscribe(() => { + this.isOpen = false; + this.show(); + }); + } + } + } +} diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index d265692b858e3c471593c20e5858f460e21ddad0..859d160ba2163cbb347639df6bf1d6ded96fbc86 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -204,6 +204,7 @@ "INFO_SETUP_PRECISION_AFFICHAGE": "Display accuracy", "INFO_SETUP_PRECISION_CALCUL": "Computation accuracy", "INFO_SETUP_TITLE": "Application setup", + "INFO_SNACKBAR_RESULTS_INVALIDATED": "Results invalidated for", "INFO_SNACKBAR_SETTINGS_SAVED": "Settings saved on this device", "INFO_SNACKBAR_DEFAULT_SETTINGS_RESTORED": "Default settings restored", "INFO_THEME_CREDITS": "Credit", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index 5c40ca5d0449305e332aa163b8bc886029baed33..350dd11ada5ad8419ad7d7ce31fe58dfab3d9b55 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -204,6 +204,7 @@ "INFO_SETUP_PRECISION_AFFICHAGE": "Précision d'affichage", "INFO_SETUP_PRECISION_CALCUL": "Précision de calcul", "INFO_SETUP_TITLE": "Paramètres de l'application", + "INFO_SNACKBAR_RESULTS_INVALIDATED": "Résultats invalidés pour", "INFO_SNACKBAR_SETTINGS_SAVED": "Paramètres enregistrés sur cet appareil", "INFO_SNACKBAR_DEFAULT_SETTINGS_RESTORED": "Paramètres par défaut restaurés", "INFO_THEME_CREDITS": "Crédit",