From e3b028f83c60745448e5d3014b74649c7afa426a Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Wed, 27 Feb 2019 14:32:36 +0100 Subject: [PATCH] =?UTF-8?q?Am=C3=A9lioration=20des=20Fieldset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gestion des propriétés varCalc et methodeResolution suppression du proxy de Props (accès direct aux Props du Nub) courbe de remous: transmission de varCalc et methodeResolution comme propriétés du Nub --- .../calculator.component.ts | 1 - .../definition/concrete/form-courbe-remous.ts | 5 +- .../definition/form-compute-courbe-remous.ts | 11 +- .../formulaire/definition/form-definition.ts | 4 +- src/app/formulaire/fieldset.ts | 121 +++++++++++------- 5 files changed, 82 insertions(+), 60 deletions(-) diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index 1dfdd380e..14e30fc0a 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -402,7 +402,6 @@ export class GenericCalculatorComponent extends BaseComponent implements OnInit, * Duplicates the current calculator form */ public cloneCalculator() { - // console.log("__Nubs en session avt", Session.getInstance()["_nubs"].length); const serialisedNub: string = this._formulaire.currentNub.serialise({ title: this._formulaire.calculatorName }); const nubPointer = Session.getInstance().unserialiseSingleNub(serialisedNub); this.formulaireService.createFormulaire(nubPointer.nub.calcType, nubPointer.nub, nubPointer.meta.title).then((f) => { diff --git a/src/app/formulaire/definition/concrete/form-courbe-remous.ts b/src/app/formulaire/definition/concrete/form-courbe-remous.ts index 2789da339..5c3f0f0be 100644 --- a/src/app/formulaire/definition/concrete/form-courbe-remous.ts +++ b/src/app/formulaire/definition/concrete/form-courbe-remous.ts @@ -1,4 +1,4 @@ -import { IObservable } from "jalhyd"; +import { IObservable, MethodeResolution } from "jalhyd"; import { FormResultRemous } from "../form-result-remous"; import { FormDefSection } from "../form-def-section"; @@ -24,6 +24,9 @@ export class FormulaireCourbeRemous extends FormulaireDefinition { this._formSection = new FormDefSection(this); this._formResult = new FormResultRemous(this); this._formCompute = new FormComputeCourbeRemous(this, this._formSection, this._formResult); + // default properties + this._props["methodeResolution"] = MethodeResolution.Trapezes; + this._props["varCalc"] = undefined; // important } protected parseOptions(json: {}) { diff --git a/src/app/formulaire/definition/form-compute-courbe-remous.ts b/src/app/formulaire/definition/form-compute-courbe-remous.ts index e65553d0e..d8bf8dc2d 100644 --- a/src/app/formulaire/definition/form-compute-courbe-remous.ts +++ b/src/app/formulaire/definition/form-compute-courbe-remous.ts @@ -1,6 +1,5 @@ import { acSection, Result, MethodeResolution, CourbeRemousParams, CourbeRemous } from "jalhyd"; -import { SelectField } from "../select-field"; import { RemousResults } from "../../results/remous-results"; import { FormulaireDefinition } from "./form-definition"; import { FormDefSection } from "./form-def-section"; @@ -27,21 +26,13 @@ export class FormComputeCourbeRemous extends FormCompute { this.remousResults.parameters = prmCR; - // méthode de résolution - - const msf: SelectField = <SelectField>this._formBase.getFormulaireNodeById("select_resolution"); - const methRes: MethodeResolution = msf.getValue().value; - // variable supplémentaire à calculer - - this.remousResults.extraParamSymbol = this._formBase.getSelectedValue("select_target"); + this.remousResults.extraParamSymbol = this._formBase.currentNub.properties.getPropValue("varCalc"); // calcul - this.remousResults.result = cr.calculRemous(this.remousResults.extraParamSymbol); // données du graphe - this.remousResults.hauteurNormale = Yn.resultElement; this.remousResults.hauteurCritique = Yc.resultElement; if (this.remousResults.extraParamSymbol) { diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index b70997fea..469f34060 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -32,7 +32,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs /** * propriétés par défaut (lues si _currentNub === undefined ) */ - private _props = {}; + protected _props = {}; /** * fichier de configuration @@ -92,7 +92,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs } public initNub(props?: Props) { - this._currentNub = this.createNub(props === undefined ? new Props(this.defaultProperties) : props); + this._currentNub = this.createNub(props ? props : new Props(this.defaultProperties)); } public get currentNub(): Nub { diff --git a/src/app/formulaire/fieldset.ts b/src/app/formulaire/fieldset.ts index 489d736ea..0bfc3a85f 100644 --- a/src/app/formulaire/fieldset.ts +++ b/src/app/formulaire/fieldset.ts @@ -1,4 +1,4 @@ -import { CalculatorType, ComputeNodeType, ParamDefinition, LoiDebit, StructureType, Props, Observer, Nub } from "jalhyd"; +import { CalculatorType, ComputeNodeType, ParamDefinition, LoiDebit, StructureType, Props, Observer, Nub, MethodeResolution } from "jalhyd"; import { FormulaireElement } from "./formulaire-element"; import { Field } from "./field"; @@ -30,11 +30,11 @@ export class FieldSet extends FormulaireElement implements Observer { /** * propriétés déterminant l'état actuel du FieldSet (type de section, loi de débit, ...) */ - private _props: Props; + // private _props: Props; constructor(parent: FormulaireNode) { super(parent); - this._props = new Props(); + // this._props = new Props(); } public get nub(): Nub { @@ -44,7 +44,7 @@ export class FieldSet extends FormulaireElement implements Observer { public setNub(sn: Nub, update: boolean = true) { this._nub = sn; this.setParentNubForAllFields(); - this._props.setProps(sn.properties || new Props({}), this); + // this._props.setProps(sn.properties || new Props({}), this); if (update) { this.updateFields(); } @@ -104,15 +104,16 @@ export class FieldSet extends FormulaireElement implements Observer { } public get properties(): Props { - return this._props; + return this.nub.properties; + // return this._props; } private getPropValue(key: string): any { - return this._props.getPropValue(key); + return this.properties.getPropValue(key); } public setPropValue(key: string, val: any): boolean { - return this._props.setPropValue(key, val, this); + return this.properties.setPropValue(key, val, this); } private getNubParamFromSymbol(symbol: string): ParamDefinition { @@ -212,7 +213,7 @@ export class FieldSet extends FormulaireElement implements Observer { } /** - * @TODO WTF ? + * Reflects all properties values in the interface, through the values of the <select> fields */ private updateFields() { this.clearFields(); @@ -222,42 +223,76 @@ export class FieldSet extends FormulaireElement implements Observer { // MAJ des selects avec les valeurs actuelles des propriétés // spécifique à chaque modul de calcul, à revoir + switch (this._confId) { - if (this._confId === "fs_ouvrage") { - const sf1: SelectField = this.getFormulaireNodeById("select_ouvrage") as SelectField; - const st: StructureType = this.getPropValue("structureType"); - const se1 = sf1.getSelectedEntryFromValue(st); - sf1.setValue(se1); - - switch (st) { - case StructureType.SeuilRectangulaire: - const sf2: SelectField = this.getFormulaireNodeById("select_loidebit1") as SelectField; - const se2 = sf2.getSelectedEntryFromValue(this.getPropValue("loiDebit")); - sf2.setValue(se2); - break; + case "fs_ouvrage": + this.setSelectValueFromProperty("select_ouvrage", "structureType"); - case StructureType.VanneRectangulaire: - const sf3: SelectField = this.getFormulaireNodeById("select_loidebit2") as SelectField; - const se3 = sf3.getSelectedEntryFromValue(this.getPropValue("loiDebit")); - sf3.setValue(se3); - break; - } - } else if (this._confId === "fs_section") { - const sf: SelectField = this.getFormulaireNodeById("select_section") as SelectField; - const nt: ComputeNodeType = this.getPropValue("nodeType"); - const se = sf.getSelectedEntryFromValue(nt); - sf.setValue(se); - } + const st: StructureType = this.getPropValue("structureType"); + switch (st) { + case StructureType.SeuilRectangulaire: + this.setSelectValueFromProperty("select_loidebit1", "loiDebit"); + break; + case StructureType.VanneRectangulaire: + this.setSelectValueFromProperty("select_loidebit2", "loiDebit"); + break; + } + break; - // fin MAJ selects + case "fs_section": + this.setSelectValueFromProperty("select_section", "nodeType"); + break; + case "fs_param_calc": + this.setSelectValueFromProperty("select_resolution", "methodeResolution"); + break; + + case "fs_target_data": + this.setSelectValueFromProperty("select_target", "varCalc"); + break; + + } + + // fin MAJ selects this.applyDependencies(); } /** - * Set fieldset properties fron config file, unless config is already set (ex: structureType - * and loiDebit when deserialising existing structures) + * Reflects a property value in the interface, through the value of a <select> field, if this select exists + */ + private setSelectValueFromProperty(selectId: string, propertyKey: string) { + const selectField: SelectField = this.getFormulaireNodeById(selectId) as SelectField; + if (selectField) { + const propVal: any = this.getPropValue(propertyKey); + const selectElement = selectField.getSelectedEntryFromValue(propVal); // @TODO juste setValue() ? + try { + selectField.setValue(selectElement); + } catch (e) { + console.error(`setSelectValueFromProperty: cannot set value ${propVal} on <select> ${selectId}`); + } + } + } + + /** + * Sets Nub default property from config file, unless this property is already set + */ + private setPropertyValueFromConfig(json: {}, configKey: string, propertyKey: string, enumClass?) { + const configValue: string = json[configKey]; + const currentValue = this.properties.getPropValue(propertyKey); + if (configValue && ! currentValue) { + let formalValue = configValue; + if (enumClass) { + formalValue = enumClass[configValue]; + } + this.setPropValue(propertyKey, formalValue); + } + } + + /** + * Sets Nub default properties from config file, unless properties values are already set + * (when deserialising an existing Nub) + * @TODO default values should be held by model, not interface ! */ public parseConfig(json: {}, data?: {}) { this._jsonConfig = json; @@ -275,16 +310,10 @@ export class FieldSet extends FormulaireElement implements Observer { const node_type: ComputeNodeType = currentNt ? currentNt : (dnt ? ComputeNodeType[dnt] : parentForm.nodeType); this.setPropValue("nodeType", node_type); - const st: string = json["defaultStructType"]; - const currentSt = this.properties.getPropValue("structureType"); - if (st && ! currentSt) { - this.setPropValue("structureType", StructureType[st]); - } - const ld: string = json["defaultLoiDebit"]; - const currentLd = this.properties.getPropValue("loiDebit"); - if (ld && ! currentLd) { - this.setPropValue("loiDebit", LoiDebit[ld]); - } + this.setPropertyValueFromConfig(json, "defaultStructType", "structureType", StructureType); + this.setPropertyValueFromConfig(json, "defaultLoiDebit", "loiDebit", LoiDebit); + this.setPropertyValueFromConfig(json, "methodeResolution", "methodeResolution", MethodeResolution); + this.setPropertyValueFromConfig(json, "varCalc", "varCalc"); this.updateFields(); } @@ -400,7 +429,7 @@ export class FieldSet extends FormulaireElement implements Observer { const oldFormUid = +prm["values"]["form_uid"]; // correspondance avec l'objet mémoire - let newFormUid; + let newFormUid: string; for (const m of uidMap) { if (m["type"] === "form" && m["old"] === oldFormUid) { newFormUid = m["new"]; -- GitLab