From 516e1510a5197ba4beede7ae6bd8b642862d4bad Mon Sep 17 00:00:00 2001
From: David Dorchies <david.dorchies@irstea.fr>
Date: Mon, 28 Sep 2020 14:51:19 +0200
Subject: [PATCH 1/3] fix(PreBarrage): Check validity on all parameters

Fix #470
---
 jalhyd_branch                                 |  2 +-
 .../calculator.component.ts                   | 14 ++++++++-----
 .../formulaire/definition/form-prebarrage.ts  | 20 +++++++++++++++++--
 3 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/jalhyd_branch b/jalhyd_branch
index 22284ff35..d64531f13 100644
--- a/jalhyd_branch
+++ b/jalhyd_branch
@@ -1 +1 @@
-32-ajout-de-l-outil-prebarrage
+devel
diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts
index 8e4eaf26c..d33f2cc7d 100644
--- a/src/app/components/generic-calculator/calculator.component.ts
+++ b/src/app/components/generic-calculator/calculator.component.ts
@@ -473,8 +473,9 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
         this._isUIValid = false;
         if (! this._formulaire.calculateDisabled) {
             // all fieldsets must be valid
+            this._isUIValid = true;
             if (this._fieldsetComponents !== undefined) {
-                this._isUIValid = this._fieldsetComponents.reduce(
+                this._isUIValid = this._isUIValid && this._fieldsetComponents.reduce(
                     // callback
                     (
                         // accumulator (valeur précédente du résultat)
@@ -514,10 +515,13 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
             if (this._pabTableComponent !== undefined) {
                 this._isUIValid = this._isUIValid && this._pabTableComponent.isValid;
             }
-        }
-
-        if (this._pbSchemaComponent !== undefined) {
-            this._isUIValid = this._isUIValid && this._pbSchemaComponent.isValid;
+            if (this._pbSchemaComponent !== undefined) {
+                this._isUIValid = this._isUIValid && this._pbSchemaComponent.isValid;
+            }
+            if (this._formulaire.currentNub.calcType === CalculatorType.PreBarrage) {
+                const form: FormulairePrebarrage = this._formulaire as FormulairePrebarrage;
+                this._isUIValid = this._isUIValid && form.isValid();
+            }
         }
     }
 
diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts
index 3a2c1ea7d..b6ede951a 100644
--- a/src/app/formulaire/definition/form-prebarrage.ts
+++ b/src/app/formulaire/definition/form-prebarrage.ts
@@ -55,7 +55,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
     public get results(): CalculatorResults[] {
         // ensure help links are propagated
         this._pbResults.helpLinks = this.helpLinks;
-        return [ this._pbResults ];
+        return [this._pbResults];
     }
 
     public get hasResults(): boolean {
@@ -185,7 +185,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
      */
     private showFormElements(f: FormulaireDefinition) {
         // clear all kids except PbSchema
-        this._kids = [ this.kids[0] ];
+        this._kids = [this.kids[0]];
         for (const e of f.kids) {
             this.kids.push(e);
         }
@@ -317,4 +317,20 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
             this.refreshSchema();
         }
     }
+    /**
+     *  Check validity of model for invisible forms
+     */
+    public isValid(): boolean {
+        for (const p of this.currentNub.parameterIterator) {
+            if (!p.isCalculated) {
+                try {
+                    // will throw an error if no value is defined at all
+                    p.paramValues.check();
+                } catch (e) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
 }
-- 
GitLab


From f4d9518cf4a7ee1f7f4a9c5abeb498a0757c98aa Mon Sep 17 00:00:00 2001
From: David Dorchies <david.dorchies@irstea.fr>
Date: Mon, 28 Sep 2020 15:32:27 +0200
Subject: [PATCH 2/3] fix(PreBarrage): Empty fields for all parameters and
 debug validity

Ref #470
---
 .../formulaire/definition/form-prebarrage.ts    | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts
index b6ede951a..4c534672a 100644
--- a/src/app/formulaire/definition/form-prebarrage.ts
+++ b/src/app/formulaire/definition/form-prebarrage.ts
@@ -322,7 +322,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
      */
     public isValid(): boolean {
         for (const p of this.currentNub.parameterIterator) {
-            if (!p.isCalculated) {
+            if (!p.isCalculated && p.visible) {
                 try {
                     // will throw an error if no value is defined at all
                     p.paramValues.check();
@@ -333,4 +333,19 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
         }
         return true;
     }
+
+    /**
+     * Set value of all single parameters to undefined, except for the given parameter ids
+     */
+    public emptyFields(except: string[] = [ "Cd0", "CdWS", "CdGR", "CdGRS", "CdCunge", "CdWR", "CdO", "CdT", "CdWSL" ]) {
+        // save current calculated param, as setting value on a CALC param will
+        // change its mode and choose another calculated param by default
+        const paramCalculated = this.currentNub.calculatedParam;
+        for (const p of this.currentNub.parameterIterator) {
+            if (! except.includes(p.symbol)) {
+                p.setValue(undefined);
+            }
+        }
+        this.currentNub.calculatedParam = paramCalculated;
+    }
 }
-- 
GitLab


From 32d82c7e43d5c144c77806a22a764885dde2d6b0 Mon Sep 17 00:00:00 2001
From: David Dorchies <david.dorchies@irstea.fr>
Date: Mon, 28 Sep 2020 15:50:27 +0200
Subject: [PATCH 3/3] refactor: move parameter vailidity checking into jalhyd

Ref #278, nghyd#470
---
 jalhyd_branch                                    |  2 +-
 .../generic-calculator/calculator.component.ts   |  2 +-
 src/app/formulaire/definition/form-prebarrage.ts | 16 ----------------
 3 files changed, 2 insertions(+), 18 deletions(-)

diff --git a/jalhyd_branch b/jalhyd_branch
index d64531f13..de50629b8 100644
--- a/jalhyd_branch
+++ b/jalhyd_branch
@@ -1 +1 @@
-devel
+278-prebarrage-calculable-avec-champs-vides-cassiopee-nghyd-470
diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts
index d33f2cc7d..dc3d0900a 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.isValid();
+                this._isUIValid = this._isUIValid && form.currentNub.check();
             }
         }
     }
diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts
index 4c534672a..73b4df1c5 100644
--- a/src/app/formulaire/definition/form-prebarrage.ts
+++ b/src/app/formulaire/definition/form-prebarrage.ts
@@ -317,22 +317,6 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
             this.refreshSchema();
         }
     }
-    /**
-     *  Check validity of model for invisible forms
-     */
-    public isValid(): boolean {
-        for (const p of this.currentNub.parameterIterator) {
-            if (!p.isCalculated && p.visible) {
-                try {
-                    // will throw an error if no value is defined at all
-                    p.paramValues.check();
-                } catch (e) {
-                    return false;
-                }
-            }
-        }
-        return true;
-    }
 
     /**
      * Set value of all single parameters to undefined, except for the given parameter ids
-- 
GitLab