diff --git a/src/app/components/app-setup/app-setup.component.html b/src/app/components/app-setup/app-setup.component.html index 89c70c0a32bb662f53532c4e764f2565dc097807..c928af6fd58effaa595531ba39e680b990c3566d 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 c817748f8171aef38a802d590de67d9c133d5d41..13c2381e5d90b56e4b94c34ee9cc338c46e02615 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 76fe9463959eff6eebe225b041ebdfff8a84eaf9..0eb401ba2100bdf2a98343f9a05da72500c6ca74 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 d70cda6a814002e85a45090daeb3aedc93f4d18c..fc2a72ede92919a67479ed8afc196f3c4a1cde3f 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 bb404d860861d53be39c5a7b7a765004821f472d..bc330b47950d44baa38873d91c5afd8e79281bc0 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 98f73af2253af9fd69f2856edc2ca36663eecc42..18aff4ce809251b42820e1da10648c4da458b43e 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 afca0043d673e24a116a32f29f3ace89b1d2e0b6..1f1db90016de2f86a955686a596e8f1173854573 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",