From e36958f48885cc508fc934e34e5c251f877d5659 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr>
Date: Wed, 31 May 2023 13:54:46 +0200
Subject: [PATCH] refactor: add some enums to enumFromProperty table

refs #335
---
 src/props.ts | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/props.ts b/src/props.ts
index 01743005..8f5bc1e9 100644
--- a/src/props.ts
+++ b/src/props.ts
@@ -1,18 +1,25 @@
 import { cloneDeep } from "lodash";
 
-import { BiefRegime, CalculatorType, DivingJetSupport, FishSpecies, GrilleProfile, GrilleType, IObservable, LCMaterial, LoiDebit, MRCInclination, MethodeResolution, Observable, Observer, ParType, PressureLossType, SPPOperation, SectionType, StructureType, TrigoOperation, TrigoUnit, isNumeric } from "./internal_modules";
+import { BiefRegime, CalculatorType, DivingJetSupport, FishSpecies, GrilleProfile, GrilleType, IObservable, LCMaterial, LoiDebit, MRCInclination, MacroRugoFlowType, MethodeResolution, Observable, Observer, ParFlowRegime, ParType, PressureLossType, SPPOperation, SectionType, StructureFlowMode, StructureFlowRegime, StructureJetType, StructureType, TrigoOperation, TrigoUnit, isNumeric } from "./internal_modules";
 
 /**
  * get enum numerical value from enum class name and value as a string
  * @param enumClass enum class name
- * @param enumValueName enum value as a string
+ * @param enumValue enum value as a string
  * @returns enum numerical value
  */
-export function enumValueFromString(enumClass: string, enumValueName: string): any {
+export function enumValueFromString(enumClass: string, enumValue: string | number): any {
     // !! property names must be unique throughout JaLHyd !!
-    const enumValues = Props.enumFromProperty[enumClass];
+    let enumValues;
+    const ec = enumClass.toLowerCase();
+    for (const k of Object.keys(Props.enumFromProperty)) {
+        if (k.toLowerCase() === ec) {
+            enumValues = Props.enumFromProperty[k];
+            break;
+        }
+    }
     if (enumValues) {
-        return enumValues[enumValueName];
+        return enumValues[enumValue];
     }
     throw new Error("unknown enum class ${enumClass}");
 }
@@ -59,7 +66,10 @@ export interface IProperties extends IObservable {
  */
 export class Props implements IProperties {
 
-    /** correspondance entre les noms de propriétés et les enum associés */
+    /**
+     * correspondance entre les noms de propriétés/enums et les enum associés
+     * (les propriétés commencent par une minuscule, les enums par une majuscule)
+     */
     public static readonly enumFromProperty: any = {
         calcType: CalculatorType,
         divingJetSupported: DivingJetSupport,
@@ -77,7 +87,12 @@ export class Props implements IProperties {
         sppOperation: SPPOperation,
         structureType: StructureType,
         trigoOperation: TrigoOperation,
-        trigoUnit: TrigoUnit
+        trigoUnit: TrigoUnit,
+        MacroRugoFlowType: MacroRugoFlowType,
+        StructureFlowMode: StructureFlowMode,
+        StructureFlowRegime: StructureFlowRegime,
+        StructureJetType: StructureJetType,
+        ParFlowRegime: ParFlowRegime
     };
 
     // implémentation de IObservable par délégation
-- 
GitLab