From 08c8b26851b2fad8b16bbdc1a635da1adffb4b47 Mon Sep 17 00:00:00 2001
From: Mathias Chouet <mathias.chouet@irstea.fr>
Date: Fri, 3 Apr 2020 14:58:21 +0200
Subject: [PATCH] Option in  calculator config to disable calculation
 permanently

---
 .../generic-calculator/calculator.component.ts         |  3 ++-
 src/app/formulaire/definition/form-definition.ts       | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts
index 6e9adab42..789305b9a 100644
--- a/src/app/components/generic-calculator/calculator.component.ts
+++ b/src/app/components/generic-calculator/calculator.component.ts
@@ -438,7 +438,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
      */
     private updateUIValidity() {
         this._isUIValid = false;
-
+        if (! this._formulaire.calculateDisabled) {
         if (this._fieldsetComponents !== undefined) {
             this._isUIValid = this._fieldsetComponents.reduce(
                 // callback
@@ -481,6 +481,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe
             this._isUIValid = this._isUIValid && this._pabTableComponent.isValid;
         }
     }
+    }
 
     public getElementStyleDisplay(id: string) {
         const isDisplayed: boolean = this._formulaire.isDisplayed(id);
diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts
index 4c55719f1..d2802bd02 100644
--- a/src/app/formulaire/definition/form-definition.ts
+++ b/src/app/formulaire/definition/form-definition.ts
@@ -45,6 +45,9 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs
     /** aide en ligne pour les résultats */
     protected _resultsHelpLinks: { [key: string]: string };
 
+    /** set to true to definitely gray-out Calculate button  */
+    protected _calculateDisabled = false;
+
     /** fichier de configuration */
     private _jsonConfig: {};
 
@@ -71,6 +74,10 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs
         }
     }
 
+    public get calculateDisabled(): boolean {
+        return this._calculateDisabled;
+    }
+
     public get specificLocalisation() {
         return this._specificLocalisation;
     }
@@ -160,6 +167,9 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs
         }
         this._helpLink = json["help"];
         this._resultsHelpLinks = json["resultsHelp"];
+        if (json["calculateDisabled"] !== undefined) {
+            this._calculateDisabled = json["calculateDisabled"];
+        }
     }
 
     /** called at the end of parseConfig() */
-- 
GitLab