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

fix: fields of min/max/list values dialog filled with default values

when:
- "create calculators with empty fields" is set,
- a single value parameter is given a value,
- parameter mode changed to variable,
fields opening edition dialog are incorrectly filled.

refs #480
parent 618525ce
No related branches found
No related tags found
2 merge requests!133Release version 4.15.0,!119Resolve "Mode "champs vides par défaut" : changer le type d'un ouvrage (ex: dans Cloisons) remplit les champs"
......@@ -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);
......
......@@ -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);
}
}
}
......
......@@ -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) {
......
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