diff --git a/src/app/calculators/solveur/config.json b/src/app/calculators/solveur/config.json index 03262ac7d9120f865f2d8b225f01b1d522eef6c9..f04658c8dfe828fcbf5646c179c02facff532ea1 100644 --- a/src/app/calculators/solveur/config.json +++ b/src/app/calculators/solveur/config.json @@ -33,9 +33,8 @@ { "type": "options", "selectIds": [ "select_target_result" ], - "targetNubSelectId": "select_target_nub", + "customSelectIds": [ "select_target_nub", "select_searched_param" ], "targettedResultSelectId": "select_target_result", - "searchedParamSelectId": "select_searched_param", "_help": "solveur.html" } ] \ No newline at end of file diff --git a/src/app/calculators/verificateur/config.json b/src/app/calculators/verificateur/config.json index 8ec8d41caf8aef98f29807dbb55cca905f00a9ac..95ad28bb603de4e97a15f20770c18c30a6268448 100644 --- a/src/app/calculators/verificateur/config.json +++ b/src/app/calculators/verificateur/config.json @@ -32,8 +32,7 @@ { "type": "options", "selectIds": [ "select_pab_jet_type", "select_species_list" ], - "targetPassSelectId": "select_target_pass", - "speciesListSelectId": "select_species_list", + "customSelectIds": [ "select_target_pass" ], "help": "verification/verificateur.html" } ] diff --git a/src/app/formulaire/definition/form-fixedvar.ts b/src/app/formulaire/definition/form-fixedvar.ts index 4d553ef88508364b729404766fcaffd01212ef96..c9835398c638a90bc4459a00cc9c8c240d603c3a 100644 --- a/src/app/formulaire/definition/form-fixedvar.ts +++ b/src/app/formulaire/definition/form-fixedvar.ts @@ -7,6 +7,7 @@ import { ParamRadioConfig, NgParameter } from "../elements/ngparam"; import { FieldSet } from "../elements/fieldset"; import { Nub, IObservable } from "jalhyd"; +import { SelectFieldCustom } from '../elements/select-field-custom'; export class FormulaireFixedVar extends FormulaireDefinition { @@ -16,6 +17,9 @@ export class FormulaireFixedVar extends FormulaireDefinition { /** ids of select fields */ private _selectIds: string[] = []; + /** ids of "custom" select fields */ + private _customSelectIds: string[] = []; + constructor() { super(); this._fixedResults = new FixedResults(); @@ -70,21 +74,40 @@ export class FormulaireFixedVar extends FormulaireDefinition { } public afterParseFieldset(fs: FieldSet) { - // observe all select fields @see this.update() + // observe all Select fields @see this.update() if (this._selectIds.length > 0) { for (const sId of this._selectIds) { const sel = fs.getFormulaireNodeById(sId); if (sel) { + // Formulaire is listening to FieldSet properties (@TODO why not directly Select ?) fs.properties.addObserver(this); } } } } + protected completeParse(firstNotif: boolean = true) { + super.completeParse(firstNotif); + // observe all CustomSelect fields @TODO move to afterParseFieldset ? + if (this._customSelectIds.length > 0) { + for (const csId of this._customSelectIds) { + const sel = this.getFormulaireNodeById(csId); + // Formulaire is listening to Select value + sel.addObserver(this); + if (firstNotif) { + // force 1st observation + (sel as SelectFieldCustom).notifyValueChanged(); + } + } + } + } + protected parseOptions(json: {}) { super.parseOptions(json); // get ids of all select fields this._selectIds = this.getOption(json, "selectIds") || []; + // get ids of all "custom" select fields + this._customSelectIds = this.getOption(json, "customSelectIds") || []; } protected compute() { diff --git a/src/app/formulaire/definition/form-macrorugo-compound.ts b/src/app/formulaire/definition/form-macrorugo-compound.ts index 2fb689c5ba617cf31b0c14c2958439681995f4a4..9ab7b18ddcd43414082dc1418fd20943eb969724 100644 --- a/src/app/formulaire/definition/form-macrorugo-compound.ts +++ b/src/app/formulaire/definition/form-macrorugo-compound.ts @@ -52,6 +52,7 @@ export class FormulaireMacrorugoCompound extends FormulaireRepeatableFieldset { } protected completeParse(firstNotif: boolean = true) { + super.completeParse(firstNotif); this.fieldsetContainer.addObserver(this); if (firstNotif) { this.updateApronState(this.currentNub.properties.getPropValue("inclinedApron")); diff --git a/src/app/formulaire/definition/form-parallel-structures.ts b/src/app/formulaire/definition/form-parallel-structures.ts index 6a097c297506ccda99dd052ebba20eca84ac1318..87b34793068efa0926d7155de54083cf800a08c3 100644 --- a/src/app/formulaire/definition/form-parallel-structures.ts +++ b/src/app/formulaire/definition/form-parallel-structures.ts @@ -93,7 +93,8 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset { } protected completeParse(firstNotif: boolean = true) { - this.subscribeFieldsetContainer(); + super.completeParse(firstNotif); + this.fieldsetContainer.addObserver(this); this.helpLinks = this._resultsHelpLinks; } @@ -128,13 +129,6 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset { } } - /** - * abonnement en tant qu'observateur du FieldsetContainer - */ - private subscribeFieldsetContainer() { - this.fieldsetContainer.addObserver(this); - } - /** * abonnement en tant qu'observateur des NgParameter des FieldSet contenus dans le FieldsetContainer */ diff --git a/src/app/formulaire/definition/form-solveur.ts b/src/app/formulaire/definition/form-solveur.ts index 1e2664d9f9e0d0da55c8852e764f32b0b05a4c04..db1b2ef45f2119f00f8eb3d25603765590364ab2 100644 --- a/src/app/formulaire/definition/form-solveur.ts +++ b/src/app/formulaire/definition/form-solveur.ts @@ -11,34 +11,18 @@ import { FieldSet } from "../elements/fieldset"; */ export class FormulaireSolveur extends FormulaireFixedVar { - /** id of select configuring target Nub */ - private _targetNubSelectId: string; - /** id of select configuring targetted result */ private _targettedResultSelectId: string; - /** id of select configuring searched param */ - private _searchedParamSelectId: string; - protected parseOptions(json: {}) { super.parseOptions(json); - this._targetNubSelectId = this.getOption(json, "targetNubSelectId"); this._targettedResultSelectId = this.getOption(json, "targettedResultSelectId"); - this._searchedParamSelectId = this.getOption(json, "searchedParamSelectId"); } protected completeParse(firstNotif: boolean = true) { - super.completeParse(); - if (this._targetNubSelectId) { - const sel = this.getFormulaireNodeById(this._targetNubSelectId); - if (sel) { - sel.addObserver(this); - if (firstNotif) { - // force 1st observation - (sel as SelectFieldCustom).notifyValueChanged(); - } - } - } + super.completeParse(firstNotif); + // even though this._targettedResultSelectId is a regular select, an extra action + // is needed: refresh searched parameter selector if (this._targettedResultSelectId) { const sel = this.getFormulaireNodeById(this._targettedResultSelectId); if (sel) { @@ -49,17 +33,6 @@ export class FormulaireSolveur extends FormulaireFixedVar { } } } - if (this._searchedParamSelectId) { - const sel = this.getFormulaireNodeById(this._searchedParamSelectId); - if (sel) { - sel.addObserver(this); - if (firstNotif) { - // force 1st observation - (sel as SelectFieldCustom).notifyValueChanged(); - } - } - } - } // interface Observer @@ -111,7 +84,7 @@ export class FormulaireSolveur extends FormulaireFixedVar { inputXinit.notifyValueModified(this); } } else if (sender instanceof SelectField) { - if (sender.id === "select_target_result") { + if (sender.id === this._targettedResultSelectId) { // refresh parameters selector this.refreshParameterEntries(); } @@ -122,7 +95,7 @@ export class FormulaireSolveur extends FormulaireFixedVar { * Re-populate searched parameter selector with fresh entries */ private refreshParameterEntries() { - const pSel = this.getFormulaireNodeById(this._searchedParamSelectId) as SelectFieldCustom; + const pSel = this.getFormulaireNodeById("select_searched_param") as SelectFieldCustom; if (pSel) { pSel.updateEntries(); // reflect changes in GUI diff --git a/src/app/formulaire/definition/form-verificateur.ts b/src/app/formulaire/definition/form-verificateur.ts index 732a659a5b1f1d2c4dbe0cfc36dd88bff9ae05c0..2e55695991c174dd72c825cc1473e3604f9e2cc4 100644 --- a/src/app/formulaire/definition/form-verificateur.ts +++ b/src/app/formulaire/definition/form-verificateur.ts @@ -2,39 +2,12 @@ import { IObservable, Nub, Verificateur } from "jalhyd"; import { SelectFieldCustom } from "../elements/select-field-custom"; import { FormulaireFixedVar } from "./form-fixedvar"; -import { SelectField } from '../elements/select-field'; /** * Formulaire pour les VÊrificateurs */ export class FormulaireVerificateur extends FormulaireFixedVar { - /** id of select configuring target pass Nub */ - private _targetPassSelectId: string; - - /** id of select configuring list of species */ - private _speciesListSelectId: string; - - protected parseOptions(json: {}) { - super.parseOptions(json); - this._targetPassSelectId = this.getOption(json, "targetPassSelectId"); - this._speciesListSelectId = this.getOption(json, "speciesListSelectId"); - } - - protected completeParse(firstNotif: boolean = true) { - super.completeParse(); - if (this._targetPassSelectId) { - const sel = this.getFormulaireNodeById(this._targetPassSelectId); - if (sel) { - sel.addObserver(this); - if (firstNotif) { - // force 1st observation - (sel as SelectFieldCustom).notifyValueChanged(); - } - } - } - } - // interface Observer public update(sender: IObservable, data: any) { @@ -70,12 +43,12 @@ export class FormulaireVerificateur extends FormulaireFixedVar { public onCalculatorInit() { // refresh species list selector on each display, because Session might have gained new Espece nubs console.log(">>>> speciesList avant rafraÎchissement :", (this.currentNub as Verificateur).speciesList); - const pSel = this.getFormulaireNodeById(this._speciesListSelectId) as SelectField; + /* const pSel = this.getFormulaireNodeById(this._speciesListSelectId) as SelectField; if (pSel) { - /* pSel.clearEntries(); - pSel.parseConfig(); */ + pSel.clearEntries(); + pSel.parseConfig(); // (pSel.parent as FieldSet).updateFields() - } + } */ } }