Skip to content
Snippets Groups Projects
Commit 82a6d811 authored by mathias.chouet's avatar mathias.chouet
Browse files

Fix #172

parent c43d270d
No related branches found
No related tags found
1 merge request!40Resolve "Amélioration du système de paramètres liés"
......@@ -220,6 +220,7 @@ export class ParamFieldLineComponent implements OnChanges {
case "fix":
this.param.valueMode = ParamValueMode.SINGLE;
// reset the value to avoid "undefined" after exiting CALC or LINK mode
// @TODO not always necessary; find out why
this.param.setValue(this, this.param.paramDefinition.paramValues.singleValue);
break;
......
......@@ -155,14 +155,6 @@ export class FormDefFixedVar {
}
}
private logParams() {
for (const fe of this._formBase.allFormElements) {
if (fe instanceof NgParameter) {
console.log(`${fe.paramDefinition.symbol} : ${ParamValueMode[fe.paramDefinition.valueMode]}`);
}
}
}
/**
* gestion des événements clic sur les radios
*/
......
......@@ -56,13 +56,13 @@ export class NgParameter extends InputField implements Observer {
public static preview(p: ParamDefinition): string {
let valuePreview: string;
const i18n = ServiceFactory.instance.i18nService;
const nDigits = ServiceFactory.instance.applicationSetupService.displayDigits;
// console.log("NgParam::preview()", p.symbol, ParamValueMode[p.valueMode], p);
switch (p.valueMode) {
case ParamValueMode.SINGLE:
valuePreview = String(p.getValue());
valuePreview = String(p.getValue().toFixed(nDigits));
break;
case ParamValueMode.MINMAX:
const nDigits = ServiceFactory.instance.applicationSetupService.displayDigits;
let min: any = p.paramValues.min;
let max: any = p.paramValues.max;
let step: any = p.paramValues.step;
......@@ -81,13 +81,15 @@ export class NgParameter extends InputField implements Observer {
case ParamValueMode.LISTE:
valuePreview = i18n.localizeText("INFO_PARAMFIELD_PARAMVARIER_VALUES");
const vals = p.paramValues.valueList || [];
valuePreview += " " + vals.slice(0, 5).join("; ") + "";
valuePreview += " " + vals.slice(0, 5).map((v) => {
return v.toFixed(nDigits);
}).join("; ") + "";
break;
case ParamValueMode.CALCUL:
valuePreview = i18n.localizeText("INFO_PARAMFIELD_IN_CALCULATION");
if (p.calculability === ParamCalculability.DICHO) {
valuePreview += " (" + i18n.localizeText("INFO_PARAMFIELD_IN_CALCULATION_INITIAL_VALUE")
+ ": " + p.getValue() + ")";
+ ": " + p.getValue().toFixed(nDigits) + ")";
}
break;
case ParamValueMode.LINK:
......@@ -101,9 +103,11 @@ export class NgParameter extends InputField implements Observer {
if (p.referencedValue.hasMultipleValues()) {
// like LIST mode
valuePreview = i18n.localizeText("INFO_PARAMFIELD_PARAMVARIER_VALUES");
valuePreview += " " + p.referencedValue.nub.result.getCalculatedValues().slice(0, 5).join("; ") + "";
valuePreview += " " + p.referencedValue.nub.result.getCalculatedValues().map((v) => {
return v.toFixed(nDigits);
}).slice(0, 5).join("; ") + "";
} else {
valuePreview = String(p.referencedValue.nub.result.vCalc);
valuePreview = String(p.referencedValue.nub.result.vCalc.toFixed(nDigits));
}
} else {
valuePreview = i18n.localizeText("INFO_PARAMFIELD_IN_CALCULATION");
......@@ -120,10 +124,12 @@ export class NgParameter extends InputField implements Observer {
if (p.referencedValue.hasMultipleValues()) {
// like LIST mode
valuePreview = i18n.localizeText("INFO_PARAMFIELD_PARAMVARIER_VALUES");
valuePreview += " " + remoteValues.valueList.slice(0, 5).join("; ") + "";
valuePreview += " " + remoteValues.valueList.slice(0, 5).map((v) => {
return v.toFixed(nDigits);
}).join("; ") + "";
} else {
// like SINGLE mode
valuePreview = String(remoteValues.currentValue);
valuePreview = String(remoteValues.currentValue.toFixed(nDigits));
}
} catch (e) {
valuePreview = i18n.localizeText("INFO_PARAMFIELD_IN_CALCULATION");
......@@ -183,16 +189,19 @@ export class NgParameter extends InputField implements Observer {
return this._paramDef.valueMode;
}
// @TODO vérifier : ça a une tête à faire 40x trop d'opérations pour rien
/**
* Unlinks the parameter and updates its value when value mode changes
*/
public set valueMode(m: ParamValueMode) {
// undefined si on clique en dehors du select après l'avoir ouvert (cad sans avoir fait de sélection)
// et au même niveau, cad à côté du bouton et non à côté du menu déroulant
if (m !== undefined && this._paramDef.valueMode !== m) {
const nDigits = ServiceFactory.instance.applicationSetupService.displayDigits;
this.unlinkParameter();
this._paramDef.valueMode = m;
this.notifyObservers({
"action": "valueModeChange",
"value": this._paramDef.getValue()
"value": Number(this._paramDef.getValue().toFixed(nDigits))
});
}
}
......
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