From ea4ed26b9c3ebf81ca444934ad5a5cb21c5c2b5c Mon Sep 17 00:00:00 2001 From: David Dorchies <david.dorchies@irstea.fr> Date: Wed, 30 Sep 2020 17:32:49 +0200 Subject: [PATCH] refactor: update scheme on modification of prebarrage structure - !! console.debug everywhere Refs #469 --- .../calculator.component.ts | 2 ++ .../pb-schema/pb-schema.component.ts | 28 +++++++------------ .../formulaire/definition/form-definition.ts | 17 ++++++----- .../formulaire/definition/form-prebarrage.ts | 3 ++ src/app/formulaire/elements/pb-schema.ts | 1 + src/app/services/formulaire.service.ts | 1 + 6 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index dc3d0900a..9671f8878 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -541,6 +541,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe * réception d'un événement de changement de valeur d'un input */ public onInputChange(event: any) { + console.debug(`CalculatorComponent.onInputChange(${event?.symbol})`); this._formulaire.resetResults([], (event ? event.symbol : undefined)); } @@ -584,6 +585,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe /** réception d'un événement de clic sur un nœud du schéma de PréBarrage */ public onPBNodeSelected(event: any) { + console.debug(`GenericCalculatorComponent.onPBNodeSelected(${event?.node?.uid})`); // show proper form (actually subform elements) or proper results, // depending on what was clicked (this._formulaire as FormulairePrebarrage).nodeSelected(event.node); diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 026f5e3ee..0ba88a7ba 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -298,6 +298,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } private selectNode(item: any) { + console.debug(`PbSchemaComponent.selectNode(${item?.id})`); // highlight clicked element this.clearHighlightedItems(); item.classList.add("node-highlighted"); @@ -449,9 +450,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.model.addChild(new PbCloison(undefined, this._selectedItem.bassinAval)); } } - this.unselect(); - this.refresh(); this.clearResults(); + this.refreshWithSelection(); this.calculatorComponent.showPBInputData = true; } @@ -476,10 +476,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval); wallCopy.loadObjectRepresentation(wall.objectRepresentation()); this.model.addChild(wallCopy); - this.unselect(); - this.refresh(); - this.selectNodeOnSchema(wallCopy); this.clearResults(); + this.refreshWithSelection(wallCopy.uid); this.calculatorComponent.showPBInputData = true; } @@ -491,10 +489,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni public onAddBasinClick() { const newBasin = new PbBassin(new PbBassinParams(20, 99)); this.model.addChild(newBasin); - this.unselect(); - this.refresh(); - this.selectNodeOnSchema(newBasin); this.clearResults(); + this.refreshWithSelection(newBasin.uid); this.calculatorComponent.showPBInputData = true; } @@ -526,10 +522,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni result.down === 0 ? undefined : this.model.bassins[result.down - 1] ); this.model.addChild(wall); - this.unselect(); - this.refresh(); - this.selectNodeOnSchema(wall); this.clearResults(); + this.refreshWithSelection(wall.uid); this.calculatorComponent.showPBInputData = true; } }); @@ -552,10 +546,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.model.moveBasin(this._selectedItem.uid, this.model.findBasinPosition(this._selectedItem.uid) - 1); } const basin = this._selectedItem; - this.unselect(); - this.refresh(); - this.selectNodeOnSchema(basin); this.clearResults(); + this.refreshWithSelection(this._selectedItem.uid); this.calculatorComponent.showPBInputData = true; } @@ -576,10 +568,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.model.moveBasin(this._selectedItem.uid, this.model.findBasinPosition(this._selectedItem.uid) + 1); } const basin = this._selectedItem; - this.unselect(); - this.refresh(); - this.selectNodeOnSchema(basin); this.clearResults(); + this.refreshWithSelection(this._selectedItem.uid); this.calculatorComponent.showPBInputData = true; } @@ -659,6 +649,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } private unselect() { + console.debug(`PbSchemaComponent.unselect()`); this._selectedItem = undefined; this.clearHighlightedItems(); this.nodeSelected.emit({}); // nothing selected @@ -667,7 +658,6 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni /** clear all PB form results whenever the basins / walls layout is changed */ private clearResults() { this.pbSchema.form.reset(); - this.refreshWithSelection(); } /** @@ -675,6 +665,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni * nub uid, else keeps previous selection */ private refreshWithSelection(uid ?: string) { + console.debug(`PbSchemaComponent.refreshWithSelection(${uid})`); // remember previously selected node const selectedNodeUID = this._selectedItem?.uid; this.unselect(); @@ -691,6 +682,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni // interface Observer public update(sender: IObservable, data: any) { + console.debug(`PbSchemaComponent.update:`, data); if (sender instanceof PbSchema) { if (data.action === "refresh") { this.refreshWithSelection(data.value); diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index 54231bc1a..f98124d81 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -419,13 +419,16 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs * links will be considered as dependencies @see jalhyd#98 */ public resetResults(visited: string[] = [], symbol?: string, forceResetAllDependencies: boolean = false) { - visited.push(this.currentNub.uid); - // reset GUI results - this.resetFormResults(); - // reset model results - this.currentNub.resetResult(); - // reset the result panels of all forms depending on this one - ServiceFactory.formulaireService.resetAllDependingFormsResults(this, visited, symbol, forceResetAllDependencies); + console.debug(`FormulaireDefinition.resetResults(${visited})`); + if (this.currentNub.result !== undefined) { + visited.push(this.currentNub.uid); + // reset GUI results + this.resetFormResults(); + // reset model results + this.currentNub.resetResult(); + // reset the result panels of all forms depending on this one + ServiceFactory.formulaireService.resetAllDependingFormsResults(this, visited, symbol, forceResetAllDependencies); + } } protected abstract compute(); diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts index 73b4df1c5..92dddd70c 100644 --- a/src/app/formulaire/definition/form-prebarrage.ts +++ b/src/app/formulaire/definition/form-prebarrage.ts @@ -125,6 +125,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { * envoie un événement "nodeSelected" (on a cliqué sur un nœud) */ public nodeSelected(node: PbBassin | PbCloison) { + console.debug(`FormulairePrebarrage.NodeSelected(${node?.uid})`); // did something change, or we just clicked again on the node that was already selected ? if (this._selectedItem !== node) { // store for results formatting @@ -199,6 +200,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { // interface Observer public update(sender: IObservable, data: any) { + console.debug("FormulairePrebarrage.update:", data); super.update(sender, data); if (sender instanceof FormulairePbCloison) { if (data.action === "updateBasin") { @@ -300,6 +302,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { } public resetResults() { + console.debug("FormulairePrebarrage.resetResults()"); const hasToRedraw = (this._currentNub.result !== undefined); super.resetResults(); // reset all children nubs diff --git a/src/app/formulaire/elements/pb-schema.ts b/src/app/formulaire/elements/pb-schema.ts index f9c5afae5..75565d6a5 100644 --- a/src/app/formulaire/elements/pb-schema.ts +++ b/src/app/formulaire/elements/pb-schema.ts @@ -38,6 +38,7 @@ export class PbSchema extends FormulaireElement { /** Asks PbSchemaComponent to redraw the schema */ public refresh(nodeUidToSelect?: string) { + console.debug(`PbSchema.refresh(${nodeUidToSelect})`); this.notifyObservers({ action: "refresh", value: nodeUidToSelect diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index 9a1abbe1a..9e000fc0c 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -815,6 +815,7 @@ export class FormulaireService extends Observable { if (form) { const hadResults = form.hasResults; // form might not have a result, but still have another form depending on it ! + console.debug(`FormulaireService.resetAllDependingFormsResults(form->${dn.uid})`); form.resetResults(visited); if (hadResults) { if (notify) { -- GitLab