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

Aperçu des paramètres liés: gestion des résultats de calcul

parent e488c136
No related branches found
No related tags found
1 merge request!40Resolve "Amélioration du système de paramètres liés"
......@@ -51,9 +51,11 @@ export class NgParameter extends InputField implements Observer {
/**
* Returns a text preview of the current value(s), depending on the value mode
* @TODO use display precision to limit decimals
*/
public static preview(p: ParamDefinition): string {
let valuePreview: string;
const i18n = ServiceFactory.instance.i18nService;
// console.log("NgParam::preview()", p.symbol, ParamValueMode[p.valueMode], p);
switch (p.valueMode) {
case ParamValueMode.SINGLE:
......@@ -73,30 +75,59 @@ export class NgParameter extends InputField implements Observer {
if (step) {
step = step.toFixed(nDigits);
}
valuePreview = ServiceFactory.instance.i18nService.localizeText("INFO_PARAMFIELD_PARAMVARIER_MINMAXSTEP");
valuePreview = i18n.localizeText("INFO_PARAMFIELD_PARAMVARIER_MINMAXSTEP");
valuePreview = sprintf(valuePreview, min, max, step);
break;
case ParamValueMode.LISTE:
valuePreview = ServiceFactory.instance.i18nService.localizeText("INFO_PARAMFIELD_PARAMVARIER_VALUES");
valuePreview = i18n.localizeText("INFO_PARAMFIELD_PARAMVARIER_VALUES");
const vals = p.paramValues.valueList || [];
valuePreview += " " + vals.slice(0, 5).join("; ") + "";
break;
case ParamValueMode.CALCUL:
valuePreview = ServiceFactory.instance.i18nService.localizeText("INFO_PARAMFIELD_IN_CALCULATION");
valuePreview = i18n.localizeText("INFO_PARAMFIELD_IN_CALCULATION");
if (p.calculability === ParamCalculability.DICHO) {
valuePreview += " (" + ServiceFactory.instance.i18nService.localizeText("INFO_PARAMFIELD_IN_CALCULATION_INITIAL_VALUE")
valuePreview += " (" + i18n.localizeText("INFO_PARAMFIELD_IN_CALCULATION_INITIAL_VALUE")
+ ": " + p.getValue() + ")";
}
break;
case ParamValueMode.LINK:
if (p.isReferenceDefined()) {
if (p.referencedValue.isParameter()) {
// recursive call
valuePreview = NgParameter.preview(p.referencedValue.element as ParamDefinition);
const targetParam = (p.referencedValue.element as ParamDefinition);
// calculated param ?
if (targetParam.valueMode === ParamValueMode.CALCUL) {
// was the result already computed ?
if (p.referencedValue.nub.result) {
if (p.referencedValue.hasMultipleValues()) {
// like LIST mode
valuePreview = i18n.localizeText("INFO_PARAMFIELD_PARAMVARIER_VALUES");
valuePreview += " " + p.referencedValue.nub.result.getCalculatedValues().slice(0, 5).join("; ") + "";
} else {
valuePreview = String(p.referencedValue.nub.result.vCalc);
}
} else {
valuePreview = i18n.localizeText("INFO_PARAMFIELD_IN_CALCULATION");
}
} else {
// recursive call
valuePreview = NgParameter.preview(targetParam);
}
} else {
// @TODO what if the result was already computed ?
// Is the computed value fresh or stale ?
valuePreview = ServiceFactory.instance.i18nService.localizeText("INFO_PARAMFIELD_IN_CALCULATION");
// was the result already computed ?
try {
const remoteValues = p.referencedValue.getParamValues();
// @TODO is the computed value fresh or stale ?
if (p.referencedValue.hasMultipleValues()) {
// like LIST mode
valuePreview = i18n.localizeText("INFO_PARAMFIELD_PARAMVARIER_VALUES");
valuePreview += " " + remoteValues.valueList.slice(0, 5).join("; ") + "";
} else {
// like SINGLE mode
valuePreview = String(remoteValues.currentValue);
}
} catch (e) {
valuePreview = i18n.localizeText("INFO_PARAMFIELD_IN_CALCULATION");
}
}
}
}
......
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