From 1ca4cea46e5d64769fcde48b34c33cbec60c4ca7 Mon Sep 17 00:00:00 2001
From: "mathias.chouet" <mathias.chouet@irstea.fr>
Date: Thu, 11 Apr 2019 17:02:56 +0200
Subject: [PATCH] =?UTF-8?q?Fix=20#189=20ajout=20du=20module=20Passe=20?=
 =?UTF-8?q?=C3=A0=20bassin=20-=20nombre=20de=20bassins?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

simplification des chemins de configuration des modules
---
 .../pab-nombre/pab-nombre.config.json         | 29 +++++++
 .../calculators/pab-nombre/pab-nombre.en.json |  6 ++
 .../calculators/pab-nombre/pab-nombre.fr.json |  6 ++
 .../services/formulaire/formulaire.service.ts | 78 ++++++-------------
 src/locale/messages.en.json                   |  5 +-
 src/locale/messages.fr.json                   |  5 +-
 6 files changed, 72 insertions(+), 57 deletions(-)
 create mode 100644 src/app/calculators/pab-nombre/pab-nombre.config.json
 create mode 100644 src/app/calculators/pab-nombre/pab-nombre.en.json
 create mode 100644 src/app/calculators/pab-nombre/pab-nombre.fr.json

diff --git a/src/app/calculators/pab-nombre/pab-nombre.config.json b/src/app/calculators/pab-nombre/pab-nombre.config.json
new file mode 100644
index 000000000..1534195af
--- /dev/null
+++ b/src/app/calculators/pab-nombre/pab-nombre.config.json
@@ -0,0 +1,29 @@
+[
+    {
+        "id": "fs_nombre",
+        "type": "fieldset",
+        "option": "cal",
+        "fields": [
+            {
+                "type": "input",
+                "id": "DHT",
+                "unit": "m"
+            },
+            {
+                "type": "input",
+                "id": "N",
+                "unit": ""
+            },
+            {
+                "type": "input",
+                "id": "DH",
+                "unit": "m"
+            }
+        ]
+    },
+    {
+        "type": "options",
+        "idCal": "N",
+        "help": "pab/nombre"
+    }
+]
\ No newline at end of file
diff --git a/src/app/calculators/pab-nombre/pab-nombre.en.json b/src/app/calculators/pab-nombre/pab-nombre.en.json
new file mode 100644
index 000000000..2af024c56
--- /dev/null
+++ b/src/app/calculators/pab-nombre/pab-nombre.en.json
@@ -0,0 +1,6 @@
+{
+    "fs_nombre": "Basin dimensions",
+    "DHT": "Total fall",
+    "N": "Number of basins",
+    "DH": "Fall between basins"
+}
\ No newline at end of file
diff --git a/src/app/calculators/pab-nombre/pab-nombre.fr.json b/src/app/calculators/pab-nombre/pab-nombre.fr.json
new file mode 100644
index 000000000..bee20ccb8
--- /dev/null
+++ b/src/app/calculators/pab-nombre/pab-nombre.fr.json
@@ -0,0 +1,6 @@
+{
+    "fs_nombre": "Dimensions du bassin",
+    "DHT": "Chute totale",
+    "N": "Nombre de bassins",
+    "DH": "Chute entre bassins"
+}
\ No newline at end of file
diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts
index d8a6e6830..1f80b90b4 100644
--- a/src/app/services/formulaire/formulaire.service.ts
+++ b/src/app/services/formulaire/formulaire.service.ts
@@ -25,6 +25,9 @@ import { NotificationsService } from "../notifications/notifications.service";
 
 @Injectable()
 export class FormulaireService extends Observable {
+
+    private calculatorPaths = {};
+
     /** list of known forms */
     private _formulaires: FormulaireDefinition[];
 
@@ -32,7 +35,6 @@ export class FormulaireService extends Observable {
 
     /** to avoid loading language files multiple times */
     private languageCache = {};
-
     constructor(
         private i18nService: I18nService,
         private appSetupService: ApplicationSetupService,
@@ -42,6 +44,22 @@ export class FormulaireService extends Observable {
     ) {
         super();
         this._formulaires = [];
+
+        // register calculator config paths here
+        this.calculatorPaths[CalculatorType.ConduiteDistributrice] = "cond_distri";
+        this.calculatorPaths[CalculatorType.LechaptCalmon] = "lechapt-calmon";
+        this.calculatorPaths[CalculatorType.SectionParametree] = "section-param";
+        this.calculatorPaths[CalculatorType.RegimeUniforme] = "regime-uniforme";
+        this.calculatorPaths[CalculatorType.CourbeRemous] = "remous";
+        this.calculatorPaths[CalculatorType.PabChute] = "pab-chute";
+        this.calculatorPaths[CalculatorType.PabDimensions] = "pab-dimensions";
+        this.calculatorPaths[CalculatorType.PabNombre] = "pab-nombre";
+        this.calculatorPaths[CalculatorType.PabPuissance] = "pab-puissance";
+        this.calculatorPaths[CalculatorType.Structure] = "ouvrages";
+        this.calculatorPaths[CalculatorType.ParallelStructure] = "parallel-structures";
+        this.calculatorPaths[CalculatorType.Dever] = "dever";
+        this.calculatorPaths[CalculatorType.Cloisons] = "cloisons";
+        this.calculatorPaths[CalculatorType.MacroRugo] = "macrorugo";
     }
 
     private get _intlService(): I18nService {
@@ -172,13 +190,6 @@ export class FormulaireService extends Observable {
     private newFormulaire(ct: CalculatorType, jsonState?: {}): FormulaireDefinition {
         let f: FormulaireDefinition;
         switch (ct) {
-            case CalculatorType.ConduiteDistributrice:
-            case CalculatorType.PabChute:
-            case CalculatorType.PabDimensions:
-            case CalculatorType.PabPuissance:
-            case CalculatorType.MacroRugo:
-                f = new FormulaireBase();
-                break;
 
             case CalculatorType.LechaptCalmon:
                 f = new FormulaireLechaptCalmon();
@@ -203,7 +214,7 @@ export class FormulaireService extends Observable {
                 break;
 
             default:
-                throw new Error(`FormulaireService.newFormulaire() : type de module de calcul ${CalculatorType[ct]} non pris en charge`);
+                f = new FormulaireBase();
         }
 
         f.defaultProperties["calcType"] = ct;
@@ -338,53 +349,10 @@ export class FormulaireService extends Observable {
     }
 
     public getConfigPathPrefix(ct: CalculatorType): string {
-        if (ct === undefined) {
-            throw new Error("FormulaireService.getConfigPathPrefix() : CalculatorType is undefined");
-        }
-
-        switch (ct) {
-            case CalculatorType.ConduiteDistributrice:
-                return "app/calculators/cond_distri/cond_distri.";
-
-            case CalculatorType.LechaptCalmon:
-                return "app/calculators/lechapt-calmon/lechapt-calmon.";
-
-            case CalculatorType.SectionParametree:
-                return "app/calculators/section-param/section-param.";
-
-            case CalculatorType.RegimeUniforme:
-                return "app/calculators/regime-uniforme/regime-uniforme.";
-
-            case CalculatorType.CourbeRemous:
-                return "app/calculators/remous/remous.";
-
-            case CalculatorType.PabDimensions:
-                return "app/calculators/pab-dimensions/pab-dimensions.";
-
-            case CalculatorType.PabPuissance:
-                return "app/calculators/pab-puissance/pab-puissance.";
-
-            case CalculatorType.Structure:
-                return "app/calculators/ouvrages/ouvrages.";
-
-            case CalculatorType.ParallelStructure:
-                return "app/calculators/parallel-structures/parallel-structures.";
-
-            case CalculatorType.Dever:
-                return "app/calculators/dever/dever.";
-
-            case CalculatorType.Cloisons:
-                return "app/calculators/cloisons/cloisons.";
-
-            case CalculatorType.MacroRugo:
-                return "app/calculators/macrorugo/macrorugo.";
-
-            case CalculatorType.PabChute:
-                return "app/calculators/pab-chute/pab-chute.";
-
-            default:
-                throw new Error("FormulaireService.getConfigPathPrefix() : valeur de CalculatorType " + ct + " non implémentée");
+        if (! this.calculatorPaths.hasOwnProperty(ct)) {
+            throw new Error("FormulaireService.getConfigPathPrefix() : valeur de CalculatorType " + ct + " non implémentée");
         }
+        return "app/calculators/" + this.calculatorPaths[ct] + "/"  + this.calculatorPaths[ct] + ".";
     }
 
     /**
diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json
index 0a6edaaad..1772e4a1c 100644
--- a/src/locale/messages.en.json
+++ b/src/locale/messages.en.json
@@ -80,6 +80,7 @@
     "INFO_EXTRARES_LIB_B": "Surface width (m)",
     "INFO_EXTRARES_LIB_CV": "Cv: Velocity coefficient",
     "INFO_EXTRARES_LIB_CVQT": "CV.QT: Corrected discharge (m³/s)",
+    "INFO_EXTRARES_LIB_DHR": "DHR : Residual fall (m)",
     "INFO_EXTRARES_LIB_EC": "EC: Kinetic energy (m)",
     "INFO_EXTRARES_LIB_ENUM_MACRORUGOFLOWTYPE": "Flow type",
     "INFO_EXTRARES_LIB_FLU": "Subcritical water line",
@@ -156,9 +157,11 @@
     "INFO_OPTION_NONE_F": "None",
     "INFO_OUVRAGE": "Structure",
     "INFO_PABCHUTE_TITRE": "Fish ladder: fall",
-    "INFO_PABCHUTE_TITRE_COURT": "FL: fall",
+    "INFO_PABCHUTE_TITRE_COURT": "FL: fall between basins",
     "INFO_PABDIMENSIONS_TITRE": "Fish ladder: dimensions",
     "INFO_PABDIMENSIONS_TITRE_COURT": "FL: dimensions",
+    "INFO_PABNOMBRE_TITRE": "Fish ladder : number of basins",
+    "INFO_PABNOMBRE_TITRE_COURT": "FL : number",
     "INFO_PABPUISSANCE_TITRE": "Fish ladder: dissipated power",
     "INFO_PABPUISSANCE_TITRE_COURT": "FL: diss. power",
     "INFO_PARALLELSTRUCTURE_TITRE": "Parallel structures",
diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json
index d1457e74f..88e8961ce 100644
--- a/src/locale/messages.fr.json
+++ b/src/locale/messages.fr.json
@@ -80,6 +80,7 @@
     "INFO_EXTRARES_LIB_B": "Largeur au miroir (m)",
     "INFO_EXTRARES_LIB_CV": "Cv: Coefficient de vitesse d'approche",
     "INFO_EXTRARES_LIB_CVQT": "CV.QT: Débit corrigé (m³/s)",
+    "INFO_EXTRARES_LIB_DHR": "DHR: Chute résiduelle (m)",
     "INFO_EXTRARES_LIB_EC": "EC: Énergie cinétique (m)",
     "INFO_EXTRARES_LIB_ENUM_MACRORUGOFLOWTYPE": "Type d'écoulement",
     "INFO_EXTRARES_LIB_FLU": "Ligne d'eau fluviale",
@@ -155,10 +156,12 @@
     "INFO_OPTION_NONE": "Aucun",
     "INFO_OPTION_NONE_F": "Aucune",
     "INFO_OUVRAGE": "Ouvrage",
-    "INFO_PABCHUTE_TITRE": "Passe à bassin&nbsp;: chute",
+    "INFO_PABCHUTE_TITRE": "Passe à bassin&nbsp;: chute entre bassins",
     "INFO_PABCHUTE_TITRE_COURT": "PAB&nbsp;: chute",
     "INFO_PABDIMENSIONS_TITRE": "Passe à bassin&nbsp;: dimensions",
     "INFO_PABDIMENSIONS_TITRE_COURT": "PAB&nbsp;: dimensions",
+    "INFO_PABNOMBRE_TITRE": "Passe à bassin&nbsp;: nombre de bassins",
+    "INFO_PABNOMBRE_TITRE_COURT": "PAB&nbsp;: nombre",
     "INFO_PABPUISSANCE_TITRE": "Passe à bassin&nbsp;: puissance dissipée",
     "INFO_PABPUISSANCE_TITRE_COURT": "PAB&nbsp;: puissance",
     "INFO_PARALLELSTRUCTURE_TITRE": "Lois d'ouvrages",
-- 
GitLab