From 1522b18cd93b5ee0c4126d7e085d6007a4c818dc Mon Sep 17 00:00:00 2001
From: Jean-Pascal <jean-pascal.aubry@inrae.fr>
Date: Mon, 3 Jun 2024 15:06:22 +0000
Subject: [PATCH] fix: display solver field labels and empty error messages
 Refs #                 668

---
 .../formulaire/elements/formulaire-element.ts |  7 +++---
 .../select/select-field-searched-param.ts     | 13 ++++++++---
 .../select-field-solver-targeted-result.ts    |  3 ++-
 .../select/select-field-solveur-target.ts     | 12 ++++++++--
 .../elements/select/select-field.ts           | 22 ++++++++++---------
 5 files changed, 37 insertions(+), 20 deletions(-)

diff --git a/src/app/formulaire/elements/formulaire-element.ts b/src/app/formulaire/elements/formulaire-element.ts
index 25b5943fa..6005f2baa 100644
--- a/src/app/formulaire/elements/formulaire-element.ts
+++ b/src/app/formulaire/elements/formulaire-element.ts
@@ -71,13 +71,12 @@ export abstract class FormulaireElement extends FormulaireNode {
 
     /**
      * Updates localisation for this element: first the label then all the element's children
-     * @param loc calculator-specific localised messages map
-     * @param key Element label key
+     * @param fromConfig if false avoid call of selectField.updateLocalisation()
      */
-    public updateLocalisation() {
+    public updateLocalisation(fromConfig: boolean = true) {
         this._label = this.formulaireService.localizeText(this._confId, this.parentForm.currentNub.calcType);
         for (const f of this.getKids()) {
-            f.updateLocalisation();
+            f.updateLocalisation(fromConfig);
         }
     }
 
diff --git a/src/app/formulaire/elements/select/select-field-searched-param.ts b/src/app/formulaire/elements/select/select-field-searched-param.ts
index 978cdebc9..c4b2c779d 100644
--- a/src/app/formulaire/elements/select/select-field-searched-param.ts
+++ b/src/app/formulaire/elements/select/select-field-searched-param.ts
@@ -3,6 +3,8 @@ import { decodeHtml } from "app/util/util";
 import { acSection, Nub, Solveur } from "jalhyd";
 import { SelectEntry } from "./select-entry";
 import { SelectField } from "./select-field";
+import { FormulaireNode } from "../formulaire-node";
+import { FormulaireElement } from "../formulaire-element";
 
 /*
     "id": "select_searched_param",
@@ -12,6 +14,11 @@ import { SelectField } from "./select-field";
 
 // Solveur, paramètre recherché (à faire varier)
 export class SelectFieldSearchedParam extends SelectField {
+    constructor(parent: FormulaireNode) {
+        super(parent);
+        this._messageWhenEmpty = "INFO_VERIF_SOLVER_SEARCHED_PARAM";
+    }
+
     protected populate() {
         const fs = ServiceFactory.formulaireService;
 
@@ -28,7 +35,7 @@ export class SelectFieldSearchedParam extends SelectField {
             if (p.visible) {
                 let calcTitle;
                 // if form already exist
-                if(fs.getFormulaireFromId(p.originNub.uid)) {
+                if (fs.getFormulaireFromId(p.originNub.uid)) {
                     calcTitle = fs.getFormulaireFromId(p.originNub.uid).calculatorName;
                 }
                 // prevent issue #369 (loading session)
@@ -58,7 +65,7 @@ export class SelectFieldSearchedParam extends SelectField {
     }
 
     public updateLocalisation() {
-        // do not override localisation done in populate()
-        // ie. avoid what is done by SelectField.updateLocalisation()
+        // call grand parent updateLocalisation()
+        super.updateLocalisation(false);
     }
 }
diff --git a/src/app/formulaire/elements/select/select-field-solver-targeted-result.ts b/src/app/formulaire/elements/select/select-field-solver-targeted-result.ts
index 36094a8dd..fd1537b40 100644
--- a/src/app/formulaire/elements/select/select-field-solver-targeted-result.ts
+++ b/src/app/formulaire/elements/select/select-field-solver-targeted-result.ts
@@ -40,7 +40,8 @@ export class SelectFieldSolverTargetedResult extends SelectField {
     }
 
     public updateLocalisation() {
-        FormulaireElement.prototype.updateLocalisation.call(this);
+        // call grand parent updateLocalisation()
+        super.updateLocalisation(false);
         for (const e of this._entries) {
             // @WARNING clodo hack for Solveur
             // 1. calculated param
diff --git a/src/app/formulaire/elements/select/select-field-solveur-target.ts b/src/app/formulaire/elements/select/select-field-solveur-target.ts
index 3d752aa43..fb3eba4c3 100644
--- a/src/app/formulaire/elements/select/select-field-solveur-target.ts
+++ b/src/app/formulaire/elements/select/select-field-solveur-target.ts
@@ -9,9 +9,17 @@ import { decodeHtml } from "../../../util/util";
 import { Session, Solveur } from "jalhyd";
 import { SelectEntry } from "./select-entry";
 import { SelectField } from "./select-field";
+import { FormulaireElement } from "../formulaire-element";
+import { FormulaireNode } from "../formulaire-node";
 
 // Solveur, module cible (à calculer)
 export class SelectFieldSolverTarget extends SelectField {
+
+    constructor(parent: FormulaireNode) {
+        super(parent);
+        this._messageWhenEmpty = "INFO_VERIF_CREATE_ATLEAST_ONE_TARGETNUB";
+    }
+
     protected populate() {
 
         const fs = ServiceFactory.formulaireService;
@@ -48,7 +56,7 @@ export class SelectFieldSolverTarget extends SelectField {
     }
 
     public updateLocalisation() {
-        // do not override localisation done in populate()
-        // ie. avoid what is done by SelectField.updateLocalisation()
+        // call grand parent updateLocalisation()
+        super.updateLocalisation(false);
     }
 }
diff --git a/src/app/formulaire/elements/select/select-field.ts b/src/app/formulaire/elements/select/select-field.ts
index d4d1cf2c3..425cfd192 100644
--- a/src/app/formulaire/elements/select/select-field.ts
+++ b/src/app/formulaire/elements/select/select-field.ts
@@ -4,7 +4,7 @@ import { arraysAreEqual } from "../../../util/util";
 import { FormulaireNode } from "../formulaire-node";
 import { ServiceFactory } from "app/services/service-factory";
 import { FormulaireDefinition } from "../../definition/form-definition";
-import { enumValueFromString, Message, Nub } from "jalhyd";
+import { enumValueFromString, Message, Nub, PabChute, SectionNub } from "jalhyd";
 
 export abstract class SelectField extends Field {
 
@@ -296,7 +296,7 @@ export abstract class SelectField extends Field {
     public isEmptySelectField() {
         return this._selectedEntry !== undefined && Object.keys(this._selectedEntry).length === 0;
     }
-    
+
 
     public get messageWhenEmpty(): string {
         let msg: string;
@@ -314,15 +314,17 @@ export abstract class SelectField extends Field {
         return this._multiple;
     }
 
-    public updateLocalisation() {
+    public updateLocalisation(fromConfig: boolean = true) {
         super.updateLocalisation();
-        for (const e of this._entries) {
-            const aId = e.id.split("_");
-            const trad = ServiceFactory.formulaireService.localizeText(
-                `${aId[1].toUpperCase()}_${aId[2]}`,
-                this.parentForm.currentNub.calcType
-            );
-            e.label = trad;
+        if (fromConfig) {
+            for (const e of this._entries) {
+                const aId = e.id.split("_");
+                const trad = ServiceFactory.formulaireService.localizeText(
+                    `${aId[1].toUpperCase()}_${aId[2]}`,
+                    this.parentForm.currentNub.calcType
+                );
+                e.label = trad;
+            }
         }
     }
 }
-- 
GitLab