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

Fix #292 - custom order for Grille results

parent b1fd9ff2
No related branches found
No related tags found
No related merge requests found
......@@ -72,6 +72,116 @@ export class FixedResultsComponent extends ResultsComponent {
* Returns a set of parameters and results for mat-table
*/
public get dataSet() {
if (
this._fixedResults !== undefined
&& Array.isArray(this._fixedResults.variablesOrder)
&& this._fixedResults.variablesOrder.length > 0
) {
return this.buildCustomOrderedDataset();
} else {
return this.buildDefaultOrderedDataset();
}
}
/**
* When this.variablesOrder is defined and not empty, builds an ordered set of
* data according to the given symbols order; variables whose symbol is not
* mentioned in this.variablesOrder are not displayed !
*/
protected buildCustomOrderedDataset() {
const data = [];
for (const symbol of this._fixedResults.variablesOrder) {
// is it a fixed parameter ?
for (const fp of this.fixedParams) {
if (fp.symbol === symbol) {
let label = this.formattedLabel(fp);
// add structure position before label
if (fp.paramDefinition.parentNub instanceof Structure) {
const pos = fp.paramDefinition.parentNub.findPositionInParent();
label = this.intlService.localizeText("INFO_OUVRAGE") + "" + (pos + 1) + ": " + label;
}
data.push({
label: label,
value: this.formattedValue(fp),
isCalcResult: false // for CSS
});
}
}
// is it a result or child result ?const res = this._fixedResults.result;
const res = this._fixedResults.result;
if (
res
&& res.resultElements.length > 0
&& res.resultElement
&& res.resultElement.count() > 0
) {
const sn = this._fixedResults.result.sourceNub;
let found = false;
// 2.1 all results
for (const k of res.resultElement.keys) {
if (k === symbol) {
found = true;
const er: number = res.resultElement.getValue(k);
// calculator type for translation
let ct = sn.calcType;
if (sn.parent) {
ct = sn.parent.calcType;
}
let unit;
// is k the calculated parameter ? If so, extract its unit
try {
const p = res.sourceNub.getParameter(k);
if (p) {
unit = p.unit;
}
} catch (e) { /* silent fail */ }
const label = this.formService.expandVariableNameAndUnit(ct, k, unit);
data.push({
label: label,
value: this.intlService.formatResult(k, er),
isCalcResult: true // for CSS
});
}
}
// 2.2. children results
if (! found) {
for (const c of sn.getChildren()) {
if (c.result) {
for (const k of c.result.resultElement.keys) {
if (k === symbol) {
const er: number = c.result.resultElement.getValue(k);
// calculator type for translation
let ct = sn.calcType;
if (sn.parent) {
ct = sn.parent.calcType;
}
const cn = capitalize(this.intlService.childName(sn));
data.push({
label: sprintf(this.intlService.localizeText("INFO_STUFF_N"), cn)
+ (c.findPositionInParent() + 1) + " : "
+ this.formService.expandVariableNameAndUnit(ct, k),
value: this.intlService.formatResult(k, er),
isCalcResult: true // for CSS
});
}
}
}
}
}
}
}
return data;
}
/**
* When this.variablesOrder is empty or undefined, builds an ordered set of
* data with fixed parameters first, then parent results, then children results
*/
protected buildDefaultOrderedDataset() {
const data = [];
// 1. fixed parameters
for (const fp of this.fixedParams) {
......
......@@ -2,6 +2,7 @@ import { IObservable } from "jalhyd";
import { FormulaireBase } from "./form-base";
import { FieldSet } from "../../fieldset";
import { FormResultFixedVar } from "../form-result-fixedvar";
/**
* Formulaire pour les Grilles (perte de charge)
......@@ -14,6 +15,17 @@ export class FormulaireGrille extends FormulaireBase {
/** id of select configuring grid type */
private _gridTypeSelectId: string;
constructor() {
super();
// custom variables order for results tables
(this._formResult as FormResultFixedVar).fixedResults.variablesOrder = [
"QMax", "CRad", "CEau", "H", "CSomGrille", "HG", "B", "S", "SPDG", "VA", "VAPDG",
"Beta", "Alpha", "LG", "D", "DG", "SG", "VN",
"b", "p", "e", "RFB", "REEB", "OB", "O", "OEntH", "cIncl",
"DH00", "DH05", "DH10", "DH15", "DH20", "DH25", "DH30", "DH35", "DH40", "DH45", "DH50", "DH55", "DH60"
];
}
protected parseOptions(json: {}) {
super.parseOptions(json);
this._gridProfileSelectId = this.getOption(json, "gridProfileSelectId");
......
......@@ -7,9 +7,8 @@ import { CalculatorResults } from "../../results/calculator-results";
import { ChartType } from "../../results/chart-type";
export class FormResultFixedVar extends FormResult {
/**
* résultats fixes/variables
*/
/** résultats fixes/variables */
protected _fixedResults: FixedResults;
protected _varResults: VarResults;
......
......@@ -22,6 +22,9 @@ export abstract class CalculatedParamResults extends CalculatorResults {
*/
public result: Result;
/** custom variables order for results tables */
public variablesOrder: string[] = [];
protected reset() {
this._calculatedParam = undefined;
this.calculatedParameterHeader = undefined;
......
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