diff --git a/src/app/components/fixedvar-results/fixed-results.component.ts b/src/app/components/fixedvar-results/fixed-results.component.ts index 004c46c9cd7eb69fb9f9a9025fb14080cc9d838e..32660b36862b5b0c3650fc5b133a0be1535743fd 100644 --- a/src/app/components/fixedvar-results/fixed-results.component.ts +++ b/src/app/components/fixedvar-results/fixed-results.component.ts @@ -36,7 +36,6 @@ export class FixedResultsComponent extends ResultsComponentDirective { } public set results(r: FixedResults) { - console.log("->->->->-> je suis FRC et j'ai reçu des résultats", r === undefined ? "keud" : r.result); this._fixedResults = r; } diff --git a/src/app/components/pb-results/pb-results-table.component.ts b/src/app/components/pb-results/pb-results-table.component.ts index de2545a6c84fc94575d064d190a05c617180b9e0..1bab32668741394955ebd9bb918d752ab1724720 100644 --- a/src/app/components/pb-results/pb-results-table.component.ts +++ b/src/app/components/pb-results/pb-results-table.component.ts @@ -37,7 +37,6 @@ export class PbResultsTableComponent extends ResultsComponentDirective { public set results(r: PrebarrageResults) { this._pbResults = r; - console.log("Set results dans PBRTC !", r); this._dataSet = []; if ( diff --git a/src/app/components/pb-results/pb-results.component.ts b/src/app/components/pb-results/pb-results.component.ts index 5a031da132bb4735afc5ab0ab5762d075021e84e..ed974c71b519e0734e440a84e0a06ab5048ad291 100644 --- a/src/app/components/pb-results/pb-results.component.ts +++ b/src/app/components/pb-results/pb-results.component.ts @@ -281,7 +281,6 @@ export class PbResultsComponent implements DoCheck { * @returns true si les résultats ont pu être mis à jour */ private updateResults() { - console.log("------------ update results -----------"); let pabUpdated: boolean; let profileChartUpdated: boolean; let selectorUpdated: boolean; diff --git a/src/app/components/pb-schema/pb-schema.component.scss b/src/app/components/pb-schema/pb-schema.component.scss index c0834e6b705c5bfbf69eef224c464be9f7ff0a32..72baa1eddf75dd87f56fcb64057f22af2bab8d93 100644 --- a/src/app/components/pb-schema/pb-schema.component.scss +++ b/src/app/components/pb-schema/pb-schema.component.scss @@ -37,6 +37,7 @@ mat-card-content { .related-entity-title { vertical-align: middle; font-weight: bold; + display: none; // @TODO show it in a way that doesn't make the buttons fall on the next line ? } .hyd-window-btns { text-align: right; diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index 615af66cdbb74a9a6ccf3717225cb9e404164316..6d2503d9990802cb147648d10d3218bd234ac11e 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -341,6 +341,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } this.unselect(); this.refresh(); + this.clearResults(); } public get uitextRemove() { @@ -367,6 +368,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.unselect(); this.refresh(); this.selectNodeOnSchema(wallCopy); + this.clearResults(); } public get uitextCopy() { @@ -380,6 +382,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.unselect(); this.refresh(); this.selectNodeOnSchema(newBasin); + this.clearResults(); } public get uitextAddBasin() { @@ -413,6 +416,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.unselect(); this.refresh(); this.selectNodeOnSchema(wall); + this.clearResults(); } }); } @@ -437,6 +441,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.unselect(); this.refresh(); this.selectNodeOnSchema(basin); + this.clearResults(); } public get uitextMoveBasinUp() { @@ -459,6 +464,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.unselect(); this.refresh(); this.selectNodeOnSchema(basin); + this.clearResults(); } public get uitextMoveBasinDown() { @@ -507,6 +513,11 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni this.nodeSelected.emit({}); // nothing selected } + /** clear all PB form results whenever the basins / walls layout is changed */ + private clearResults() { + this.pbSchema.form.reset(); + } + // interface Observer public update(sender: IObservable, data: any) { diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index 4ee4564b68f72a0235a33c73c0ea437d47c584b1..24aafceacc96923ff735efc95599fa78fc8ab4ff 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -56,8 +56,8 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs /** copy of options.resultsHelp read by FormDefinition.parseOptions() */ public helpLinks: { [key: string]: string }; - constructor() { - super(undefined); + constructor(parent?: FormulaireNode) { + super(parent); } // surcharge de FormulaireNode::get:uid() diff --git a/src/app/formulaire/definition/form-fixedvar.ts b/src/app/formulaire/definition/form-fixedvar.ts index 87b008f0cad3c3f773555908e934c894789db049..b376cfa7ce07e2c442484c243bb390199cd44a65 100644 --- a/src/app/formulaire/definition/form-fixedvar.ts +++ b/src/app/formulaire/definition/form-fixedvar.ts @@ -5,6 +5,7 @@ import { ChartType } from "../../results/chart-type"; import { CalculatorResults } from "../../results/calculator-results"; import { ParamRadioConfig, NgParameter } from "../elements/ngparam"; import { FieldSet } from "../elements/fieldset"; +import { FormulaireNode } from "../elements/formulaire-node"; import { Nub, IObservable } from "jalhyd"; import { SelectFieldCustom } from "../elements/select-field-custom"; @@ -20,8 +21,8 @@ export class FormulaireFixedVar extends FormulaireDefinition { /** ids of "custom" select fields */ private _customSelectIds: string[] = []; - constructor() { - super(); + constructor(parent?: FormulaireNode) { + super(parent); this._fixedResults = new FixedResults(); this._varResults = new VarResults(); } diff --git a/src/app/formulaire/definition/form-pb-cloison.ts b/src/app/formulaire/definition/form-pb-cloison.ts index d41333580e3ebd3864c97beb0f08b6d5223eafad..0327b95aa34a124dd9012c80c8b5442bfad58cfe 100644 --- a/src/app/formulaire/definition/form-pb-cloison.ts +++ b/src/app/formulaire/definition/form-pb-cloison.ts @@ -2,9 +2,10 @@ import { FormulaireParallelStructure } from "./form-parallel-structures"; import { SelectFieldNub } from "../elements/select-field-nub"; import { IObservable, Nub, PbCloison, PbBassin, Structure } from "jalhyd"; -import { FieldSet } from '../elements/fieldset'; -import { FormulaireNode } from '../elements/formulaire-node'; -import { FieldsetContainer } from '../elements/fieldset-container'; +import { FieldSet } from "../elements/fieldset"; +import { FormulaireNode } from "../elements/formulaire-node"; +import { FieldsetContainer } from "../elements/fieldset-container"; +import { FormulairePrebarrage } from "./form-prebarrage"; export class FormulairePbCloison extends FormulaireParallelStructure { @@ -43,8 +44,10 @@ export class FormulairePbCloison extends FormulaireParallelStructure { if (sender instanceof FieldsetContainer) { switch (data.action) { case "newFieldset": - // this.reset(); - console.log("||| reset PAS NON PLUS :) |||"); + // still reset all results when a fieldset if manually added + if (data.resetResults !== false) { + this.reset(); + } this.subscribeStructureInputFields(data["fieldset"]); this.subscribeStructureSelectFields(data["fieldset"]); } @@ -124,12 +127,45 @@ export class FormulairePbCloison extends FormulaireParallelStructure { parent.kids.push(res); } - console.log("\\\ reset PAS ///"); - // this.resetResults(); + // still reset all results when a fieldset if manually added + if (data["resetResults"] !== false) { + this.reset(); + (this.parent as FormulairePrebarrage).reset(); + } return res; } else { return super.createFieldset(parent, json, data); } } + + /** + * réinitialisation du formulaire suite à un changement d'une valeur, d'une option, ... : + * effacement des résultats, application des dépendances, ... + */ + public reset() { + // also reset parent results (that will reset all its children results) + (this.parent as FormulairePrebarrage).reset(); + // prévenir les composants qu'il faut détecter les changements + this.notifyReset(); + } + + // ensure all PBresults are reset + public moveFieldsetUp(fs: FieldSet) { + super.moveFieldsetUp(fs); + this.reset(); + } + + // ensure all PBresults are reset + public moveFieldsetDown(fs: FieldSet) { + super.moveFieldsetDown(fs); + this.reset(); + } + + // ensure all PBresults are reset + public removeFieldset(fs: FieldSet) { + super.removeFieldset(fs); + this.reset(); + } + } diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts index 3027888615f593d83ecc161f6d8d36b2d8e19ba0..117612ef15bc733340ef7f2bdfc3be66f8232ea6 100644 --- a/src/app/formulaire/definition/form-prebarrage.ts +++ b/src/app/formulaire/definition/form-prebarrage.ts @@ -125,7 +125,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { this.showFormElements(this.riverForm); } else if (node instanceof PbBassin) { - this.basinForm = new FormulaireFixedVar(); + this.basinForm = new FormulaireFixedVar(this); this.basinForm.defaultProperties["calcType"] = CalculatorType.PbBassin; this.basinForm.currentNub = node; this.basinForm.preparseConfig(this.basinFormConfig); @@ -134,7 +134,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { this.showFormElements(this.basinForm); } else if (node instanceof PbCloison) { - const wallForm = new FormulairePbCloison(); + const wallForm = new FormulairePbCloison(this); wallForm.defaultProperties["calcType"] = CalculatorType.PbCloison; wallForm.currentNub = node; wallForm.preparseConfig(this.wallFormConfig); @@ -147,7 +147,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { for (const struct of node.structures) { for (const e of wallForm.allFormElements) { if (e instanceof FieldsetContainer) { // @TODO manage many containers one day ? - e.addFromTemplate(0, undefined, struct); + e.addFromTemplate(0, undefined, struct, { resetResults: false }); } } } @@ -155,7 +155,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar { // if there was no existing structure, add a default one for (const e of wallForm.allFormElements) { if (e instanceof FieldsetContainer) { - e.addFromTemplate(0); + e.addFromTemplate(0, undefined, undefined, { resetResults: false }); break; } } @@ -225,7 +225,6 @@ export class FormulairePrebarrage extends FormulaireFixedVar { this.pbResults.reset(); // afficher les résultats de cloison - console.log("RRC => cloison !", this._selectedItem.uid, this._selectedItem.result); this.fixedResults.result = this._selectedItem.result; if (computedParam !== undefined) { this.fixedResults.calculatedParameter = computedParam; @@ -243,9 +242,27 @@ export class FormulairePrebarrage extends FormulaireFixedVar { } } + /** + * réinitialisation du formulaire suite à un changement d'une valeur, d'une option, ... : + * effacement des résultats, application des dépendances, ... + */ + public reset() { + this.resetResults(); + } + public resetResults() { super.resetResults(); this._fixedResults.reset(); this._pbResults.reset(); + // reset all children nubs + for (const c of this.currentNub.getChildren()) { + c.resetResult(); + } + // reset all wall forms + for (const k of this.kids) { + if (k instanceof FormulaireDefinition) { + k.reset(); + } + } } } diff --git a/src/app/formulaire/elements/fieldset-container.ts b/src/app/formulaire/elements/fieldset-container.ts index 96f719fcf0dd192ee0f7af1bf613bb9b69309b48..a8c1ecbe60f98fabcfd8ad96e80465e1f23389c6 100644 --- a/src/app/formulaire/elements/fieldset-container.ts +++ b/src/app/formulaire/elements/fieldset-container.ts @@ -71,19 +71,23 @@ export class FieldsetContainer extends FormulaireElement { * crée un FieldSet à partir d'un template * @param templateIndex indice du template dans la liste * @param after insère le nouveau FieldSet après cette position, à la fin sinon + * @param nub attaches the given Nub to the new FieldSet + * @param extra extra key-value pairs to add to the "newFieldset" event */ - public addFromTemplate(templateIndex: number, after?: number, nub?: Nub): FieldSet { + public addFromTemplate(templateIndex: number, after?: number, nub?: Nub, extra?: any): FieldSet { const templ: FieldsetTemplate = this._templates[templateIndex]; - const inst: FieldSet = templ.instantiateTemplate(this, after, nub); + const inst: FieldSet = templ.instantiateTemplate(this, after, nub, extra); this.updateLocalisation(); // notification de création d'un FieldSet - this.notifyObservers({ + let info = { "action": "newFieldset", "fieldset": inst - }, this); + }; + info = { ...info, ...extra }; + this.notifyObservers(info, this); return inst; } diff --git a/src/app/formulaire/elements/fieldset-template.ts b/src/app/formulaire/elements/fieldset-template.ts index 3c9071131a974222b80bd5e26762f715de9e1864..b65b48874c37bc13364cb622c05da35bd4f4ebd9 100644 --- a/src/app/formulaire/elements/fieldset-template.ts +++ b/src/app/formulaire/elements/fieldset-template.ts @@ -42,10 +42,13 @@ export class FieldsetTemplate { * @param cont conteneur * @param after position à laquelle on ajoute le nouveau FieldSet * @param nub Nub existant à injecter dans le Fieldset + * @param extra extra key-value pairs to add to the "newFieldset" event */ - public instantiateTemplate(cont: FieldsetContainer, after: number, nub?: Nub): FieldSet { + public instantiateTemplate(cont: FieldsetContainer, after: number, nub?: Nub, extra?: any): FieldSet { const parentForm = cont.parent as FormulaireDefinition; - const res = parentForm.createFieldset(cont, this._jsonConfig, { "template": this, "after": after }, nub); + let info = { "template": this, "after": after }; + info = { ...info, ... extra }; + const res = parentForm.createFieldset(cont, this._jsonConfig, info, nub); res.parseConfig(this._jsonConfig); parentForm.afterParseFieldset(res); return res; diff --git a/src/app/formulaire/elements/pb-schema.ts b/src/app/formulaire/elements/pb-schema.ts index 07e10889018d02c9abf2cb94098b95b53181f469..7ec01a39c892e0744b28faad6c4e37fab8f71053 100644 --- a/src/app/formulaire/elements/pb-schema.ts +++ b/src/app/formulaire/elements/pb-schema.ts @@ -1,6 +1,7 @@ import { PreBarrage } from "jalhyd"; import { FormulaireElement } from "./formulaire-element"; +import { FormulairePrebarrage } from "../definition/form-prebarrage"; /** * The interactive schema for calculator type "PreBarrage" (form element). @@ -14,6 +15,15 @@ export class PbSchema extends FormulaireElement { this._confId = json["id"]; } + /** + * Returns the Prebarrage model associated to the parent form + */ + public get form(): FormulairePrebarrage { + if (this.parentForm) { + return this.parentForm as FormulairePrebarrage; + } + } + /** * Returns the Prebarrage model associated to the parent form */