diff --git a/src/app/calculators/parallel-structures/parallel-structures.config.json b/src/app/calculators/parallel-structures/parallel-structures.config.json index 3f1f91f918b8aadb17d7e93b2cc96ea6c13c9b70..990459e12efa70ecd468b6a0f7dc57375be8199c 100644 --- a/src/app/calculators/parallel-structures/parallel-structures.config.json +++ b/src/app/calculators/parallel-structures/parallel-structures.config.json @@ -2,6 +2,7 @@ { "id": "fs_param_hydro", "type": "fieldset", + "calcType": "ParallelStructure", "option": "cal", "fields": [ { @@ -26,56 +27,130 @@ ] }, { - "id": "fs_struct_cem88d", + "id": "fs_ouvrage", "type": "fieldset_template", "calcType": "Structure", - "nodeType": "StructureRectangle", - "structType": "Cem88d", + "nodeType": "None", "option": "cal", "fields": [ { - "type": "input", - "id": "ZDV", - "unit": "m", - "value": 1 + "id": "select_ouvrage", + "type": "select", + "select": [ + { + "id": "select_ouvrage_vanne_rect" + }, + { + "id": "select_ouvrage_vanne_circ" + }, + { + "id": "select_ouvrage_seuil_rect" + }, + { + "id": "select_ouvrage_seuil_trap" + }, + { + "id": "select_ouvrage_vanne_trap" + } + ] }, { - "type": "input", - "id": "L", - "unit": "m", - "value": 1 + "id": "select_loidebit1", + "type": "select", + "select": [ + { + "id": "select_loidebit1_cemagref88" + }, + { + "id": "select_loidebit1_vannedenoye" + }, + { + "id": "select_loidebit1_vannenoye" + } + ], + "dep_exist": [ + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_vanne_rect" + }, + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_vanne_circ" + }, + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_seuil_rect" + } + ] }, { - "type": "input", - "id": "Cd", - "value": 0.5 - } - ] - }, - { - "id": "fs_struct_cem88v", - "type": "fieldset_template", - "calcType": "Structure", - "nodeType": "StructureRectangle", - "structType": "Cem88v", - "option": "cal", - "fields": [ + "id": "select_loidebit2", + "type": "select", + "select": [ + { + "id": "select_loidebit2_cemagref88" + } + ], + "dep_exist": [ + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_seuil_trap" + }, + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_vanne_trap" + } + ] + }, { "type": "input", - "id": "ZDV", + "id": "W", "unit": "m", - "value": 1 + "value": 0.5, + "dep_exist": [ + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_vanne_rect" + }, + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_vanne_circ" + } + ] }, { "type": "input", "id": "L", "unit": "m", - "value": 1 + "value": 2, + "nodeType": "StructureRectangle", + "dep_exist": [ + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_vanne_rect" + }, + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_vanne_circ" + } + ] }, { "type": "input", "id": "Cd", - "value": 0.5 + "unit": "", + "value": 0.4, + "nodeType": "StructureRectangle", + "dep_exist": [ + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_vanne_rect" + }, + { + "refid": "select_ouvrage", + "refvalue": "select_ouvrage_vanne_circ" + } + ] } ] }, @@ -83,13 +158,13 @@ "id": "struct_container", "type": "template_container", "templates": [ - "fs_struct_cem88d", - "fs_struct_cem88v" + "fs_ouvrage" ] }, { "id": "fs_param_calc", "type": "fieldset", + "calcType": "ParallelStructure", "option": "fix", "fields": [ { @@ -101,4 +176,4 @@ { "type": "options" } -] \ No newline at end of file +] diff --git a/src/app/calculators/parallel-structures/parallel-structures.fr.json b/src/app/calculators/parallel-structures/parallel-structures.fr.json index e1845957330d709863de8bfa89f0c8c1c316a8e3..fa436a240d6d51f7ee101b4cf43bb483a5f3a5c7 100644 --- a/src/app/calculators/parallel-structures/parallel-structures.fr.json +++ b/src/app/calculators/parallel-structures/parallel-structures.fr.json @@ -3,12 +3,24 @@ "Q": "Débit total", "Z1": "Cote amont", "Z2": "Cote aval", - "fs_struct_cem88d": "Cem88d", + "fs_ouvrage": "Ouvrage", + "select_ouvrage": "Ouvrage", + "select_ouvrage_vanne_circ": "Vanne circulaire", + "select_ouvrage_vanne_rect": "Vanne rectangulaire", + "select_ouvrage_seuil_rect": "Seuil rectangulaire", + "select_ouvrage_seuil_trap": "Seuil trapézoïdal", + "select_ouvrage_vanne_trap": "Vanne trapézoïdale", + "W": "Ouverture de vanne", + "select_loidebit1": "Loi de débit", + "select_loidebit1_cemagref88": "Déversoir/Orifice Cemagref 88", + "select_loidebit1_vannedenoye": "Vanne dénoyé", + "select_loidebit1_vannenoye": "Vanne noyé", + "select_loidebit2": "Loi de débit", + "select_loidebit2_cemagref88": "Déversoir/Orifice Cemagref 88", "ZDV": "Cote de la crête du déversoir ou du radier de la vanne", "L": "Largeur du déversoir", "Cd": "Coefficient de débit", - "fs_struct_cem88v": "Cem88v", "struct_container": "Ouvrages", "fs_param_calc": "Paramètres de calcul", "Pr": "Précision de calcul" -} \ No newline at end of file +} diff --git a/src/app/components/fieldset-container/fieldset-container.component.html b/src/app/components/fieldset-container/fieldset-container.component.html index d29466053902fa9286b8b00e279665af64ab038b..65763fa18a30d3fbd58e59124e44d8c1b6e5d92e 100644 --- a/src/app/components/fieldset-container/fieldset-container.component.html +++ b/src/app/components/fieldset-container/fieldset-container.component.html @@ -2,6 +2,10 @@ <div class="row"> <h4>{{title}}</h4> </div> -</div> -<field-set *ngFor="let fs of fieldsets" [fieldSet]=fs> -</field-set> + <div class="row"> + <!-- bouton d'ajout d'un ouvrage --> + <button type="button" class="btn btn-grey waves-light" mdbRippleRadius (click)="addStructure()">Ajouter un ouvrage</button> + </div> + <field-set *ngFor="let fs of fieldsets" [fieldSet]=fs> + </field-set> +</div> \ No newline at end of file diff --git a/src/app/components/fieldset-container/fieldset-container.component.ts b/src/app/components/fieldset-container/fieldset-container.component.ts index 4cf663b58037b5e18f0044cff97bf711ca1c15c1..c5b5e492703b47500c8d2913de8fbcb7979b5a0c 100644 --- a/src/app/components/fieldset-container/fieldset-container.component.ts +++ b/src/app/components/fieldset-container/fieldset-container.component.ts @@ -16,7 +16,11 @@ export class FieldsetContainerComponent { return this._container.label; } - private get fielsets() { + private get fieldsets() { return this._container.fieldsets; } + + private addStructure() { + this._container.addFromTemplate(this._container.templates[0].id); + } } \ No newline at end of file diff --git a/src/app/formulaire/fieldset-container.ts b/src/app/formulaire/fieldset-container.ts index 3025fd96e1291a3b7e065179255e850f2b6729c3..67266e30352a75d2e0489c660e628888d54b2b6b 100644 --- a/src/app/formulaire/fieldset-container.ts +++ b/src/app/formulaire/fieldset-container.ts @@ -3,10 +3,13 @@ import { ComputeNodeType } from "jalhyd"; import { FormulaireElement } from "./formulaire-element"; import { FieldSet } from "./fieldset"; import { Dependency } from "./dependency"; +import { StringMap } from "../stringmap"; export class FieldsetContainer extends FormulaireElement { private _templates: FieldSet[]; + private _localisation: StringMap; + public title: string constructor(id: string, formId: number) { @@ -44,14 +47,31 @@ export class FieldsetContainer extends FormulaireElement { public addFromTemplate(templId: string) { const templ: FieldSet = this.getTemplate(templId); - this._templates.push(templ.instanciateTemplate()); + this.fieldsets.push(templ.instanciateTemplate()); + this.updateLocalisation() } public get fieldsets(): FieldSet[] { return this.kids as FieldSet[]; } + public get templates(): FieldSet[] { + return this._templates; + } + protected verifyDependency(d: Dependency): boolean { return true; } + + public updateLocalisation(loc?: StringMap) { + if (loc == undefined) + loc = this._localisation; + else + this._localisation = loc; + + super.updateLocalisation(loc); + + for (let t of this._templates) + t.updateLocalisation(loc); + } } diff --git a/src/app/formulaire/formulaire-definition.ts b/src/app/formulaire/formulaire-definition.ts index 8b4ae86299051ae4d3b4cc160d5e414a0d0865a3..14b55b6d301226f19b2522363f0fe93dcacc08c4 100644 --- a/src/app/formulaire/formulaire-definition.ts +++ b/src/app/formulaire/formulaire-definition.ts @@ -507,6 +507,8 @@ export class FormulaireDefinition extends Observable implements Observer { //, I dep.slaveValue = d["value"]; this._dependencies.push(dep); } + else + throw new Error(`la dépendance de valeur de '${slave.id}' fait référence à un élément inconnu '${d["refid"]}'`); } } @@ -540,6 +542,8 @@ export class FormulaireDefinition extends Observable implements Observer { //, I let dep = new ExistenceDependency(masterField, slave, mc); this._dependencies.push(dep); } + else + throw new Error(`la dépendance d'existence de '${slave.id}' fait référence à un élément inconnu '${d["refid"]}'`); } } @@ -583,8 +587,15 @@ export class FormulaireDefinition extends Observable implements Observer { //, I return res; } - private parse_input(calc_type: CalculatorType, node_type: ComputeNodeType, fieldset: {}, field: {}): NgParameter { + private parse_input(default_calc_type: CalculatorType, default_node_type: ComputeNodeType, fieldset: {}, field: {}): NgParameter { let input_id: string = field["id"]; + + const ct: string = field["calcType"]; + let calc_type: CalculatorType = ct == undefined ? default_calc_type : CalculatorType[ct]; + + const nt: string = field["nodeType"]; + let node_type: ComputeNodeType = nt == undefined ? default_node_type : ComputeNodeType[nt]; + let res: NgParameter = this.paramService.createParameter(calc_type, node_type, input_id, this._uid); if (res == undefined) throw new Error(`pas de paramètre '${input_id}' trouvé dans le noeud ${ComputeNodeType[node_type]} (${node_type}) ou ComputeNodeType.None`); @@ -636,6 +647,13 @@ export class FormulaireDefinition extends Observable implements Observer { //, I this.parse_dependencies(res, json); } + private getFieldsetTemplate(id: string) { + for (const t of this.topFieldsets) + if (t.id === id && t.isTemplate) + return t; + throw new Error(`Pas de template nommé '${id}'`); + } + private parse_template_container(json: {}) { const fsc_id: string = json["id"]; @@ -643,7 +661,7 @@ export class FormulaireDefinition extends Observable implements Observer { //, I const templs: string[] = json["templates"]; for (const t of templs) - fsc.addTemplate(this.getFieldSet(t)); + fsc.addTemplate(this.getFieldsetTemplate(t)); this.formElements.push(fsc); } diff --git a/src/app/formulaire/formulaire-element.ts b/src/app/formulaire/formulaire-element.ts index 2eecd25e9df733742783bf9d567020bb63044610..42f844a4248ced92be788e1bb020cf0f0bc699c4 100644 --- a/src/app/formulaire/formulaire-element.ts +++ b/src/app/formulaire/formulaire-element.ts @@ -75,6 +75,11 @@ export abstract class FormulaireElement { public updateLocalisation(loc: StringMap) { this._label = loc[this.id]; + if (this._label == undefined) + console.log(`WARNING : pas de traduction pour l'id ${this.id}`); + + for (let f of this.kids) + f.updateLocalisation(loc); } public toString() { diff --git a/src/app/formulaire/ngparam.ts b/src/app/formulaire/ngparam.ts index 0e394d02dd3b4ee700f9b2512acc801e7f63ab3a..d4f13fdd5b409c597ff7fe40aa77b5dae4fd2f5b 100644 --- a/src/app/formulaire/ngparam.ts +++ b/src/app/formulaire/ngparam.ts @@ -294,7 +294,8 @@ export class NgParameter extends InputField implements IObservable { res._minValue = this._minValue; res._maxValue = this._maxValue; res._stepValue = this._stepValue; - res._valueList = this._valueList.slice(0); // copîe + if (this._valueList != undefined) + res._valueList = this._valueList.slice(0); // copie return res; }