diff --git a/jalhyd_branch b/jalhyd_branch index 47cea457363c1be429e2baf6b5bfb8207cb69e13..626e97d71d9e3364f9abe16f7e3c8d70dea5a7fa 100644 --- a/jalhyd_branch +++ b/jalhyd_branch @@ -1 +1 @@ -261-pab-pouvoir-lier-et-varier-le-debit-d-attrait +devel \ No newline at end of file diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index 718ff08f5a873b395b553155be771e2e4b3d3a69..2608ce76e149a26609f9fc4f60194b0f0b1c3fbb 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -520,7 +520,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe } if (this._formulaire.currentNub.calcType === CalculatorType.PreBarrage) { const form: FormulairePrebarrage = this._formulaire as FormulairePrebarrage; - this._isUIValid = this._isUIValid && form.currentNub.check(); + this._isUIValid = this._isUIValid && form.checkParameters().length === 0; } } } diff --git a/src/app/components/pb-schema/pb-schema.component.ts b/src/app/components/pb-schema/pb-schema.component.ts index cdbe3fad0932b9ebd36b8fc3ad8c692c166d987a..40217b619a7b18f79624bd14496f2433fe7ca2a1 100644 --- a/src/app/components/pb-schema/pb-schema.component.ts +++ b/src/app/components/pb-schema/pb-schema.component.ts @@ -138,6 +138,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } catch (e) { console.error(e); } + this.highlightErrorItems(null); } /** @@ -229,6 +230,8 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni def.push("classDef basin fill:#e0f3fb,stroke:#003A80;"); // irstea-ocean 50 / 500 def.push("classDef basin::first-line color:green,font-size:0.5em;"); def.push("classDef node-highlighted fill:#4DBBE9;"); // irstea-ocean (material "accent"), 300 + def.push("classDef node-error fill:#ec7430;"); // irstea-rouille (material "accent"), 400 + def.push("classDef node-highlighted-error fill:#d92f03;"); // irstea-rouille (material "accent"), 900 const sortedWalls: PbCloison[] = []; for (const c of this.model.children) { @@ -240,6 +243,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni sortedWalls.push(c); } } + // sort then draw walls sortedWalls.sort(this.triCloisonsGaucheDroite); for (const c of sortedWalls) { @@ -308,6 +312,7 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni } else { this._selectedItem = this.model.findChild(item.id); } + this.highlightErrorItems(item.id); // show proper form and hide results this.nodeSelected.emit({ node: this._selectedItem @@ -649,6 +654,29 @@ export class PbSchemaComponent implements AfterViewInit, AfterContentInit, OnIni }); } + private highlightErrorItems(selectedUid: string) { + this.nativeElement.querySelectorAll("g.node").forEach(item => { + item.classList.remove("node-error"); + item.classList.remove("node-highlighted-error"); + }); + const invalidUids: string[] = this.pbSchema.form.checkParameters(); + this.nativeElement.querySelectorAll("g.node").forEach(item => { + let itemId: string; + if ([this.upstreamId, this.downstreamId].includes(item.id)) { + itemId = this.model.uid; + } else { + itemId = item.id + } + if (invalidUids.includes(itemId)) { + if (item.id === selectedUid) { + item.classList.add("node-highlighted-error"); + } else { + item.classList.add("node-error"); + } + } + }); + } + private unselect() { // console.debug(`PbSchemaComponent.unselect()`); this._selectedItem = undefined; diff --git a/src/app/formulaire/definition/form-prebarrage.ts b/src/app/formulaire/definition/form-prebarrage.ts index 4400467c8535c95d25367bc66dca6ebf98e6db17..143a6991de916dacb0dad8b7fb48b2772e4c36a2 100644 --- a/src/app/formulaire/definition/form-prebarrage.ts +++ b/src/app/formulaire/definition/form-prebarrage.ts @@ -1,4 +1,4 @@ -import { CalculatorType, PbBassin, PbCloison, IObservable, PreBarrage, VariatedDetails, ParamDefinition } from "jalhyd"; +import { CalculatorType, PbBassin, PbCloison, IObservable, PreBarrage, VariatedDetails, ParamDefinition, IParamDefinitionIterator, ParamDefinitionIterator } from "jalhyd"; import { FormulaireFixedVar } from "./form-fixedvar"; import { PbSchema } from "../elements/pb-schema"; @@ -335,4 +335,34 @@ export class FormulairePrebarrage extends FormulaireFixedVar { } this.currentNub.calculatedParam = paramCalculated; } + + /** + * Check validity of all model parameters + * @param withChildren check parameters of child nub as well + * @return array of uid nubs in error + */ + public checkParameters(withChildren: boolean = true): string[] { + let prmIt: IParamDefinitionIterator; + if(withChildren) { + prmIt = this.currentNub.parameterIterator; + } else { + prmIt = new ParamDefinitionIterator(this.currentNub.prms); + } + const uids: string[] = []; + for (const p of prmIt) { + if (!p.isCalculated && p.visible) { + try { + // will throw an error if no value is defined at all + p.paramValues.check(); + } catch (e) { + if (p.parentNub.calcType === CalculatorType.Structure) { + uids.push(p.parentNub.getParent().uid); + } else { + uids.push(p.parentNub.uid); + } + } + } + } + return uids; + } }