Commit b424c10b authored by Grand Francois's avatar Grand Francois
Browse files

fix: predams: fields not empty on basin creation

refs #503
Showing with 28 additions and 2 deletions
+28 -2
...@@ -5,7 +5,7 @@ import * as screenfull from "screenfull"; ...@@ -5,7 +5,7 @@ import * as screenfull from "screenfull";
import { Screenfull } from "screenfull"; // @see https://github.com/sindresorhus/screenfull.js/issues/126#issuecomment-488796645 import { Screenfull } from "screenfull"; // @see https://github.com/sindresorhus/screenfull.js/issues/126#issuecomment-488796645
import { import {
PreBarrage, PbBassin, PbBassinParams, PbCloison, Observer, IObservable PreBarrage, PbBassin, PbBassinParams, PbCloison, Observer, IObservable, ParamDefinition, ParamValueMode
} from "jalhyd"; } from "jalhyd";
import * as mermaid from "mermaid"; import * as mermaid from "mermaid";
...@@ -20,6 +20,7 @@ import { FormulairePrebarrage } from "../../formulaire/definition/form-prebarrag ...@@ -20,6 +20,7 @@ import { FormulairePrebarrage } from "../../formulaire/definition/form-prebarrag
import { AppComponent } from "../../app.component"; import { AppComponent } from "../../app.component";
import { fv } from "app/util"; import { fv } from "app/util";
import { FormulaireNode } from "app/formulaire/elements/formulaire-node";
/** /**
* The interactive schema for calculator type "PreBarrage" (component) * The interactive schema for calculator type "PreBarrage" (component)
...@@ -491,10 +492,35 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni ...@@ -491,10 +492,35 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni
return this.i18nService.localizeText("INFO_FIELDSET_COPY"); return this.i18nService.localizeText("INFO_FIELDSET_COPY");
} }
/**
* Set value of all single parameters to undefined, except for the given parameter ids
*/
private emptyFields(basin: PbBassin, except: string[] = FormulaireNode.NeverEmptyFields) {
// save current calculated param, as setting value on a CALC param will
// change its mode and choose another calculated param by default
let calcP: ParamDefinition;
for (const p of basin.parameterIterator) {
if (
[ParamValueMode.SINGLE, ParamValueMode.CALCUL].includes(p.valueMode)
&& !except.includes(p.symbol)
) {
if (p.valueMode === ParamValueMode.CALCUL) {
calcP = p;
}
p.setValue(undefined);
}
}
// restore original calculated param
if (calcP !== undefined) {
calcP.setCalculated();
}
}
/** Adds a new lone basin */ /** Adds a new lone basin */
public onAddBasinClick() { public onAddBasinClick() {
const newBasin = new PbBassin(new PbBassinParams(20, 99)); const newBasin = new PbBassin(new PbBassinParams(20, 99));
this.model.addChild(newBasin); this.model.addChild(newBasin);
this.emptyFields(newBasin);
this.clearResults(); this.clearResults();
this.refreshWithSelection(newBasin.uid); this.refreshWithSelection(newBasin.uid);
this.calculatorComponent.showPBInputData = true; this.calculatorComponent.showPBInputData = true;
......
...@@ -12,7 +12,7 @@ export abstract class FormulaireNode implements IObservable { ...@@ -12,7 +12,7 @@ export abstract class FormulaireNode implements IObservable {
/** /**
* fields in fieldset that must not be empty due to enableEmptyFieldsOnFormInit option * fields in fieldset that must not be empty due to enableEmptyFieldsOnFormInit option
*/ */
protected static NeverEmptyFields = ["Cd0", "CdWS", "CdGR", "CdGRS", "CdCunge", "CdWR", "CdO", "CdT", "CdWSL"]; public static readonly NeverEmptyFields = ["Cd0", "CdWS", "CdGR", "CdGRS", "CdCunge", "CdWR", "CdO", "CdT", "CdWSL"];
/** aide en ligne */ /** aide en ligne */
protected _helpLink: string; protected _helpLink: string;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment