diff --git a/src/app/components/dialog-generate-pab/dialog-generate-pab.component.ts b/src/app/components/dialog-generate-pab/dialog-generate-pab.component.ts index 65454306a07d4162b4a1756d6c0cfb22f4ace63f..202aa1fd89632c45871623cdc91bcbece1f12737 100644 --- a/src/app/components/dialog-generate-pab/dialog-generate-pab.component.ts +++ b/src/app/components/dialog-generate-pab/dialog-generate-pab.component.ts @@ -18,8 +18,6 @@ export class DialogGeneratePABComponent { public coteAmont = 102; - public chute: number; - public nbBassins = 6; constructor( @@ -31,19 +29,15 @@ export class DialogGeneratePABComponent { const nDigits = this.appSetupService.displayPrecision; this.coteAmont = data.coteAmont ? round(data.coteAmont, nDigits) : undefined; this.debit = data.debit ? round(data.debit, nDigits) : undefined; - this.chute = round(data.chute, nDigits); this.nbBassins = data.nbBassins; } public generatePAB() { - // calculate downstream elevation - const coteAval = +this.coteAmont - (this.chute * +this.nbBassins); // create PAB this.dialogRef.close({ generate: true, debit: +this.debit, coteAmont: +this.coteAmont, - coteAval: coteAval, nbBassins: +this.nbBassins }); } diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index 1957962103d6e56b42a5f477760d8fecdef1abe8..9650543c6a0add5f27c5b2c5bb7aa61ea0e44f64 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -1,5 +1,7 @@ -import { Component, OnInit, DoCheck, OnDestroy, ViewChild, ViewChildren, - QueryList, AfterViewChecked, ElementRef, Inject, forwardRef, isDevMode } from "@angular/core"; +import { + Component, OnInit, DoCheck, OnDestroy, ViewChild, ViewChildren, + QueryList, AfterViewChecked, ElementRef, Inject, forwardRef, isDevMode +} from "@angular/core"; import { ActivatedRoute, Router } from "@angular/router"; import { @@ -308,7 +310,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe } public get quicknavItems() { - const elts = [ "input", "results" ]; + const elts = ["input", "results"]; if (this.isWide && this.hasResults) { elts.push("charts"); } @@ -329,7 +331,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe * the UI validity state) */ ngDoCheck() { - this.isCalculateDisabled = ! this._isUIValid; + this.isCalculateDisabled = !this._isUIValid; } ngOnDestroy() { @@ -363,7 +365,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe } public ngAfterViewChecked() { - if (! this.firstViewChecked) { + if (!this.firstViewChecked) { this.firstViewChecked = true; this.afterFirstViewChecked(); } @@ -394,7 +396,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe } public doCompute() { - if (! isDevMode()) { + if (!isDevMode()) { this.matomoTracker.trackEvent("userAction", "triggerCalculation", CalculatorType[this._formulaire.currentNub.calcType]); } this._formulaire.resetResults([]); @@ -445,7 +447,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe try { this.appComponent.scrollToQuicknav("results"); } catch (e) { - const element = document.getElementById ("fake-results-anchor"); + const element = document.getElementById("fake-results-anchor"); if (element) { element.scrollIntoView(); } @@ -472,7 +474,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe */ private updateUIValidity() { this._isUIValid = false; - if (! this._formulaire.calculateDisabled) { + if (!this._formulaire.calculateDisabled) { // all fieldsets must be valid this._isUIValid = true; if (this._fieldsetComponents !== undefined) { @@ -695,14 +697,14 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe private allParamsAreFixed(except: string[] = []) { let ret = true; for (const p of this._formulaire.currentNub.parameterIterator) { - if (! except.includes(p.symbol)) { + if (!except.includes(p.symbol)) { if (p.valueMode === ParamValueMode.LINK) { - ret = ret && (! p.hasMultipleValues); + ret = ret && (!p.hasMultipleValues); } else { // avoid calling hasMultipleValues here, because changing parameter mode in GUI // switches valueMode before setting min/max/step or valuesList, and iterator // checker fails to count values that do not exist yet - ret = ret && (! [ ParamValueMode.LISTE, ParamValueMode.MINMAX ].includes(p.valueMode)); + ret = ret && (![ParamValueMode.LISTE, ParamValueMode.MINMAX].includes(p.valueMode)); } } } @@ -717,10 +719,10 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe } public get uitextGeneratePabTitle() { - if (! this.hasResults) { + if (!this.hasResults) { return this.intlService.localizeText("INFO_CALCULATE_FIRST"); } - if (! this.allParamsAreFixed()) { + if (!this.allParamsAreFixed()) { return this.intlService.localizeText("INFO_PARAMETRES_FIXES"); } return ""; @@ -737,41 +739,43 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe const zAmont = cloisons.prms.Z1.V; const nbBassins = ServiceFactory.applicationSetupService.enableEmptyFieldsOnFormInit ? undefined : 6; const dialogRef = this.generatePABDialog.open( - DialogGeneratePABComponent, - { - data: { - chute: chute, - debit: debit, - coteAmont: zAmont, - nbBassins: nbBassins - }, - disableClose: false - } + DialogGeneratePABComponent, + { + data: { + debit: debit, + coteAmont: zAmont, + nbBassins: nbBassins + }, + disableClose: false + } ); dialogRef.afterClosed().subscribe(async result => { - if (result) { - if (result.generate) { - const f: FormulaireDefinition = await this.formulaireService.createFormulaire(CalculatorType.Pab); - const pab = (f.currentNub as Pab); - const params = pab.prms; - // paramètres hydrauliques - params.Q.singleValue = result.debit; - params.Z1.singleValue = result.coteAmont; - params.Z2.singleValue = result.coteAval; - // création des bassins - pab.deleteChild(0); - pab.addCloisonsFromModel(this._formulaire.currentNub as Cloisons, result.nbBassins); - // go to new PAB - this.router.navigate(["/calculator", f.uid]); + if (result) { + if (result.generate) { + const f: FormulaireDefinition = await this.formulaireService.createFormulaire(CalculatorType.Pab); + const pab = (f.currentNub as Pab); + const params = pab.prms; + // calculate downstream elevation + const chute = cloisons.prms.DH.V; + const coteAval = result.coteAmont - (chute * result.nbBassins); + // paramètres hydrauliques + params.Q.singleValue = result.debit; + params.Z1.singleValue = result.coteAmont; + params.Z2.singleValue = coteAval; + // création des bassins + pab.deleteChild(0); + pab.addCloisonsFromModel(this._formulaire.currentNub as Cloisons, result.nbBassins); + // go to new PAB + this.router.navigate(["/calculator", f.uid]); + } } - } }); } public get generateSPAmontEnabled(): boolean { const bief = (this._formulaire.currentNub as Bief); if (bief.prms.Z1 === bief.calculatedParam) { - return this.hasResults && ! bief.result.hasErrorMessages(); + return this.hasResults && !bief.result.hasErrorMessages(); } else { // check that linked values are available, if any return ( @@ -784,7 +788,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe public get generateSPAvalEnabled(): boolean { const bief = (this._formulaire.currentNub as Bief); if (bief.prms.Z2 === bief.calculatedParam) { - return this.hasResults && ! bief.result.hasErrorMessages(); + return this.hasResults && !bief.result.hasErrorMessages(); } else { // check that linked values are available, if any return ( @@ -795,7 +799,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe } public get uitextGenerateSPAmontTitle(): string { - if (! this.generateSPAmontEnabled) { + if (!this.generateSPAmontEnabled) { return this.intlService.localizeText("INFO_CALCULATE_FIRST"); } else { return ""; @@ -803,7 +807,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe } public get uitextGenerateSPAvalTitle(): string { - if (! this.generateSPAvalEnabled) { + if (!this.generateSPAvalEnabled) { return this.intlService.localizeText("INFO_CALCULATE_FIRST"); } else { return ""; @@ -841,7 +845,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe const bief = (this._formulaire.currentNub as Bief); return generateValuesCombination( bief, - [ Z, ZF ], + [Z, ZF], (nub: Nub, values: { [key: string]: number }): number => { return round(values[Z.symbol] - values[ZF.symbol], 3); } @@ -855,7 +859,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe const bief = (this._formulaire.currentNub as Bief); return generateValuesCombination( bief, - [ bief.prms.ZF1, bief.prms.ZF2, bief.prms.Long ], + [bief.prms.ZF1, bief.prms.ZF2, bief.prms.Long], (nub: Nub, values: { [key: string]: number }): number => { return round((values["ZF1"] - values["ZF2"]) / values["Long"], 5); } @@ -879,7 +883,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe // "If" is hidden in Bief, for ex. bief.section.getParameter(p.symbol).visible // do not link Y and If - && ! [ "If", "Y" ].includes(p.symbol) + && !["If", "Y"].includes(p.symbol) ) { const bP = bief.section.getParameter(p.symbol); if (bP.valueMode === ParamValueMode.LINK) { @@ -901,11 +905,11 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe } public get generateRuSpEnabled(): boolean { - return this.hasResults && ! this._formulaire.currentNub.result.hasErrorMessages(); + return this.hasResults && !this._formulaire.currentNub.result.hasErrorMessages(); } public get uitextGenerateRuSpTitle(): string { - if (! this.generateRuSpEnabled) { + if (!this.generateRuSpEnabled) { return this.intlService.localizeText("INFO_CALCULATE_FIRST"); } else { return ""; @@ -941,7 +945,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe const parCalage = (this._formulaire.currentNub as Par); return ( this.hasResults - && ! parCalage.result.hasErrorMessages() + && !parCalage.result.hasErrorMessages() && parCalage.prms.Z1.isDefined && parCalage.prms.Z2.isDefined ); @@ -949,12 +953,12 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe public get uitextGenerateParSimulationTitle(): string { const parCalage = (this._formulaire.currentNub as Par); - if (! this.hasResults || parCalage.result.hasErrorMessages()) { + if (!this.hasResults || parCalage.result.hasErrorMessages()) { return this.intlService.localizeText("INFO_CALCULATE_FIRST"); } if ( - ! parCalage.prms.Z1.isDefined - || ! parCalage.prms.Z2.isDefined + !parCalage.prms.Z1.isDefined + || !parCalage.prms.Z2.isDefined ) { return this.intlService.localizeText("INFO_Z1_Z2_MUST_BE_DEFINED"); } @@ -1031,7 +1035,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe public get exportAllPbResultsEnabled(): boolean { const pb = (this._formulaire as FormulairePrebarrage).currentNub as PreBarrage; - return (pb.result !== undefined && ! pb.result.hasOnlyErrors); + return (pb.result !== undefined && !pb.result.hasOnlyErrors); } /** @@ -1169,11 +1173,11 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe protected async doGenerateParSimWithValues(v: any) { const parCalage = (this._formulaire.currentNub as Par); const psim = new ParSimulationParams( - round(v.Q, 3), round(v.Z1, 3), round(v.Z2, 3), - round(v.S, 3), round(v.P, 3), round(v.Nb, 3), - round(v.ZR1, 3), round(v.ZD1, 3), round(v.ZR2, 3), - round(v.ZD2, 3), round(v.L, 3), round(v.a, 3), - round(v.N, 3), round(v.M, 3) + round(v.Q, 3), round(v.Z1, 3), round(v.Z2, 3), + round(v.S, 3), round(v.P, 3), round(v.Nb, 3), + round(v.ZR1, 3), round(v.ZD1, 3), round(v.ZR2, 3), + round(v.ZD2, 3), round(v.L, 3), round(v.a, 3), + round(v.N, 3), round(v.M, 3) ); const parSimulation = new ParSimulation(psim); parSimulation.parType = parCalage.parType; @@ -1194,7 +1198,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe const dialogRef = this.loadPredefinedEspeceDialog.open( DialogLoadPredefinedEspeceComponent, { - data: { }, + data: {}, disableClose: false } ); @@ -1217,7 +1221,7 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, AfterViewChe DialogConfirmCloseCalcComponent, { data: { - uid: this._formulaire.currentNub.uid + uid: this._formulaire.currentNub.uid }, disableClose: true }