From 4a8ed8bc65451d7d911307430e722b45bf13e146 Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Tue, 30 Apr 2019 17:48:53 +0200
Subject: [PATCH] =?UTF-8?q?Adaptation=20=C3=A0=20JaLHyd=20:=20properly=20s?=
 =?UTF-8?q?eparating=20singleValue=20and=20currentValue=20concepts?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Panneau des résultats fixés: protection contre un résultat vide
Mode calcul : protection contre valeur non définie
---
 .../fixedvar-results/fixed-results.component.ts       |  1 +
 .../ngparam-input/ngparam-input.component.ts          |  4 +---
 .../param-field-line/param-field-line.component.ts    |  3 ---
 src/app/formulaire/definition/form-compute.ts         |  5 ++---
 src/app/formulaire/ngparam.ts                         | 11 ++++++++---
 5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/app/components/fixedvar-results/fixed-results.component.ts b/src/app/components/fixedvar-results/fixed-results.component.ts
index 182ed6f68..a6909ac0b 100644
--- a/src/app/components/fixedvar-results/fixed-results.component.ts
+++ b/src/app/components/fixedvar-results/fixed-results.component.ts
@@ -84,6 +84,7 @@ export class FixedResultsComponent {
         const res = this._fixedResults.result;
         if (
             res
+            && res.nbResultElements > 0
             && res.resultElement
             && res.extraResults
         ) {
diff --git a/src/app/components/ngparam-input/ngparam-input.component.ts b/src/app/components/ngparam-input/ngparam-input.component.ts
index 2717729d8..c61a4fb78 100644
--- a/src/app/components/ngparam-input/ngparam-input.component.ts
+++ b/src/app/components/ngparam-input/ngparam-input.component.ts
@@ -47,9 +47,7 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse
      */
     protected afterSetModel() {
         if (this._paramDef) {
-            if (this._paramDef.isDefined) {
-                this._tmp = this._paramDef.getValue();
-            }
+            this._tmp = this._paramDef.getValue();
             this._paramDef.addObserver(this);
         }
     }
diff --git a/src/app/components/param-field-line/param-field-line.component.ts b/src/app/components/param-field-line/param-field-line.component.ts
index 8aae7a7c7..df956b33a 100644
--- a/src/app/components/param-field-line/param-field-line.component.ts
+++ b/src/app/components/param-field-line/param-field-line.component.ts
@@ -208,9 +208,6 @@ export class ParamFieldLineComponent implements OnChanges {
         switch (option) {
             case "fix":
                 this.param.valueMode = ParamValueMode.SINGLE;
-                // reset the value to avoid "undefined" after exiting CALC or LINK mode
-                // @TODO not always necessary; find out why
-                this.param.setValue(this, this.param.paramDefinition.singleValue);
                 break;
 
             case "var":
diff --git a/src/app/formulaire/definition/form-compute.ts b/src/app/formulaire/definition/form-compute.ts
index 64dd70555..af5c587cd 100644
--- a/src/app/formulaire/definition/form-compute.ts
+++ b/src/app/formulaire/definition/form-compute.ts
@@ -43,9 +43,8 @@ export abstract class FormCompute implements Observer {
             computedParam = nub.calculatedParam;
         }
 
-        // require chain computation; redundant with Nub.CalcSerie but required
-        // to get initial value here...
-        const computedParamValue = computedParam.getValue();
+        // const computedParamValue = computedParam.getValue();
+        const computedParamValue = computedParam.singleValue;
 
         switch (computedParam.domain.domain) {
             case ParamDomainValue.ANY:
diff --git a/src/app/formulaire/ngparam.ts b/src/app/formulaire/ngparam.ts
index 5681b58cd..294bbc53f 100644
--- a/src/app/formulaire/ngparam.ts
+++ b/src/app/formulaire/ngparam.ts
@@ -266,11 +266,16 @@ export class NgParameter extends InputField implements Observer {
     }
 
     /**
-     * Asks the ParamDefinition for its current value
-     * @TODO replace with singleValue to avoid displaying computation results ?
+     * Asks the ParamDefinition for its singleValue (not currentValue,
+     * to avoid displaying computation results); calculated linked
+     * value might not be available yet
      */
     public getValue() {
-        return this._paramDef.getValue();
+        try {
+            return this._paramDef.getValue();
+        } catch (error) {
+            return undefined;
+        }
     }
 
     /**
-- 
GitLab