From cf7bfec91bd21e400fac67e2fdd58c2d0c2f7f41 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Thu, 17 Sep 2020 16:07:05 +0200 Subject: [PATCH] Fix many problems in PreBarrage schema do not replace walls when basins selectors value was not changed when showing results, go back to input data after removing a wall or basin --- .../pb-schema/pb-schema.component.ts | 1 + .../formulaire/definition/form-pb-cloison.ts | 52 +++++++++++-------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 7a9ed20fe..7ca98ce67 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -337,6 +337,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.unselect(); this.refresh(); this.clearResults(); + this.calculatorComponent.showPBInputData = true; } public get uitextRemove() { diff --git a/src/app/formulaire/definition/form-pb-cloison.ts b/src/app/formulaire/definition/form-pb-cloison.ts index 311f8f918..f7680be3a 100644 --- a/src/app/formulaire/definition/form-pb-cloison.ts +++ b/src/app/formulaire/definition/form-pb-cloison.ts @@ -46,31 +46,39 @@ 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 === "select_upstream_basin") { - // remove and recreate wall (easier for pointers consistency) but preserve UID - const uid = nub.uid; - const oldDownstreamBasin = nub.bassinAval; - pb.deleteChild(pb.findChildPosition(nub.uid)); - const newWall = new PbCloison(newBasin, oldDownstreamBasin); - newWall.setUid(uid); - // copy structures - for (const s of nub.structures) { - newWall.addChild(s); + // update only if upstream basin changed (prevents updating on unwanted events) + if (newBasin?.uid !== nub.bassinAmont?.uid) { + // remove and recreate wall (easier for pointers consistency) but preserve UID + const uid = nub.uid; + const oldDownstreamBasin = nub.bassinAval; + pb.deleteChild(pb.findChildPosition(nub.uid)); + const newWall = new PbCloison(newBasin, oldDownstreamBasin); + newWall.setUid(uid); + // copy structures + for (const s of nub.structures) { + newWall.addChild(s); + } + pb.addChild(newWall); + this.currentNub = newWall; + this.reset(); } - pb.addChild(newWall); - this.currentNub = newWall; } else if (sender.id === "select_downstream_basin") { - // remove and recreate wall (easier for pointers consistency) but preserve UID - const uid = nub.uid; - const oldUpstreamBasin = nub.bassinAmont; - pb.deleteChild(pb.findChildPosition(nub.uid)); - const newWall = new PbCloison(oldUpstreamBasin, newBasin); - newWall.setUid(uid); - // copy structures - for (const s of nub.structures) { - newWall.addChild(s); + // update only if downstream basin changed (prevents updating on unwanted events) + if (newBasin?.uid !== nub.bassinAval?.uid) { + // remove and recreate wall (easier for pointers consistency) but preserve UID + const uid = nub.uid; + const oldUpstreamBasin = nub.bassinAmont; + pb.deleteChild(pb.findChildPosition(nub.uid)); + const newWall = new PbCloison(oldUpstreamBasin, newBasin); + newWall.setUid(uid); + // copy structures + for (const s of nub.structures) { + newWall.addChild(s); + } + pb.addChild(newWall); + this.currentNub = newWall; + this.reset(); } - pb.addChild(newWall); - this.currentNub = newWall; } this.notifyObservers({ action: "updateBasin", -- GitLab