From c6b1c461f65effb89be80543e684c76bb71e6ec3 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Tue, 23 Jun 2020 16:38:00 +0200 Subject: [PATCH] [WIP] PbCloison form --- .../formulaire/definition/form-prebarrage.ts | 20 ++++++++++++++++++- src/app/formulaire/elements/select-field.ts | 10 +++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts index dd175247a..7d69abf7a 100644 --- a/src/app/formulaire/definition/form-prebarrage.ts +++ b/src/app/formulaire/definition/form-prebarrage.ts @@ -5,6 +5,7 @@ import { PbSchema } from "../elements/pb-schema"; import { FormulaireDefinition } from "./form-definition"; import { ServiceFactory } from "../../services/service-factory"; import { FormulairePbCloison } from "./form-pb-cloison"; +import { FieldsetContainer } from "../elements/fieldset-container"; /** * Formulaire pour les PréBarrage @@ -100,12 +101,29 @@ export class FormulairePrebarrage extends FormulaireFixedVar { this.showFormElements(this.basinForm); } else if (node instanceof PbCloison) { + console.log("---------------> new wall form !!"); this.wallForm = new FormulairePbCloison(); this.wallForm.defaultProperties["calcType"] = CalculatorType.PbCloison; this.wallForm.currentNub = node; this.wallForm.preparseConfig(this.wallFormConfig); this.wallForm.parseConfig(this.wallFormConfig); - this.wallForm.addObserver(this); // subscribe to upstream/downstream basin change + // add fieldsets for existing Structures + console.log(`Node ${node.uid} : ${node.structures.length} structures, Form ${this.uid} : ${this._kids.length} form elements`); + if (node.structures.length > 0) { + console.log(">> adding fieldsets for existing structures"); + for (const struct of node.structures) { + for (const e of this.allFormElements) { + if (e instanceof FieldsetContainer) { // @TODO manage many containers one day ? + e.addFromTemplate(0, undefined, struct); + } + } + } + } else { + // if there was no existing structure, add a default one ! @TODO + console.log("TODO add default structure"); + } + // subscribe to upstream/downstream basin change + this.wallForm.addObserver(this); ServiceFactory.instance.formulaireService.loadUpdateFormulaireLocalisation(this.wallForm); this.showFormElements(this.wallForm); } diff --git a/src/app/formulaire/elements/select-field.ts b/src/app/formulaire/elements/select-field.ts index 220fc7e2d..468dca562 100644 --- a/src/app/formulaire/elements/select-field.ts +++ b/src/app/formulaire/elements/select-field.ts @@ -5,7 +5,8 @@ import { StructureType, LoiDebit, Session, - Solveur + Solveur, + StructureProperties } from "jalhyd"; import { Field } from "./field"; @@ -192,9 +193,12 @@ export class SelectField extends Field { case "device_loi_debit": // get current structure type from appropriate Nub child const child = nub.getChildren()[this.parent.indexAsKid()]; - const cst = child.properties.getPropValue("structureType"); const la = (nub as ParallelStructure).getLoisAdmissibles(); - const stName = StructureType[cst]; + const loiDebit = child.properties.getPropValue("loiDebit"); + const stCode = StructureProperties.findCompatibleStructure(loiDebit, nub as ParallelStructure); + const stName = StructureType[stCode]; + // console.log(`__device_loi_debit__ : child=${child.constructor.name}, loiDebit=${loiDebit}, stCode=${stCode}, stName=${stName}`); + // console.log("(child.properties)", child.properties.props); for (const ld of la[stName]) { const e: SelectEntry = new SelectEntry(this._entriesBaseId + LoiDebit[ld], ld); this.addEntry(e); -- GitLab