From 43ac184ad8b45a3e3d0b8af1b2ac6f58a0181c08 Mon Sep 17 00:00:00 2001 From: Mathias Chouet <mathias.chouet@irstea.fr> Date: Mon, 22 Jun 2020 16:46:47 +0200 Subject: [PATCH] PreBarrage: move walls --- .../select-model-field-line.component.ts | 2 +- .../formulaire/definition/form-definition.ts | 1 - .../formulaire/definition/form-pb-cloison.ts | 26 ++++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/app/components/select-model-field-line/select-model-field-line.component.ts b/src/app/components/select-model-field-line/select-model-field-line.component.ts index f88877835..fdf8af949 100644 --- a/src/app/components/select-model-field-line/select-model-field-line.component.ts +++ b/src/app/components/select-model-field-line/select-model-field-line.component.ts @@ -80,7 +80,7 @@ export class SelectModelFieldLineComponent implements OnInit { public async createModel() { const f = await this._formService.createFormulaire(this._select.calcType); this.router.navigate(["/calculator", f.uid]); - // on ajoute un ouvrage aux modulex de type "parallèle" + // on ajoute un ouvrage aux modules de type "parallèle" for (const e of f.allFormElements) { if (e instanceof FieldsetContainer) { e.addFromTemplate(0); diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index cf5fa11d2..dd6797765 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -272,7 +272,6 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs break; case "template_container": - console.log("parsing template container !", conf); this.parse_template_container(conf, templates); break; diff --git a/src/app/formulaire/definition/form-pb-cloison.ts b/src/app/formulaire/definition/form-pb-cloison.ts index d448f6a99..90ac294ec 100644 --- a/src/app/formulaire/definition/form-pb-cloison.ts +++ b/src/app/formulaire/definition/form-pb-cloison.ts @@ -17,26 +17,18 @@ export class FormulairePbCloison extends FormulaireParallelStructure { this._downstreamBasinSelectId = this.getOption(json, "downstreamBasinSelectId"); } - protected completeParse(json: {}, firstNotif: boolean = true) { + protected completeParse(json: {}) { super.completeParse(json); if (this._upstreamBasinSelectId) { const sel = this.getFormulaireNodeById(this._upstreamBasinSelectId); if (sel) { sel.addObserver(this); - if (firstNotif) { - // force 1st observation - (sel as SelectFieldNub).notifySelectValueChanged(); - } } } if (this._downstreamBasinSelectId) { const sel = this.getFormulaireNodeById(this._downstreamBasinSelectId); if (sel) { sel.addObserver(this); - if (firstNotif) { - // force 1st observation - (sel as SelectFieldNub).notifySelectValueChanged(); - } } } } @@ -64,13 +56,23 @@ export class FormulairePbCloison extends FormulaireParallelStructure { // empty "" data.value.value should return undefined, which is good for amont/aval const newBasin = pb.findChild(data.value.value) as PbBassin; if (sender.id === this._upstreamBasinSelectId) { - nub.bassinAmont = newBasin; + // remove and recreate wall (easier for pointers consistency) + const oldDownstreamBasin = nub.bassinAval; + pb.deleteChild(pb.findChildPosition(nub.uid)); + const newWall = new PbCloison(newBasin, oldDownstreamBasin); + pb.addChild(newWall); + this.currentNub = newWall; } else if (sender.id === this._downstreamBasinSelectId) { - nub.bassinAval = newBasin; + // remove and recreate wall (easier for pointers consistency) + const oldUpstreamBasin = nub.bassinAmont; + pb.deleteChild(pb.findChildPosition(nub.uid)); + const newWall = new PbCloison(oldUpstreamBasin, newBasin); + pb.addChild(newWall); + this.currentNub = newWall; } this.notifyObservers({ action: "updateBasin", - value: nub.uid // node to select on the schema + value: this._currentNub.uid // node to select on the schema }, this); } } -- GitLab