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

fix: set parameter radio config back when cancel button is clicked in variable values dialog

refs #508
parent 6843eb43
No related branches found
No related tags found
2 merge requests!133Release version 4.15.0,!121Resolve "Remettre le paramètre dans son état initial quand le dialogue "Varier" est annulé"
......@@ -53,7 +53,7 @@ export class DialogEditParamValuesComponent implements OnInit {
private fb: FormBuilder,
@Inject(MAT_DIALOG_DATA) public data: any
) {
this.param = data.param.clone();
this.param = data.param;
// an explicit ReactiveForm is required for file input component
const initialValue = (this.param.valueMode === ParamValueMode.LISTE ? this.valuesList : "");
this.valuesListForm = this.fb.group({
......
......@@ -120,10 +120,10 @@ export class ParamFieldLineComponent implements OnChanges {
private _formService: FormulaireService;
/**
* valeur du mode de paramètre avant clic sur un des radios, utilisé pour restaurer le mode en cas de cancel
* du dialogue de modification des valeurs en mode variable
* sauvegarde de certaines propriétés du paramètre avant clic sur le radio "varier", utilisé pour
* restaurer le paramètre en cas de cancel du dialogue de modification des valeurs en mode variable
*/
private oldValueMode: ParamValueMode;
private paramBackup: NgParameter;
/*
* gestion des événements clic sur les radios :
......@@ -242,16 +242,18 @@ export class ParamFieldLineComponent implements OnChanges {
}
public onRadioClick(option: string) {
this.oldValueMode = this.param.valueMode;
const oldValueMode = this.param.valueMode;
switch (option) {
case "fix":
this.param.valueMode = ParamValueMode.SINGLE;
break;
case "var":
this.paramBackup = this.param.clone();
// prevent setting LISTE mode back to MINMAX if someone clicks "variable" again
// after setting variable mode to LISTE
if (this.oldValueMode !== ParamValueMode.MINMAX && this.oldValueMode !== ParamValueMode.LISTE) {
if (oldValueMode !== ParamValueMode.MINMAX && oldValueMode !== ParamValueMode.LISTE) {
this.param.valueMode = ParamValueMode.MINMAX; // min/max par défaut
}
if (this._paramValuesComponent) {
......@@ -279,7 +281,7 @@ export class ParamFieldLineComponent implements OnChanges {
}
this.radio.emit({
"param": this.param,
"oldValueMode": this.oldValueMode
"oldValueMode": oldValueMode
});
// MAJ validité
this.emitValidity();
......@@ -314,7 +316,7 @@ export class ParamFieldLineComponent implements OnChanges {
break;
case "cancelvar": // cancel button clicked in DialogEditParamValuesComponent
this.param.valueMode = this.oldValueMode;
this.param.setFrom(this.paramBackup);
break;
}
}
......
......@@ -67,10 +67,11 @@ export class ParamValuesComponent implements AfterViewInit, Observer {
}
);
dlgRef.afterClosed().toPromise().then(result => {
if (result.cancelled)
if (result.cancelled) {
this.change.emit({
action: "cancelvar"
});
}
});
}
......
......@@ -46,6 +46,7 @@ export class NgParameter extends InputField implements Observer {
const ret: NgParameter = new NgParameter(this._paramDef.clone(), this.parent);
ret._allowEmpty = this._allowEmpty;
ret.unit = this.unit;
ret.radioConfig = this.radioConfig;
ret.disabled = this.disabled;
return ret;
}
......@@ -185,6 +186,9 @@ export class NgParameter extends InputField implements Observer {
return this._paramDef;
}
/**
* compute radio state from value mode
*/
public get radioState() {
switch (this._paramDef.valueMode) {
case ParamValueMode.SINGLE:
......@@ -390,6 +394,16 @@ export class NgParameter extends InputField implements Observer {
}
}
/**
* assign given parameter to this
*/
public setFrom(p: NgParameter) {
this._allowEmpty = p._allowEmpty;
this.unit = p.unit;
this.radioConfig = p.radioConfig;
this._paramDef = p._paramDef;
}
/**
* supprime un lien avec un paramètre
*/
......
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