From 16b0a293cb972cde6657a63544d7910073000dfa Mon Sep 17 00:00:00 2001 From: Mathias Chouet <mathias.chouet@irstea.fr> Date: Thu, 11 Jun 2020 15:01:00 +0200 Subject: [PATCH] PreBarrage: enhance node selection on schema --- .../pb-schema/pb-schema.component.ts | 31 +++++++++++++++++-- .../formulaire/definition/form-pb-cloison.ts | 5 ++- .../formulaire/definition/form-prebarrage.ts | 6 ++-- src/app/formulaire/elements/pb-schema.ts | 7 +++-- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 695243eab..25cee4728 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -391,6 +391,17 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni return desc; } + /** + * Selects and highlights on the schema the given wall or basin + */ + private selectNodeOnSchema(element: PbBassin | PbCloison) { + this.nativeElement.querySelectorAll("g.node").forEach(item => { + if (item.id === element.uid) { + this.selectNode(item); + } + }); + } + private findBasinPosition(basin: PbBassin): number { let i = 0; for (const b of this.model.bassins) { @@ -431,8 +442,9 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni const wall = this._selectedItem as PbCloison; const wallCopy = new PbCloison(wall.bassinAmont, wall.bassinAval); this.model.addChild(wallCopy); - this.unselect(); // @TODO select new wall ? + this.unselect(); this.refresh(); + this.selectNodeOnSchema(wallCopy); } public get uitextCopy() { @@ -441,9 +453,11 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni /** Adds a new lone basin */ public onAddBasinClick() { - this.model.addChild(new PbBassin(new PbBassinParams(20, 99))); - this.unselect(); // @TODO select new basin ? + const newBasin = new PbBassin(new PbBassinParams(20, 99)); + this.model.addChild(newBasin); + this.unselect(); this.refresh(); + this.selectNodeOnSchema(newBasin); } public get uitextAddBasin() { @@ -476,6 +490,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.model.addChild(wall); this.unselect(); this.refresh(); + this.selectNodeOnSchema(wall); } }); } @@ -496,7 +511,10 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni if (this._selectedItem instanceof PbBassin) { this.model.moveBasin(this._selectedItem.uid, this.findBasinPosition(this._selectedItem) - 1); } + const basin = this._selectedItem; + this.unselect(); this.refresh(); + this.selectNodeOnSchema(basin); } public get uitextMoveBasinUp() { @@ -515,7 +533,10 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni if (this._selectedItem instanceof PbBassin) { this.model.moveBasin(this._selectedItem.uid, this.findBasinPosition(this._selectedItem) + 1); } + const basin = this._selectedItem; + this.unselect(); this.refresh(); + this.selectNodeOnSchema(basin); } public get uitextMoveBasinDown() { @@ -568,6 +589,10 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni if (data.action === "refresh") { this.unselect(); this.refresh(); + // select a node on the schema ? + if (data.value !== undefined) { + this.selectNodeOnSchema(this.model.findChild(data.value)); + } } } } diff --git a/src/app/formulaire/definition/form-pb-cloison.ts b/src/app/formulaire/definition/form-pb-cloison.ts index 5ea0bc823..d448f6a99 100644 --- a/src/app/formulaire/definition/form-pb-cloison.ts +++ b/src/app/formulaire/definition/form-pb-cloison.ts @@ -68,7 +68,10 @@ export class FormulairePbCloison extends FormulaireParallelStructure { } else if (sender.id === this._downstreamBasinSelectId) { nub.bassinAval = newBasin; } - this.notifyObservers({ action: "updateBasin" }, this); + this.notifyObservers({ + action: "updateBasin", + value: nub.uid // node to select on the schema + }, this); } } } diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts index 95d4ee703..dd175247a 100644 --- a/src/app/formulaire/definition/form-prebarrage.ts +++ b/src/app/formulaire/definition/form-prebarrage.ts @@ -124,9 +124,9 @@ export class FormulairePrebarrage extends FormulaireFixedVar { } } - private refreshSchema() { + private refreshSchema(nodeUidToSelect: string) { const pbs = this.kids[0] as PbSchema; - pbs.refresh(); + pbs.refresh(nodeUidToSelect); } // interface Observer @@ -136,7 +136,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { if (sender instanceof FormulairePbCloison) { // console.log("HOH PUTAIN CE BIG QUATTRO HOYOYOYOYOY", this.kids[0].constructor.name); if (data.action === "updateBasin") { - this.refreshSchema(); + this.refreshSchema(data.value); } } } diff --git a/src/app/formulaire/elements/pb-schema.ts b/src/app/formulaire/elements/pb-schema.ts index 94a7d452a..07e108890 100644 --- a/src/app/formulaire/elements/pb-schema.ts +++ b/src/app/formulaire/elements/pb-schema.ts @@ -24,7 +24,10 @@ export class PbSchema extends FormulaireElement { } /** Asks PbSchemaComponent to redraw the schema */ - public refresh() { - this.notifyObservers({ action: "refresh" }, this); + public refresh(nodeUidToSelect: string) { + this.notifyObservers({ + action: "refresh", + value: nodeUidToSelect + }, this); } } -- GitLab