Skip to content
Snippets Groups Projects
Commit 405bb347 authored by mathias.chouet's avatar mathias.chouet
Browse files

Fix #178

parent 9fa635c4
No related branches found
No related tags found
No related merge requests found
......@@ -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">
......
......@@ -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() {
......
......@@ -3,6 +3,7 @@
"displayPrecision": 0.001,
"computePrecision": 0.0001,
"newtonMaxIterations": 50,
"enableNotifications": true,
"language": "fr"
},
"themes": [
......
......@@ -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;
......
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 */
......
......@@ -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",
......
......@@ -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",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment