Skip to content
Snippets Groups Projects
Commit 68eaa8cd authored by Dorchies David's avatar Dorchies David
Browse files

Merge branch '590-optimiser-l-affichage-des-unites' into 'devel'

Resolve "Optimiser l'affichage des unités"

Closes #590

See merge request !195
parents 8d74156a 1e289986
No related branches found
No related tags found
2 merge requests!225Release v4.17.0,!195Resolve "Optimiser l'affichage des unités"
Pipeline #140144 passed
Showing
with 39 additions and 32 deletions
...@@ -36,11 +36,11 @@ describe("Lechapt&Calmon - ", () => { ...@@ -36,11 +36,11 @@ describe("Lechapt&Calmon - ", () => {
await browser.sleep(200); await browser.sleep(200);
// open Lechapt-Calmon calculator // open Lechapt-Calmon calculator
await listPage.clickMenuEntryForCalcType(1); await listPage.clickMenuEntryForCalcType(35);
await browser.sleep(200); await browser.sleep(200);
} }
it("when material is modified, results should change", async () => { xit("when material is modified, results should change", async () => { // temporairement débranché, cf. jalhyd#334 / nghyd#585
await setup(); await setup();
// select last material type // select last material type
......
334-restructurer-lechapt-et-calmon-pour-de-nouvelles-lois-de-pertes-de-charge 338-optimiser-l-affichage-des-unites
...@@ -20,7 +20,7 @@ export class SelectFieldChartType extends SelectField { ...@@ -20,7 +20,7 @@ export class SelectFieldChartType extends SelectField {
protected populate() { protected populate() {
for (const v of this._entryValues) { for (const v of this._entryValues) {
const id: string = ChartType[v]; const id: string = ChartType[v];
this.addEntry(new SelectEntry(id, v)); this.addEntry(this.createOrGetEntry(id, v));
} }
} }
...@@ -50,4 +50,4 @@ export class SelectFieldChartType extends SelectField { ...@@ -50,4 +50,4 @@ export class SelectFieldChartType extends SelectField {
this._label = this.intlService.localizeText("INFO_PARAMFIELD_CHART_TYPE"); this._label = this.intlService.localizeText("INFO_PARAMFIELD_CHART_TYPE");
} }
} }
\ No newline at end of file
...@@ -47,7 +47,7 @@ export class SelectFieldDeviceLoiDebit extends SelectField { ...@@ -47,7 +47,7 @@ export class SelectFieldDeviceLoiDebit extends SelectField {
const stName = StructureType[stCode]; const stName = StructureType[stCode];
if (la[stName] !== undefined) { if (la[stName] !== undefined) {
for (const ld of la[stName]) { for (const ld of la[stName]) {
const e: SelectEntry = new SelectEntry(this._entriesBaseId + LoiDebit[ld], ld); const e: SelectEntry = this.createOrGetEntry(this._entriesBaseId + LoiDebit[ld], ld);
this.addEntry(e); this.addEntry(e);
} }
} }
......
...@@ -24,7 +24,7 @@ export class SelectFieldDeviceStructureType extends SelectField { ...@@ -24,7 +24,7 @@ export class SelectFieldDeviceStructureType extends SelectField {
protected populate() { protected populate() {
// possible values depend on CalcType // possible values depend on CalcType
for (const st in (this.nub as ParallelStructure).getLoisAdmissibles()) { for (const st in (this.nub as ParallelStructure).getLoisAdmissibles()) {
const e: SelectEntry = new SelectEntry(this._entriesBaseId + st, StructureType[st]); const e: SelectEntry = this.createOrGetEntry(this._entriesBaseId + st, StructureType[st]);
this.addEntry(e); this.addEntry(e);
} }
} }
......
...@@ -19,13 +19,13 @@ export class SelectFieldDownstreamBasin extends SelectField { ...@@ -19,13 +19,13 @@ export class SelectFieldDownstreamBasin extends SelectField {
for (const b of preBarrageD.bassins) { for (const b of preBarrageD.bassins) {
const pos = b.findPositionInParent(); const pos = b.findPositionInParent();
if (posUb === undefined || pos > posUb) { if (posUb === undefined || pos > posUb) {
const e = new SelectEntry(this._entriesBaseId + b.uid, b.uid); const e = this.createOrGetEntry(this._entriesBaseId + b.uid, b.uid);
e.intlInfo = b.description; e.intlInfo = b.description;
this.addEntry(e); this.addEntry(e);
} }
} }
// river downstream // river downstream
const e = new SelectEntry(this._entriesBaseId + "none", undefined); const e = this.createOrGetEntry(this._entriesBaseId + "none", undefined);
e.intlInfo = "INFO_LIB_AVAL"; e.intlInfo = "INFO_LIB_AVAL";
this.addEntry(e); this.addEntry(e);
} }
......
...@@ -31,7 +31,7 @@ export class SelectFieldNubProperty extends SelectField { ...@@ -31,7 +31,7 @@ export class SelectFieldNubProperty extends SelectField {
if (enumClass !== undefined) { if (enumClass !== undefined) {
// add one select entry per enum entry, in the enum order // add one select entry per enum entry, in the enum order
for (let j = 0; j < Object.keys(enumClass).length / 2; j++) { for (let j = 0; j < Object.keys(enumClass).length / 2; j++) {
this.addEntry(new SelectEntry(this._entriesBaseId + j, j)); this.addEntry(this.createOrGetEntry(this._entriesBaseId + j, j));
} }
} }
} }
......
...@@ -19,9 +19,9 @@ export class SelectFieldRemousTarget extends SelectField { ...@@ -19,9 +19,9 @@ export class SelectFieldRemousTarget extends SelectField {
protected populate() { protected populate() {
// driven by string[], not enum (easier for variable names) // driven by string[], not enum (easier for variable names)
this.addEntry(new SelectEntry(this._entriesBaseId + "none", "")); this.addEntry(this.createOrGetEntry(this._entriesBaseId + "none", ""));
for (const at of CourbeRemous.availableTargets) { for (const at of CourbeRemous.availableTargets) {
const e: SelectEntry = new SelectEntry(this._entriesBaseId + at, at); const e: SelectEntry = this.createOrGetEntry(this._entriesBaseId + at, at);
this.addEntry(e); this.addEntry(e);
} }
} }
......
...@@ -28,7 +28,7 @@ export class SelectFieldSearchedParam extends SelectField { ...@@ -28,7 +28,7 @@ export class SelectFieldSearchedParam extends SelectField {
const calc = fs.getFormulaireFromId(p.originNub.uid).calculatorName; const calc = fs.getFormulaireFromId(p.originNub.uid).calculatorName;
const varName = fs.expandVariableName(p.originNub.calcType, p.symbol); const varName = fs.expandVariableName(p.originNub.calcType, p.symbol);
const label = `${p.symbol} - ${varName} (${calc})`; const label = `${p.symbol} - ${varName} (${calc})`;
this.addEntry(new SelectEntry(this._entriesBaseId + p.getParentComputeNode(false).uid + "_" + p.symbol, p, decodeHtml(label))); this.addEntry(this.createOrGetEntry(this._entriesBaseId + p.getParentComputeNode(false).uid + "_" + p.symbol, p, decodeHtml(label)));
} }
} }
} }
......
...@@ -24,12 +24,12 @@ export class SelectFieldSolverTargetedResult extends SelectField { ...@@ -24,12 +24,12 @@ export class SelectFieldSolverTargetedResult extends SelectField {
// 1. calculated param // 1. calculated param
const ntc = (this.nub as Solveur).nubToCalculate; const ntc = (this.nub as Solveur).nubToCalculate;
if (ntc?.calculatedParam !== undefined) { // some nubs have no calculatedParam, for ex. SectionParam if (ntc?.calculatedParam !== undefined) { // some nubs have no calculatedParam, for ex. SectionParam
this.addEntry(new SelectEntry(this._entriesBaseId + "none", "")); this.addEntry(this.createOrGetEntry(this._entriesBaseId + "none", ""));
} }
// 2. extra results // 2. extra results
if (ntc?.resultsFamilies !== undefined) { if (ntc?.resultsFamilies !== undefined) {
for (const er of Object.keys(ntc.resultsFamilies)) { for (const er of Object.keys(ntc.resultsFamilies)) {
const e: SelectEntry = new SelectEntry(this._entriesBaseId + er, er); const e: SelectEntry = this.createOrGetEntry(this._entriesBaseId + er, er);
this.addEntry(e); this.addEntry(e);
} }
} }
......
...@@ -33,7 +33,7 @@ export class SelectFieldSolverTarget extends SelectField { ...@@ -33,7 +33,7 @@ export class SelectFieldSolverTarget extends SelectField {
const varName = fs.expandVariableName(cn.calcType, cn.calculatedParam.symbol); const varName = fs.expandVariableName(cn.calcType, cn.calculatedParam.symbol);
label += ` / ${varName} (${cn.calculatedParam.symbol})`; label += ` / ${varName} (${cn.calculatedParam.symbol})`;
} }
this.addEntry(new SelectEntry(this._entriesBaseId + cn.uid, cn.uid, decodeHtml(label))); this.addEntry(this.createOrGetEntry(this._entriesBaseId + cn.uid, cn.uid, decodeHtml(label)));
} else { } else {
// silent fail, this Solveur nub was probably loaded before all the candidate nubs are done loading // silent fail, this Solveur nub was probably loaded before all the candidate nubs are done loading
} }
......
...@@ -24,14 +24,14 @@ export class SelectFieldSpeciesList extends SelectField { ...@@ -24,14 +24,14 @@ export class SelectFieldSpeciesList extends SelectField {
const especeNubs = Session.getInstance().getAllNubs().filter((element) => element.calcType === CalculatorType.Espece); const especeNubs = Session.getInstance().getAllNubs().filter((element) => element.calcType === CalculatorType.Espece);
for (const en of especeNubs) { for (const en of especeNubs) {
const form = ServiceFactory.formulaireService.getFormulaireFromNubId(en.uid); const form = ServiceFactory.formulaireService.getFormulaireFromNubId(en.uid);
const e = new SelectEntry(this._entriesBaseId + en.uid, en.uid); const e = this.createOrGetEntry(this._entriesBaseId + en.uid, en.uid);
e.intlInfo = { "isnub": true, "code": "INFO_VERIFICATEUR_CUSTOM_SPECIES", "id": en.uid }; e.intlInfo = { "isnub": true, "code": "INFO_VERIFICATEUR_CUSTOM_SPECIES", "id": en.uid };
this.addEntry(e); this.addEntry(e);
} }
// add all FishSpecies // add all FishSpecies
for (let j = 1; j < Object.keys(FishSpecies).length / 2; j++) { // exclude "0" (SPECIES_CUSTOM) for (let j = 1; j < Object.keys(FishSpecies).length / 2; j++) { // exclude "0" (SPECIES_CUSTOM)
const spgId = FishSpecies[j].substring(FishSpecies[j].lastIndexOf("_") + 1); const spgId = FishSpecies[j].substring(FishSpecies[j].lastIndexOf("_") + 1);
const e = new SelectEntry(this._entriesBaseId + spgId, FishSpecies[j]); const e = this.createOrGetEntry(this._entriesBaseId + spgId, FishSpecies[j]);
e.intlInfo = { "isnub": false, "code": FishSpecies[j] } e.intlInfo = { "isnub": false, "code": FishSpecies[j] }
this.addEntry(e); this.addEntry(e);
} }
......
...@@ -33,7 +33,7 @@ export class SelectFieldTargetPass extends SelectField { ...@@ -33,7 +33,7 @@ export class SelectFieldTargetPass extends SelectField {
const nub = fs.getFormulaireFromId(cn.uid); const nub = fs.getFormulaireFromId(cn.uid);
if (nub) { if (nub) {
const label = nub.calculatorName + " (" + fs.getLocalisedTitleFromCalculatorType(nub.calculatorType) + ")"; const label = nub.calculatorName + " (" + fs.getLocalisedTitleFromCalculatorType(nub.calculatorType) + ")";
this.addEntry(new SelectEntry(this._entriesBaseId + cn.uid, cn.uid, decodeHtml(label))); this.addEntry(this.createOrGetEntry(this._entriesBaseId + cn.uid, cn.uid, decodeHtml(label)));
} else { } else {
// silent fail, this Verificateur nub was probably loaded before all the candidate nubs are done loading // silent fail, this Verificateur nub was probably loaded before all the candidate nubs are done loading
} }
......
...@@ -17,7 +17,7 @@ export class SelectFieldUpstreamBasin extends SelectField { ...@@ -17,7 +17,7 @@ export class SelectFieldUpstreamBasin extends SelectField {
const posDb = pbWallU.bassinAval?.findPositionInParent(); const posDb = pbWallU.bassinAval?.findPositionInParent();
// river upstream // river upstream
const e = new SelectEntry(this._entriesBaseId + "none", undefined); const e = this.createOrGetEntry(this._entriesBaseId + "none", undefined);
e.intlInfo = "INFO_LIB_AMONT"; e.intlInfo = "INFO_LIB_AMONT";
this.addEntry(e); this.addEntry(e);
...@@ -25,7 +25,7 @@ export class SelectFieldUpstreamBasin extends SelectField { ...@@ -25,7 +25,7 @@ export class SelectFieldUpstreamBasin extends SelectField {
for (const b of preBarrageU.bassins) { for (const b of preBarrageU.bassins) {
const pos = b.findPositionInParent(); const pos = b.findPositionInParent();
if (posDb === undefined || pos < posDb) { if (posDb === undefined || pos < posDb) {
const e = new SelectEntry(this._entriesBaseId + b.uid, b.uid); const e = this.createOrGetEntry(this._entriesBaseId + b.uid, b.uid);
e.intlInfo = b.description; e.intlInfo = b.description;
this.addEntry(e); this.addEntry(e);
} }
......
...@@ -36,6 +36,11 @@ export abstract class SelectField extends Field { ...@@ -36,6 +36,11 @@ export abstract class SelectField extends Field {
*/ */
protected _messageWhenEmpty: string; protected _messageWhenEmpty: string;
/**
* map id <-> select entry
*/
protected _entryMap: { [key: string]: SelectEntry } = {};
constructor(parent: FormulaireNode) { constructor(parent: FormulaireNode) {
super(parent); super(parent);
this.clearEntries(); this.clearEntries();
...@@ -210,6 +215,15 @@ export abstract class SelectField extends Field { ...@@ -210,6 +215,15 @@ export abstract class SelectField extends Field {
this._entries.push(e); this._entries.push(e);
} }
protected createOrGetEntry(id: string, val: any, lbl?: string): SelectEntry {
let res: SelectEntry = this._entryMap[id];
if (res === undefined) {
res = new SelectEntry(id, val, lbl);
this._entryMap[id] = res;
}
return res;
}
public getEntryFromValue(val: any): SelectEntry { public getEntryFromValue(val: any): SelectEntry {
for (const se of this._entries) { for (const se of this._entries) {
if (se.value === val) { if (se.value === val) {
......
...@@ -58,6 +58,7 @@ import { FormulaireEspece } from "../formulaire/definition/form-espece"; ...@@ -58,6 +58,7 @@ import { FormulaireEspece } from "../formulaire/definition/form-espece";
import { FormulairePrebarrage } from "../formulaire/definition/form-prebarrage"; import { FormulairePrebarrage } from "../formulaire/definition/form-prebarrage";
import { ServiceFactory } from "./service-factory"; import { ServiceFactory } from "./service-factory";
import { FormulairePressureLoss } from "app/formulaire/definition/form-pressureloss"; import { FormulairePressureLoss } from "app/formulaire/definition/form-pressureloss";
import { getNubResultUnit } from "jalhyd";
@Injectable() @Injectable()
export class FormulaireService extends Observable { export class FormulaireService extends Observable {
...@@ -194,7 +195,7 @@ export class FormulaireService extends Observable { ...@@ -194,7 +195,7 @@ export class FormulaireService extends Observable {
* Returns variable name and unit from symbol * Returns variable name and unit from symbol
* @param calcType * @param calcType
* @param symbol * @param symbol
* @param forceUnit if given, will be used as nuit * @param forceUnit if given, will be used as unit
*/ */
public expandVariableNameAndUnit(calcType: CalculatorType, symbol: string, forceUnit?: string): string { public expandVariableNameAndUnit(calcType: CalculatorType, symbol: string, forceUnit?: string): string {
let s = this.expandVariableName(calcType, symbol); let s = this.expandVariableName(calcType, symbol);
...@@ -217,16 +218,8 @@ export class FormulaireService extends Observable { ...@@ -217,16 +218,8 @@ export class FormulaireService extends Observable {
if (forceUnit) { if (forceUnit) {
unit = forceUnit; unit = forceUnit;
} else { } else {
// create dummy Nub from CalcType just to get results units unit = getNubResultUnit(calcType, symbol);
let dummyNub: Nub; if (unit === undefined) {
try {
dummyNub = Session.getInstance().createNub(new Props({ "calcType": calcType }));
} catch (e) {
// silent fail
}
if (dummyNub?.resultsUnits && dummyNub.resultsUnits[symbol]) {
unit = dummyNub.resultsUnits[symbol];
} else {
// last chance: if unit cannot be read in model, use translation files // last chance: if unit cannot be read in model, use translation files
const unitKey = "UNIT_" + symbolBase; const unitKey = "UNIT_" + symbolBase;
if (langCache && langCache[unitKey] !== undefined) { if (langCache && langCache[unitKey] !== undefined) {
......
  • David Dorchies :zany_face: @david.dorchies

    mentioned in issue #592 (closed)

    By Grand Francois on 2023-01-23T10:36:31 (imported from GitLab)

    ·

    mentioned in issue #592 (closed)

    By Grand Francois on 2023-01-23T10:36:31 (imported from GitLab)

    Toggle commit list
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