From 2e519f7710185e4c7706cdfeee532d0ed990640e Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Tue, 26 Mar 2019 17:26:01 +0100 Subject: [PATCH] Removed debug messages; worked on notifications for chained computation --- src/app/app.component.ts | 14 ++++---------- .../calculator.component.ts | 2 +- src/app/formulaire/definition/form-compute.ts | 19 +++++++++++++++---- .../formulaire/definition/form-definition.ts | 2 -- .../services/formulaire/formulaire.service.ts | 2 +- src/app/services/service-factory.ts | 3 +++ src/locale/messages.en.json | 1 + src/locale/messages.fr.json | 1 + 8 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 4e9c48e53..e12e52603 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -18,6 +18,7 @@ import { nghydDateRev } from "../date_revision"; import { DialogConfirmEmptySessionComponent } from "./components/dialog-confirm-empty-session/dialog-confirm-empty-session.component"; import { DialogLoadSessionComponent } from "./components/dialog-load-session/dialog-load-session.component"; import { DialogSaveSessionComponent } from "./components/dialog-save-session/dialog-save-session.component"; +import { NotificationsService } from "./services/notifications/notifications.service"; @Component({ @@ -66,6 +67,7 @@ export class AppComponent implements OnInit, OnDestroy, Observer { private router: Router, private formulaireService: FormulaireService, private httpService: HttpService, + private notificationsService: NotificationsService, private confirmEmptySessionDialog: MatDialog, private saveSessionDialog: MatDialog, private loadSessionDialog: MatDialog, @@ -76,6 +78,7 @@ export class AppComponent implements OnInit, OnDestroy, Observer { ServiceFactory.instance.applicationSetupService = appSetupService; ServiceFactory.instance.i18nService = intlService; ServiceFactory.instance.formulaireService = formulaireService; + ServiceFactory.instance.notificationsService = notificationsService; this.router.events.subscribe((event: Event) => { // close side navigation when clicking a calculator tab @@ -217,16 +220,7 @@ export class AppComponent implements OnInit, OnDestroy, Observer { // interface Observer update(sender: any, data: any): void { - if (sender instanceof ErrorService) { - // on ouvre un dialogue avec le message d'erreur reçu - // if (this._displayErrorDialog) { - // let dialogRef = this.dialog.open(AlertDialog); - // let ad: AlertDialog = dialogRef.componentInstance; - // ad.text = String(data); - // } - // else - console.log(data); - } else if (sender instanceof FormulaireService) { + if (sender instanceof FormulaireService) { switch (data["action"]) { case "createForm": // add newly created form to calculators list diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index c6c9afed1..d385c1f60 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -164,7 +164,6 @@ export class GenericCalculatorComponent extends BaseComponent implements OnInit, } ngDoCheck() { - console.log(">>> UI validity", this._isUIValid); this.isCalculateDisabled = ! this._isUIValid; } @@ -203,6 +202,7 @@ export class GenericCalculatorComponent extends BaseComponent implements OnInit, this._formulaire.onRadioClick(this._pendingRadioClickInfo); this._pendingRadioClickInfo = undefined; } + // @TODO call this._isUIValid here ? } public onCloseForm() { diff --git a/src/app/formulaire/definition/form-compute.ts b/src/app/formulaire/definition/form-compute.ts index d1e848b28..9a32be715 100644 --- a/src/app/formulaire/definition/form-compute.ts +++ b/src/app/formulaire/definition/form-compute.ts @@ -3,12 +3,22 @@ import { Nub, Result, ParamDomainValue, Observer } from "jalhyd"; import { FormResult } from "./form-result"; import { FormulaireDefinition } from "./form-definition"; import { NgParameter } from "../ngparam"; +import { NotificationsService } from "../../services/notifications/notifications.service"; +import { ServiceFactory } from "../../services/service-factory"; +import { I18nService } from "../../services/internationalisation/internationalisation.service"; export abstract class FormCompute implements Observer { + private notificationsService: NotificationsService; + + private intlService: I18nService; + constructor(protected _formBase: FormulaireDefinition, protected _formResult: FormResult) { // indirectly subscribe to Nub result updates this._formBase.addObserver(this); + + this.notificationsService = ServiceFactory.instance.notificationsService; + this.intlService = ServiceFactory.instance.i18nService; } protected abstract compute(); @@ -107,10 +117,11 @@ export abstract class FormCompute implements Observer { case "nubResultUpdated": // forward Nub results update notification to FormCompute objects this.reaffectResultComponents(); - /* console.log("_____forwarding 2"); - this._formBase.notifyObservers({ - "action": "resultsUpdated", - }, this._formBase); */ + // @TODO reenable later wen chain computation is executed only once or it is a snackbar hell ! + /* this.notificationsService.notify( + this.intlService.localizeText("INFO_SNACKBAR_RESULTS_CALCULATED") + " " + this._formBase.calculatorName, + 1500 + ); */ break; } } diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index daa57be19..be1369a87 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -115,7 +115,6 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs // replace Nub this._currentNub = n; // subscribe to new Nub (for result updates) - console.log("SET CURRENT NUB -- (re)subscribe to Nub", this._currentNub.uid); this._currentNub.addObserver(this); } @@ -487,7 +486,6 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs // interface Observer public update(sender: any, data: any) { - console.log("--- FormDefinition received update", sender.constructor.name, data); if (sender instanceof Nub) { switch (data.action) { case "resultUpdated": diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 367b8d5b7..79f728dcb 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -616,7 +616,7 @@ export class FormulaireService extends Observable { if (notify) { this.notificationsService.notify( this.intlService.localizeText("INFO_SNACKBAR_RESULTS_INVALIDATED") + " " + form.calculatorName, - 2000 + 1500 ); } } diff --git a/src/app/services/service-factory.ts b/src/app/services/service-factory.ts index 0627bdf99..838a00cfc 100644 --- a/src/app/services/service-factory.ts +++ b/src/app/services/service-factory.ts @@ -2,6 +2,7 @@ import { ApplicationSetupService } from "./app-setup/app-setup.service"; import { FormulaireService } from "./formulaire/formulaire.service"; import { I18nService } from "./internationalisation/internationalisation.service"; import { HttpService } from "./http/http.service"; +import { NotificationsService } from "./notifications/notifications.service"; export class ServiceFactory { private static _instance: ServiceFactory; // instance pour le pattern singleton @@ -16,6 +17,8 @@ export class ServiceFactory { public httpService: HttpService; + public notificationsService: NotificationsService; + public static get instance() { if (ServiceFactory._instance === undefined) { ServiceFactory._instance = new ServiceFactory(); diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index 859d160ba..beb07be9f 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_CALCULATED": "Results calculated for", "INFO_SNACKBAR_RESULTS_INVALIDATED": "Results invalidated for", "INFO_SNACKBAR_SETTINGS_SAVED": "Settings saved on this device", "INFO_SNACKBAR_DEFAULT_SETTINGS_RESTORED": "Default settings restored", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index 350dd11ad..2dddd1782 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_CALCULATED": "Résultats calculés pour", "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", -- GitLab