From cdb6f84f12d45d2b94fbceebe484193d84afb857 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Tue, 23 Jul 2019 17:55:27 +0200 Subject: [PATCH] Results reset : track cause of reset for smarter depending Nubs detection (for jalhyd#98) --- .../generic-calculator/calculator.component.ts | 4 ++-- .../generic-input/generic-input.component.ts | 6 +++++- .../param-field-line.component.ts | 2 +- .../components/param-link/param-link.component.ts | 5 +++-- .../param-values/param-values.component.ts | 6 +++++- .../formulaire/definition/concrete/form-base.ts | 7 +++++-- src/app/formulaire/definition/form-definition.ts | 4 ++-- src/app/services/formulaire/formulaire.service.ts | 15 ++++++++++++--- 8 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index 623091c90..be369c0b5 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -406,8 +406,8 @@ export class GenericCalculatorComponent extends BaseComponent implements OnInit, /** * réception d'un événement de changement de valeur d'un input */ - public onInputChange() { - this._formulaire.resetResults([]); + public onInputChange(event: any) { + this._formulaire.resetResults([], event.symbol); } /** diff --git a/src/app/components/generic-input/generic-input.component.ts b/src/app/components/generic-input/generic-input.component.ts index 3ed95a301..42481be86 100644 --- a/src/app/components/generic-input/generic-input.component.ts +++ b/src/app/components/generic-input/generic-input.component.ts @@ -197,7 +197,11 @@ export abstract class GenericInputComponent extends BaseComponent implements OnC * événement de changement de la valeur du modèle */ private emitModelChanged() { - this.change.emit({ "action": "model", "value": this.getModelValue() }); + this.change.emit({ + action: "model", + value: this.getModelValue(), + symbol: (this._model instanceof NgParameter ? this._model.symbol : undefined) + }); } protected setAndValidateModel(sender: any, v: any) { diff --git a/src/app/components/param-field-line/param-field-line.component.ts b/src/app/components/param-field-line/param-field-line.component.ts index ecbbbeb48..0e3c35446 100644 --- a/src/app/components/param-field-line/param-field-line.component.ts +++ b/src/app/components/param-field-line/param-field-line.component.ts @@ -260,7 +260,7 @@ export class ParamFieldLineComponent implements OnChanges { break; case "model": - this.inputChange.emit(); + this.inputChange.emit(event); break; } } diff --git a/src/app/components/param-link/param-link.component.ts b/src/app/components/param-link/param-link.component.ts index fd3a6b4cd..ed0cad6f3 100644 --- a/src/app/components/param-link/param-link.component.ts +++ b/src/app/components/param-link/param-link.component.ts @@ -257,8 +257,9 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { // console.log("undefined target value (pending calculation)"); } this.change.emit({ - "action": "model", - "value": value + action: "model", + value: value, + symbol: this.param.symbol }); } diff --git a/src/app/components/param-values/param-values.component.ts b/src/app/components/param-values/param-values.component.ts index ca4bc9c1c..65277721e 100644 --- a/src/app/components/param-values/param-values.component.ts +++ b/src/app/components/param-values/param-values.component.ts @@ -86,7 +86,11 @@ export class ParamValuesComponent implements AfterViewInit, Observer { * événement de changement de la valeur du modèle */ private emitModelChanged() { - this.change.emit({ "action": "model", "value": this.param.getValue() }); + this.change.emit({ + action: "model", + value: this.param.getValue(), + symbol: this.param.symbol + }); } public update(sender: any, data: any): void { diff --git a/src/app/formulaire/definition/concrete/form-base.ts b/src/app/formulaire/definition/concrete/form-base.ts index e54548b98..976cf3368 100644 --- a/src/app/formulaire/definition/concrete/form-base.ts +++ b/src/app/formulaire/definition/concrete/form-base.ts @@ -21,15 +21,18 @@ export class FormulaireBase extends FormulaireDefinition { /** * Resets the form results, the results panel on screen, the model * results, and does the same for all depending modules + * @param symbol symbol of the parameter whose value change triggered this method + * @param forceResetAllDependencies if true, even non-calculated non-modified parameters + * links will be considered as dependencies @see jalhyd#98 */ - public resetResults(visited: string[] = []) { + public resetResults(visited: string[] = [], symbol?: string, forceResetAllDependencies: boolean = false) { visited.push(this.currentNub.uid); // reset GUI results this._formResult.resetResults(); // reset model results this.currentNub.resetResult(); // reset the result panels of all forms depending on this one - ServiceFactory.instance.formulaireService.resetAllDependingFormsResults(this, visited); + ServiceFactory.instance.formulaireService.resetAllDependingFormsResults(this, visited, symbol, forceResetAllDependencies); } public doCompute() { diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index 1e90fa201..f10ec8662 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -380,7 +380,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs * effacement des résultats, application des dépendances, ... */ public reset() { - this.resetResults([]); + this.resetResults([], undefined, true); this.applyDependencies(); // prévenir les composants qu'il faut détecter les changements @@ -413,7 +413,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs } } - public abstract resetResults(visited: string[]); + public abstract resetResults(visited: string[], symbol?: string, forceResetAllDependencies?: boolean); public abstract doCompute(); public abstract get hasResults(): boolean; public abstract get results(): CalculatorResults[]; diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index b834703ab..0b499b5d8 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -497,7 +497,7 @@ export class FormulaireService extends Observable { // reset the result panels of all forms depending on this one // @TODO UI should detect model change instead of doing this manually - this.resetAllDependingFormsResults(form, [], false); + this.resetAllDependingFormsResults(form, [], undefined, true, false); } if (nub) { // reset model results (important, also resets dependent Nubs results in chain) @@ -721,9 +721,18 @@ export class FormulaireService extends Observable { /** * Resets the results of all forms depending on the given form "f" * @param f + * @param symbol symbol of the parameter whose value change triggered this method + * @param forceResetAllDependencies if true, even non-calculated non-modified parameters + * links will be considered as dependencies @see jalhyd#98 */ - public resetAllDependingFormsResults(f: FormulaireDefinition, visited: string[] = [], notify: boolean = true) { - const dependingNubs = Session.getInstance().getDependingNubs(f.currentNub.uid); + public resetAllDependingFormsResults( + f: FormulaireDefinition, + visited: string[] = [], + symbol?: string, + forceResetAllDependencies: boolean = false, + notify: boolean = true + ) { + const dependingNubs = Session.getInstance().getDependingNubs(f.currentNub.uid, symbol, forceResetAllDependencies); for (const dn of dependingNubs) { if (! visited.includes(dn.uid)) { const form = this.getFormulaireFromNubId(dn.uid); -- GitLab