From e0e477d0eae860930e2eb55a9b3f0918b5c23671 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Tue, 12 Nov 2019 17:34:01 +0100 Subject: [PATCH] Fixed input and results prefixing for children Nubs --- .../fixed-results.component.ts | 26 ++++++++++++------- .../generic-input/generic-input.component.ts | 7 +++-- .../param-computed.component.ts | 5 ++-- .../param-link/param-link.component.ts | 5 ++-- .../param-values/param-values.component.ts | 5 ++-- src/app/formulaire/fieldset.ts | 4 +-- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/src/app/components/fixedvar-results/fixed-results.component.ts b/src/app/components/fixedvar-results/fixed-results.component.ts index 5d676ff58..ab00d2350 100644 --- a/src/app/components/fixedvar-results/fixed-results.component.ts +++ b/src/app/components/fixedvar-results/fixed-results.component.ts @@ -8,7 +8,7 @@ import { FormulaireService } from "../../services/formulaire.service"; import { ResultsComponent } from "./results.component"; import { AppComponent } from "../../app.component"; -import { Structure, capitalize } from "jalhyd"; +import { capitalize } from "jalhyd"; import { sprintf } from "sprintf-js"; @@ -95,10 +95,14 @@ export class FixedResultsComponent extends ResultsComponent { 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") + " n°" + (pos + 1) + ": " + label; + const nub = fp.paramDefinition.parentNub; + // add child type and position before label + if (nub && nub.parent && nub.parent.childrenType) { + const pos = nub.findPositionInParent(); + // label = this.intlService.localizeText("INFO_OUVRAGE") + " n°" + (pos + 1) + ": " + label; + const cn = capitalize(this.intlService.childName(nub.parent)); + label = sprintf(this.intlService.localizeText("INFO_STUFF_N"), cn) + + (pos + 1) + ": " + label; } label += this._fixedResults.getHelpLink(symbol); data.push({ @@ -189,10 +193,14 @@ export class FixedResultsComponent extends ResultsComponent { // 1. fixed parameters for (const fp of this.fixedParams) { 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") + " n°" + (pos + 1) + ": " + label; + const nub = fp.paramDefinition.parentNub; + // add child type and position before label + if (nub && nub.parent && nub.parent.childrenType) { + const pos = nub.findPositionInParent(); + // label = this.intlService.localizeText("INFO_OUVRAGE") + " n°" + (pos + 1) + ": " + label; + const cn = capitalize(this.intlService.childName(nub.parent)); + label = sprintf(this.intlService.localizeText("INFO_STUFF_N"), cn) + + (pos + 1) + ": " + label; } label += this._fixedResults.getHelpLink(fp.symbol); data.push({ diff --git a/src/app/components/generic-input/generic-input.component.ts b/src/app/components/generic-input/generic-input.component.ts index f49b62c0e..0e946cfed 100644 --- a/src/app/components/generic-input/generic-input.component.ts +++ b/src/app/components/generic-input/generic-input.component.ts @@ -1,6 +1,6 @@ import { Input, Output, EventEmitter, ChangeDetectorRef, OnChanges, ViewChild } from "@angular/core"; import { NgModel } from "@angular/forms"; -import { isNumeric, Structure, Pab, MacrorugoCompound } from "jalhyd"; +import { isNumeric, Structure, Pab, MacrorugoCompound, SPP } from "jalhyd"; import { FormulaireDefinition } from "../../formulaire/definition/form-definition"; import { NgParameter } from "../../formulaire/ngparam"; import { I18nService } from "../../services/internationalisation.service"; @@ -42,10 +42,9 @@ export abstract class GenericInputComponent implements OnChanges { if (this._model instanceof NgParameter) { const param = this._model as NgParameter; id = param.symbol; - // if inside a nested Structure, prefix with Structure position - // to disambiguate + // if inside a child Nub, prefix with child position to disambiguate const nub = param.paramDefinition.parentNub; - if (nub && (nub instanceof Structure || nub.parent instanceof Pab || nub.parent instanceof MacrorugoCompound)) { + if (nub && nub.parent && nub.parent.childrenType) { id = nub.findPositionInParent() + "_" + id; } } diff --git a/src/app/components/param-computed/param-computed.component.ts b/src/app/components/param-computed/param-computed.component.ts index b6779c083..54bbe75fb 100644 --- a/src/app/components/param-computed/param-computed.component.ts +++ b/src/app/components/param-computed/param-computed.component.ts @@ -25,10 +25,9 @@ export class ParamComputedComponent { */ public get inputId() { let id = "calc_" + this.param.symbol; - // if inside a nested Structure, prefix with Structure position - // to disambiguate + // if inside a child Nub, prefix with child position to disambiguate const nub = this.param.paramDefinition.parentNub; - if (nub && nub instanceof Structure) { + if (nub && nub.parent && nub.parent.childrenType) { id = nub.findPositionInParent() + "_" + id; } return id; diff --git a/src/app/components/param-link/param-link.component.ts b/src/app/components/param-link/param-link.component.ts index ab7b72c47..f12c7cb64 100644 --- a/src/app/components/param-link/param-link.component.ts +++ b/src/app/components/param-link/param-link.component.ts @@ -41,10 +41,9 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { public get selectId() { let id = "linked_" + this.param.symbol; - // if inside a nested Structure, prefix with Structure position - // to disambiguate + // if inside a child Nub, prefix with child position to disambiguate const nub = this.param.paramDefinition.parentNub; - if (nub && nub instanceof Structure) { + if (nub && nub.parent && nub.parent.childrenType) { id = nub.findPositionInParent() + "_" + id; } return id; diff --git a/src/app/components/param-values/param-values.component.ts b/src/app/components/param-values/param-values.component.ts index a22cc098c..6246b6825 100644 --- a/src/app/components/param-values/param-values.component.ts +++ b/src/app/components/param-values/param-values.component.ts @@ -45,10 +45,9 @@ export class ParamValuesComponent implements AfterViewInit, Observer { public get inputId() { let id = "var_" + this.param.symbol; - // if inside a nested Structure, prefix with Structure position - // to disambiguate + // if inside a child Nub, prefix with child position to disambiguate const nub = this.param.paramDefinition.parentNub; - if (nub && nub instanceof Structure) { + if (nub && nub.parent && nub.parent.childrenType) { id = nub.findPositionInParent() + "_" + id; } return id; diff --git a/src/app/formulaire/fieldset.ts b/src/app/formulaire/fieldset.ts index 64d33ddf1..9865597dd 100644 --- a/src/app/formulaire/fieldset.ts +++ b/src/app/formulaire/fieldset.ts @@ -297,8 +297,8 @@ export class FieldSet extends FormulaireElement implements Observer { this.setSelectValueFromProperty("select_unit", "trigoUnit"); break; - case "spp_operation": // SPP - this.setSelectValueFromProperty("spp_operation", "sppOperation"); + case "fs_spp": // SPP + this.setSelectValueFromProperty("select_spp_operation", "sppOperation"); break; } } -- GitLab