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 1/3] 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


From 17e600533a3fd50b287deeeb010184118072f027 Mon Sep 17 00:00:00 2001
From: David Dorchies <david.dorchies@irstea.fr>
Date: Wed, 15 Dec 2021 17:13:52 +0100
Subject: [PATCH 2/3] fix(PreBarrage): regression after
 17ca971a9eda2962cec744c987e1d7e8ad0471ca

- migrate empty parameter check to FormPrebarrage

Refs #484
---
 .../calculator.component.ts                   |  2 +-
 .../pb-schema/pb-schema.component.ts          |  2 +-
 .../formulaire/definition/form-prebarrage.ts  | 32 ++++++++++++++++++-
 3 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts
index 668a28eeb..2608ce76e 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().length === 0;
+                this._isUIValid = this._isUIValid && form.checkParameters().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 853cdd6cd..40217b619 100644
--- a/src/app/components/pb-schema/pb-schema.component.ts
+++ b/src/app/components/pb-schema/pb-schema.component.ts
@@ -659,7 +659,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
             item.classList.remove("node-error");
             item.classList.remove("node-highlighted-error");
         });
-        const invalidUids: string[] = this.model.check();
+        const invalidUids: string[] = this.pbSchema.form.checkParameters();
         this.nativeElement.querySelectorAll("g.node").forEach(item => {
             let itemId: string;
             if ([this.upstreamId, this.downstreamId].includes(item.id)) {
diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts
index 4400467c8..143a6991d 100644
--- a/src/app/formulaire/definition/form-prebarrage.ts
+++ b/src/app/formulaire/definition/form-prebarrage.ts
@@ -1,4 +1,4 @@
-import { CalculatorType, PbBassin, PbCloison, IObservable, PreBarrage, VariatedDetails, ParamDefinition } from "jalhyd";
+import { CalculatorType, PbBassin, PbCloison, IObservable, PreBarrage, VariatedDetails, ParamDefinition, IParamDefinitionIterator, ParamDefinitionIterator } from "jalhyd";
 
 import { FormulaireFixedVar } from "./form-fixedvar";
 import { PbSchema } from "../elements/pb-schema";
@@ -335,4 +335,34 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
         }
         this.currentNub.calculatedParam = paramCalculated;
     }
+
+    /**
+     *  Check validity of all model parameters
+     *  @param withChildren check parameters of child nub as well
+     *  @return array of uid nubs in error
+     */
+         public checkParameters(withChildren: boolean = true): string[] {
+            let prmIt: IParamDefinitionIterator;
+            if(withChildren) {
+                prmIt = this.currentNub.parameterIterator;
+            } else {
+                prmIt = new ParamDefinitionIterator(this.currentNub.prms);
+            }
+            const uids: string[] = [];
+            for (const p of prmIt) {
+                if (!p.isCalculated && p.visible) {
+                    try {
+                        // will throw an error if no value is defined at all
+                        p.paramValues.check();
+                    } catch (e) {
+                        if (p.parentNub.calcType === CalculatorType.Structure) {
+                            uids.push(p.parentNub.getParent().uid);
+                        } else {
+                            uids.push(p.parentNub.uid);
+                        }
+                    }
+                }
+            }
+            return uids;
+        }
 }
-- 
GitLab


From 104178195fcbf51ce32fa0cdce1238bf444d0695 Mon Sep 17 00:00:00 2001
From: David Dorchies <david.dorchies@irstea.fr>
Date: Tue, 15 Feb 2022 15:29:59 +0100
Subject: [PATCH 3/3] update jalhyd_branch before merge to devel

Refs #484
---
 jalhyd_branch | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/jalhyd_branch b/jalhyd_branch
index 3aff35fb1..626e97d71 100644
--- a/jalhyd_branch
+++ b/jalhyd_branch
@@ -1 +1 @@
-298-prebarrages-mettre-les-enfants-invalides-en-rouge-dans-le-schema-cassiopee-nghyd-484
+devel
\ No newline at end of file
-- 
GitLab