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

fix: wrong default value for discharge law select

refs #483
parent f91dfa6e
No related branches found
No related tags found
No related merge requests found
...@@ -497,23 +497,23 @@ Dans chaque fichier de langue du dossier `src/locale`, ajouter les traductions p ...@@ -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…). 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 ```json
{ {
"id": "fs_ouvrage", "id": "fs_ouvrage",
"type": "fieldset_template", "type": "fieldset_template",
"calcType": "Structure", "calcType": "Structure",
"defaultStructType": "VanneFondRectangulaire",
"defaultLoiDebit": "GateCem88v",
"fields": [ "fields": [
{ {
"id": "select_structure", "id": "select_structure",
"type": "select", "type": "select",
"default": "VanneFondRectangulaire",
}, },
{ {
"id": "select_loidebit", "id": "select_loidebit",
"type": "select", "type": "select",
"default": "GateCem88v",
"help": { "help": {
"Orifice_OrificeSubmerged": "structures/orifice_noye.html", "Orifice_OrificeSubmerged": "structures/orifice_noye.html",
"SeuilRectangulaire_WeirVillemonte": "structures/kivi.html", "SeuilRectangulaire_WeirVillemonte": "structures/kivi.html",
......
...@@ -57,11 +57,6 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset { ...@@ -57,11 +57,6 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
} }
protected createChildNub(templ: FieldsetTemplate): Nub { 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 = {}; const params = {};
params["calcType"] = templ.calcTypeFromConfig; params["calcType"] = templ.calcTypeFromConfig;
params["structureType"] = templ.defaultStructTypeFromConfig; params["structureType"] = templ.defaultStructTypeFromConfig;
......
...@@ -21,7 +21,7 @@ export class FieldsetContainer extends FormulaireElement { ...@@ -21,7 +21,7 @@ export class FieldsetContainer extends FormulaireElement {
if (this._template !== undefined) { if (this._template !== undefined) {
throw new Error("template already set!"); throw new Error("template already set!");
} }
this._template = new FieldsetTemplate(fst); this._template = fst;
} }
public addFieldset(fs: FieldSet) { public addFieldset(fs: FieldSet) {
...@@ -105,7 +105,9 @@ export class FieldsetContainer extends FormulaireElement { ...@@ -105,7 +105,9 @@ export class FieldsetContainer extends FormulaireElement {
for (const t of templateNames) { for (const t of templateNames) {
for (const d of templates) { for (const d of templates) {
if (d.id === t) { 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"; ...@@ -2,13 +2,16 @@ import { FieldSet } from "./fieldset";
import { CalculatorType, LoiDebit, Nub, StructureType, SectionType } from "jalhyd"; import { CalculatorType, LoiDebit, Nub, StructureType, SectionType } from "jalhyd";
import { FormulaireDefinition } from "../definition/form-definition"; import { FormulaireDefinition } from "../definition/form-definition";
import { FieldsetContainer } from "./fieldset-container"; import { FieldsetContainer } from "./fieldset-container";
import { SelectFieldFactory } from "./select/select-field-factory";
export class FieldsetTemplate { export class FieldsetTemplate {
private _jsonConfig: {}; private _jsonConfig: {};
constructor(config: {}) { // parsed default structure type from JSON configuration file (from select_structure field)
this._jsonConfig = config; private _defaultStructureType: StructureType;
}
// parsed default stage discharge law from JSON configuration file (from select_loidebit field)
private _defaultLoiDebit: LoiDebit;
public get config() { public get config() {
return this._jsonConfig; return this._jsonConfig;
...@@ -20,16 +23,41 @@ export class FieldsetTemplate { ...@@ -20,16 +23,41 @@ export class FieldsetTemplate {
} }
public get defaultStructTypeFromConfig(): StructureType { public get defaultStructTypeFromConfig(): StructureType {
const st: string = this._jsonConfig["defaultStructType"]; return this._defaultStructureType;
return StructureType[st];
} }
public get defaultLoiDebitFromConfig(): LoiDebit { public get defaultLoiDebitFromConfig(): LoiDebit {
const ld: string = this._jsonConfig["defaultLoiDebit"]; return this._defaultLoiDebit;
if (LoiDebit[ld] === undefined) { }
throw new Error(`FieldsetTemplate.defaultLoiDebitFromConfig: La loi de débit ${ld} n'est pas définie`);
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 { ...@@ -22,13 +22,27 @@ export class SelectFieldDeviceLoiDebit extends SelectField {
this._configDefaultValue = json["default"]; 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() { protected populate() {
// possible values depend on CalcType // possible values depend on CalcType
// get current structure type from appropriate Nub child // get current structure type from appropriate Nub child
const child = this.nub.getChildren()[this.parent.indexAsKid()]; const la = this.nub.getLoisAdmissibles();
const la = (this.nub as ParallelStructure).getLoisAdmissibles(); const loiDebit: LoiDebit = this.loiDebit;
const loiDebit = child.properties.getPropValue("loiDebit");
const stCode = StructureProperties.findCompatibleStructure(loiDebit, this.nub as ParallelStructure); const stCode = StructureProperties.findCompatibleStructure(loiDebit, this.nub as ParallelStructure);
const stName = StructureType[stCode]; const stName = StructureType[stCode];
if (la[stName] !== undefined) { if (la[stName] !== undefined) {
...@@ -40,6 +54,7 @@ export class SelectFieldDeviceLoiDebit extends SelectField { ...@@ -40,6 +54,7 @@ export class SelectFieldDeviceLoiDebit extends SelectField {
} }
protected initSelectedValue() { 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"; ...@@ -13,12 +13,24 @@ import { SelectFieldTargetPass } from "./select-field-target-pass";
import { SelectFieldNubProperty } from "./select-field-nub-prop"; import { SelectFieldNubProperty } from "./select-field-nub-prop";
export class SelectFieldFactory { 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 { public static newSelectField(json: {}, parent: FormulaireNode): SelectField {
switch (json["id"]) { switch (json["id"]) {
case "select_downstream_basin": case "select_downstream_basin":
return new SelectFieldDownstreamBasin(parent); return new SelectFieldDownstreamBasin(parent);
case "select_loidebit": case SelectFieldFactory.SelectId_LoiDebit:
return new SelectFieldDeviceLoiDebit(parent); return new SelectFieldDeviceLoiDebit(parent);
case "select_searched_param": case "select_searched_param":
...@@ -27,7 +39,7 @@ export class SelectFieldFactory { ...@@ -27,7 +39,7 @@ export class SelectFieldFactory {
case "select_species_list": case "select_species_list":
return new SelectFieldSpeciesList(parent); return new SelectFieldSpeciesList(parent);
case "select_structure": case SelectFieldFactory.SelectId_StructureType:
return new SelectFieldDeviceStructureType(parent); return new SelectFieldDeviceStructureType(parent);
case "select_target": case "select_target":
......
...@@ -125,11 +125,13 @@ export abstract class SelectField extends Field { ...@@ -125,11 +125,13 @@ export abstract class SelectField extends Field {
/** /**
* try to find a default value to select * try to find a default value to select
*/ */
protected findAndSetDefaultValue() { protected findAndSetDefaultValue(value?: string) {
// default to first available entry if any // default to first available entry if any
if (this._entries.length > 0) { if (this._entries.length > 0) {
let val; let val: SelectEntry;
if (this._configDefaultValue === undefined) { if (value !== undefined) {
val = this.getEntryFromValue(enumValueFromString(this._associatedProperty, value));
} else if (this._configDefaultValue === undefined) {
val = this._entries[0]; val = this._entries[0];
} else { } else {
val = this.getEntryFromValue(enumValueFromString(this._associatedProperty, this._configDefaultValue)); 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