From 117f1d12a214473003675821082b9d47c9a26571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 11 Jan 2023 13:37:12 +0100 Subject: [PATCH] refactor : do not create a Nub to get results units refs #590 --- src/app/services/formulaire.service.ts | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index e54805c7d..880741539 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -58,6 +58,7 @@ import { FormulaireEspece } from "../formulaire/definition/form-espece"; import { FormulairePrebarrage } from "../formulaire/definition/form-prebarrage"; import { ServiceFactory } from "./service-factory"; import { FormulairePressureLoss } from "app/formulaire/definition/form-pressureloss"; +import { getNubResultUnit } from "jalhyd"; @Injectable() export class FormulaireService extends Observable { @@ -194,7 +195,7 @@ export class FormulaireService extends Observable { * Returns variable name and unit from symbol * @param calcType * @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 { let s = this.expandVariableName(calcType, symbol); @@ -217,16 +218,8 @@ export class FormulaireService extends Observable { if (forceUnit) { unit = forceUnit; } else { - // create dummy Nub from CalcType just to get results units - let dummyNub: Nub; - try { - dummyNub = Session.getInstance().createNub(new Props({ "calcType": calcType })); - } catch (e) { - // silent fail - } - if (dummyNub?.resultsUnits && dummyNub.resultsUnits[symbol]) { - unit = dummyNub.resultsUnits[symbol]; - } else { + unit = getNubResultUnit(calcType, symbol); + if (unit === undefined) { // last chance: if unit cannot be read in model, use translation files const unitKey = "UNIT_" + symbolBase; if (langCache && langCache[unitKey] !== undefined) { -- GitLab