From a6568efcc131425e280f8a062e96a1d29296f4b1 Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Fri, 12 Jul 2019 15:47:28 +0200
Subject: [PATCH] Cloisons: PAB generation button is disabled if any parameter
 is varying

---
 .../generic-calculator/calculator.component.html |  3 ++-
 .../generic-calculator/calculator.component.ts   | 16 ++++++++++++++++
 src/locale/messages.en.json                      |  1 +
 src/locale/messages.fr.json                      |  1 +
 4 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/app/components/generic-calculator/calculator.component.html b/src/app/components/generic-calculator/calculator.component.html
index f3fb61d6c..f94d21d49 100644
--- a/src/app/components/generic-calculator/calculator.component.html
+++ b/src/app/components/generic-calculator/calculator.component.html
@@ -74,7 +74,8 @@
                             <h1 [innerHTML]="uitextResultsTitle"></h1>
                         </mat-card-title>
                         <div fxFlex></div>
-                        <button mat-raised-button color="accent" id="generate-pab" *ngIf="isPABCloisons" (click)="generatePAB()">
+                        <button mat-raised-button color="accent" id="generate-pab" *ngIf="isPABCloisons" (click)="generatePAB()"
+                            [disabled]="! generatePABEnabled" [title]="uitextGeneratePabTitle">
                             {{ uitextGeneratePAB }}
                         </button>
                     </mat-card-header>
diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts
index e662fc437..ea5c95b41 100644
--- a/src/app/components/generic-calculator/calculator.component.ts
+++ b/src/app/components/generic-calculator/calculator.component.ts
@@ -455,6 +455,22 @@ export class GenericCalculatorComponent extends BaseComponent implements OnInit,
         );
     }
 
+    // PAB generation is enabled only if no parameter is varying
+    public get generatePABEnabled(): boolean {
+        let ret = true;
+        for (const p of this._formulaire.currentNub.parameterIterator) {
+            ret = ret && (! p.hasMultipleValues);
+        }
+        return ret;
+    }
+
+    public get uitextGeneratePabTitle() {
+        if (! this.generatePABEnabled) {
+            return this.intlService.localizeText("INFO_PAB_PARAMETRES_FIXES");
+        }
+        return "";
+    }
+
     /**
      * Génère une passe à bassins à partir du modèle de cloisons en cours
      */
diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json
index 1fce8bfcd..cbd1869b3 100644
--- a/src/locale/messages.en.json
+++ b/src/locale/messages.en.json
@@ -253,6 +253,7 @@
     "INFO_PAB_HEADER_PARAMETERS": "Parameters",
     "INFO_PAB_HEADER_VALUES": "Values",
     "INFO_PAB_CLOISON_OUVRAGE_N": "Wall : device #%s",
+    "INFO_PAB_PARAMETRES_FIXES": "All parameters must be fixed",
     "INFO_PAB_TITRE_COURT": "Fish ladder",
     "INFO_PAB_TITRE": "Fish ladder",
     "INFO_PAB_TITRE_PROFIL": "Fish ladder longitudinal profile",
diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json
index 1c4ace04c..a789665c6 100644
--- a/src/locale/messages.fr.json
+++ b/src/locale/messages.fr.json
@@ -253,6 +253,7 @@
     "INFO_PAB_HEADER_PARAMETERS": "Paramètres",
     "INFO_PAB_HEADER_VALUES": "Valeurs",
     "INFO_PAB_CLOISON_OUVRAGE_N": "Cloison : ouvrage n° %s",
+    "INFO_PAB_PARAMETRES_FIXES": "Tous les paramètres doivent être fixés",
     "INFO_PAB_TITRE_COURT": "PAB",
     "INFO_PAB_TITRE": "Passe à bassins",
     "INFO_PAB_TITRE_PROFIL": "Profil en long de la passe",
-- 
GitLab