From 17ca971a9eda2962cec744c987e1d7e8ad0471ca Mon Sep 17 00:00:00 2001 From: David Dorchies <david.dorchies@irstea.fr> Date: Tue, 14 Dec 2021 16:16:25 +0100 Subject: [PATCH] feat(PreBarrage): highlight in red items in error - known issue: The color changes only on item selection Refs #484 --- jalhyd_branch | 2 +- .../calculator.component.ts | 2 +- .../pb-schema/pb-schema.component.ts | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/jalhyd_branch b/jalhyd_branch index 1f7391f92..3aff35fb1 100644 --- a/jalhyd_branch +++ b/jalhyd_branch @@ -1 +1 @@ -master +298-prebarrages-mettre-les-enfants-invalides-en-rouge-dans-le-schema-cassiopee-nghyd-484 diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index 718ff08f5..668a28eeb 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -520,7 +520,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe } if (this._formulaire.currentNub.calcType === CalculatorType.PreBarrage) { const form: FormulairePrebarrage = this._formulaire as FormulairePrebarrage; - this._isUIValid = this._isUIValid && form.currentNub.check(); + this._isUIValid = this._isUIValid && form.currentNub.check().length === 0; } } } diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index cdbe3fad0..853cdd6cd 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -138,6 +138,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } catch (e) { console.error(e); } + this.highlightErrorItems(null); } /** @@ -229,6 +230,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni def.push("classDef basin fill:#e0f3fb,stroke:#003A80;"); // irstea-ocean 50 / 500 def.push("classDef basin::first-line color:green,font-size:0.5em;"); def.push("classDef node-highlighted fill:#4DBBE9;"); // irstea-ocean (material "accent"), 300 + def.push("classDef node-error fill:#ec7430;"); // irstea-rouille (material "accent"), 400 + def.push("classDef node-highlighted-error fill:#d92f03;"); // irstea-rouille (material "accent"), 900 const sortedWalls: PbCloison[] = []; for (const c of this.model.children) { @@ -240,6 +243,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni sortedWalls.push(c); } } + // sort then draw walls sortedWalls.sort(this.triCloisonsGaucheDroite); for (const c of sortedWalls) { @@ -308,6 +312,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } else { this._selectedItem = this.model.findChild(item.id); } + this.highlightErrorItems(item.id); // show proper form and hide results this.nodeSelected.emit({ node: this._selectedItem @@ -649,6 +654,29 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni }); } + private highlightErrorItems(selectedUid: string) { + this.nativeElement.querySelectorAll("g.node").forEach(item => { + item.classList.remove("node-error"); + item.classList.remove("node-highlighted-error"); + }); + const invalidUids: string[] = this.model.check(); + this.nativeElement.querySelectorAll("g.node").forEach(item => { + let itemId: string; + if ([this.upstreamId, this.downstreamId].includes(item.id)) { + itemId = this.model.uid; + } else { + itemId = item.id + } + if (invalidUids.includes(itemId)) { + if (item.id === selectedUid) { + item.classList.add("node-highlighted-error"); + } else { + item.classList.add("node-error"); + } + } + }); + } + private unselect() { // console.debug(`PbSchemaComponent.unselect()`); this._selectedItem = undefined; -- GitLab