Commit ea4ed26b authored by Dorchies David's avatar Dorchies David
Browse files

refactor: update scheme on modification of prebarrage structure

- !! console.debug everywhere

Refs #469
Showing with 27 additions and 25 deletions
+27 -25
......@@ -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);
......
......@@ -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);
......
......@@ -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();
......
......@@ -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
......
......@@ -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
......
......@@ -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) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment