diff --git a/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts b/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts index 6a0a68d5919412d7af1bc7a04643192253e82da8..f5200cfd0e09da4212e8b4e9dd1893184cc66c60 100644 --- a/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts +++ b/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts @@ -11,6 +11,7 @@ import { sprintf } from "sprintf-js"; import { ParamValueMode, ExtensionStrategy } from "jalhyd"; import { fv } from "../../util"; +import { ServiceFactory } from "app/services/service-factory"; @Component({ selector: "dialog-edit-param-values", @@ -395,28 +396,29 @@ export class DialogEditParamValuesComponent implements OnInit { } private initVariableValues() { + const canFill: boolean = !ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit; // init min / max / step if (this.isMinMax) { const pVal = this.param.getValue(); - if (this.param.minValue === undefined) { - this.param.setMinValue(this, pVal !== undefined ? this.param.getValue() / 2 : undefined); + if (this.param.minValue === undefined && canFill) { + this.param.resetMinValue(this, pVal !== undefined ? this.param.getValue() / 2 : undefined); } - if (this.param.maxValue === undefined) { - this.param.setMaxValue(this, pVal !== undefined ? this.param.getValue() * 2 : undefined); + if (this.param.maxValue === undefined && canFill) { + this.param.resetMaxValue(this, pVal !== undefined ? this.param.getValue() * 2 : undefined); } let step = this.param.stepValue; - if (step === undefined) { + if (step === undefined && canFill) { step = pVal !== undefined ? ((this.param.maxValue - this.param.minValue) / 20) : undefined; + this.param.resetStepValue(this, step); } - this.param.setStepValue(this, step); } // init values list if (this.isListe) { - if (this.param.valueList === undefined) { + if (this.param.valueList === undefined && canFill) { if (this.param.isDefined) { - this.param.setValueList(this, [ this.param.getValue() ]); + this.param.resetValueList(this, [this.param.getValue()]); } else { - this.param.setValueList(this, []); + this.param.resetValueList(this, []); } // set form control initial value this.valuesListForm.controls.valuesList.setValue(this.valuesList); diff --git a/src/app/formulaire/elements/formulaire-node.ts b/src/app/formulaire/elements/formulaire-node.ts index dca5bbe5d21d768c66b9692b81b385801b1bad14..b0e214f5ebd3f41a30c9918b2aea7ae5b4b3056c 100644 --- a/src/app/formulaire/elements/formulaire-node.ts +++ b/src/app/formulaire/elements/formulaire-node.ts @@ -161,7 +161,7 @@ export abstract class FormulaireNode implements IObservable { if (p.valueMode === ParamValueMode.CALCUL) { calcP = p; } - p.setValue(this, undefined); + p.resetValue(this, undefined); } } } diff --git a/src/app/formulaire/elements/ngparam.ts b/src/app/formulaire/elements/ngparam.ts index c79dc844f3483004130079e660f5d3dea2bac417..d2e4b0bd493e774e35ef471faba2847c21d52771 100644 --- a/src/app/formulaire/elements/ngparam.ts +++ b/src/app/formulaire/elements/ngparam.ts @@ -394,6 +394,18 @@ export class NgParameter extends InputField implements Observer { ); } + /** + * fixe la valeur du paramètre en tant que valeur par défaut + */ + public resetValue(sender: any, val: number) { + const changed = (this._paramDef.getValue() !== val); + this._isValueModified = false; + if (changed) { + this._paramDef.setValue(val, sender); + this.notifyValueModified(sender); + } + } + /** * fixe la valeur du paramètre. * une notification préalable est envoyée pour laisser l'occasion aux objets liés de préciser le contexte @@ -402,8 +414,20 @@ export class NgParameter extends InputField implements Observer { * @param val */ public setValue(sender: any, val: number) { - this._paramDef.setValue(val, sender); - this.notifyValueModified(sender); + const changed = (this._paramDef.getValue() !== val); + if (changed) { + this._paramDef.setValue(val, sender); + this.notifyValueModified(sender); + } + } + + public resetMinValue(sender: any, v: number) { + const changed = (this._paramDef.min !== v); + this._isValueModified = false; + if (changed) { + this._paramDef.min = v; + this.notifyMinValueModified(sender); + } } public setMinValue(sender: any, v: number) { @@ -415,6 +439,15 @@ export class NgParameter extends InputField implements Observer { } } + public resetMaxValue(sender: any, v: number) { + const changed = (this._paramDef.max !== v); + this._isValueModified = false; + if (changed) { + this._paramDef.max = v; + this.notifyMaxValueModified(sender); + } + } + public setMaxValue(sender: any, v: number) { const changed = (this._paramDef.max !== v); if (changed) { @@ -424,6 +457,15 @@ export class NgParameter extends InputField implements Observer { } } + public resetStepValue(sender: any, v: number) { + const changed = (this._paramDef.step !== v); + this._isValueModified = false; + if (changed) { + this._paramDef.step = v; + this.notifyStepValueModified(sender); + } + } + public setStepValue(sender: any, v: number) { const changed = (this._paramDef.step !== v); if (changed) { @@ -433,6 +475,15 @@ export class NgParameter extends InputField implements Observer { } } + public resetValueList(sender: any, l: number[]) { + const changed = (JSON.stringify(this._paramDef.valueList) !== JSON.stringify(l)); + this._isValueModified = false; + if (changed) { + this._paramDef.valueList = l; + this.notifyListValueModified(sender); + } + } + public setValueList(sender: any, l: number[]) { const changed = (JSON.stringify(this._paramDef.valueList) !== JSON.stringify(l)); if (changed) {