Commit e36958f4 authored by Grand Francois's avatar Grand Francois
Browse files

refactor: add some enums to enumFromProperty table

refs #335
parent 867938cc
No related merge requests found
Showing with 22 additions and 7 deletions
+22 -7
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
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment