From 405bb3476b9e7db94d0830354e950e0aaf3cac52 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Tue, 4 Jun 2019 17:34:17 +0200 Subject: [PATCH] Fix #178 --- .../app-setup/app-setup.component.html | 5 +++++ .../app-setup/app-setup.component.ts | 17 +++++++++++++++++ src/app/config.json | 1 + .../services/app-setup/app-setup.service.ts | 9 +++++++++ .../notifications/notifications.service.ts | 19 ++++++++++++------- src/locale/messages.en.json | 1 + src/locale/messages.fr.json | 1 + 7 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/app/components/app-setup/app-setup.component.html b/src/app/components/app-setup/app-setup.component.html index 89c70c0a3..c928af6fd 100644 --- a/src/app/components/app-setup/app-setup.component.html +++ b/src/app/components/app-setup/app-setup.component.html @@ -67,6 +67,11 @@ </mat-error> </mat-form-field> + <!-- notifications (snackbar) --> + <mat-checkbox name="notifications" [(ngModel)]="enableNotifications" [ngModelOptions]="{standalone: true}"> + {{ uitextEnableNotifications }} + </mat-checkbox> + <!-- langue --> <mat-form-field> <mat-select [placeholder]="uitextLanguage" [(value)]="currentLanguageCode" data-testid="language-select"> diff --git a/src/app/components/app-setup/app-setup.component.ts b/src/app/components/app-setup/app-setup.component.ts index c817748f8..13c2381e5 100644 --- a/src/app/components/app-setup/app-setup.component.ts +++ b/src/app/components/app-setup/app-setup.component.ts @@ -52,6 +52,15 @@ export class ApplicationSetupComponent extends BaseComponent implements Observer this.appSetupService.language = this.intlService.currentLanguage; } + /** notifications à l'écran (snackbar) */ + public get enableNotifications(): boolean { + return this.appSetupService.enableNotifications; + } + + public set enableNotifications(v: boolean) { + this.appSetupService.enableNotifications = v; + } + public get uitextTitle(): string { return this.intlService.localizeText("INFO_SETUP_TITLE"); } @@ -72,10 +81,15 @@ export class ApplicationSetupComponent extends BaseComponent implements Observer return this.intlService.localizeText("INFO_SETUP_NEWTON_MAX_ITER"); } + public get uitextEnableNotifications(): string { + return this.intlService.localizeText("INFO_SETUP_ENABLE_NOTIFICATIONS"); + } + public get uitextMustBeANumber(): string { return this.intlService.localizeText("ERROR_PARAM_MUST_BE_A_NUMBER"); } + public storePreferences() { this.appSetupService.saveValuesIntoLocalStorage(); this.snackBar.open(this.intlService.localizeText("INFO_SNACKBAR_SETTINGS_SAVED"), "OK", { @@ -104,6 +118,9 @@ export class ApplicationSetupComponent extends BaseComponent implements Observer // modèle du composant BaseParamInputComponent du max d'itérations pour Newton this.newtonMaxIter = new NgBaseParam("nmi", ParamDomainValue.POS, this.appSetupService.newtonMaxIterations); this.newtonMaxIter.addObserver(this); + + // notifications + this.enableNotifications = this.appSetupService.enableNotifications; } ngOnInit() { diff --git a/src/app/config.json b/src/app/config.json index 76fe94639..0eb401ba2 100644 --- a/src/app/config.json +++ b/src/app/config.json @@ -3,6 +3,7 @@ "displayPrecision": 0.001, "computePrecision": 0.0001, "newtonMaxIterations": 50, + "enableNotifications": true, "language": "fr" }, "themes": [ diff --git a/src/app/services/app-setup/app-setup.service.ts b/src/app/services/app-setup/app-setup.service.ts index d70cda6a8..fc2a72ede 100644 --- a/src/app/services/app-setup/app-setup.service.ts +++ b/src/app/services/app-setup/app-setup.service.ts @@ -19,6 +19,8 @@ export class ApplicationSetupService extends Observable { public displayPrecision = 0.001; public computePrecision = 0.0001; public newtonMaxIterations = 50; + public enableNotifications = true; + /** * just stores the current language preference, does not transmit it to I18nService, that is * not available here. @@ -82,6 +84,7 @@ export class ApplicationSetupService extends Observable { this.storage.set(this.LOCAL_STORAGE_PREFIX + "displayPrecision", this.displayPrecision); this.storage.set(this.LOCAL_STORAGE_PREFIX + "computePrecision", this.computePrecision); this.storage.set(this.LOCAL_STORAGE_PREFIX + "newtonMaxIterations", this.newtonMaxIterations); + this.storage.set(this.LOCAL_STORAGE_PREFIX + "enableNotifications", this.enableNotifications); this.storage.set(this.LOCAL_STORAGE_PREFIX + "language", this.language); } @@ -119,6 +122,11 @@ export class ApplicationSetupService extends Observable { this.newtonMaxIterations = newtonMaxIterations; loadedKeys.push("newtonMaxIterations"); } + const enableNotifications = this.storage.get(this.LOCAL_STORAGE_PREFIX + "enableNotifications"); + if (enableNotifications !== undefined) { + this.enableNotifications = enableNotifications; + loadedKeys.push("enableNotifications"); + } const language = this.storage.get(this.LOCAL_STORAGE_PREFIX + "language"); if (language !== undefined) { this.language = language; @@ -136,6 +144,7 @@ export class ApplicationSetupService extends Observable { this.displayPrecision = data.params.displayPrecision; this.computePrecision = data.params.computePrecision; this.newtonMaxIterations = data.params.newtonMaxIterations; + this.enableNotifications = data.params.enableNotifications; this.language = data.params.language; // load themes for calculators list page this.themes = data.themes; diff --git a/src/app/services/notifications/notifications.service.ts b/src/app/services/notifications/notifications.service.ts index bb404d860..bc330b479 100644 --- a/src/app/services/notifications/notifications.service.ts +++ b/src/app/services/notifications/notifications.service.ts @@ -1,6 +1,8 @@ import { Injectable } from "@angular/core"; import { MatSnackBar } from "@angular/material"; +import { ApplicationSetupService } from "../app-setup/app-setup.service"; + /** * Displays a notifications queue as consecutive snackbars */ @@ -13,7 +15,8 @@ export class NotificationsService { private isOpen: boolean; public constructor( - private snackBar: MatSnackBar + private snackBar: MatSnackBar, + private setupService: ApplicationSetupService ) { this.notifications = []; this.isOpen = false; @@ -21,12 +24,14 @@ export class NotificationsService { /** Push a notification and display it as soon as possible */ public notify(message: string, duration: number = 2000, action: string = "OK") { - this.notifications.push({ - message: message, - duration: duration, - action: action - }); - this.show(); + if (this.setupService.enableNotifications) { + this.notifications.push({ + message: message, + duration: duration, + action: action + }); + this.show(); + } } /** Show all messages in the FIFO queue one after another */ diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index 98f73af22..18aff4ce8 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -258,6 +258,7 @@ "INFO_REQUIRES": "requires", "INFO_SECTIONPARAMETREE_TITRE_COURT": "Param. section", "INFO_SECTIONPARAMETREE_TITRE": "Parametric section", + "INFO_SETUP_ENABLE_NOTIFICATIONS": "Enable on-screen notifications", "INFO_SETUP_LANGUAGE": "Language", "INFO_SETUP_NEWTON_MAX_ITER": "Newton iteration limit", "INFO_SETUP_PRECISION_AFFICHAGE": "Display accuracy", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index afca0043d..1f1db9001 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -258,6 +258,7 @@ "INFO_REQUIRES": "dépend de", "INFO_SECTIONPARAMETREE_TITRE_COURT": "Sec. param.", "INFO_SECTIONPARAMETREE_TITRE": "Section paramétrée", + "INFO_SETUP_ENABLE_NOTIFICATIONS": "Activer les notifications à l'écran", "INFO_SETUP_LANGUAGE": "Langue", "INFO_SETUP_NEWTON_MAX_ITER": "Newton : nombre d'itérations maximum", "INFO_SETUP_PRECISION_AFFICHAGE": "Précision d'affichage", -- GitLab