diff --git a/src/app/formulaire/ngparam.ts b/src/app/formulaire/ngparam.ts index 8a43648546066c4a5a3db7efe5b657e7d1e02d46..de3ce46dcb0e232156d02eb5b3fb550c9c69d9db 100644 --- a/src/app/formulaire/ngparam.ts +++ b/src/app/formulaire/ngparam.ts @@ -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"); + } } } }