From 8d30c71000facfaf31ec6c1518958f8e23fff9f1 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Tue, 27 Aug 2019 15:57:00 +0200 Subject: [PATCH] Improve #221 --- .../macrorugo-compound.en.json | 1 + .../macrorugo-compound.fr.json | 1 + .../field-set/field-set.component.ts | 26 +++++-------------- .../fixed-results.component.ts | 11 +++++--- .../definition/form-compute-fixedvar.ts | 7 ++++- src/app/results/calculator-results.ts | 9 ++++--- src/app/results/var-results.ts | 10 ++++--- .../internationalisation.service.ts | 15 ++++++++++- src/locale/messages.en.json | 1 + src/locale/messages.fr.json | 1 + 10 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/app/calculators/macrorugo-compound/macrorugo-compound.en.json b/src/app/calculators/macrorugo-compound/macrorugo-compound.en.json index 5a0c150cf..635eddb02 100644 --- a/src/app/calculators/macrorugo-compound/macrorugo-compound.en.json +++ b/src/app/calculators/macrorugo-compound/macrorugo-compound.en.json @@ -18,6 +18,7 @@ "BR": "Total width", "ZF1": "Apron elevation", "B": "Width", + "xCenter": "Mid-apron abscissa", "select_pass_type_0": "Multiple aprons", "select_pass_type_1": "Inclined apron" diff --git a/src/app/calculators/macrorugo-compound/macrorugo-compound.fr.json b/src/app/calculators/macrorugo-compound/macrorugo-compound.fr.json index 3bd851bf0..c1999b7e5 100644 --- a/src/app/calculators/macrorugo-compound/macrorugo-compound.fr.json +++ b/src/app/calculators/macrorugo-compound/macrorugo-compound.fr.json @@ -18,6 +18,7 @@ "BR": "Largeur totale", "ZF1": "Cote de radier", "B": "Largeur", + "xCenter": "Abscisse du milieu du radier", "select_pass_type_0": "Radiers multiples", "select_pass_type_1": "Radier incliné" diff --git a/src/app/components/field-set/field-set.component.ts b/src/app/components/field-set/field-set.component.ts index e083be328..45601ca85 100644 --- a/src/app/components/field-set/field-set.component.ts +++ b/src/app/components/field-set/field-set.component.ts @@ -332,20 +332,6 @@ export class FieldSetComponent implements DoCheck { return this.i18nService.localizeText("INFO_FIELDSET_MOVE_DOWN"); } - /** - * Returns the localized name for the children type of the current Nub - * @param plural if true, will return plural name - */ - private childName(plural: boolean = false) { - const type: string = this._fieldSet.nub.parent.childrenType; - console.log(`Child type for nub ${this._fieldSet.nub.constructor.name} : ${type}`); - let k = "INFO_CHILD_TYPE_" + type.toUpperCase(); - if (plural) { - k += "_PLUR"; - } - return this.i18nService.localizeText(k); - } - /** * clic sur le bouton ajouter */ @@ -358,10 +344,10 @@ export class FieldSetComponent implements DoCheck { } let msg: string; if (this.childrenToAdd === 1) { - const cns = this.childName(); + const cns = this.i18nService.childName(this._fieldSet.nub.parent); msg = sprintf(this.i18nService.localizeText("INFO_STUFF_ADDED"), cns); } else { - const cnp = this.childName(true); + const cnp = this.i18nService.childName(this._fieldSet.nub.parent, true); msg = sprintf(this.i18nService.localizeText("INFO_STUFF_ADDED_N_TIMES"), this.childrenToAdd, cnp); } this.notifService.notify(msg); @@ -380,7 +366,7 @@ export class FieldSetComponent implements DoCheck { } const pos = (this._fieldSet.parent as FieldsetContainer).getFieldsetPosition(this._fieldSet) + 1; let msg: string; - const cns = capitalize(this.childName()); + const cns = capitalize(this.i18nService.childName(this._fieldSet.nub.parent)); if (this.childrenToAdd === 1) { msg = sprintf(this.i18nService.localizeText("INFO_STUFF_COPIED"), cns, pos); } else { @@ -396,7 +382,7 @@ export class FieldSetComponent implements DoCheck { private onRemoveClick() { const pos = (this._fieldSet.parent as FieldsetContainer).getFieldsetPosition(this._fieldSet) + 1; this.removeFieldset.emit(this._fieldSet); - const cns = capitalize(this.childName()); + const cns = capitalize(this.i18nService.childName(this._fieldSet.nub.parent)); this.notifService.notify( sprintf(this.i18nService.localizeText("INFO_STUFF_REMOVED"), cns, pos) ); @@ -408,7 +394,7 @@ export class FieldSetComponent implements DoCheck { private onMoveUpClick() { const pos = (this._fieldSet.parent as FieldsetContainer).getFieldsetPosition(this._fieldSet) + 1; this.moveFieldsetUp.emit(this._fieldSet); - const cns = capitalize(this.childName()); + const cns = capitalize(this.i18nService.childName(this._fieldSet.nub.parent)); this.notifService.notify( sprintf(this.i18nService.localizeText("INFO_STUFF_MOVED"), cns, pos) ); @@ -420,7 +406,7 @@ export class FieldSetComponent implements DoCheck { private onMoveDownClick() { const pos = (this._fieldSet.parent as FieldsetContainer).getFieldsetPosition(this._fieldSet) + 1; this.moveFieldsetDown.emit(this._fieldSet); - const cns = capitalize(this.childName()); + const cns = capitalize(this.i18nService.childName(this._fieldSet.nub.parent)); this.notifService.notify( sprintf(this.i18nService.localizeText("INFO_STUFF_MOVED"), cns, pos) ); diff --git a/src/app/components/fixedvar-results/fixed-results.component.ts b/src/app/components/fixedvar-results/fixed-results.component.ts index 6a38cb84e..411f4f833 100644 --- a/src/app/components/fixedvar-results/fixed-results.component.ts +++ b/src/app/components/fixedvar-results/fixed-results.component.ts @@ -5,10 +5,14 @@ import { NgParameter } from "../../formulaire/ngparam"; import { CalculatorResults } from "../../results/calculator-results"; import { I18nService } from "../../services/internationalisation/internationalisation.service"; import { ApplicationSetupService } from "../../services/app-setup/app-setup.service"; -import * as XLSX from "xlsx"; -import { Structure } from "jalhyd"; import { FormulaireService } from "../../services/formulaire/formulaire.service"; +import { Structure, Nub, capitalize } from "jalhyd"; + +import * as XLSX from "xlsx"; + +import { sprintf } from "sprintf-js"; + @Component({ selector: "fixed-results", templateUrl: "./fixed-results.component.html", @@ -122,8 +126,9 @@ export class FixedResultsComponent { if (sn.parent) { ct = sn.parent.calcType; } + const cn = capitalize(this.intlService.childName(sn)); data.push({ - label: this.intlService.localizeText("INFO_OUVRAGE_N") + label: sprintf(this.intlService.localizeText("INFO_STUFF_N"), cn) + (c.findPositionInParent() + 1) + " : " + this.formService.expandVariableNameAndUnit(ct, k), value: this.intlService.formatResult(k, er), diff --git a/src/app/formulaire/definition/form-compute-fixedvar.ts b/src/app/formulaire/definition/form-compute-fixedvar.ts index 00d5793b3..ede113a8f 100644 --- a/src/app/formulaire/definition/form-compute-fixedvar.ts +++ b/src/app/formulaire/definition/form-compute-fixedvar.ts @@ -29,7 +29,12 @@ export class FormComputeFixedVar extends FormCompute { } private getComputedParameter(): NgParameter { - return this._formBase.getDisplayedParamFromState(ParamRadioConfig.CAL); + const cpd = this._formBase.currentNub.calculatedParam; + let ngparam = this._formBase.getParamFromSymbol(cpd.symbol); + if (ngparam === undefined) { // calculated parameter is not displayed on screen + ngparam = new NgParameter(cpd, this._formBase); + } + return ngparam; } protected compute() { diff --git a/src/app/results/calculator-results.ts b/src/app/results/calculator-results.ts index 36f23984c..0fcc1c090 100644 --- a/src/app/results/calculator-results.ts +++ b/src/app/results/calculator-results.ts @@ -1,11 +1,13 @@ +import { Nub, capitalize } from "jalhyd"; + import { NgParameter } from "../formulaire/ngparam"; -import { Nub } from "jalhyd"; import { ServiceFactory } from "../services/service-factory"; +import { sprintf } from "sprintf-js"; + export abstract class CalculatorResults { /** - * * @param p parameter to generate label for * @param displaySymbol if true, will prefix label with parameter symbol (ex: "ZDV") * @param referenceNub if given, will detect if parameter belongs to a child of this reference Nub, and @@ -18,10 +20,11 @@ export abstract class CalculatorResults { if (referenceNub) { const children = referenceNub.getChildren(); const parameterNub = p.paramDefinition.parentNub; + const cn = capitalize(ServiceFactory.instance.i18nService.childName(parameterNub)); if (children.includes(parameterNub)) { isChildParam = true; const pos = parameterNub.findPositionInParent() + 1; - res = ServiceFactory.instance.i18nService.localizeText("INFO_OUVRAGE_N") + pos + " : "; + res = sprintf(ServiceFactory.instance.i18nService.localizeText("INFO_OUVRAGE_N"), cn) + pos + " : "; } } if (displaySymbol && ! isChildParam) { diff --git a/src/app/results/var-results.ts b/src/app/results/var-results.ts index a3823065c..f0354dad7 100644 --- a/src/app/results/var-results.ts +++ b/src/app/results/var-results.ts @@ -1,11 +1,13 @@ import { CalculatorResults } from "./calculator-results"; import { CalculatedParamResults } from "./param-calc-results"; import { NgParameter } from "../formulaire/ngparam"; -import { ResultElement, ParamFamily } from "jalhyd"; +import { ResultElement, ParamFamily, capitalize } from "jalhyd"; import { ServiceFactory } from "../services/service-factory"; import { PlottableData } from "./plottable-data"; import { GraphType } from "./graph-type"; +import { sprintf } from "sprintf-js"; + export class VarResults extends CalculatedParamResults implements PlottableData { /** * paramètres variés @@ -132,7 +134,8 @@ export class VarResults extends CalculatedParamResults implements PlottableData const pos = +match[1]; ct = sn.getChildren()[pos].calcType; symbol = match[2]; - ret += ServiceFactory.instance.i18nService.localizeText("INFO_OUVRAGE_N") + (pos + 1) + " : "; + const cn = capitalize(ServiceFactory.instance.i18nService.childName(sn)); + ret += sprintf(ServiceFactory.instance.i18nService.localizeText("INFO_STUFF_N"), cn) + (pos + 1) + " : "; } ret += ServiceFactory.instance.formulaireService.expandVariableNameAndUnit(ct, symbol); return ret; @@ -360,10 +363,11 @@ export class VarResults extends CalculatedParamResults implements PlottableData // entêtes des résultats des enfants for (const c of sn.getChildren()) { if (c.result) { + const cn = capitalize(ServiceFactory.instance.i18nService.childName(sn)); // using latest ResultElement; results count / types are supposed to be the same on every iteration for (const k of c.result.resultElement.keys) { this._resultHeaders.push( - ServiceFactory.instance.i18nService.localizeText("INFO_OUVRAGE_N") + sprintf(ServiceFactory.instance.i18nService.localizeText("INFO_STUFF_N"), cn) + (c.findPositionInParent() + 1) + " : " + ServiceFactory.instance.formulaireService.expandVariableNameAndUnit(c.calcType, k) ); diff --git a/src/app/services/internationalisation/internationalisation.service.ts b/src/app/services/internationalisation/internationalisation.service.ts index 7590f251d..23621adbe 100644 --- a/src/app/services/internationalisation/internationalisation.service.ts +++ b/src/app/services/internationalisation/internationalisation.service.ts @@ -1,6 +1,6 @@ import { Injectable, isDevMode } from "@angular/core"; -import { Message, MessageCode, Observable, Observer, CalculatorType, LoiDebit } from "jalhyd"; +import { Message, MessageCode, Observable, Observer, CalculatorType, LoiDebit, Nub } from "jalhyd"; import { StringMap } from "../../stringmap"; import { ApplicationSetupService } from "../app-setup/app-setup.service"; @@ -201,6 +201,19 @@ export class I18nService extends Observable implements Observer { return value.toFixed(nDigits); } + /** + * Returns the localized name for the children type of the current Nub + * @param plural if true, will return plural name + */ + public childName(nub: Nub, plural: boolean = false) { + const type: string = nub.childrenType; + let k = "INFO_CHILD_TYPE_" + type.toUpperCase(); + if (plural) { + k += "_PLUR"; + } + return this.localizeText(k); + } + // interface Observer /** diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index 4a82cf001..2a22bfec4 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -129,6 +129,7 @@ "INFO_STUFF_COPIED_N_TIMES": "%s #%s copied %s times", "INFO_STUFF_MOVED": "%s #%s moved", "INFO_STUFF_REMOVED": "%s #%s removed", + "INFO_STUFF_N": "%s #", "INFO_CHILD_TYPE_STRUCTURE": "device", "INFO_CHILD_TYPE_STRUCTURE_PLUR": "devices", "INFO_CHILD_TYPE_MACRORUGO": "apron", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index f60e1d225..7155a166c 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -129,6 +129,7 @@ "INFO_STUFF_COPIED_N_TIMES": "%s n°%s copié(e) %s fois", "INFO_STUFF_MOVED": "%s n°%s déplacé(e)", "INFO_STUFF_REMOVED": "%s n°%s supprimé(e)", + "INFO_STUFF_N": "%s n°", "INFO_CHILD_TYPE_STRUCTURE": "ouvrage", "INFO_CHILD_TYPE_STRUCTURE_PLUR": "ouvrages", "INFO_CHILD_TYPE_MACRORUGO": "radier", -- GitLab