From 44c8c73e2a32ea8e4074b59b4eb5ea2fef5c4085 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Thu, 1 Aug 2019 17:56:37 +0200 Subject: [PATCH] ResultElement : add ordered keys() getter --- src/util/resultelement.ts | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/util/resultelement.ts b/src/util/resultelement.ts index 3a515e6f..6b98dab7 100644 --- a/src/util/resultelement.ts +++ b/src/util/resultelement.ts @@ -47,23 +47,6 @@ export class ResultElement { * for ex. with SectionParametree */ get vCalc(): number { - /* if (this.parent && this.parent.symbol) { - if (this.parent.symbol in this._values) { - return this._values[this.parent.symbol]; - } else { - // required symbol not found; if only the empty key "" is present, - // return its value (@WARNING clodo rustine) - if (this.count() > 1) { - // throw new Error("clodo rustine failed"); - return undefined; - } else { - return this.firstValue; - } - } - } - // default retrocompatible pseudo-symbol for cases like `new ResultElement(42);` - return this._values[""]; */ - return this._values[this.vCalcSymbol]; } @@ -99,6 +82,24 @@ export class ResultElement { this._values = { ...this._values, ...values }; } + /** + * Returns an array of all the keys in the local values map, + * where vCalcSymbol is always in first position (used by + * GUI to iterate on displayable results) + */ + public get keys(): string[] { + const keys = Object.keys(this._values); + // make sure vCalc symbol is always first + if (this.vCalcSymbol) { // sometimes empty (ex: SectionParametree) + const index = keys.indexOf(this.vCalcSymbol); + if (index > -1) { + keys.splice(index, 1); + } + keys.unshift(this.vCalcSymbol); + } + return keys; + } + /** * @returns the result value associated to the given symbol, or undefined if the given * symbol was not found in the local values map -- GitLab