diff --git a/src/props.ts b/src/props.ts index 01743005bfdd85440e6dbe2fc701d1a321e2f236..8f5bc1e9dfc6e0dcdfb1b374b9e18fa706cd4b6b 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