diff --git a/src/app/calculators/parallel-structures/parallel-structures.config.json b/src/app/calculators/parallel-structures/parallel-structures.config.json index 4386225537634e47d18c64fe804423d36c717768..754c7ad59e25617462c8effce9f0b2988ebc3a40 100644 --- a/src/app/calculators/parallel-structures/parallel-structures.config.json +++ b/src/app/calculators/parallel-structures/parallel-structures.config.json @@ -35,10 +35,12 @@ "type": "select", "select": [ { - "id": "select_ouvrage_vanne_rect" + "id": "select_ouvrage_vanne_rect", + "enum": "StructureType.VanneRectangulaire" }, { - "id": "select_ouvrage_seuil_rect" + "id": "select_ouvrage_seuil_rect", + "enum": "StructureType.SeuilRectangulaire" } ] }, @@ -47,19 +49,24 @@ "type": "select", "select": [ { - "id": "select_loidebit1_cem88d" + "id": "select_loidebit1_cem88d", + "enum": "LoiDebit.Cem88d" }, { - "id": "select_loidebit1_cem88v" + "id": "select_loidebit1_cem88v", + "enum": "LoiDebit.Cem88v" }, { - "id": "select_loidebit1_seuildenoye" + "id": "select_loidebit1_seuildenoye", + "enum": "LoiDebit.WeirFree" }, { - "id": "select_loidebit1_cunge80" + "id": "select_loidebit1_cunge80", + "enum": "LoiDebit.Cunge80" }, { - "id": "select_loidebit1_kivi" + "id": "select_loidebit1_kivi", + "enum": "LoiDebit.KIVI" } ], "dep_exist": [ @@ -74,19 +81,24 @@ "type": "select", "select": [ { - "id": "select_loidebit2_cem88v" + "id": "select_loidebit2_cem88v", + "enum": "LoiDebit.Cem88v" }, { - "id": "select_loidebit2_cem88d" + "id": "select_loidebit2_cem88d", + "enum": "LoiDebit.Cem88d" }, { - "id": "select_loidebit2_vannedenoye" + "id": "select_loidebit2_vannedenoye", + "enum": "LoiDebit.OrificeFree" }, { - "id": "select_loidebit2_vannenoye" + "id": "select_loidebit2_vannenoye", + "enum": "LoiDebit.OrificeSubmerged" }, { - "id": "select_loidebit2_cunge80" + "id": "select_loidebit2_cunge80", + "enum": "LoiDebit.Cunge80" } ], "dep_exist": [ diff --git a/src/app/calculators/section-param/section-param.config.json b/src/app/calculators/section-param/section-param.config.json index 4f896ad7b0584bfbf9493d1a127edda596964579..9740f86d109f9793560f6fb942687e9c907d3871 100644 --- a/src/app/calculators/section-param/section-param.config.json +++ b/src/app/calculators/section-param/section-param.config.json @@ -8,16 +8,20 @@ "type": "select", "select": [ { - "id": "select_section_trapez" + "id": "select_section_trapez", + "enum": "ComputeNodeType.SectionTrapeze" }, { - "id": "select_section_rect" + "id": "select_section_rect", + "enum": "ComputeNodeType.SectionRectangle" }, { - "id": "select_section_circ" + "id": "select_section_circ", + "enum": "ComputeNodeType.SectionCercle" }, { - "id": "select_section_puiss" + "id": "select_section_puiss", + "enum": "ComputeNodeType.SectionPuissance" } ] } @@ -212,55 +216,72 @@ "type": "select", "select": [ { - "id": "select_target_Hs" + "id": "select_target_Hs", + "value": "Hs" }, { - "id": "select_target_Hsc" + "id": "select_target_Hsc", + "value": "Hsc" }, { - "id": "select_target_B" + "id": "select_target_B", + "value": "B" }, { - "id": "select_target_P" + "id": "select_target_P", + "value": "P" }, { - "id": "select_target_S" + "id": "select_target_S", + "value": "S" }, { - "id": "select_target_R" + "id": "select_target_R", + "value": "R" }, { - "id": "select_target_V" + "id": "select_target_V", + "value": "V" }, { - "id": "select_target_Fr" + "id": "select_target_Fr", + "value": "Fr" }, { - "id": "select_target_Yc" + "id": "select_target_Yc", + "value": "Yc" }, { - "id": "select_target_Yn" + "id": "select_target_Yn", + "value": "Yn" }, { - "id": "select_target_Yf" + "id": "select_target_Yf", + "value": "Yf" }, { - "id": "select_target_Yt" + "id": "select_target_Yt", + "value": "Yt" }, { - "id": "select_target_Yco" + "id": "select_target_Yco", + "value": "Yco" }, { - "id": "select_target_J" + "id": "select_target_J", + "value": "J" }, { - "id": "select_target_I-J" + "id": "select_target_I-J", + "value": "I-J" }, { - "id": "select_target_Imp" + "id": "select_target_Imp", + "value": "Imp" }, { - "id": "select_target_Tau0" + "id": "select_target_Tau0", + "value": "Tau0" } ] } diff --git a/src/app/formulaire/definition/form-def-section.ts b/src/app/formulaire/definition/form-def-section.ts index 5cdf380a162a188eedd3428cd0855029f5e46de9..bfc65ea32d11577e60dd2b5a3e8d8cd85c61d354 100644 --- a/src/app/formulaire/definition/form-def-section.ts +++ b/src/app/formulaire/definition/form-def-section.ts @@ -54,23 +54,7 @@ export class FormDefSection implements Observer { } private getNodeTypeFromSelectField(): ComputeNodeType { - const sect = this._formBase.getSelectedValue(this._sectionSelectFieldId); - switch (sect) { - case "trapez": - return ComputeNodeType.SectionTrapeze; - - case "rect": - return ComputeNodeType.SectionRectangle; - - case "circ": - return ComputeNodeType.SectionCercle; - - case "puiss": - return ComputeNodeType.SectionPuissance; - - default: - throw new Error(`getComputeNodeTypeFromSection() : section ${sect} non pris en charge`); - } + return this._formBase.getSelectedValue(this._sectionSelectFieldId); } public initParse() { diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index 6eec33bc9d52f2195fff264f0364b8202706428f..081f7913407f55e070f6b9af3a877e6cbd445914 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -265,10 +265,9 @@ export abstract class FormulaireDefinition extends FormulaireNode { * @param selectFieldId id du SelectField * @returns valeur courante du select sans le préfixe */ - public getSelectedValue(selectFieldId: string): string { + public getSelectedValue(selectFieldId: string): any { let select: SelectField = <SelectField>this.getFieldById(selectFieldId); - let value: string = select.getValue().value; - return FormulaireElement.removePrefix(value, selectFieldId + "_"); + return select.getValue().value; } /** diff --git a/src/app/formulaire/select-entry.ts b/src/app/formulaire/select-entry.ts index 07c1eae7e9f26211bc4aa8209f988ef1e0a4e637..8da49428e9fa9e06ee76f4ceae143cb5137208a3 100644 --- a/src/app/formulaire/select-entry.ts +++ b/src/app/formulaire/select-entry.ts @@ -1,13 +1,30 @@ export class SelectEntry { - private _value: string; + /** + * id dans le fichier de config + */ + private _id: string; + + /** + * valeur associée à l'entrée + */ + private _value: any; + + /** + * texte affiché pour cette entrée + */ public label: string; - constructor(v: string, l: string) { - this._value = v; - this.label = l; + constructor(id: string, val: any, lbl?: string) { + this._id = id; + this._value = val; + this.label = lbl; + } + + get id(): string { + return this._id; } - get value(): string { + get value(): any { return this._value; } } diff --git a/src/app/formulaire/select-field.ts b/src/app/formulaire/select-field.ts index 65bfbfc9480416f38e37fbf7d3cbd82477819ca6..200963db644cf8225d17ee108fa87a5cb7d87c2e 100644 --- a/src/app/formulaire/select-field.ts +++ b/src/app/formulaire/select-field.ts @@ -1,3 +1,5 @@ +import { StructureType, LoiDebit, ComputeNodeType } from "jalhyd"; + import { Field } from "./field"; import { SelectEntry } from "./select-entry"; import { Dependency } from "./dependency/dependency"; @@ -26,6 +28,13 @@ export class SelectField extends Field { this._selectedEntry = e; } + public getSelectedEntryFromValue(val: any): SelectEntry { + for (const se of this._entries) + if (se.value === val) + return se; + return undefined; + } + public getValue() { return this._selectedEntry; } @@ -54,7 +63,7 @@ export class SelectField extends Field { switch (d.masterCondition.type) { case DependencyConditionType.HasValue: let mc: ValueDependencyCondition = <ValueDependencyCondition>d.masterCondition; - return this._selectedEntry.value === mc.value; + return this._selectedEntry.id === mc.value; default: throw "SelectField.verifyDependency() : type de condition '" + DependencyConditionType[d.masterCondition.type] + "' non pris en charge"; @@ -65,7 +74,7 @@ export class SelectField extends Field { super.updateLocalisation(loc); for (let e of this._entries) { - e.label = loc[e.value]; + e.label = loc[e.id]; } } @@ -89,7 +98,28 @@ export class SelectField extends Field { this._confId = field["id"]; const values = field["select"]; for (const v of values) { - const e: SelectEntry = new SelectEntry(v["id"], undefined); + let val; + if (v.enum) { + const tmp = v.enum.split("."); + switch (tmp[0]) { + case "ComputeNodeType": + val = ComputeNodeType[tmp[1]]; + break; + + case "StructureType": + val = StructureType[tmp[1]]; + break; + + case "LoiDebit": + val = LoiDebit[tmp[1]]; + break; + } + } + else if (v.value) + val = v.value; + + const id = v["id"]; + const e: SelectEntry = new SelectEntry(id, val); this.addEntry(e); } }