From aacc74b08cd286e4e8b7d43b114c09f6f226115d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Wed, 15 Jun 2022 11:09:38 +0200
Subject: [PATCH 1/3] fix: parallel structures: disable calculate button if
 there is no child strucure

For example in case of session loading error

refs #548
---
 .../calculator.component.ts                   | 20 +++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts
index 04726b0ab..cd11ac0b4 100644
--- a/src/app/components/generic-calculator/calculator.component.ts
+++ b/src/app/components/generic-calculator/calculator.component.ts
@@ -24,7 +24,8 @@ import {
     PreBarrage,
     PbCloison,
     Espece,
-    VariatedDetails
+    VariatedDetails,
+    ParallelStructure
 } from "jalhyd";
 
 import { generateValuesCombination, getUnformattedIthResult, getUnformattedIthValue } from "../../util";
@@ -523,9 +524,20 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
             if (this._pbSchemaComponent !== undefined) {
                 res = res && this._pbSchemaComponent.isValid;
             }
-            if (this._formulaire.currentNub.calcType === CalculatorType.PreBarrage) {
-                const form: FormulairePrebarrage = this._formulaire as FormulairePrebarrage;
-                res = res && form.checkParameters().length === 0;
+            switch (this._formulaire.currentNub.calcType) {
+                case CalculatorType.PreBarrage:
+                    const form: FormulairePrebarrage = this._formulaire as FormulairePrebarrage;
+                    res = res && form.checkParameters().length === 0;
+                    break;
+
+                case CalculatorType.CloisonAval:
+                case CalculatorType.Cloisons:
+                case CalculatorType.PbCloison:
+                case CalculatorType.Dever:
+                    // in case of parallel structures, check that child structures count > 0
+                    const pstr = this.formulaire.currentNub as ParallelStructure;
+                    res = res && pstr.getChildren().length > 0;
+                    break;
             }
         }
 
-- 
GitLab


From e310da646a2bd9b922d5b297fe98bdb6625393e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Wed, 15 Jun 2022 13:18:32 +0200
Subject: [PATCH 2/3] feat: add an "add structure" button to fieldset container
 header when empty

refs #548
---
 .../fieldset-container.component.html             |  6 ++++++
 .../fieldset-container.component.scss             |  5 +++++
 .../fieldset-container.component.ts               | 15 +++++++++++++++
 3 files changed, 26 insertions(+)

diff --git a/src/app/components/fieldset-container/fieldset-container.component.html b/src/app/components/fieldset-container/fieldset-container.component.html
index 77049de32..02a21f760 100644
--- a/src/app/components/fieldset-container/fieldset-container.component.html
+++ b/src/app/components/fieldset-container/fieldset-container.component.html
@@ -7,6 +7,12 @@
     <mat-card-title>
         {{ title }}
     </mat-card-title>
+    <div class="card-container-right">
+        <button type="button" *ngIf="enableAddStructureButton" mat-icon-button (click)="onAddStructureClick()" class="fsc-add-structure"
+            [title]="uitextAddStructure">
+            <mat-icon>add_box</mat-icon>
+        </button>
+    </div>
 </mat-card-header>
 
 <mat-card-content>
diff --git a/src/app/components/fieldset-container/fieldset-container.component.scss b/src/app/components/fieldset-container/fieldset-container.component.scss
index 0a700234c..f89f5a9c7 100644
--- a/src/app/components/fieldset-container/fieldset-container.component.scss
+++ b/src/app/components/fieldset-container/fieldset-container.component.scss
@@ -31,6 +31,11 @@ mat-card-header {
         font-size: 16px;
         margin-bottom: 8px;
     }
+
+    // c'est tout pourri, mais bon...
+    .card-container-right {
+        margin-top: -10px;
+    }
 }
 
 mat-card-content {
diff --git a/src/app/components/fieldset-container/fieldset-container.component.ts b/src/app/components/fieldset-container/fieldset-container.component.ts
index c98450cdc..5297f8b9d 100644
--- a/src/app/components/fieldset-container/fieldset-container.component.ts
+++ b/src/app/components/fieldset-container/fieldset-container.component.ts
@@ -188,6 +188,13 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit {
         this.addSubNub(evt.fs, evt.clone);
     }
 
+    /**
+     * clic sur le bouton "ajouter une structure"
+     */
+    public onAddStructureClick() {
+        this._container.addFromTemplate(0, 0);
+    }
+
     /**
     * réception d'un événement de demande de suppression d'un FieldSet
     */
@@ -227,7 +234,15 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit {
         return this._container && this._container.helpLink;
     }
 
+    public get enableAddStructureButton() {
+        return this._container.getKids().length === 0;
+    }
+
     public get uitextOpenHelp() {
         return this.i18nService.localizeText("INFO_CALCULATOR_OPEN_HELP");
     }
+
+    public get uitextAddStructure(): string {
+        return this.i18nService.localizeText("INFO_FIELDSET_ADD");
+    }
 }
-- 
GitLab


From d98cc78b7501836b6694d2f92ac184c83713bcaf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Wed, 15 Jun 2022 16:31:42 +0200
Subject: [PATCH 3/3] fix: fieldset container: calculate button not enabled
 after clicking on "add structure"

refs #548
---
 .../fieldset-container/fieldset-container.component.ts           | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/app/components/fieldset-container/fieldset-container.component.ts b/src/app/components/fieldset-container/fieldset-container.component.ts
index 5297f8b9d..b496bb944 100644
--- a/src/app/components/fieldset-container/fieldset-container.component.ts
+++ b/src/app/components/fieldset-container/fieldset-container.component.ts
@@ -193,6 +193,7 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit {
      */
     public onAddStructureClick() {
         this._container.addFromTemplate(0, 0);
+        this.validChange.emit();
     }
 
     /**
-- 
GitLab