Skip to content
Snippets Groups Projects
Commit 90ea29b9 authored by François Grand's avatar François Grand
Browse files

fix: wrong default value for discharge law select

refs #483
parent 47c2d30b
No related branches found
No related tags found
2 merge requests!225Release v4.17.0,!176Resolve "Fusionner les "select" avec "source" et les "select_custom""
Pipeline #139961 passed
......@@ -497,23 +497,23 @@ Dans chaque fichier de langue du dossier `src/locale`, ajouter les traductions p
Il faut utiliser ou étendre `FormulaireParallelStructure` (ex: Cloisons, Dever…).
Dans la configuration du module, dans le "fieldset_template", ajouter un sélecteur de structure associé à la propriété "structureType" et un sélecteur de loi de débit associé à la propriété "loiDebit", noter les propriétés "calcType" (toujours "Structure" dans ce cas), "defaultStructType" et "defaultLoiDebit" :
Dans la configuration du module, dans le "fieldset_template", ajouter un sélecteur de structure et un sélecteur de loi de débit, ajouter les propriétés "calcType" (toujours "Structure" dans ce cas) et les valeurs par défaut avec "default" dans la définition du select. A noter que les ids des select sont fixés et doivent obligatoirement être "select_structure" et "select_loidebit" :
```json
{
"id": "fs_ouvrage",
"type": "fieldset_template",
"calcType": "Structure",
"defaultStructType": "VanneFondRectangulaire",
"defaultLoiDebit": "GateCem88v",
"fields": [
{
"id": "select_structure",
"type": "select",
"default": "VanneFondRectangulaire",
},
{
"id": "select_loidebit",
"type": "select",
"default": "GateCem88v",
"help": {
"Orifice_OrificeSubmerged": "structures/orifice_noye.html",
"SeuilRectangulaire_WeirVillemonte": "structures/kivi.html",
......
......@@ -57,11 +57,6 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
}
protected createChildNub(templ: FieldsetTemplate): Nub {
// !!! attention !!!
// Il doit y avoir cohérence dans le fichier de conf entre les valeurs defaultXXX et les valeurs possibles pour les select
// cad valeur par défaut du 1er select (type d'ouvrage), du 2ème (loi de débit).
// A terme, il faudrait analyser le fichier de conf (dépendances d'existence) pour déterminer automatiquement ces valeurs
const params = {};
params["calcType"] = templ.calcTypeFromConfig;
params["structureType"] = templ.defaultStructTypeFromConfig;
......
......@@ -21,7 +21,7 @@ export class FieldsetContainer extends FormulaireElement {
if (this._template !== undefined) {
throw new Error("template already set!");
}
this._template = new FieldsetTemplate(fst);
this._template = fst;
}
public addFieldset(fs: FieldSet) {
......@@ -105,7 +105,9 @@ export class FieldsetContainer extends FormulaireElement {
for (const t of templateNames) {
for (const d of templates) {
if (d.id === t) {
this.template = d;
const tmpl = new FieldsetTemplate();
tmpl.parseConfig(d);
this.template = tmpl;
}
}
}
......
......@@ -2,13 +2,16 @@ import { FieldSet } from "./fieldset";
import { CalculatorType, LoiDebit, Nub, StructureType, SectionType } from "jalhyd";
import { FormulaireDefinition } from "../definition/form-definition";
import { FieldsetContainer } from "./fieldset-container";
import { SelectFieldFactory } from "./select/select-field-factory";
export class FieldsetTemplate {
private _jsonConfig: {};
constructor(config: {}) {
this._jsonConfig = config;
}
// parsed default structure type from JSON configuration file (from select_structure field)
private _defaultStructureType: StructureType;
// parsed default stage discharge law from JSON configuration file (from select_loidebit field)
private _defaultLoiDebit: LoiDebit;
public get config() {
return this._jsonConfig;
......@@ -20,16 +23,41 @@ export class FieldsetTemplate {
}
public get defaultStructTypeFromConfig(): StructureType {
const st: string = this._jsonConfig["defaultStructType"];
return StructureType[st];
return this._defaultStructureType;
}
public get defaultLoiDebitFromConfig(): LoiDebit {
const ld: string = this._jsonConfig["defaultLoiDebit"];
if (LoiDebit[ld] === undefined) {
throw new Error(`FieldsetTemplate.defaultLoiDebitFromConfig: La loi de débit ${ld} n'est pas définie`);
return this._defaultLoiDebit;
}
private findSelectField(id: string): any {
for (const f of this._jsonConfig["fields"]) {
if (f["type"] === "select" && f["id"] === id) {
return f;
}
}
}
public parseConfig(config: {}) {
this._jsonConfig = config;
if (this._jsonConfig["calcType"] === "Structure") {
// parse default stage discharge law
const ld: string = this.findSelectField(SelectFieldFactory.SelectId_LoiDebit)["default"];
if (LoiDebit[ld] === undefined) {
throw new Error(`FieldsetTemplate.defaultLoiDebitFromConfig : la loi de débit ${ld} n'est pas définie`);
}
this._defaultLoiDebit = LoiDebit[ld];
// parse default structure type
const st: string = this.findSelectField(SelectFieldFactory.SelectId_StructureType)["default"];
if (StructureType[st] === undefined) {
throw new Error(`FieldsetTemplate.defaultStructTypeFromConfig : le type de structure ${st} n'est pas défini`);
}
this._defaultStructureType = StructureType[st];
}
return LoiDebit[ld];
}
/**
......
......@@ -22,13 +22,27 @@ export class SelectFieldDeviceLoiDebit extends SelectField {
this._configDefaultValue = json["default"];
}
/**
* get this select's nub
*/
protected get nub(): ParallelStructure {
return super.nub as ParallelStructure;
}
/**
* get discharge law linked to this select's nub
*/
private get loiDebit(): LoiDebit {
const child = this.nub.getChildren()[this.parent.indexAsKid()];
return child.properties.getPropValue("loiDebit");
}
protected populate() {
// possible values depend on CalcType
// get current structure type from appropriate Nub child
const child = this.nub.getChildren()[this.parent.indexAsKid()];
const la = (this.nub as ParallelStructure).getLoisAdmissibles();
const loiDebit = child.properties.getPropValue("loiDebit");
const la = this.nub.getLoisAdmissibles();
const loiDebit: LoiDebit = this.loiDebit;
const stCode = StructureProperties.findCompatibleStructure(loiDebit, this.nub as ParallelStructure);
const stName = StructureType[stCode];
if (la[stName] !== undefined) {
......@@ -40,6 +54,7 @@ export class SelectFieldDeviceLoiDebit extends SelectField {
}
protected initSelectedValue() {
this.findAndSetDefaultValue();
// current discharge law from linked nub
this.findAndSetDefaultValue(LoiDebit[this.loiDebit]);
}
}
......@@ -13,12 +13,24 @@ import { SelectFieldTargetPass } from "./select-field-target-pass";
import { SelectFieldNubProperty } from "./select-field-nub-prop";
export class SelectFieldFactory {
/**
* Id of the select linked to structure type (JSON calculator configuration).
* Also used in fieldset template parsing.
*/
public static readonly SelectId_StructureType: string ="select_structure";
/**
* Id of the select linked to stage discharge law (JSON calculator configuration).
* Also used in fieldset template parsing.
*/
public static readonly SelectId_LoiDebit: string ="select_loidebit";
public static newSelectField(json: {}, parent: FormulaireNode): SelectField {
switch (json["id"]) {
case "select_downstream_basin":
return new SelectFieldDownstreamBasin(parent);
case "select_loidebit":
case SelectFieldFactory.SelectId_LoiDebit:
return new SelectFieldDeviceLoiDebit(parent);
case "select_searched_param":
......@@ -27,7 +39,7 @@ export class SelectFieldFactory {
case "select_species_list":
return new SelectFieldSpeciesList(parent);
case "select_structure":
case SelectFieldFactory.SelectId_StructureType:
return new SelectFieldDeviceStructureType(parent);
case "select_target":
......
......@@ -125,11 +125,13 @@ export abstract class SelectField extends Field {
/**
* try to find a default value to select
*/
protected findAndSetDefaultValue() {
protected findAndSetDefaultValue(value?: string) {
// default to first available entry if any
if (this._entries.length > 0) {
let val;
if (this._configDefaultValue === undefined) {
let val: SelectEntry;
if (value !== undefined) {
val = this.getEntryFromValue(enumValueFromString(this._associatedProperty, value));
} else if (this._configDefaultValue === undefined) {
val = this._entries[0];
} else {
val = this.getEntryFromValue(enumValueFromString(this._associatedProperty, this._configDefaultValue));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment