From 9504eed41f36a220585a3e659e7dae56e9cef4f6 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Thu, 30 Jul 2020 15:59:27 +0200 Subject: [PATCH] GUI for jalhyd#237 --- src/app/calculators/espece/config.json | 7 +++ src/app/calculators/espece/en.json | 5 ++ src/app/calculators/espece/fr.json | 5 ++ .../calculator.component.ts | 1 + .../generic-input/generic-input.component.ts | 25 ++++------ src/app/formulaire/definition/form-espece.ts | 46 +++++++++++++++++++ .../definition/form-macrorugo-compound.ts | 1 - .../definition/form-parallel-structures.ts | 1 - .../definition/form-verificateur.ts | 2 +- src/app/formulaire/elements/ngparam.ts | 4 ++ src/app/services/formulaire.service.ts | 5 ++ src/locale/messages.en.json | 4 ++ src/locale/messages.fr.json | 4 ++ 13 files changed, 91 insertions(+), 19 deletions(-) create mode 100644 src/app/formulaire/definition/form-espece.ts diff --git a/src/app/calculators/espece/config.json b/src/app/calculators/espece/config.json index 8764eee37..33f7af908 100644 --- a/src/app/calculators/espece/config.json +++ b/src/app/calculators/espece/config.json @@ -10,6 +10,12 @@ { "id": "PVMaxLim", "allowEmpty": true + }, + { + "id": "select_divingjetsupported", + "type": "select", + "property": "divingJetSupported", + "default": "NOT_SUPPORTED" } ] }, @@ -88,6 +94,7 @@ { "type": "options", "help": "verification/espece.html", + "selectIds": [ "select_divingjetsupported" ], "calculateDisabled": true } ] diff --git a/src/app/calculators/espece/en.json b/src/app/calculators/espece/en.json index cd76f2b62..0934829af 100644 --- a/src/app/calculators/espece/en.json +++ b/src/app/calculators/espece/en.json @@ -5,6 +5,11 @@ "fs_param_pam": "Rock-ramp fishpasses", "fs_param_par": "Humpback fishways", + "select_divingjetsupported": "Diving jets support", + + "DIVINGJETSUPPORTED_0": "Not supported", + "DIVINGJETSUPPORTED_1": "Supported", + "UNIT_DHMaxS": "m", "UNIT_DHMaxP": "m", "UNIT_BMin": "m", diff --git a/src/app/calculators/espece/fr.json b/src/app/calculators/espece/fr.json index b451dd4fd..9f8fc5034 100644 --- a/src/app/calculators/espece/fr.json +++ b/src/app/calculators/espece/fr.json @@ -5,6 +5,11 @@ "fs_param_pam": "Passes à macrorugosités", "fs_param_par": "Passes à ralentisseurs", + "select_divingjetsupported": "Support des jets plongeants", + + "DIVINGJETSUPPORTED_0": "Non supportés", + "DIVINGJETSUPPORTED_1": "Supportés", + "UNIT_DHMaxS": "m", "UNIT_DHMaxP": "m", "UNIT_BMin": "m", diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index 0e35ac269..8a328a71e 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -1005,6 +1005,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe const form = this._formulaire as FormulaireFixedVar; const nub = (form.currentNub as Espece); nub.loadPredefinedSpecies(result.selected); + console.log("================ espèce chargée, refresh tout"); form.refreshFieldsets(); } }); diff --git a/src/app/components/generic-input/generic-input.component.ts b/src/app/components/generic-input/generic-input.component.ts index 1af5e5859..3d9472e3b 100644 --- a/src/app/components/generic-input/generic-input.component.ts +++ b/src/app/components/generic-input/generic-input.component.ts @@ -18,25 +18,14 @@ import { ApplicationSetupService } from "../../services/app-setup.service"; */ @Directive() export abstract class GenericInputComponentDirective implements OnChanges { - /** - * entité mémoire gérée - */ - protected _model: NgParameter | FormulaireDefinition; // CalcName utilise un FormDefinition ici !? - /** - * flag de désactivation de l'input - */ - @Input() - private _inputDisabled = false; + /** entité mémoire gérée */ + protected _model: NgParameter | FormulaireDefinition; // CalcName utilise un FormDefinition ici !? - /** - * flag d'affichage du message d'erreur - */ + /** flag d'affichage du message d'erreur */ public showError = true; - /** - * id de l'input, utilisé notamment pour les tests - */ + /** id de l'input, utilisé notamment pour les tests */ public get inputId() { let id = "error-in-inputId"; if (this._model) { @@ -110,7 +99,11 @@ export abstract class GenericInputComponentDirective implements OnChanges { ) { } public get isDisabled(): boolean { - return this._inputDisabled; + if (this._model instanceof NgParameter) { + return this._model.disabled; + } else { + return false; + } } /** diff --git a/src/app/formulaire/definition/form-espece.ts b/src/app/formulaire/definition/form-espece.ts new file mode 100644 index 000000000..5c1893776 --- /dev/null +++ b/src/app/formulaire/definition/form-espece.ts @@ -0,0 +1,46 @@ +import { IObservable, DivingJetSupport } from "jalhyd"; + +import { FormulaireFixedVar } from "./form-fixedvar"; +import { NgParameter } from "../elements/ngparam"; + +/** + * Formulaire pour les espèces (critères de franchissement) + */ +export class FormulaireEspece extends FormulaireFixedVar { + + protected completeParse(firstNotif: boolean = true) { + super.completeParse(firstNotif); + this.updateDivingJetCriteriaInputs(this.currentNub.properties.getPropValue("divingJetSupported")); + } + + /** + * Enable or disable inputs related to diving jet PAB criteria + */ + public updateDivingJetCriteriaInputs(supported: DivingJetSupport) { + const fsPABDivingJet = this.getFormulaireNodeById("fs_param_pab_p"); + if (fsPABDivingJet !== undefined) { + console.log("> got the fieldset"); + for (const e of fsPABDivingJet.allFormElements) { + if (e instanceof NgParameter) { + console.log(">> setting parameter disabled " + e.symbol + " to", supported === DivingJetSupport.NOT_SUPPORTED); + e.disabled = (supported === DivingJetSupport.NOT_SUPPORTED); + } + } + } + } + + // interface Observer + + public update(sender: IObservable, data: any) { + super.update(sender, data); + console.log("XXX property changed !!", sender.constructor.name, data); + if (data.action === "propertyChange") { + switch (data.name) { + case "divingJetSupported": + this.updateDivingJetCriteriaInputs(data.value); + this.reset(); + break; + } + } + } +} diff --git a/src/app/formulaire/definition/form-macrorugo-compound.ts b/src/app/formulaire/definition/form-macrorugo-compound.ts index 9ab7b18dd..f04e6ccfe 100644 --- a/src/app/formulaire/definition/form-macrorugo-compound.ts +++ b/src/app/formulaire/definition/form-macrorugo-compound.ts @@ -57,7 +57,6 @@ export class FormulaireMacrorugoCompound extends FormulaireRepeatableFieldset { if (firstNotif) { this.updateApronState(this.currentNub.properties.getPropValue("inclinedApron")); } - this.helpLinks = this._resultsHelpLinks; } protected get fieldsetContainer(): FieldsetContainer { diff --git a/src/app/formulaire/definition/form-parallel-structures.ts b/src/app/formulaire/definition/form-parallel-structures.ts index 87b347930..eaffb9f33 100644 --- a/src/app/formulaire/definition/form-parallel-structures.ts +++ b/src/app/formulaire/definition/form-parallel-structures.ts @@ -95,7 +95,6 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset { protected completeParse(firstNotif: boolean = true) { super.completeParse(firstNotif); this.fieldsetContainer.addObserver(this); - this.helpLinks = this._resultsHelpLinks; } protected get fieldsetContainer(): FieldsetContainer { diff --git a/src/app/formulaire/definition/form-verificateur.ts b/src/app/formulaire/definition/form-verificateur.ts index 217298e80..1f712ada6 100644 --- a/src/app/formulaire/definition/form-verificateur.ts +++ b/src/app/formulaire/definition/form-verificateur.ts @@ -37,7 +37,7 @@ export class FormulaireVerificateur extends FormulaireFixedVar { } protected findPassVariatedParameters(): NgParameter[] { - let pvp = [] + let pvp = []; const passUid = this.verificateurNub.nubToVerify.uid; const passForm = ServiceFactory.formulaireService.getFormulaireFromNubId(passUid); pvp = passForm.getVariatedParameters(); diff --git a/src/app/formulaire/elements/ngparam.ts b/src/app/formulaire/elements/ngparam.ts index 09de48e86..f17a24b28 100644 --- a/src/app/formulaire/elements/ngparam.ts +++ b/src/app/formulaire/elements/ngparam.ts @@ -31,11 +31,15 @@ export class NgParameter extends InputField implements Observer { private _allowEmpty = false; public unit: string; + public radioConfig: ParamRadioConfig; + public disabled: boolean; + constructor(private _paramDef: ParamDefinition, parent: FormulaireNode) { super(parent); this.radioConfig = this.radioState; + this.disabled = false; } /** diff --git a/src/app/services/formulaire.service.ts b/src/app/services/formulaire.service.ts index dac713d05..71b4dee0c 100644 --- a/src/app/services/formulaire.service.ts +++ b/src/app/services/formulaire.service.ts @@ -42,6 +42,7 @@ import { FormulaireFixedVar } from "../formulaire/definition/form-fixedvar"; import { FormulaireSection } from "../formulaire/definition/form-section"; import { FormulairePAR } from "../formulaire/definition/form-par"; import { FormulaireVerificateur } from "../formulaire/definition/form-verificateur"; +import { FormulaireEspece } from "../formulaire/definition/form-espece"; @Injectable() export class FormulaireService extends Observable { @@ -318,6 +319,10 @@ export class FormulaireService extends Observable { f = new FormulaireVerificateur(); break; + case CalculatorType.Espece: + f = new FormulaireEspece(); + break; + default: f = new FormulaireFixedVar(); } diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index dffee5378..7b094eac7 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -632,6 +632,10 @@ "WARNING_VERIF_MRC_YMIN_APRON_N": "Apron #%N%: water level %Y% too low (minimum: %minY%)", "INFO_VERIF_MRC_CROSSABLE_WIDTH": "Maximum crossable width is %width% m", "ERROR_VERIF_NO_PRESET": "This species group is not compatible with this pass type", + "ERROR_VERIF_PAB_DIVING_JET_NOT_SUPPORTED": "Wall #%N%: diving jet not supported", + "ERROR_VERIF_PAB_DIVING_JET_NOT_SUPPORTED_DW": "Downwall: diving jet not supported", + "WARNING_VERIF_PAB_DIVING_JET_NOT_SUPPORTED": "Wall #%NC%, structure %NS%: diving jet not supported", + "WARNING_VERIF_PAB_DIVING_JET_NOT_SUPPORTED_DW": "Downwall, structure %NS%: diving jet not supported", "ERROR_VERIF_PAB_DHMAX": "Wall #%N%: fall %DH% too high (maximum for surface jet: %maxDHS%, maximum for diving jet: %maxDHP%)", "ERROR_VERIF_PAB_DHMAX_DW": "Downwall: fall %DH% too high (maximum for surface jet: %maxDHS%, maximum for diving jet: %maxDHP%)", "ERROR_VERIF_PAB_DHMAX_JET": "Wall #%N%: fall %DH% too high for jet type ENUM_STRUCTUREJETTYPE_%jetType% (maximum: %maxDH%)", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index 2607a0115..3ef2a212d 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -635,6 +635,10 @@ "WARNING_VERIF_MRC_YMIN_APRON_N": "Radier n°%N% : tirant d'eau %Y% insuffisant (minimum : %minY%)", "INFO_VERIF_MRC_CROSSABLE_WIDTH": "La largeur franchissable maximale est %width% m", "ERROR_VERIF_NO_PRESET": "Ce groupe d'espèces n'est pas compatible avec ce type de passe", + "ERROR_VERIF_PAB_DIVING_JET_NOT_SUPPORTED": "Cloison n°%N% : jet plongeant non supporté", + "ERROR_VERIF_PAB_DIVING_JET_NOT_SUPPORTED_DW": "Cloison aval : jet plongeant non supporté", + "WARNING_VERIF_PAB_DIVING_JET_NOT_SUPPORTED": "Cloison n°%NC%, ouvrage %NS% : jet plongeant non supporté", + "WARNING_VERIF_PAB_DIVING_JET_NOT_SUPPORTED_DW": "Cloison aval, ouvrage %NS% : jet plongeant non supporté", "ERROR_VERIF_PAB_DHMAX": "Cloison n°%N% : chute %DH% trop importante (maximum pour jet de surface : %maxDHS%, maximum pour jet plongeant : %maxDHP%)", "ERROR_VERIF_PAB_DHMAX_DW": "Cloison aval : chute %DH% trop importante (maximum pour jet de surface : %maxDHS%, maximum pour jet plongeant : %maxDHP%)", "ERROR_VERIF_PAB_DHMAX_JET": "Cloison n°%N% : chute %DH% trop importante pour le jet ENUM_STRUCTUREJETTYPE_%jetType% (maximum : %maxDH%)", -- GitLab