From 2964b3391786b957414b01dee8effb6598ffd178 Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Mon, 29 Apr 2019 17:46:04 +0200
Subject: [PATCH] [WIP] properly separating singleValue and currntValue
 concepts

---
 src/app/components/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                                | 4 ++--
 4 files changed, 5 insertions(+), 11 deletions(-)

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..bf012039c 100644
--- a/src/app/formulaire/ngparam.ts
+++ b/src/app/formulaire/ngparam.ts
@@ -266,8 +266,8 @@ 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
      */
     public getValue() {
         return this._paramDef.getValue();
-- 
GitLab