diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 4e9c48e531fd1469389d35ccac7ccb011f166064..e12e5260384b0dd74c73386f24e6389de43142df 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 c6c9afed11cfc800c2e839055946bb7332cf1bb9..d385c1f607a2244755e3d2b57d67836f46c8d5e6 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 d1e848b28cb3c79ee81d2fdff7e39c4325c736cc..9a32be7155c1c6286f8f0812173d0267e3f26bed 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 daa57be194f36df52f60597dd48d540606cabee4..be1369a871436581e6880e1f191960e1ef7c2af5 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 367b8d5b717fed206dbca889f03ac70bea4a40de..79f728dcbe4404a21f454ebb9657b523d3fcbad1 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 0627bdf99a223a0bf9b7712945dcdb7849075c1a..838a00cfc468b4c98954a00f73d4b7d9cc6b9c37 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 859d160ba2163cbb347639df6bf1d6ded96fbc86..beb07be9fd2ebccfc24adc2fcda97df98a05f50b 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 350dd11ada5ad8419ad7d7ce31fe58dfab3d9b55..2dddd1782c9445c20efb72e7314f663a016d02a4 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",