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

Nouveau service de notifications multiples; l'utilisateur est averti lorsque...

Nouveau service de notifications multiples; l'utilisateur est averti lorsque des résultats sont invalidés
parent 486a60f6
No related branches found
No related tags found
1 merge request!40Resolve "Amélioration du système de paramètres liés"
......@@ -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
......
......@@ -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
);
}
}
}
}
......
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();
});
}
}
}
}
......@@ -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",
......
......@@ -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",
......
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