diff --git a/src/app/app.component.html b/src/app/app.component.html index 3b1cd9241b28bf2965144f246e0cd758f90c7714..57e075866ee72757a83238b10f146f3c5ef5a5cc 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -18,7 +18,7 @@ <div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li class="nav-item" *ngFor="let c of _calculators"> - <a class="nav-link waves-light {{getHighlightClass(c.uid)}}" mdbRippleRadius [routerLink]="['/calculator/',c.uid]">{{c.title}}</a> + <a class="nav-link waves-light {{getHighlightClass(c.uid)}}" mdbRippleRadius [routerLink]="['/calculator/',c.uid]">{{ c.title }}</a> </li> <li class="nav-item"> <i class="fa fa-plus-square fa-2x fa-inverse" style='vertical-align: middle' (click)='newCalc()'></i> @@ -36,14 +36,14 @@ <div id="mySidenav" class="sidenav"> <!-- ATTENTION ! pas de href="#" sous peine de rechargement de la page et réinitialisation de l'appli --> <a class="closebtn" (click)="closeNav()">×</a> - <a (click)="newCalc()">{{uitextSidenavNewCalc}}</a> - <a (click)="loadSession()">{{uitextSidenavLoadSession}}</a> - <a (click)="params()">{{uitextSidenavParams}}</a> + <a (click)="newCalc()">{{ uitextSidenavNewCalc }}</a> + <a (click)="loadSession()">{{ uitextSidenavLoadSession }}</a> + <a (click)="params()">{{ uitextSidenavParams }}</a> <a target="_blank" href="assets/docs-fr/">Aide</a> <div class="hyd_fillvertical"></div> <div class="hyd_version"> - JaLHyd version: {{getDateRevision()[0]}}<br/> - ngHyd version: {{getDateRevision()[1]}} + JaLHyd version: {{ getDateRevision()[0] }}<br/> + ngHyd version: {{ getDateRevision()[1] }} </div> </div> </div> diff --git a/src/app/components/app-setup/app-setup.component.html b/src/app/components/app-setup/app-setup.component.html index 433caf89aeb3a2bc564e2a6c3974f70550aa84a0..a5e51fa3b2c7eb8b730ef4b51f597b29775a2361 100644 --- a/src/app/components/app-setup/app-setup.component.html +++ b/src/app/components/app-setup/app-setup.component.html @@ -1,7 +1,7 @@ <div class="container-fluid"> <div class="row"> <div class="col-4 mx-auto"> - <h1>{{uitextTitle}}</h1> + <h1>{{ uitextTitle }}</h1> <br/> </div> </div> @@ -33,12 +33,12 @@ <div class="col-4 mx-auto"> <div class="btn-group" dropdown> <button dropdownToggle mdbRippleRadius type="button" class="btn btn-primary dropdown-toggle"> - Language ({{currentLanguageLabel}}) + Language ({{ currentLanguageLabel }}) <span class="caret"></span> </button> <ul *dropdownMenu class="dropdown-menu" role="menu"> <li role="menuitem" *ngFor="let l of intlService.languages"> - <a class="dropdown-item" (click)="selectLang(l.code)">{{l.label}}</a> + <a class="dropdown-item" (click)="selectLang(l.code)">{{ l.label }}</a> </li> </ul> </div> diff --git a/src/app/components/app-setup/app-setup.component.ts b/src/app/components/app-setup/app-setup.component.ts index b8a07cf7cd0f662b2558eb158aaed7da8ff2ef4d..16115b15f8716a6e82aeab7df564fec490f387f4 100644 --- a/src/app/components/app-setup/app-setup.component.ts +++ b/src/app/components/app-setup/app-setup.component.ts @@ -2,8 +2,8 @@ import { Component, ViewChild } from "@angular/core"; import { BaseParam, ParamDomainValue, Observer } from "jalhyd"; -import { ApplicationSetupService } from '../../services/app-setup/app-setup.service'; -import { InternationalisationService, Language, LanguageCode } from '../../services/internationalisation/internationalisation.service'; +import { ApplicationSetupService } from "../../services/app-setup/app-setup.service"; +import { InternationalisationService, Language, LanguageCode } from "../../services/internationalisation/internationalisation.service"; import { NgBaseParam, BaseParamInputComponent } from "../base-param-input/base-param-input.component"; import { BaseComponent } from "../base/base.component"; diff --git a/src/app/components/base-param-input/base-param-input.component.ts b/src/app/components/base-param-input/base-param-input.component.ts index bb60d971a867d3d9ca25a61b9cde615589e8a312..f879a787b01580e72c5b0b0199826001cebc2598 100644 --- a/src/app/components/base-param-input/base-param-input.component.ts +++ b/src/app/components/base-param-input/base-param-input.component.ts @@ -72,25 +72,24 @@ export class BaseParamInputComponent extends GenericInputComponent { this._tmp = v; try { this._paramDef.setValue(v); - } - catch (e) { + } catch (e) { // géré par validateModelValue() } } protected validateModelValue(v: any): { isValid: boolean, message: string } { - let msg = undefined; + let msg; let valid = false; try { this._paramDef.checkValue(v); valid = true; - } - catch (e) { - if (e instanceof Message) + } catch (e) { + if (e instanceof Message) { msg = this.intlService.localizeMessage(e); - else + } else { msg = "invalid value"; + } } return { isValid: valid, message: msg }; @@ -101,14 +100,15 @@ export class BaseParamInputComponent extends GenericInputComponent { } protected validateUIValue(ui: string): { isValid: boolean, message: string } { - let valid: boolean = false; - let msg: string = undefined; + let valid = false; + let msg: string; - let v: NumericalString = new NumericalString(ui); - if (!v.isNumerical) + const v: NumericalString = new NumericalString(ui); + if (!v.isNumerical) { msg = "Veuillez entrer une valeur numérique"; - else + } else { valid = true; + } return { isValid: valid, message: msg }; } diff --git a/src/app/components/base/base.component.ts b/src/app/components/base/base.component.ts index d1c3efca70e802d4b6e0ebeaacd8088168ebccac..0fefbaf2cf96b66d53d9c577610e319d0cec9c68 100644 --- a/src/app/components/base/base.component.ts +++ b/src/app/components/base/base.component.ts @@ -9,7 +9,7 @@ export abstract class BaseComponent implements AfterViewChecked, OnChanges { /** * true si on souhaite qu'un événement soit émis en même temps que l'appel à afterFirstViewChecked() */ - protected emitFirstViewCheck: boolean = false; + protected emitFirstViewCheck = false; /** * événement émis en même temps que l'appel à afterFirstViewChecked() @@ -27,8 +27,9 @@ export abstract class BaseComponent implements AfterViewChecked, OnChanges { this.afterFirstViewChecked(); - if (this.emitFirstViewCheck) + if (this.emitFirstViewCheck) { this.onFirstViewCheck.emit(); + } } } @@ -40,4 +41,4 @@ export abstract class BaseComponent implements AfterViewChecked, OnChanges { */ protected afterFirstViewChecked() { } -} \ No newline at end of file +} diff --git a/src/app/components/calculator-list/calculator-list.component.ts b/src/app/components/calculator-list/calculator-list.component.ts index 718988b209bbeca6469df352553204a963e45901..d964e63cb4eccc9885ce29a1a90cec1de659f43a 100644 --- a/src/app/components/calculator-list/calculator-list.component.ts +++ b/src/app/components/calculator-list/calculator-list.component.ts @@ -16,8 +16,8 @@ class ListElement { this._label = ServiceFactory.instance.formulaireService.getLocalisedTitleFromCalculatorType(_type); } - public get label() { return this._label } - public get type() { return this._type } + public get label() { return this._label; } + public get type() { return this._type; } } @Component({ diff --git a/src/app/components/calculator-results/calculator-results.component.ts b/src/app/components/calculator-results/calculator-results.component.ts index 76eb9842a035c4d881165502268979895bb0df81..9457d73854937e97ae06aecbd3e2684d0c1906ef 100644 --- a/src/app/components/calculator-results/calculator-results.component.ts +++ b/src/app/components/calculator-results/calculator-results.component.ts @@ -42,8 +42,7 @@ export class CalculatorResultsComponent implements AfterViewChecked { this.fixedVarResultsComponent.results = undefined; this.sectionResultsComponent.results = undefined; this.remousResultsComponent.results = undefined; - } - else { + } else { this.fixedVarResultsComponent.results = f.results; this.sectionResultsComponent.results = f.results; this.remousResultsComponent.results = f.results; diff --git a/src/app/components/canvas/canvas.component.ts b/src/app/components/canvas/canvas.component.ts index ece63d209f2ef4f3e2fbffcacfa2aeef51c35bb5..ac359001a61b24ad41254b6aa3f3d2f8b4224fe4 100644 --- a/src/app/components/canvas/canvas.component.ts +++ b/src/app/components/canvas/canvas.component.ts @@ -1,7 +1,7 @@ -import { Component, Input, ViewChild, ElementRef, AfterViewInit } from '@angular/core'; +import { Component, Input, ViewChild, ElementRef, AfterViewInit } from "@angular/core"; @Component({ - selector: 'calc-canvas', + selector: "calc-canvas", template: `<canvas #canvas [attr.width] = '_width' [attr.height] = '_height'> @@ -9,8 +9,8 @@ import { Component, Input, ViewChild, ElementRef, AfterViewInit } from '@angular ` }) export class CalcCanvasComponent implements AfterViewInit { - private _width: number = 300; - private _height: number = 200; + private _width = 300; + private _height = 200; public get width(): number { return this._calcCanvas.nativeElement.width; @@ -38,24 +38,25 @@ export class CalcCanvasComponent implements AfterViewInit { ngAfterViewInit() { // wait for the view to init before using the element this._context2d = this._calcCanvas.nativeElement.getContext("2d"); - //this._context2d.fillStyle = 'blue'; + // this._context2d.fillStyle = 'blue'; // this._context2d.fillRect(10, 10, 350, 350); // this.drawRect(0, 0, this._width, this._height); } public clear() { - if (this._context2d != undefined) + if (this._context2d != undefined) { this._context2d.clearRect(0, 0, this.width, this.height); + } } public setStrokeColor(r: number, g: number, b: number) { - let col: string = "rgb(" + r + "," + g + "," + b + ")"; + const col: string = "rgb(" + r + "," + g + "," + b + ")"; this._context2d.strokeStyle = col; } public setFillColor(r: number, g: number, b: number) { - let col: string = "rgb(" + r + "," + g + "," + b + ")"; + const col: string = "rgb(" + r + "," + g + "," + b + ")"; this._context2d.fillStyle = col; } @@ -94,7 +95,7 @@ export class CalcCanvasComponent implements AfterViewInit { } /** - * + * * @param x The x axis of the coordinate for the ellipse's center. * @param y The y axis of the coordinate for the ellipse's center. * @param radiusX The ellipse's major-axis radius. diff --git a/src/app/components/check-field-line/check-field-line.component.html b/src/app/components/check-field-line/check-field-line.component.html index 5d0d8a993cee34c51d2649699618619318246f9a..26d8b9c2fd3c11aa48e6dd1ffc74026eeff330c0 100644 --- a/src/app/components/check-field-line/check-field-line.component.html +++ b/src/app/components/check-field-line/check-field-line.component.html @@ -1,5 +1,5 @@ <tr> - <td align="right">{{_check.label}}</td> + <td align="right">{{ _check.label }}</td> <td colspan="3"> <!-- <input type="checkbox" > diff --git a/src/app/components/field-set/field-set.component.html b/src/app/components/field-set/field-set.component.html index a90516337b1cf31eafd6187cd76897581cbf2ac1..1fc1b0c5e0007f57268be9569af3416b1704a999 100644 --- a/src/app/components/field-set/field-set.component.html +++ b/src/app/components/field-set/field-set.component.html @@ -1,6 +1,6 @@ <div class="row fieldset_backgrd"> <div class="col fieldset_title"> - {{title}} + {{ title }} </div> <div *ngIf="_showButtons" class="col-sm-4 fa-stack fa-2x hyd-window-btns"> <i class="fa fa-plus" (click)='onAddClick()'></i> diff --git a/src/app/components/field-set/field-set.component.ts b/src/app/components/field-set/field-set.component.ts index 9b4a682c13c56d9b1a00a8f69b1ad476382da19d..49f1f9db2137abf55a43225521e0dc6dd44a3c00 100644 --- a/src/app/components/field-set/field-set.component.ts +++ b/src/app/components/field-set/field-set.component.ts @@ -14,16 +14,75 @@ import { CheckField } from "../../formulaire/check-field"; styleUrls: ["./field-set.component.scss"] }) export class FieldSetComponent implements DoCheck { - /** - * field set attribute - */ - private _fieldSet: FieldSet; @Input() private set fieldSet(fs: FieldSet) { this._fieldSet = fs; } + private get fields() { + return this._fieldSet.kids; + } + + public set showButtons(b: boolean) { + this._showButtons = b; + } + + public set enableUpButton(b: boolean) { + this._enableUpButton = b; + } + + public set enableDownButton(b: boolean) { + this._enableDownButton = b; + } + + public set enableRemoveButton(b: boolean) { + this._enableRemoveButton = b; + } + + public set fieldsetNumber(n: number) { + this._fieldSet.labelNumber = n; + } + + private get title(): string { + if (this._fieldSet == undefined) { + return "fs undefined"; + } + if (this._fieldSet.label == undefined) { + return "label undefined"; + } + return this._fieldSet.label; + } + + public get isValid() { + return this._isValid; + } + + /** + * couleur du bouton monter + */ + private get upButtonColor(): string { + return this._enableUpButton ? "black" : "lightgrey"; + } + + /** + * couleur du bouton descendre + */ + private get downButtonColor(): string { + return this._enableDownButton ? "black" : "lightgrey"; + } + + /** + * couleur du bouton supprimer + */ + private get removeButtonColor(): string { + return this._enableRemoveButton ? "black" : "lightgrey"; + } + /** + * field set attribute + */ + private _fieldSet: FieldSet; + @ViewChildren(ParamFieldLineComponent) private _paramComponents: QueryList<ParamFieldLineComponent>; @@ -66,54 +125,36 @@ export class FieldSetComponent implements DoCheck { /** * flag de validité de la saisie */ - private _isValid: boolean = false; + private _isValid = false; /** * flag d'affichage des boutons ajouter, supprimer, monter, descendre */ - private _showButtons: boolean = false; + private _showButtons = false; /** * flag d'activation du bouton monter */ - private _enableUpButton: boolean = true; + private _enableUpButton = true; /** * flag d'activation du bouton descendre */ - private _enableDownButton: boolean = true; + private _enableDownButton = true; /** * flag d'activation du bouton supprimer */ - private _enableRemoveButton: boolean = true; - - private get fields() { - return this._fieldSet.kids; - } - - public set showButtons(b: boolean) { - this._showButtons = b; - } - - public set enableUpButton(b: boolean) { - this._enableUpButton = b; - } - - public set enableDownButton(b: boolean) { - this._enableDownButton = b; - } - - public set enableRemoveButton(b: boolean) { - this._enableRemoveButton = b; - } + private _enableRemoveButton = true; - public set fieldsetNumber(n: number) { - this._fieldSet.labelNumber = n; - } + /** + * événement de changement d'état d'un radio + */ + @Output() + private onRadio = new EventEmitter<any>(); private hasRadioFix(): boolean { - if (this._fieldSet.hasInputs) + if (this._fieldSet.hasInputs) { switch (this._fieldSet.getInput(0).radioConfig) { case ParamRadioConfig.FIX: return false; @@ -121,11 +162,12 @@ export class FieldSetComponent implements DoCheck { default: return true; } + } return false; } private hasRadioVar(): boolean { - if (this._fieldSet.hasInputs) + if (this._fieldSet.hasInputs) { switch (this._fieldSet.getInput(0).radioConfig) { case ParamRadioConfig.VAR: case ParamRadioConfig.CAL: @@ -134,11 +176,12 @@ export class FieldSetComponent implements DoCheck { default: return false; } + } return false; } private hasRadioCal(): boolean { - if (this._fieldSet.hasInputs) + if (this._fieldSet.hasInputs) { switch (this._fieldSet.getInput(0).radioConfig) { case ParamRadioConfig.CAL: return true; @@ -146,17 +189,10 @@ export class FieldSetComponent implements DoCheck { default: return false; } + } return false; } - private get title(): string { - if (this._fieldSet == undefined) - return "fs undefined"; - if (this._fieldSet.label == undefined) - return "label undefined"; - return this._fieldSet.label; - } - /** * détermine si un Field est du type InputField */ @@ -188,23 +224,13 @@ export class FieldSetComponent implements DoCheck { this.onRadio.emit(info); } - /** - * événement de changement d'état d'un radio - */ - @Output() - private onRadio = new EventEmitter<any>(); - - public get isValid() { - return this._isValid; - } - /** * calcul de la validité de tous les ParamFieldLineComponent de la vue */ private updateValidity() { this._isValid = false; - if (this._paramComponents != undefined) + if (this._paramComponents != undefined) { this._isValid = this._paramComponents.reduce( // callback ( @@ -221,6 +247,7 @@ export class FieldSetComponent implements DoCheck { } // valeur initiale , true); + } this.validChange.emit(); } @@ -268,44 +295,26 @@ export class FieldSetComponent implements DoCheck { * clic sur le bouton supprimer */ private onRemoveClick() { - if (this._enableRemoveButton) + if (this._enableRemoveButton) { this.removeFieldset.emit(this._fieldSet); + } } /** * clic sur le bouton monter */ private onMoveUpClick() { - if (this._enableUpButton) + if (this._enableUpButton) { this.moveFieldsetUp.emit(this._fieldSet); + } } /** * clic sur le bouton descendre */ private onMoveDownClick() { - if (this._enableDownButton) + if (this._enableDownButton) { this.moveFieldsetDown.emit(this._fieldSet); - } - - /** - * couleur du bouton monter - */ - private get upButtonColor(): string { - return this._enableUpButton ? "black" : "lightgrey"; - } - - /** - * couleur du bouton descendre - */ - private get downButtonColor(): string { - return this._enableDownButton ? "black" : "lightgrey"; - } - - /** - * couleur du bouton supprimer - */ - private get removeButtonColor(): string { - return this._enableRemoveButton ? "black" : "lightgrey"; + } } } diff --git a/src/app/components/fieldset-container/fieldset-container.component.html b/src/app/components/fieldset-container/fieldset-container.component.html index 96cb31b2cd8827cd8280ab58e5827c3cfa4a18fc..8655d7213c1170ca1a1c35ce77bd6236cf26399e 100644 --- a/src/app/components/fieldset-container/fieldset-container.component.html +++ b/src/app/components/fieldset-container/fieldset-container.component.html @@ -1,6 +1,6 @@ <div class="container-fluid" style="border-style:solid; border-color: lightgray; border-radius: 10px; margin-bottom: 10px;"> <div class="row"> - <h4 class="col">{{title}}</h4> + <h4 class="col">{{ title }}</h4> </div> <field-set *ngFor="let fs of fieldsets" [fieldSet]=fs (onRadio)=onRadioClick($event) (onValid)=onFieldsetValid() (inputChange)=onInputChange() diff --git a/src/app/components/fieldset-container/fieldset-container.component.ts b/src/app/components/fieldset-container/fieldset-container.component.ts index 947302dee60faf8f7c06174212a4a6641545725d..886c17241f154054cfa58621ad1de64b24c7e779 100644 --- a/src/app/components/fieldset-container/fieldset-container.component.ts +++ b/src/app/components/fieldset-container/fieldset-container.component.ts @@ -10,6 +10,21 @@ import { FormulaireDefinition } from "../../formulaire/definition/form-definitio templateUrl: "./fieldset-container.component.html" }) export class FieldsetContainerComponent implements DoCheck, AfterViewInit { + + private get title(): string { + if (this._container == undefined) { + return undefined; + } + return this._container.label; + } + + private get fieldsets() { + return this._container.fieldsets; + } + + public get isValid() { + return this._isValid; + } @Input("container") private _container: FieldsetContainer; @@ -22,23 +37,32 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit { /** * flag de validité des FieldSet enfants */ - private _isValid: boolean = false; + private _isValid = false; - private get title(): string { - if (this._container == undefined) - return undefined; - return this._container.label; - } + /** + * événément de changement d'état d'un radio + */ + @Output() + private onRadio = new EventEmitter<any>(); - private get fieldsets() { - return this._container.fieldsets; - } + /** + * événément de changement de validité + */ + @Output() + private validChange = new EventEmitter(); + + /** + * événément de changement de valeur d'un input + */ + @Output() + private inputChange = new EventEmitter(); private addStructure(after?: FieldSet) { - if (after) + if (after) { this._container.addFromTemplate(0, after.indexAsKid()); - else + } else { this._container.addFromTemplate(0); + } } private onFielsetListChange() { @@ -49,19 +73,19 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit { if (this._fieldsetComponents.length == 1) { const fs = this._fieldsetComponents.last as FieldSetComponent; fs.enableRemoveButton = false; - } - else + } else { this._fieldsetComponents.forEach(fs => fs.enableRemoveButton = true); + } // désactivation du bouton monter pour le 1er this._fieldsetComponents.forEach(fs => { fs.enableUpButton = true; fs.enableDownButton = true; }); - this._fieldsetComponents.first.enableUpButton = false + this._fieldsetComponents.first.enableUpButton = false; // désactivation du bouton monter pour le dernier - this._fieldsetComponents.last.enableDownButton = false + this._fieldsetComponents.last.enableDownButton = false; // renumérotation let n = 1; @@ -87,12 +111,6 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit { this.onRadio.emit(info); } - /** - * événément de changement d'état d'un radio - */ - @Output() - private onRadio = new EventEmitter<any>(); - public ngDoCheck() { this.updateValidity(); } @@ -103,7 +121,7 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit { private updateValidity() { this._isValid = false; - if (this._fieldsetComponents != undefined) + if (this._fieldsetComponents != undefined) { this._isValid = this._fieldsetComponents.reduce( // callback ( @@ -120,20 +138,11 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit { } // valeur initiale , this._fieldsetComponents.length > 0); + } this.validChange.emit(); } - public get isValid() { - return this._isValid; - } - - /** - * événément de changement de validité - */ - @Output() - private validChange = new EventEmitter(); - /** * réception d'un événement de validité de FieldSet */ @@ -141,12 +150,6 @@ export class FieldsetContainerComponent implements DoCheck, AfterViewInit { this.updateValidity(); } - /** - * événément de changement de valeur d'un input - */ - @Output() - private inputChange = new EventEmitter(); - /** * réception d'un événement de changement de valeur d'un input */ diff --git a/src/app/components/fixedvar-results/fixed-results.component.html b/src/app/components/fixedvar-results/fixed-results.component.html index a7080adb26f7ff5db75d1da1eaf03feef1152aed..011abed0f0852afed2b74e9887ec325f5ab8c91b 100644 --- a/src/app/components/fixedvar-results/fixed-results.component.html +++ b/src/app/components/fixedvar-results/fixed-results.component.html @@ -8,18 +8,18 @@ <table class="table" style="border: 1px solid rgb(230,230,230);"> <tr> <th class="result_center"> - {{uitextParamFixes}} + {{ uitextParamFixes }} </th> <th class="result_center"> - {{uitextValeurs}} + {{ uitextValeurs }} </th> </tr> <tr *ngFor="let r of fixedParams; let i=index"> <td class="result_right {{getFixedParamClass(i)}}"> - {{formattedLabel(r)}} + {{ formattedLabel(r) }} </td> <td class="result_center {{getFixedParamClass(i)}}"> - {{formattedValue(r)}} + {{ formattedValue(r) }} </td> </tr> <tr *ngIf="hasParameterResult" vertical-result-element [result-element]=resultElement [label]=resultLabel> diff --git a/src/app/components/fixedvar-results/fixedvar-results.component.ts b/src/app/components/fixedvar-results/fixedvar-results.component.ts index 7908509065b6b4c505c8c8b5c5624cb6adc5bf01..089c3055ec718f49dd0c56453346ae9742e25913 100644 --- a/src/app/components/fixedvar-results/fixedvar-results.component.ts +++ b/src/app/components/fixedvar-results/fixedvar-results.component.ts @@ -1,7 +1,7 @@ import { Component, ViewChild, DoCheck } from "@angular/core"; import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; -import { LogComponent } from '../../components/log/log.component'; +import { LogComponent } from "../../components/log/log.component"; import { FixedResults } from "../../results/fixed-results"; import { VarResults } from "../../results/var-results"; import { ResultsGraphComponent } from "../results-graph/results-graph.component"; @@ -45,7 +45,7 @@ export class FixedVarResultsComponent implements DoCheck { /** * true si les résultats doiventt être remis à jour */ - private _doUpdate: boolean = false; + private _doUpdate = false; @ViewChild(FixedResultsComponent) private fixedResultsComponent: FixedResultsComponent; @@ -73,85 +73,98 @@ export class FixedVarResultsComponent implements DoCheck { public set results(rs: CalculatorResults[]) { this._fixedResults = undefined; this._varResults = undefined; - if (rs != undefined) + if (rs != undefined) { for (const r of rs) { - if (r instanceof FixedResults) + if (r instanceof FixedResults) { this._fixedResults = r; - else - if (r instanceof VarResults) + } else + if (r instanceof VarResults) { this._varResults = r; + } } + } this.updateView(); } public updateView() { this.logComponent.log = undefined; - if (this.fixedResultsComponent) + if (this.fixedResultsComponent) { this.fixedResultsComponent.results = undefined; - if (this.varResultsComponent) + } + if (this.varResultsComponent) { this.varResultsComponent.results = undefined; - if (this.resultsGraphComponent) + } + if (this.resultsGraphComponent) { this.resultsGraphComponent.results = undefined; + } this._doUpdate = false; - if (this._fixedResults != undefined) + if (this._fixedResults != undefined) { this._doUpdate = this._fixedResults.hasResults || this._fixedResults.hasLog; - if (this._varResults != undefined) + } + if (this._varResults != undefined) { this._doUpdate = this._doUpdate || this._varResults.hasResults || this._varResults.hasLog; + } } public ngDoCheck() { - if (this._doUpdate) + if (this._doUpdate) { this._doUpdate = !this.updateResults(); + } } private mergeLog(result: Result, log: cLog) { if (result && result.hasLog) { - if (result.hasGlobalLog) + if (result.hasGlobalLog) { log.addLog(result.globalLog); - else + } else { log.addLog(result.log); + } } } private get mergedGlobalLogs(): cLog { const res = new cLog(); - if (this._fixedResults) + if (this._fixedResults) { this.mergeLog(this._fixedResults.result, res); + } - if (this._varResults) + if (this._varResults) { this.mergeLog(this._varResults.result, res); + } return res; } - /** + /** * met à jour l'affichage des résultats * @returns true si les résultats ont pu être mis à jour */ private updateResults() { const fixedUpdated = this._fixedResults != undefined && this.fixedResultsComponent != undefined; - if (fixedUpdated) + if (fixedUpdated) { this.fixedResultsComponent.results = this._fixedResults; + } if (this._varResults && this._varResults.hasResults) { - var varUpdated = this.varResultsComponent != undefined; - if (varUpdated) + const varUpdated = this.varResultsComponent != undefined; + if (varUpdated) { this.varResultsComponent.results = this._varResults; + } - var graphUpdated = this.resultsGraphComponent != undefined; + const graphUpdated = this.resultsGraphComponent != undefined; if (graphUpdated) { this.resultsGraphComponent.results = this._varResults; this.resultsGraphComponent.updateView(); } - } - else { + } else { varUpdated = true; graphUpdated = true; } const logUpdated = this.logComponent != undefined; - if (logUpdated) + if (logUpdated) { this.logComponent.log = this.mergedGlobalLogs; + } return fixedUpdated && varUpdated && logUpdated && graphUpdated; } diff --git a/src/app/components/fixedvar-results/var-results.component.html b/src/app/components/fixedvar-results/var-results.component.html index 4c3a42601406cdbc697c47bb3e8331ad191f97bd..01a77a44949cf0d5f17a73294b697c9f25a64faa 100644 --- a/src/app/components/fixedvar-results/var-results.component.html +++ b/src/app/components/fixedvar-results/var-results.component.html @@ -4,12 +4,12 @@ <div class="col"> <table class="table table-striped" style="border: 1px solid rgb(230,230,230);"> <tr> - <th *ngFor="let h of headers">{{h}}</th> + <th *ngFor="let h of headers">{{ h }}</th> </tr> <tr *ngFor="let r of _results; let i=index"> <!-- paramètre varié --> <td class="result_center"> - {{r.param}} + {{ r.param }} </td> <!-- résultat --> <td horizontal-result-element [result-element]=r.result [headerKeys]=extraResultKeys> diff --git a/src/app/components/fixedvar-results/var-results.component.ts b/src/app/components/fixedvar-results/var-results.component.ts index ee35aa4049f2c5c9178d57a8f7f5a11627a0efb3..de891f29b61477151d0a0dff8d2ec7c0310d4270 100644 --- a/src/app/components/fixedvar-results/var-results.component.ts +++ b/src/app/components/fixedvar-results/var-results.component.ts @@ -42,7 +42,7 @@ export class VarResultsComponent { for (const x of this._varResults.variatedParameter.valuesIterator) { const pval = x.toFixed(nDigits); this._results.push({ "param": pval, "result": this._varResults.resultElements[i] }); - i++ + i++; } this._headers.push(this._varResults.variableParamHeader); diff --git a/src/app/components/generic-calculator/calc-name.component.ts b/src/app/components/generic-calculator/calc-name.component.ts index 6e2452fbc05f60d1b46a25d88f8f5e3b37b9a3fd..45334b4abca1d98a572bfa205a5b4284c5d917fe 100644 --- a/src/app/components/generic-calculator/calc-name.component.ts +++ b/src/app/components/generic-calculator/calc-name.component.ts @@ -3,7 +3,7 @@ import { GenericInputComponent } from "../generic-input/generic-input.component" import { FormulaireDefinition } from "../../formulaire/definition/form-definition"; @Component({ - selector: 'calc-name', + selector: "calc-name", templateUrl: "../generic-input/generic-input.component.html", }) export class CalculatorNameComponent extends GenericInputComponent { @@ -23,8 +23,9 @@ export class CalculatorNameComponent extends GenericInputComponent { * retourne la valeur du modèle */ protected getModelValue(): any { - if (this._form == undefined) + if (this._form == undefined) { return undefined; + } return this._form.calculatorName; } @@ -43,13 +44,14 @@ export class CalculatorNameComponent extends GenericInputComponent { * @returns message : message d'erreur */ protected validateModelValue(v: any): { isValid: boolean, message: string } { - let msg = undefined; + let msg; let valid = false; - if (!(typeof (v) == "string") || v.length < 1) + if (!(typeof (v) == "string") || v.length < 1) { msg = "Veuillez entrer un nom"; - else + } else { valid = true; + } return { isValid: valid, message: msg }; } @@ -68,13 +70,14 @@ export class CalculatorNameComponent extends GenericInputComponent { * @returns message : message d'erreur */ protected validateUIValue(ui: string): { isValid: boolean, message: string } { - let valid: boolean = false; - let msg: string = undefined; + let valid = false; + let msg: string; - if (ui == undefined || ui.length < 1) + if (ui == undefined || ui.length < 1) { msg = "Veuillez entrer un nom"; - else + } else { valid = true; + } return { isValid: valid, message: msg }; } diff --git a/src/app/components/generic-calculator/calculator.component.html b/src/app/components/generic-calculator/calculator.component.html index b0ef881e1432ceeee6354a774bbca3b6bf72b039..72a35461382dc02658794c73f6dcf21a81ce6c21 100644 --- a/src/app/components/generic-calculator/calculator.component.html +++ b/src/app/components/generic-calculator/calculator.component.html @@ -38,7 +38,7 @@ <div class="row"> <div class="col-12 text-center"> <button type="button" [ngClass]="(isCalculateDisabled) ? 'button_compute_err' : 'button_compute_ok'" name="Calculer" (click)="doCompute()" - [disabled]="isCalculateDisabled">{{uitextCalculer}}</button> + [disabled]="isCalculateDisabled">{{ uitextCalculer }}</button> <p></p> <p></p> </div> @@ -60,14 +60,14 @@ <button type="button" class="close pull-right" aria-label="Close" (click)="confirmModal.hide()"> <span aria-hidden="true">×</span> </button> - <h4 class="modal-title w-100" id="myModalLabel">{{uitextCloseDialogTitle}}</h4> + <h4 class="modal-title w-100" id="myModalLabel">{{ uitextCloseDialogTitle }}</h4> </div> <div class="modal-body"> <h4 [innerHTML]="uitextCloseDialogText"></h4> </div> <div class="modal-footer"> - <button type="button" class="btn btn-danger relative waves-light" (click)="confirmModal.hide();onCloseForm()" mdbRippleRadius>{{uitextCloseDialogYes}}</button> - <button type="button" class="btn btn-success waves-light" aria-label="Close" (click)="confirmModal.hide()" mdbRippleRadius>{{uitextCloseDialogNo}}</button> + <button type="button" class="btn btn-danger relative waves-light" (click)="confirmModal.hide();onCloseForm()" mdbRippleRadius>{{ uitextCloseDialogYes }}</button> + <button type="button" class="btn btn-success waves-light" aria-label="Close" (click)="confirmModal.hide()" mdbRippleRadius>{{ uitextCloseDialogNo }}</button> </div> </div> </div> diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index 5556911711c6da46b3ffd70df8e3d3eaf4662d88..d9c5dc26740d52f792218eafa3787e9f9ddb9962 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -250,7 +250,7 @@ export class GenericCalculatorComponent extends BaseComponent implements OnInit, } private getFieldsetStyleDisplay(id: string) { - let isDisplayed: boolean = this._formulaire.isDisplayed(id); + const isDisplayed: boolean = this._formulaire.isDisplayed(id); return isDisplayed ? "block" : "none"; } diff --git a/src/app/components/generic-input/generic-input.component.ts b/src/app/components/generic-input/generic-input.component.ts index 29bfb23cfcee5cf272b1e1f79f0e4fb94301fe47..3b2c311cdb221302c6574aeb9babbafc51d634b8 100644 --- a/src/app/components/generic-input/generic-input.component.ts +++ b/src/app/components/generic-input/generic-input.component.ts @@ -31,8 +31,8 @@ export abstract class GenericInputComponent extends BaseComponent { /** * flag de désactivation de l'input */ - @Input('inputDisabled') - private _inputDisabled: boolean = false; + @Input("inputDisabled") + private _inputDisabled = false; /** * flag d'affichage du message d'erreur @@ -42,7 +42,7 @@ export abstract class GenericInputComponent extends BaseComponent { /** * chaîne affichée dans l'input quand aucune valeur n'est saisie */ - @Input('title') + @Input("title") private _title: string; /** @@ -98,10 +98,11 @@ export abstract class GenericInputComponent extends BaseComponent { * détection des changements dans l'UI par le ChangeDetector du framework */ protected detectChanges() { - if (this.cdRef != undefined) + if (this.cdRef != undefined) { // if (!this.cdRef['destroyed']) // pour éviter l'erreur "Attempt to use a destroyed view: detectChanges" // this.cdRef.detectChanges(); this.cdRef.markForCheck(); + } } /** @@ -114,12 +115,13 @@ export abstract class GenericInputComponent extends BaseComponent { private setUIValid(b: boolean) { const old = this.isValid; this._isValidUI = b; - if (this.isValid != old) + if (this.isValid != old) { this.emitValidChanged(); + } } private validateUI() { - let { isValid, message } = this.validateUIValue(this._uiValue); + const { isValid, message } = this.validateUIValue(this._uiValue); this._errorMessageUI = message; this.detectChanges(); this.setUIValid(isValid); @@ -129,12 +131,13 @@ export abstract class GenericInputComponent extends BaseComponent { private setModelValid(b: boolean) { const old = this.isValid; this._isValidModel = b; - if (this.isValid != old) + if (this.isValid != old) { this.emitValidChanged(); + } } private validateModel() { - let { isValid, message } = this.validateModelValue(this.getModelValue()); + const { isValid, message } = this.validateModelValue(this.getModelValue()); this._errorMessageModel = message; this.detectChanges(); this.setModelValid(isValid); @@ -150,8 +153,9 @@ export abstract class GenericInputComponent extends BaseComponent { * L'erreur de forme (UI) est prioritaire */ private get errorMessage() { - if (this._errorMessageUI != undefined) + if (this._errorMessageUI != undefined) { return this._errorMessageUI; + } return this._errorMessageModel; } @@ -206,8 +210,9 @@ export abstract class GenericInputComponent extends BaseComponent { * met à jour le modèle d'après la saisie */ public updateModelFromUI() { - if (this.validateUI()) + if (this.validateUI()) { this.setAndValidateModel(this, this.uiToModel(this._uiValue)); + } } private updateAll() { diff --git a/src/app/components/generic-select/generic-select.component.html b/src/app/components/generic-select/generic-select.component.html index 53bcde259c0c9cb0b6cdc1bbaf88964af02d089d..1d4c81a98c662650288f15242987ecf0761e3062 100644 --- a/src/app/components/generic-select/generic-select.component.html +++ b/src/app/components/generic-select/generic-select.component.html @@ -1,8 +1,8 @@ <div class="btn-group" dropdown (selected)="onSelect($event)"> <button dropdownToggle class="btn btn-primary dropdown-toggle waves-light my-1" type="button" mdbRippleRadius> - {{currentLabel}} + {{ currentLabel }} </button> <div class="dropdown-menu"> - <a class="dropdown-item" *ngFor="let e of entries" [value]=e>{{entryLabel(e)}}</a> + <a class="dropdown-item" *ngFor="let e of entries" [value]=e>{{ entryLabel(e) }}</a> </div> </div> \ No newline at end of file diff --git a/src/app/components/load-calculator/load-calculator-anchor.directive.ts b/src/app/components/load-calculator/load-calculator-anchor.directive.ts index f270813f12348a6a9b894f9ba5180d47b73f375f..dda9149986157dacc41587e57bc5ad7584027070 100644 --- a/src/app/components/load-calculator/load-calculator-anchor.directive.ts +++ b/src/app/components/load-calculator/load-calculator-anchor.directive.ts @@ -1,10 +1,10 @@ -import { Directive, ComponentFactoryResolver, ComponentFactory, ComponentRef } from '@angular/core'; +import { Directive, ComponentFactoryResolver, ComponentFactory, ComponentRef } from "@angular/core"; -import { ViewContainerRef } from '@angular/core'; -import { LoadCalculatorComponent } from './load-calculator.component'; +import { ViewContainerRef } from "@angular/core"; +import { LoadCalculatorComponent } from "./load-calculator.component"; @Directive({ - selector: '[loadCalcDialogAnchor]' + selector: "[loadCalcDialogAnchor]" }) export class LoadCalcDialogAnchorDirective { constructor( @@ -15,8 +15,8 @@ export class LoadCalcDialogAnchorDirective { public createDialog(): ComponentRef<LoadCalculatorComponent> { this.viewContainer.clear(); - let compFactory: ComponentFactory<LoadCalculatorComponent> = this.componentFactoryResolver.resolveComponentFactory(LoadCalculatorComponent); - let compRef: ComponentRef<LoadCalculatorComponent> = this.viewContainer.createComponent(compFactory); + const compFactory: ComponentFactory<LoadCalculatorComponent> = this.componentFactoryResolver.resolveComponentFactory(LoadCalculatorComponent); + const compRef: ComponentRef<LoadCalculatorComponent> = this.viewContainer.createComponent(compFactory); // compRef.instance.confirmResult.subscribe(() => { // compRef.destroy(); diff --git a/src/app/components/load-calculator/load-calculator.component.html b/src/app/components/load-calculator/load-calculator.component.html index b596cadbf55f04ffd5ee4cf376c706549d00654d..c8b8ad926b21d8991b37220eb51af734cd338389 100644 --- a/src/app/components/load-calculator/load-calculator.component.html +++ b/src/app/components/load-calculator/load-calculator.component.html @@ -2,22 +2,22 @@ <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> - <h4 class="modal-title w-100" id="myModalLabel">{{uitextDialogTitle}}</h4> + <h4 class="modal-title w-100" id="myModalLabel">{{ uitextDialogTitle }}</h4> </div> <div class="modal-body"> <div> <input type="file" #fileSelector multiple="false" accept="*.json" (change)="onFileSelect()"> </div> <div *ngFor="let c of _calculators"> - <input type="checkbox" value={{c.uid}} checked={{isSelected(c)}} (change)="onCheckCalc($event)">{{c.title}} + <input type="checkbox" value={{c.uid}} checked={{isSelected(c)}} (change)="onCheckCalc($event)">{{ c.title }} </div> - <button *ngIf="showSelectButtons" type="button" class="btn btn-mdb-color waves-light" (click)="selectAll()" mdbRippleRadius>{{uitextSelectAll}}</button> - <button *ngIf="showSelectButtons" type="button" class="btn btn-mdb-color waves-light" (click)="deselectAll()" mdbRippleRadius>{{uitextDeselectAll}}</button> + <button *ngIf="showSelectButtons" type="button" class="btn btn-mdb-color waves-light" (click)="selectAll()" mdbRippleRadius>{{ uitextSelectAll }}</button> + <button *ngIf="showSelectButtons" type="button" class="btn btn-mdb-color waves-light" (click)="deselectAll()" mdbRippleRadius>{{ uitextDeselectAll }}</button> </div> <div class="modal-footer"> - <button type="button" class="btn btn-danger relative waves-light" (click)="loadDialog.hide();cancelLoad()" mdbRippleRadius>{{uitextCancel}}</button> + <button type="button" class="btn btn-danger relative waves-light" (click)="loadDialog.hide();cancelLoad()" mdbRippleRadius>{{ uitextCancel }}</button> <button type="button" class="btn btn-success waves-light" [disabled]="disableLoadButton" (click)="loadDialog.hide();confirmLoad()" - mdbRippleRadius>{{uitextLoad}}</button> + mdbRippleRadius>{{ uitextLoad }}</button> </div> </div> </div> diff --git a/src/app/components/load-calculator/load-calculator.component.ts b/src/app/components/load-calculator/load-calculator.component.ts index c1a3f8b710f1e50228323e7a7c9b8457f1f8a0c7..7d48e120ba84ea8a3d89eaf73cafa3760f08238c 100644 --- a/src/app/components/load-calculator/load-calculator.component.ts +++ b/src/app/components/load-calculator/load-calculator.component.ts @@ -4,11 +4,11 @@ import { ServiceFactory } from "../../services/service-factory"; import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; @Component({ - selector: 'load-calc', + selector: "load-calc", templateUrl: "./load-calculator.component.html" }) export class LoadCalculatorComponent { - @ViewChild('fileSelector') fileSelector; + @ViewChild("fileSelector") fileSelector; private _selectFile: File; @@ -59,14 +59,18 @@ export class LoadCalculatorComponent { */ private get disableLoadButton() { // pas de fichier sélectionné -> bouton grisé - if (this._selectFile === undefined) + if (this._selectFile === undefined) { return true; + } // au moins une calculette sélectionnée -> dégrisé - if (this._calculators !== undefined) - for (const c of this._calculators) - if (c.selected) + if (this._calculators !== undefined) { + for (const c of this._calculators) { + if (c.selected) { return false; + } + } + } // grisé sinon return true; @@ -91,22 +95,26 @@ export class LoadCalculatorComponent { private getSelectedFile(): File { const files: { [key: string]: File } = this.fileSelector.nativeElement.files; - for (const key in files) - if (!isNaN(parseInt(key))) + for (const key in files) { + if (!isNaN(parseInt(key))) { return files[key]; + } + } return undefined; } private onFileSelect() { const formService = ServiceFactory.instance.formulaireService; this._selectFile = this.getSelectedFile(); - if (this._selectFile !== undefined) + if (this._selectFile !== undefined) { formService.calculatorInfosFromSessionFile(this._selectFile).then( calcInfos => { this._calculators = calcInfos; - for (const n of this._calculators) + for (const n of this._calculators) { n["selected"] = true; + } }); + } } public get selectedFile(): File { @@ -122,21 +130,24 @@ export class LoadCalculatorComponent { } private onCheckCalc(event: any) { - for (const c of this._calculators) + for (const c of this._calculators) { if (c.uid == +event.target.value) { c.selected = event.target.checked; break; } + } } private selectAll() { - for (const c of this._calculators) + for (const c of this._calculators) { c.selected = true; + } } private deselectAll() { - for (const c of this._calculators) + for (const c of this._calculators) { c.selected = false; + } } private set confirmed(b: boolean) { diff --git a/src/app/components/log/log.component.html b/src/app/components/log/log.component.html index 37ecc7a8eb42e8fcccfdf195bfd4cfbd0a3605c3..2214487f0b43c7e61bed36fe34762b16f7feef6d 100644 --- a/src/app/components/log/log.component.html +++ b/src/app/components/log/log.component.html @@ -2,7 +2,7 @@ <div class="col-12"> <div class="hyd_log"> <!-- titre --> - <div class="titre">{{uitextTitreJournal}}</div> + <div class="titre">{{ uitextTitreJournal }}</div> <!-- entrées du journal --> <ng-template ngFor let-m [ngForOf]="messages"> diff --git a/src/app/components/log/log.component.ts b/src/app/components/log/log.component.ts index 93d567509a15cf1230395e10b361dda9e2c8f1ed..6ce8d23126925e5086b07e6f3ec8f37157d0f9fe 100644 --- a/src/app/components/log/log.component.ts +++ b/src/app/components/log/log.component.ts @@ -1,6 +1,6 @@ import { Component } from "@angular/core"; -import { cLog, Message } from 'jalhyd'; +import { cLog, Message } from "jalhyd"; import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; @@ -39,7 +39,7 @@ export class LogComponent { ) { } private get uitextTitreJournal() { - return this.intlService.localizeText("INFO_REMOUSRESULTS_TITREJOURNAL") + return this.intlService.localizeText("INFO_REMOUSRESULTS_TITREJOURNAL"); } private get hasEntries(): boolean { diff --git a/src/app/components/ngparam-input/ngparam-input.component.ts b/src/app/components/ngparam-input/ngparam-input.component.ts index bba17a97f99d03cb6696d95801689d46af2f3386..1e8aea960eca9d173e54a243f9414b94e438d846 100644 --- a/src/app/components/ngparam-input/ngparam-input.component.ts +++ b/src/app/components/ngparam-input/ngparam-input.component.ts @@ -35,8 +35,9 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse * appelé avant le changement de modèle */ protected beforeSetModel() { - if (this._paramDef != undefined) + if (this._paramDef != undefined) { this._paramDef.removeObserver(this); + } } /** @@ -44,8 +45,9 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse */ protected afterSetModel() { if (this._paramDef != undefined) { - if (this._paramDef.isDefined) + if (this._paramDef.isDefined) { this._tmp = this._paramDef.getValue(); + } this._paramDef.addObserver(this); } } @@ -58,29 +60,29 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse this._tmp = v; try { this._paramDef.setValue(sender, v); - } - catch (e) { + } catch (e) { // géré par validateModelValue() } } protected validateModelValue(v: any): { isValid: boolean, message: string } { - let msg = undefined; + let msg; let valid = false; - if (this._paramDef == undefined) + if (this._paramDef == undefined) { msg = "internal error, model undefined"; - else + } else { try { this._paramDef.checkValue(v); valid = true; - } - catch (e) { - if (e instanceof Message) + } catch (e) { + if (e instanceof Message) { msg = this.intlService.localizeMessage(e); - else + } else { msg = "invalid value"; + } } + } return { isValid: valid, message: msg }; } @@ -90,14 +92,15 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse } protected validateUIValue(ui: string): { isValid: boolean, message: string } { - let valid: boolean = false; - let msg: string = undefined; + let valid = false; + let msg: string; - let v: NumericalString = new NumericalString(ui); - if (!v.isNumerical) + const v: NumericalString = new NumericalString(ui); + if (!v.isNumerical) { msg = "Veuillez entrer une valeur numérique"; - else + } else { valid = true; + } return { isValid: valid, message: msg }; } diff --git a/src/app/components/param-field-line/param-field-line.component.html b/src/app/components/param-field-line/param-field-line.component.html index 2a4d3ca4035f6bc4bdb5ab0b75d206cf049ccda5..9e20986daff20da97ddda8e576092622ecbdfc73 100644 --- a/src/app/components/param-field-line/param-field-line.component.html +++ b/src/app/components/param-field-line/param-field-line.component.html @@ -13,25 +13,25 @@ <!-- radio "fixé" --> <label *ngIf="hasRadioFix()" class="{{radioFixClass}} h-75 px-3 py-3" [(ngModel)]="radioModel" mdbRadio="Left" name="radio_param_{{symbol}}" value="fix" (click)="onRadioClick('fix')" [checked]=radioFixCheck [disabled]=isDisabled id="radio_fix"> - {{uitextParamFixe}} + {{ uitextParamFixe }} </label> <!-- radio "varier" --> <label *ngIf="hasRadioVar()" class="{{radioVarClass}} h-75 px-3 py-3" [(ngModel)]="radioModel" mdbRadio="Middle" name="radio_param_{{symbol}}" value="var" (click)="onRadioClick('var')" [checked]=radioVarCheck [disabled]=isDisabled id="radio_var"> - {{uitextParamVarier}} + {{ uitextParamVarier }} </label> <!-- radio "calculer" --> <label *ngIf="hasRadioCal()" class="{{radioCalClass}} h-75 px-3 py-3" [(ngModel)]="radioModel" mdbRadio="Right" name="radio_param_{{symbol}}" value="cal" (click)="onRadioClick('cal')" [checked]=radioCalCheck [disabled]=isDisabled id="radio_cal"> - {{uitextParamCalculer}} + {{ uitextParamCalculer }} </label> <!-- radio "lié" --> <label *ngIf="hasRadioLink()" class="{{radioLinkClass}} h-75 px-3 py-3" [(ngModel)]="radioModel" mdbRadio="Right" name="radio_param_{{symbol}}" value="link" (click)="onRadioClick('link')" [checked]=radioLinkCheck [disabled]=isDisabled id="radio_link"> - {{uitextParamLie}} + {{ uitextParamLie }} </label> </div> </div> diff --git a/src/app/components/param-field-line/param-field-line.component.ts b/src/app/components/param-field-line/param-field-line.component.ts index c957e6b1a8a9a766c3ce67f64b083c8b478eccaf..195156e703f78e94d5b24abdeecad5b7343db46e 100644 --- a/src/app/components/param-field-line/param-field-line.component.ts +++ b/src/app/components/param-field-line/param-field-line.component.ts @@ -29,34 +29,6 @@ import { ParamLinkComponent } from "../param-link/param-link.component"; ] }) export class ParamFieldLineComponent implements OnChanges { - @Input("param") - private _param: NgParameter; - - @ViewChild(NgParamInputComponent) - private _ngParamInputComponent: NgParamInputComponent; - - @ViewChild(ParamLinkComponent) - private _paramLinkComponent: ParamLinkComponent; - - @Output() - private onValid: EventEmitter<void>; - - @Output() - private inputChange: EventEmitter<void>; - - /** - * true si la valeur saisie est valide - */ - private _isInputValid: boolean = false; - - /** - * true si le min-max/liste est valide - */ - private _isRangeValid: boolean = true; - - private intlService: InternationalisationService; - - private _formService: FormulaireService; constructor() { this.intlService = ServiceFactory.instance.internationalisationService; @@ -67,10 +39,12 @@ export class ParamFieldLineComponent implements OnChanges { private get title(): string { let t = ""; - if (this._param.label != undefined) + if (this._param.label != undefined) { t = this._param.label; - if (this._param.unit != undefined && this._param.unit != "") + } + if (this._param.unit != undefined && this._param.unit != "") { t = t + " (" + this._param.unit + ")"; + } return t; } @@ -97,66 +71,6 @@ export class ParamFieldLineComponent implements OnChanges { return this._param.symbol; } - /** - * calcule la présence du radio "paramètre fixé" - */ - private hasRadioFix(): boolean { - switch (this._param.radioConfig) { - case ParamRadioConfig.FIX: - return this.hasRadioLink(); - - default: - return true; - } - } - - /** - * calcule la présence du radio "paramètre à varier" - */ - private hasRadioVar(): boolean { - switch (this._param.radioConfig) { - case ParamRadioConfig.VAR: - case ParamRadioConfig.CAL: - return true; - - default: - return false; - } - } - - /** - * calcule la présence du radio "paramètre à calculer" - */ - private hasRadioCal(): boolean { - switch (this._param.radioConfig) { - case ParamRadioConfig.CAL: - return true; - - default: - return false; - } - } - - /** - * calcule la présence du radio "paramètre lié" (importé d'une autre calculette) - */ - private hasRadioLink(): boolean { - if (this._formService.formulaires.length > 0) { - // au moins 2 calculettes ouvertes - if (this._formService.formulaires.length > 1) - return this._formService.filterLinkableValues(this._formService.getLinkableValues(this._param)).length > 0; - - // ou une seule calculette "ouvrages parallèles" - if (this._formService.formulaires[0].calculatorType == CalculatorType.ParallelStructure) { - const ps: ParallelStructure = this._formService.formulaires[0].currentSessionNub.nub as ParallelStructure; - if (ps.structures.length > 1) - return this._formService.filterLinkableValues(this._formService.getLinkableValues(this._param)).length > 0; - } - - } - return false; - } - /** * calcule l'état du radio "paramètre fixé" */ @@ -175,8 +89,9 @@ export class ParamFieldLineComponent implements OnChanges { * calcule l'état du radio "paramètre à calculer" */ private get radioCalCheck(): string { - if (this._param.radioState == ParamRadioConfig.CAL) + if (this._param.radioState == ParamRadioConfig.CAL) { return "checked"; + } return undefined; } @@ -184,8 +99,9 @@ export class ParamFieldLineComponent implements OnChanges { * calcule l'état du radio "paramètre lié" */ private get radioLinkCheck(): string { - if (this._param.radioState == ParamRadioConfig.LINK) + if (this._param.radioState == ParamRadioConfig.LINK) { return "checked"; + } return undefined; } @@ -210,47 +126,6 @@ export class ParamFieldLineComponent implements OnChanges { return this._param.radioState == ParamRadioConfig.LINK; } - /* - * gestion des événements clic sur les radios : - * envoi d'un message au composant parent - * cf. https://angular.io/guide/component-interaction#parent-listens-for-child-event - */ - - @Output() - private onRadio = new EventEmitter<any>(); - - private onRadioClick(option: string) { - const oldValue = this._param.valueMode; - - switch (option) { - case "fix": - const oldValueMode = this._param.valueMode; - this._param.valueMode = ParamValueMode.SINGLE; - this._param.setValue(this, this._param.paramDefinition.paramValues.singleValue); - break; - - case "var": - this._param.valueMode = ParamValueMode.MINMAX; // min/max par défaut - break; - - case "cal": - this._param.valueMode = ParamValueMode.CALCUL; - break; - - case "link": - this._param.valueMode = ParamValueMode.LINK; - break; - } - - this.onRadio.emit({ - "param": this._param, - "oldValueMode": oldValue - }); - - // MAJ validité - this.emitValidity(); - } - /** * désactivation de tous les boutons radio si paramètre par défaut à "CAL" */ @@ -264,16 +139,10 @@ export class ParamFieldLineComponent implements OnChanges { private get isInputDisabled(): boolean { return this._param.radioState != ParamRadioConfig.FIX; } - - /** - * classe du radio "fixé" - */ - private on = true; - private onClass = "btn-on" - private offClass = "btn-off" private get radioFixClass(): string { - if (this.on) + if (this.on) { return this.radioFixCheck == undefined ? this.offClass : this.onClass; + } return ""; } @@ -281,8 +150,9 @@ export class ParamFieldLineComponent implements OnChanges { * classe du radio "varier" */ private get radioVarClass(): string { - if (this.on) + if (this.on) { return this.radioVarCheck == undefined ? this.offClass : this.onClass; + } return ""; } @@ -290,8 +160,9 @@ export class ParamFieldLineComponent implements OnChanges { * classe du radio "calculer" */ private get radioCalClass(): string { - if (this.on) + if (this.on) { return this.radioCalCheck == undefined ? this.offClass : this.onClass; + } return ""; } @@ -299,8 +170,9 @@ export class ParamFieldLineComponent implements OnChanges { * classe du radio "lié" */ private get radioLinkClass(): string { - if (this.on) + if (this.on) { return this.radioLinkCheck == undefined ? this.offClass : this.onClass; + } return ""; } @@ -310,7 +182,7 @@ export class ParamFieldLineComponent implements OnChanges { public get isValid(): boolean { switch (this._param.radioState) { case ParamRadioConfig.FIX: - return this._isInputValid + return this._isInputValid; case ParamRadioConfig.VAR: return this._isRangeValid; @@ -320,11 +192,153 @@ export class ParamFieldLineComponent implements OnChanges { } } + private get formHasResults(): boolean { + return ServiceFactory.instance.formulaireService.currentFormHasResults; + } + @Input("param") + private _param: NgParameter; + + @ViewChild(NgParamInputComponent) + private _ngParamInputComponent: NgParamInputComponent; + + @ViewChild(ParamLinkComponent) + private _paramLinkComponent: ParamLinkComponent; + + @Output() + private onValid: EventEmitter<void>; + + @Output() + private inputChange: EventEmitter<void>; + + /** + * true si la valeur saisie est valide + */ + private _isInputValid = false; + + /** + * true si le min-max/liste est valide + */ + private _isRangeValid = true; + + private intlService: InternationalisationService; + + private _formService: FormulaireService; + + /* + * gestion des événements clic sur les radios : + * envoi d'un message au composant parent + * cf. https://angular.io/guide/component-interaction#parent-listens-for-child-event + */ + + @Output() + private onRadio = new EventEmitter<any>(); + + /** + * classe du radio "fixé" + */ + private on = true; + private onClass = "btn-on"; + private offClass = "btn-off"; + + /** + * calcule la présence du radio "paramètre fixé" + */ + private hasRadioFix(): boolean { + switch (this._param.radioConfig) { + case ParamRadioConfig.FIX: + return this.hasRadioLink(); + + default: + return true; + } + } + + /** + * calcule la présence du radio "paramètre à varier" + */ + private hasRadioVar(): boolean { + switch (this._param.radioConfig) { + case ParamRadioConfig.VAR: + case ParamRadioConfig.CAL: + return true; + + default: + return false; + } + } + + /** + * calcule la présence du radio "paramètre à calculer" + */ + private hasRadioCal(): boolean { + switch (this._param.radioConfig) { + case ParamRadioConfig.CAL: + return true; + + default: + return false; + } + } + + /** + * calcule la présence du radio "paramètre lié" (importé d'une autre calculette) + */ + private hasRadioLink(): boolean { + if (this._formService.formulaires.length > 0) { + // au moins 2 calculettes ouvertes + if (this._formService.formulaires.length > 1) { + return this._formService.filterLinkableValues(this._formService.getLinkableValues(this._param)).length > 0; + } + + // ou une seule calculette "ouvrages parallèles" + if (this._formService.formulaires[0].calculatorType == CalculatorType.ParallelStructure) { + const ps: ParallelStructure = this._formService.formulaires[0].currentSessionNub.nub as ParallelStructure; + if (ps.structures.length > 1) { + return this._formService.filterLinkableValues(this._formService.getLinkableValues(this._param)).length > 0; + } + } + + } + return false; + } + + private onRadioClick(option: string) { + const oldValue = this._param.valueMode; + + switch (option) { + case "fix": + const oldValueMode = this._param.valueMode; + this._param.valueMode = ParamValueMode.SINGLE; + this._param.setValue(this, this._param.paramDefinition.paramValues.singleValue); + break; + + case "var": + this._param.valueMode = ParamValueMode.MINMAX; // min/max par défaut + break; + + case "cal": + this._param.valueMode = ParamValueMode.CALCUL; + break; + + case "link": + this._param.valueMode = ParamValueMode.LINK; + break; + } + + this.onRadio.emit({ + "param": this._param, + "oldValueMode": oldValue + }); + + // MAJ validité + this.emitValidity(); + } + /** * émission d'un événement de validité */ private emitValidity() { - this.onValid.emit() + this.onValid.emit(); } /** @@ -348,7 +362,7 @@ export class ParamFieldLineComponent implements OnChanges { */ private onParamValuesValid(event: boolean) { this._isRangeValid = event; - this.emitValidity() + this.emitValidity(); } public ngOnChanges() { @@ -356,10 +370,6 @@ export class ParamFieldLineComponent implements OnChanges { this._ngParamInputComponent.showError = this.isRadioFixChecked; } - private get formHasResults(): boolean { - return ServiceFactory.instance.formulaireService.currentFormHasResults; - } - /** * relit la valeur dans l'interface et met à jour le NgParameter */ @@ -371,7 +381,8 @@ export class ParamFieldLineComponent implements OnChanges { * met à jour les paramètres liés */ public updateLinkedParameter() { - if (this._paramLinkComponent !== undefined) + if (this._paramLinkComponent !== undefined) { this._paramLinkComponent.updateParamList(); + } } } diff --git a/src/app/components/param-link/param-link.component.html b/src/app/components/param-link/param-link.component.html index 1fc1166766aeb759588caf42bd7188988076d4c3..e3a515552dac0c165ba958286084819f44186e78 100644 --- a/src/app/components/param-link/param-link.component.html +++ b/src/app/components/param-link/param-link.component.html @@ -1,13 +1,13 @@ <div class="row"> <div class="btn-group col-6 col-sm-3" dropdown (click)="onSelectLinkableParam($event)"> <button dropdownToggle class="btn btn-primary dropdown-toggle waves-light my-1" type="button" mdbRippleRadius> - {{currentLinkedParamLabel}} + {{ currentLinkedParamLabel }} </button> <div class="dropdown-menu"> - <a class="dropdown-item" *ngFor="let e of _linkableParams" [value]=e>{{selectItemLabel(e)}}</a> + <a class="dropdown-item" *ngFor="let e of _linkableParams" [value]=e>{{ selectItemLabel(e) }}</a> </div> </div> <div class="col-6 text-danger"> - {{_message}} + {{ _message }} </div> </div> \ No newline at end of file diff --git a/src/app/components/param-link/param-link.component.ts b/src/app/components/param-link/param-link.component.ts index 7cecef0a68b24b33a0e620c558a18818acb38a5b..977f439082b55b785a32872b7d5fac8a6f418a39 100644 --- a/src/app/components/param-link/param-link.component.ts +++ b/src/app/components/param-link/param-link.component.ts @@ -31,7 +31,7 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { /** * liste des paramètres liables sous la forme * {"name":<étiquette>, "value":<valeur liable>, "nub":<Nub d'origine du paramètre>, "formTitle":<nom de la calculette liée au nub>} - * + * * l'étiquette "name" (cf. INubReference.defineReference dans jalhyd) est de la forme <n | ouvrage[n] | N1>[.[N2]] * n : indice de de l'ouvrage dans le cas des ouvrages parallèles * N1 : un nom de paramètre/résultat (dans le cas d'un résultat, il est suivi d'un point) @@ -68,13 +68,14 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { const next = event.target.value; let i = 0; - for (const e of this._linkableParams) + for (const e of this._linkableParams) { if (this._linkableParams[i].value.uid == next.value.uid) { this.linkTo(i); break; - } - else + } else { i++; + } + } } /** @@ -82,8 +83,9 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { */ private get currentLinkedParamLabel(): string { if (this._linkableParams !== undefined) { - if (this._currentIndex === -1 || this._currentIndex >= this._linkableParams.length) + if (this._currentIndex === -1 || this._currentIndex >= this._linkableParams.length) { return undefined; + } return this.selectItemLabel(this._linkableParams[this._currentIndex]); } @@ -113,31 +115,34 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { const re5 = /(\d+)\.(.+)\.$/; // forme <nombre>.xxx. (résultat d'ouvrage) const match5 = re5.exec(s); if (match5 !== null) { - const n = +match5[1] + 1 + const n = +match5[1] + 1; return `${match5[2]} (résultat de ${c}, ouvrage n°${n})`; } const re1 = /([^\.]+)\.$/; // forme xxx. (résultat) const match1 = re1.exec(s); - if (match1 !== null) + if (match1 !== null) { return `${match1[1]} (résultat de ${c})`; + } const re4 = /(\d+)\.(.+)/; // forme <nombre>.xxx (ouvrage) const match4 = re4.exec(s); if (match4 !== null) { - const n = +match4[1] + 1 + const n = +match4[1] + 1; return `${match4[2]} (${c}, ouvrage n°${n})`; } const re2 = /([^\.]+)\.(.+)/; // forme xxx.yyy (résultat complémentaire) const match2 = re2.exec(s); - if (match2 !== null) + if (match2 !== null) { return `${match2[2]} (${c}, résultat complémentaire de ${match2[1]})`; + } const re3 = /^\.(.+)/; // forme .xxx (résultat complémentaire) const match3 = re3.exec(s); - if (match3 !== null) + if (match3 !== null) { return `${match3[1]} (${c}, résultat complémentaire)`; + } return `${s} (${c})`; // forme simple (paramètre) } @@ -158,27 +163,29 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { public updateParamList() { // liste des paramètres liables - if (this._param.valueMode === ParamValueMode.LINK) + if (this._param.valueMode === ParamValueMode.LINK) { this._linkableParams = this._formService.filterLinkableValues(this._formService.getLinkableValues(this._param)); - else + } else { this._linkableParams = []; + } // initialisation de l'indice courant if (this._linkableParams.length > 0) { - if (this._currentIndex === -1) + if (this._currentIndex === -1) { this.linkTo(0); + } this._message = undefined; - } - else { + } else { this._currentIndex = -1; this._message = "Aucun paramètre compatible trouvé"; } } public ngOnChanges() { - if (this._param !== undefined) + if (this._param !== undefined) { this._param.removeObserver(this); + } this._param.addObserver(this); this.updateParamList(); @@ -188,7 +195,7 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { this._param.removeObserver(this); } - // interface Observer + // interface Observer public update(sender: any, data: any) { if (sender instanceof FormulaireService) { diff --git a/src/app/components/param-values/ngparam-max.component.ts b/src/app/components/param-values/ngparam-max.component.ts index e67b8b71f758aaa60786127c25b64ff28372f639..8e4cc2c6c8536f90de25067e64250719434edfda 100644 --- a/src/app/components/param-values/ngparam-max.component.ts +++ b/src/app/components/param-values/ngparam-max.component.ts @@ -23,8 +23,9 @@ export class NgParamMaxComponent extends GenericInputComponent { } protected getModelValue(): any { - if (this._param == undefined) + if (this._param == undefined) { return undefined; + } return this._param.maxValue; } @@ -33,36 +34,39 @@ export class NgParamMaxComponent extends GenericInputComponent { } protected validateModelValue(v: any): { isValid: boolean, message: string } { - let msg = undefined; + let msg; let valid = false; - if (this._param == undefined) + if (this._param == undefined) { msg = "internal error, model undefined"; - else { - if (!this._param.checkMax(v)) + } else { + if (!this._param.checkMax(v)) { msg = "La valeur n'est pas dans ]" + this._param.minValue + " , " + this._param.domain.maxValue + "]"; - else + } else { valid = true; + } } return { isValid: valid, message: msg }; } protected modelToUI(v: any): string { - if (typeof (v) == "number") + if (typeof (v) == "number") { return String(v); + } return undefined; } protected validateUIValue(ui: string): { isValid: boolean, message: string } { - let valid: boolean = false; - let msg: string = undefined; + let valid = false; + let msg: string; - let v: NumericalString = new NumericalString(ui); - if (!v.isNumerical) + const v: NumericalString = new NumericalString(ui); + if (!v.isNumerical) { msg = "Veuillez entrer une valeur numérique"; - else + } else { valid = true; + } return { isValid: valid, message: msg }; } diff --git a/src/app/components/param-values/ngparam-min.component.ts b/src/app/components/param-values/ngparam-min.component.ts index a599c42bebb86a0701300e8f8cd31f434dc7df58..cf5e85221d9a456af1f435687ca44a08dda1ef1c 100644 --- a/src/app/components/param-values/ngparam-min.component.ts +++ b/src/app/components/param-values/ngparam-min.component.ts @@ -23,8 +23,9 @@ export class NgParamMinComponent extends GenericInputComponent { } protected getModelValue(): any { - if (this._param == undefined) + if (this._param == undefined) { return undefined; + } return this._param.minValue; } @@ -33,36 +34,39 @@ export class NgParamMinComponent extends GenericInputComponent { } protected validateModelValue(v: any): { isValid: boolean, message: string } { - let msg = undefined; + let msg; let valid = false; - if (this._param == undefined) + if (this._param == undefined) { msg = "internal error, model undefined"; - else { - if (!this._param.checkMin(v)) + } else { + if (!this._param.checkMin(v)) { msg = "La valeur n'est pas dans [" + this._param.domain.minValue + " , " + this._param.maxValue + "["; - else + } else { valid = true; + } } return { isValid: valid, message: msg }; } protected modelToUI(v: any): string { - if (typeof (v) == "number") + if (typeof (v) == "number") { return String(v); + } return undefined; } protected validateUIValue(ui: string): { isValid: boolean, message: string } { - let valid: boolean = false; - let msg: string = undefined; + let valid = false; + let msg: string; - let v: NumericalString = new NumericalString(ui); - if (!v.isNumerical) + const v: NumericalString = new NumericalString(ui); + if (!v.isNumerical) { msg = "Veuillez entrer une valeur numérique"; - else + } else { valid = true; + } return { isValid: valid, message: msg }; } diff --git a/src/app/components/param-values/ngparam-step.component.ts b/src/app/components/param-values/ngparam-step.component.ts index 2750dae0117f5120f50fbc416cc917b2d5581515..61a43cbfb0e3ace484a49a573c34e7cd84df9a31 100644 --- a/src/app/components/param-values/ngparam-step.component.ts +++ b/src/app/components/param-values/ngparam-step.component.ts @@ -23,8 +23,9 @@ export class NgParamStepComponent extends GenericInputComponent { } protected getModelValue(): any { - if (this._param == undefined) + if (this._param == undefined) { return undefined; + } return this._param.stepValue; } @@ -33,44 +34,46 @@ export class NgParamStepComponent extends GenericInputComponent { } protected validateModelValue(v: any): { isValid: boolean, message: string } { - let msg = undefined; + let msg; let valid = false; - if (this._param == undefined) + if (this._param == undefined) { msg = "internal error, model undefined"; - else { + } else { if (this._param.isMinMaxValid) { if (!this._param.checkStep(v)) { msg = "La valeur n'est pas dans " + this._param.stepRefValue.toString(); - } - else { + } else { valid = v > 0; - if (!valid) + if (!valid) { msg = "La valeur ne peut pas être <= 0"; + } } - } - else + } else { msg = "Veuillez corriger le min/max"; + } } return { isValid: valid, message: msg }; } protected modelToUI(v: any): string { - if (typeof (v) == "number") + if (typeof (v) == "number") { return String(v); + } return "<invalid>"; } protected validateUIValue(ui: string): { isValid: boolean, message: string } { - let valid: boolean = false; - let msg: string = undefined; + let valid = false; + let msg: string; - let v: NumericalString = new NumericalString(ui); - if (!v.isNumerical) + const v: NumericalString = new NumericalString(ui); + if (!v.isNumerical) { msg = "Veuillez entrer une valeur numérique"; - else + } else { valid = true; + } return { isValid: valid, message: msg }; } diff --git a/src/app/components/param-values/param-values.component.html b/src/app/components/param-values/param-values.component.html index 0335d8bddfbd2a6ee34e288de944edd1d8b307c5..76c3984cdfb8021a83c60d9ddb016bfd58d2c569 100644 --- a/src/app/components/param-values/param-values.component.html +++ b/src/app/components/param-values/param-values.component.html @@ -1,10 +1,10 @@ <div class="row"> <div class="btn-group col-12 col-sm-3" dropdown (click)="onSelectValueMode($event)"> <button dropdownToggle class="btn btn-primary dropdown-toggle waves-light my-1" type="button" mdbRippleRadius> - {{currentModeSelectLabel}} + {{ currentModeSelectLabel }} </button> <div class="dropdown-menu"> - <a class="dropdown-item" *ngFor="let e of _valueModes" [value]=e.value>{{e.label}}</a> + <a class="dropdown-item" *ngFor="let e of _valueModes" [value]=e.value>{{ e.label }}</a> </div> </div> diff --git a/src/app/components/param-values/param-values.component.ts b/src/app/components/param-values/param-values.component.ts index 36761b432690baecbecafc7447b664ab7e593491..159f1599421522e558d40a373919273e096b4c41 100644 --- a/src/app/components/param-values/param-values.component.ts +++ b/src/app/components/param-values/param-values.component.ts @@ -44,32 +44,32 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec /** * true si la valeur min est valide */ - private _validMin: boolean = false; + private _validMin = false; /** * true si la valeur max est valide */ - private _validMax: boolean = false; + private _validMax = false; /** * true si la valeur du pas est valide */ - private _validStep: boolean = false; + private _validStep = false; /** * true si la liste de valeurs est valide */ - private _validList: boolean = false; + private _validList = false; /** * flag signalant qu'il faut initialiser le composant ValueListComponent (par ex quand on a sélectionné le mode "liste") */ - private _doInitList: boolean = false; + private _doInitList = false; /** * flag signalant qu'il faut initialiser les composants min/max/pas */ - private _doInitMinmax: boolean = false; + private _doInitMinmax = false; /** * composant de saisie du minimum @@ -114,13 +114,15 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec // valeur pour min : celle déjà définie ou celle déduite de la valeur saisie let min: number = this._param.minValue; - if (min == undefined) + if (min == undefined) { min = this._param.getValue() / 2; + } // valeur pour max : celle déjà définie ou celle déduite de la valeur saisie let max: number = this._param.maxValue; - if (max == undefined) + if (max == undefined) { max = this._param.getValue() * 2; + } this._param.minValue = min; this._minComponent.model = this._param; @@ -130,8 +132,9 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec // valeur du pas let step = this._param.stepValue; - if (step == undefined) + if (step == undefined) { step = (max - min) / 20; + } this._param.stepValue = step; this._stepComponent.model = this._param; @@ -154,10 +157,11 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec this._doInitList = false; let l = this._param.valueList; if (l == undefined) { - if (this._param.isDefined) + if (this._param.isDefined) { l = [this._param.getValue()]; - else + } else { l = []; + } } this._param.valueList = l; @@ -169,14 +173,18 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec * revalidation de tous les composants enfants */ private validateAll() { - if (this._minComponent != undefined) + if (this._minComponent != undefined) { this._minComponent.validate(); - if (this._maxComponent != undefined) + } + if (this._maxComponent != undefined) { this._maxComponent.validate(); - if (this._stepComponent != undefined) + } + if (this._stepComponent != undefined) { this._stepComponent.validate(); - if (this._listComponent != undefined) + } + if (this._listComponent != undefined) { this._listComponent.validate(); + } } /** @@ -198,7 +206,7 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec * réception d'un événement de NgParamMinComponent */ private onMinChanged(event: any) { - if (this._initCompleted) + if (this._initCompleted) { switch (event.action) { case "model": this.validateAll(); @@ -209,13 +217,14 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec this.emitValidity(); break; } + } } /** * réception d'un événement de NgParamMaxComponent */ private onMaxChanged(event: any) { - if (this._initCompleted) + if (this._initCompleted) { switch (event.action) { case "model": this.validateAll(); @@ -226,13 +235,14 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec this.emitValidity(); break; } + } } /** * réception d'un événement de NgParamStepComponent */ private onStepChanged(event: any) { - if (this._initCompleted) + if (this._initCompleted) { switch (event.action) { case "model": this.validateAll(); @@ -243,13 +253,14 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec this.emitValidity(); break; } + } } /** * réception d'un événement de ValueListComponent */ private onListChanged(event: any) { - if (this._initCompleted) + if (this._initCompleted) { switch (event.action) { case "model": this.validateAll(); @@ -260,6 +271,7 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec this.emitValidity(); break; } + } } private get uitextValeurMini() { @@ -320,20 +332,21 @@ export class ParamValuesComponent extends BaseComponent implements AfterViewChec break; default: - throw "valeur " + next + " de ParamValueMode non prise en charge"; + throw new Error("valeur " + next + " de ParamValueMode non prise en charge"); } this._param.valueMode = next; } - /** + /** * appelé quand les @Input changent */ ngOnChanges() { - if (this.isMinMax) + if (this.isMinMax) { this._doInitMinmax = true; - else + } else { this._doInitList = true; + } } ngAfterViewChecked() { diff --git a/src/app/components/param-values/value-list.component.ts b/src/app/components/param-values/value-list.component.ts index 9b1e5150a9fd469c594c58f96787ee96ae548490..d53e9801381df27b94367cbbb39e5d13a4ff3f6e 100644 --- a/src/app/components/param-values/value-list.component.ts +++ b/src/app/components/param-values/value-list.component.ts @@ -22,8 +22,9 @@ export class ValueListComponent extends GenericInputComponent { } protected getModelValue(): any { - if (this._param == undefined) + if (this._param == undefined) { return undefined; + } return this._param.valueList; } @@ -31,71 +32,76 @@ export class ValueListComponent extends GenericInputComponent { if (typeof (l) == "number") { this._param.valueList = []; this._param.valueList.push(l); - } - else + } else { this._param.valueList = l; + } } protected validateModelValue(v: any): { isValid: boolean, message: string } { - let msg = undefined; + let msg; let valid = false; if (v instanceof Array) { valid = true; try { this._param.checkList(v); - } - catch (ex) { + } catch (ex) { valid = false; - if (ex instanceof Message) + if (ex instanceof Message) { msg = this.intlService.localizeMessage(ex); - else + } else { msg = "invalid value"; + } } - } - else + } else { msg = "Veuillez entrer une liste de nombres"; + } return { isValid: valid, message: msg }; } protected modelToUI(v: any): string { let res = ""; - if (v != undefined) - for (let e of v) { - if (res != "") + if (v != undefined) { + for (const e of v) { + if (res != "") { res += ";"; + } res += String(e); } + } return res; } protected validateUIValue(ui: string): { isValid: boolean, message: string } { - let valid: boolean = false; - let msg: string = undefined; + let valid = false; + let msg: string; - let tmp: string[] = ui.split(";"); + const tmp: string[] = ui.split(";"); let res = true; - for (let v of tmp) { - let isnum = v != "" && (+v == +v); + for (const v of tmp) { + const isnum = v != "" && (+v == +v); res = res && isnum; - if (!res) + if (!res) { break; + } } - if (!res) + if (!res) { msg = "Veuillez entrer une liste de nombres"; - else + } else { valid = true; + } return { isValid: valid, message: msg }; } protected uiToModel(ui: string) { - let tmp: string[] = ui.split(";"); - let res = []; - for (let v of tmp) + const tmp: string[] = ui.split(";"); + const res = []; + for (const v of tmp) { res.push(+v); + } return res; } } diff --git a/src/app/components/remous-results/remous-results.component.ts b/src/app/components/remous-results/remous-results.component.ts index a986c11d1f9f34b312d801ad697fffbefa089b49..5b2ec3e8e830175ffcb967efbfba31774ca394f3 100644 --- a/src/app/components/remous-results/remous-results.component.ts +++ b/src/app/components/remous-results/remous-results.component.ts @@ -308,21 +308,25 @@ export class RemousResultsComponent { const itX = this.abscisseIterator; for (const re of this._remousResults.result.resultElements) { - if (!itX.hasNext) + if (!itX.hasNext) { throw new Error("RemousResultsComponent.generateGraph() : erreur interne (itérateur sur x)"); + } const x = itX.next().value; const yExtra = re.getExtraResult(this._remousResults.extraParamSymbol); - if (yExtra !== undefined) + if (yExtra !== undefined) { lineExtra.mapPoint(x, yExtra); + } const yFlu = re.getExtraResult("flu"); - if (yFlu !== undefined) + if (yFlu !== undefined) { lineFlu.mapPoint(x, yFlu); + } const yTor = re.getExtraResult("tor"); - if (yTor !== undefined) + if (yTor !== undefined) { lineTor.mapPoint(x, yTor); + } } if (this._remousResults.hasExtra) { @@ -345,10 +349,12 @@ export class RemousResultsComponent { // ajout des données au graphique - if (lineTor !== undefined) + if (lineTor !== undefined) { lineTor.data = { label: this.uitextLigneTorrentielle, tension: 0, borderColor: "#77A3CD", pointBackgroundColor: "#77A3CD", pointRadius: 4, backgroundColor: "#D1D0D4" }; - if (lineFlu !== undefined) + } + if (lineFlu !== undefined) { lineFlu.data = { label: this.uitextLigneFluviale, tension: 0, borderColor: "#0093BD", pointBackgroundColor: "#0093BD", pointRadius: 4, backgroundColor: "#D1D0D4" }; + } this.graph1_data = gr1.data; @@ -441,8 +447,9 @@ class LineData { constructor(gr: GraphData) { this._parentGraph = gr; this._tx = gr.tx; - for (let i = this._tx.length - 1; i >= 0; i--) + for (let i = this._tx.length - 1; i >= 0; i--) { this._ty.push(null); + } } public getYat(x: number) { @@ -468,9 +475,11 @@ class LineData { } public hasYs(): boolean { - for (const y of this._ty) - if (y != null) + for (const y of this._ty) { + if (y != null) { return true; + } + } return false; } @@ -561,15 +570,18 @@ class GraphData { public get data() { const ds = []; this._lines.sort((a, b) => { - if (a.z > b.z) + if (a.z > b.z) { return -1; - if (a.z < b.z) + } + if (a.z < b.z) { return 1; + } return 0; }); - for (const l of this._lines) + for (const l of this._lines) { ds.push(l.data); + } return { labels: this._tx, diff --git a/src/app/components/result-element/horizontal-result-element.component.html b/src/app/components/result-element/horizontal-result-element.component.html index 11883ac01839fcd4bce7b6e42a5fead15adef04d..5b40239d3b81eee340e96c805916fdc6ac7f330f 100644 --- a/src/app/components/result-element/horizontal-result-element.component.html +++ b/src/app/components/result-element/horizontal-result-element.component.html @@ -25,12 +25,12 @@ <!-- valeur --> <span *ngIf="!hasError" [mdbTooltip]="popTemplate" [isDisabled]="tooltipDisabled"> - {{resultValue}} + {{ resultValue }} </span> <!-- template de création de td supplémentaires pour les extraResult --> <ng-template #extraResultTd let-v="extraResultValue"> <td> - {{v}} + {{ v }} </td> </ng-template> \ No newline at end of file diff --git a/src/app/components/result-element/horizontal-result-element.component.ts b/src/app/components/result-element/horizontal-result-element.component.ts index 48b269ce9d3a3c227641d7bea716cdfd072dda33..6404ab4ff488148dd5991f082456e0a6739d16ef 100644 --- a/src/app/components/result-element/horizontal-result-element.component.ts +++ b/src/app/components/result-element/horizontal-result-element.component.ts @@ -1,6 +1,6 @@ import { Component, Input, ViewChild, TemplateRef, ViewContainerRef } from "@angular/core"; -import { ResultElement } from 'jalhyd'; +import { ResultElement } from "jalhyd"; import { ApplicationSetupService } from "../../services/app-setup/app-setup.service"; import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; @@ -33,12 +33,14 @@ export class HorizontalResultElementComponent extends ResultElementBaseComponent super.ngOnChanges(); this.vcRef.clear(); - if (this._headerKeys && this._resultElement) + if (this._headerKeys && this._resultElement) { for (const h of this._headerKeys) { let v = this._resultElement.extraResults[h]; - if (typeof (v) === "number") + if (typeof (v) === "number") { v = this.intlService.formatResult(h, v); + } this.vcRef.createEmbeddedView(this.tdTemplate, { extraResultValue: v }); } + } } } diff --git a/src/app/components/result-element/result-element-base.component.ts b/src/app/components/result-element/result-element-base.component.ts index 90247172240ecaae5672a9734a265ce51467cb14..485c4d9675e962a2a079698f721288c87c2ec9ae 100644 --- a/src/app/components/result-element/result-element-base.component.ts +++ b/src/app/components/result-element/result-element-base.component.ts @@ -1,6 +1,6 @@ import { Component, Input } from "@angular/core"; -import { ResultElement } from 'jalhyd'; +import { ResultElement } from "jalhyd"; import { ApplicationSetupService } from "../../services/app-setup/app-setup.service"; import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; @@ -49,7 +49,7 @@ export class ResultElementBaseComponent implements OnChanges { /** * true si pas de texte à afficher dans le tooltip */ - protected _emptyTooltip: boolean = false; + protected _emptyTooltip = false; protected appSetupService: ApplicationSetupService; @@ -81,12 +81,14 @@ export class ResultElementBaseComponent implements OnChanges { let res = ""; - if (this._resultElement != undefined) - for (let m of this._resultElement.log.messages) { - if (res.length > 0) + if (this._resultElement != undefined) { + for (const m of this._resultElement.log.messages) { + if (res.length > 0) { res += "<br/>"; + } res += this.intlService.localizeMessage(m); } + } this._htmlTooltip = res; this._emptyTooltip = this._htmlTooltip.length == 0; diff --git a/src/app/components/results-graph/graph-type.component.ts b/src/app/components/results-graph/graph-type.component.ts index 1dcece55e702522aca3f584ccd11f44ce9668ae7..dcb6daa53241a88227c1d1d76fbef9b64a5dbb26 100644 --- a/src/app/components/results-graph/graph-type.component.ts +++ b/src/app/components/results-graph/graph-type.component.ts @@ -1,8 +1,8 @@ -import { Component } from '@angular/core'; +import { Component } from "@angular/core"; import { Observable, IObservable, Observer } from "jalhyd"; -import { GenericSelectComponent } from '../generic-select/generic-select.component'; +import { GenericSelectComponent } from "../generic-select/generic-select.component"; import { GraphType } from "../../results/var-results"; @Component({ diff --git a/src/app/components/results-graph/results-graph.component.ts b/src/app/components/results-graph/results-graph.component.ts index 9744b769ff67512526085d6b23c5b62ca7831c53..60dd65aef4198cf5b66f2873b9d5cc7a77baa2d2 100644 --- a/src/app/components/results-graph/results-graph.component.ts +++ b/src/app/components/results-graph/results-graph.component.ts @@ -1,13 +1,13 @@ -import { Component, ViewChild, AfterContentInit } from '@angular/core'; +import { Component, ViewChild, AfterContentInit } from "@angular/core"; import { Observer } from "jalhyd"; import { VarResults, GraphType } from "../../results/var-results"; -import { GraphTypeSelectComponent } from './graph-type.component'; +import { GraphTypeSelectComponent } from "./graph-type.component"; @Component({ - selector: 'results-graph', - templateUrl: './results-graph.component.html' + selector: "results-graph", + templateUrl: "./results-graph.component.html" }) export class ResultsGraphComponent implements AfterContentInit, Observer { private _results: VarResults; @@ -37,8 +37,9 @@ export class ResultsGraphComponent implements AfterContentInit, Observer { public set results(r: VarResults) { this._results = r; - if (this._results && this._graphTypeComponent) + if (this._results && this._graphTypeComponent) { this._graphTypeComponent.selectedValue = r.graphType; + } } public updateView() { @@ -68,8 +69,8 @@ export class ResultsGraphComponent implements AfterContentInit, Observer { * génère les données d'un graphe de type "line" */ private generateLineGraph() { - let labs = []; - let dat = []; + const labs = []; + const dat = []; let i = 0; for (const x of this._results.variatedParameter.valuesIterator) { labs.push(String(x)); @@ -96,8 +97,8 @@ export class ResultsGraphComponent implements AfterContentInit, Observer { * génère les données d'un graphe de type "bar" */ private generateBarGraph() { - let labs = []; - let dat = []; + const labs = []; + const dat = []; let i = 0; for (const x of this._results.variatedParameter.valuesIterator) { labs.push(x); @@ -132,7 +133,7 @@ export class ResultsGraphComponent implements AfterContentInit, Observer { * génère les données d'un graphe de type "scatter" */ private generateScatterGraph() { - let dat = []; + const dat = []; let i = 0; for (const x of this._results.variatedParameter.valuesIterator) { const y = this._results.yValues[i]; @@ -143,12 +144,12 @@ export class ResultsGraphComponent implements AfterContentInit, Observer { this.graph_options.title.text = this._results.graphTitle; this.graph_options["scales"] = { xAxes: [{ - type: 'linear', - position: 'bottom' + type: "linear", + position: "bottom" }], yAxes: [{ - type: 'linear', - position: 'left' + type: "linear", + position: "left" }] }; @@ -165,7 +166,7 @@ export class ResultsGraphComponent implements AfterContentInit, Observer { }; } - // interface Observer + // interface Observer update(sender: any, data: any) { this.updateView(); diff --git a/src/app/components/save-calculator/save-calculator-anchor.directive.ts b/src/app/components/save-calculator/save-calculator-anchor.directive.ts index 4317ff3ac192d721ba1bbdc97ff3a719f1384848..012ffef46f393f7a3e15713c2347f9c4bcab36b1 100644 --- a/src/app/components/save-calculator/save-calculator-anchor.directive.ts +++ b/src/app/components/save-calculator/save-calculator-anchor.directive.ts @@ -1,10 +1,10 @@ -import { Directive, ComponentFactoryResolver, ComponentFactory, ComponentRef } from '@angular/core'; +import { Directive, ComponentFactoryResolver, ComponentFactory, ComponentRef } from "@angular/core"; -import { ViewContainerRef } from '@angular/core'; -import { SaveCalculatorComponent } from './save-calculator.component'; +import { ViewContainerRef } from "@angular/core"; +import { SaveCalculatorComponent } from "./save-calculator.component"; @Directive({ - selector: '[saveCalcDialogAnchor]' + selector: "[saveCalcDialogAnchor]" }) export class SaveCalcDialogAnchorDirective { constructor( @@ -15,8 +15,8 @@ export class SaveCalcDialogAnchorDirective { public createDialog(): ComponentRef<SaveCalculatorComponent> { this.viewContainer.clear(); - let compFactory: ComponentFactory<SaveCalculatorComponent> = this.componentFactoryResolver.resolveComponentFactory(SaveCalculatorComponent); - let compRef: ComponentRef<SaveCalculatorComponent> = this.viewContainer.createComponent(compFactory); + const compFactory: ComponentFactory<SaveCalculatorComponent> = this.componentFactoryResolver.resolveComponentFactory(SaveCalculatorComponent); + const compRef: ComponentRef<SaveCalculatorComponent> = this.viewContainer.createComponent(compFactory); // dialogComponentRef.instance.close.subscribe(() => { // dialogComponentRef.destroy(); diff --git a/src/app/components/save-calculator/save-calculator.component.html b/src/app/components/save-calculator/save-calculator.component.html index cab54103edd0c849cfc77b83bb377ec6a90d3bbd..129a1dcaacbd8cc12a7d67e526c3da9cc4e82f9f 100644 --- a/src/app/components/save-calculator/save-calculator.component.html +++ b/src/app/components/save-calculator/save-calculator.component.html @@ -2,19 +2,19 @@ <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> - <h4 class="modal-title w-100" id="myModalLabel">{{uitextDialogTitle}}</h4> + <h4 class="modal-title w-100" id="myModalLabel">{{ uitextDialogTitle }}</h4> </div> <div class="modal-body"> <!-- liste de calculettes avec check --> <div *ngFor="let c of _calculators"> - <input type="checkbox" value={{c.uid}} checked={{isSelected(c)}} (change)="onCheckCalc($event)">{{c.title}} + <input type="checkbox" value={{c.uid}} checked={{isSelected(c)}} (change)="onCheckCalc($event)">{{ c.title }} </div> <!-- bouton "tout sélectionnner" --> - <button type="button" class="btn btn-mdb-color waves-light" (click)="selectAll()" mdbRippleRadius>{{uitextSelectAll}}</button> + <button type="button" class="btn btn-mdb-color waves-light" (click)="selectAll()" mdbRippleRadius>{{ uitextSelectAll }}</button> <!-- bouton "tout désélectionnner" --> - <button type="button" class="btn btn-mdb-color waves-light py-10" (click)="deselectAll()" mdbRippleRadius>{{uitextDeselectAll}}</button> + <button type="button" class="btn btn-mdb-color waves-light py-10" (click)="deselectAll()" mdbRippleRadius>{{ uitextDeselectAll }}</button> <!-- nom du fichier --> <div class="md-form form-sm mt-4"> @@ -24,8 +24,8 @@ </div> </div> <div class="modal-footer"> - <button type="button" class="btn btn-danger relative waves-light" (click)="saveDialog.hide();cancelSave()" mdbRippleRadius>{{uitextCloseDialogNo}}</button> - <button type="button" class="btn btn-success waves-light" aria-label="Close " (click)="saveDialog.hide();confirmSave()" mdbRippleRadius>{{uitextCloseDialogYes}}</button> + <button type="button" class="btn btn-danger relative waves-light" (click)="saveDialog.hide();cancelSave()" mdbRippleRadius>{{ uitextCloseDialogNo }}</button> + <button type="button" class="btn btn-success waves-light" aria-label="Close " (click)="saveDialog.hide();confirmSave()" mdbRippleRadius>{{ uitextCloseDialogYes }}</button> </div> </div> </div> diff --git a/src/app/components/save-calculator/save-calculator.component.ts b/src/app/components/save-calculator/save-calculator.component.ts index 6e30cd2db078144cdd70ca127f3b5c29fc5861b4..65f7e89d06423431be090639d009126c21082f47 100644 --- a/src/app/components/save-calculator/save-calculator.component.ts +++ b/src/app/components/save-calculator/save-calculator.component.ts @@ -3,7 +3,7 @@ import { ServiceFactory } from "../../services/service-factory"; import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; @Component({ - selector: 'save-calc', + selector: "save-calc", templateUrl: "./save-calculator.component.html" }) export class SaveCalculatorComponent { @@ -18,7 +18,7 @@ export class SaveCalculatorComponent { /** * nom du fichier */ - private _filename: string = "session"; + private _filename = "session"; private _filenameTitle = "Nom de fichier"; @@ -40,7 +40,7 @@ export class SaveCalculatorComponent { } private get uitextCloseDialogYes() { - //return this.intlService.localizeText("INFO_OPTION_YES"); + // return this.intlService.localizeText("INFO_OPTION_YES"); return "Sauver"; } @@ -81,19 +81,23 @@ export class SaveCalculatorComponent { } private onCheckCalc(event: any) { - for (const c of this._calculators) - if (c.uid == +event.target.value) + for (const c of this._calculators) { + if (c.uid == +event.target.value) { c.selected = event.target.checked; + } + } } private selectAll() { - for (const c of this._calculators) + for (const c of this._calculators) { c.selected = true; + } } private deselectAll() { - for (const c of this._calculators) + for (const c of this._calculators) { c.selected = false; + } } private set confirmed(b: boolean) { diff --git a/src/app/components/section-canvas/section-canvas.component.ts b/src/app/components/section-canvas/section-canvas.component.ts index ce5d8ef7cee5bcc60a3de392b9c1fee9b35fac52..de7ce18ef09b570e5b8510e4cbe693e23497ba52 100644 --- a/src/app/components/section-canvas/section-canvas.component.ts +++ b/src/app/components/section-canvas/section-canvas.component.ts @@ -1,14 +1,14 @@ -import { Component, ViewChild } from '@angular/core'; +import { Component, ViewChild } from "@angular/core"; import { acSection, cSnTrapez, ParamsSectionTrapez, cSnRectang, ParamsSectionRectang, cSnCirc, ParamsSectionCirc, cSnPuiss, ParamsSectionPuiss, Result -} from 'jalhyd'; +} from "jalhyd"; -import { CalcCanvasComponent } from '../canvas/canvas.component'; +import { CalcCanvasComponent } from "../canvas/canvas.component"; @Component({ - selector: 'section-canvas', + selector: "section-canvas", template: `<calc-canvas #calcCanvas [width] = '_size' [height] = '_size'> @@ -19,17 +19,17 @@ export class SectionCanvasComponent { /** * taille (pixels) du canvas (c'est un carré) */ - private _size: number = 400; + private _size = 400; /** * marges gauche/droite pour le texte (pixels) */ - private _textMargin: number = 90; + private _textMargin = 90; /** * marge basse (pixels) */ - private _bottomMargin: number = 5; + private _bottomMargin = 5; /** * facteurs d'échelle (coordonnées en m <-> coordonnées en pixels) @@ -47,8 +47,9 @@ export class SectionCanvasComponent { public set section(s: acSection) { this._section = s; - if (this._section != undefined) + if (this._section != undefined) { this.draw(); + } } public reset() { @@ -66,14 +67,14 @@ export class SectionCanvasComponent { * convertit une abscisse en m en pixels */ private Xm2pix(x: number) { - return this._textMargin + x * this._scaleX + return this._textMargin + x * this._scaleX; } /** * convertit une ordonnée en m en pixels */ private Ym2pix(y: number) { - return this._size - this._bottomMargin - y * this._scaleY + return this._size - this._bottomMargin - y * this._scaleY; } public addLevel(val: number, label: string, rgb: {}) { @@ -101,17 +102,17 @@ export class SectionCanvasComponent { } private drawSectionTrapez(): number { - let sect: cSnTrapez = <cSnTrapez>this._section; - let prms: ParamsSectionTrapez = <ParamsSectionTrapez>sect.prms; + const sect: cSnTrapez = <cSnTrapez>this._section; + const prms: ParamsSectionTrapez = <ParamsSectionTrapez>sect.prms; // cote de berge - let yb: number = prms.YB.v; + const yb: number = prms.YB.v; // largeur de la partie pentue - let lp: number = prms.Fruit.v * prms.YB.v; + const lp: number = prms.Fruit.v * prms.YB.v; // largeur totale de la section - let maxWidth: number = lp * 2 + prms.LargeurFond.v; + const maxWidth: number = lp * 2 + prms.LargeurFond.v; // hauteur totale de la section let maxHeight: number = this.getMaxLevel(); @@ -135,14 +136,14 @@ export class SectionCanvasComponent { } private drawSectionRect() { - let sect: cSnRectang = <cSnRectang>this._section; - let prms: ParamsSectionRectang = <ParamsSectionRectang>sect.prms; + const sect: cSnRectang = <cSnRectang>this._section; + const prms: ParamsSectionRectang = <ParamsSectionRectang>sect.prms; // cote de berge - let yb: number = prms.YB.v; + const yb: number = prms.YB.v; // largeur totale de la section - let maxWidth: number = prms.LargeurBerge.v; + const maxWidth: number = prms.LargeurBerge.v; // hauteur totale de la section let maxHeight: number = this.getMaxLevel(); @@ -166,24 +167,25 @@ export class SectionCanvasComponent { } private drawSectionCirc() { - let sect: cSnCirc = <cSnCirc>this._section; - let prms: ParamsSectionCirc = <ParamsSectionCirc>sect.prms; + const sect: cSnCirc = <cSnCirc>this._section; + const prms: ParamsSectionCirc = <ParamsSectionCirc>sect.prms; // cote de berge - let yb: number = prms.YB.v; + const yb: number = prms.YB.v; // diamètre, rayon - let D: number = prms.D.v; - let r: number = D / 2; + const D: number = prms.D.v; + const r: number = D / 2; try { // largeur au miroir - let B: Result = sect.Calc("B", yb); - if (!B.ok) + const B: Result = sect.Calc("B", yb); + if (!B.ok) { throw B; + } // largeur totale de la section - let maxWidth: number = yb < r ? B.vCalc : D; + const maxWidth: number = yb < r ? B.vCalc : D; // hauteur totale de la section let maxHeight: number = this.getMaxLevel(); @@ -196,40 +198,40 @@ export class SectionCanvasComponent { this._calcCanvas.setStrokeColor(0, 0, 0); this._calcCanvas.setLineWidth(5); - let wx: number = maxWidth / 2; - let alpha: Result = sect.Calc("Alpha", yb); - if (!alpha.ok) + const wx: number = maxWidth / 2; + const alpha: Result = sect.Calc("Alpha", yb); + if (!alpha.ok) { throw alpha; + } - let s: number = Math.PI / 2 - alpha.vCalc; - let e: number = Math.PI / 2 + alpha.vCalc; + const s: number = Math.PI / 2 - alpha.vCalc; + const e: number = Math.PI / 2 + alpha.vCalc; this.drawSectionEllipse(wx, r, r, r, 0, s, e); // pointillés du haut - let w: number = yb > r ? (D - B.vCalc) / 2 : 0; + const w: number = yb > r ? (D - B.vCalc) / 2 : 0; this.drawTopDashLines(w, maxWidth - w, yb, maxHeight); return maxWidth; - } - catch (e) { - let r: Result = e as Result; + } catch (e) { + const r: Result = e as Result; this.drawText("error : " + r.log.toString(), 0, 0); } } private drawSectionPara() { - let sect: cSnPuiss = <cSnPuiss>this._section; - let prms: ParamsSectionPuiss = <ParamsSectionPuiss>sect.prms; + const sect: cSnPuiss = <cSnPuiss>this._section; + const prms: ParamsSectionPuiss = <ParamsSectionPuiss>sect.prms; // cote de berge - let yb: number = prms.YB.v; + const yb: number = prms.YB.v; // largeur au miroir - let B: number = prms.LargeurBerge.v; + const B: number = prms.LargeurBerge.v; // largeur totale de la section - let maxWidth: number = B; + const maxWidth: number = B; // hauteur totale de la section let maxHeight: number = this.getMaxLevel(); @@ -241,14 +243,14 @@ export class SectionCanvasComponent { this._calcCanvas.setStrokeColor(0, 0, 0); this._calcCanvas.setLineWidth(5); - let k: number = prms.k.v; - let lambda: number = B / Math.pow(yb, k); - let inv_k: number = 1 / k; + const k: number = prms.k.v; + const lambda: number = B / Math.pow(yb, k); + const inv_k: number = 1 / k; - let n = 20; + const n = 20; this.beginPath(); for (let x: number = -B / 2; x <= B / 2; x += B / n) { - let y: number = Math.pow(Math.abs(x) * 2 / lambda, inv_k); + const y: number = Math.pow(Math.abs(x) * 2 / lambda, inv_k); this.lineTo(x + B / 2, y); } this.closePath(); @@ -292,25 +294,31 @@ export class SectionCanvasComponent { * @returns largeur de la section (en m) */ private drawSection(): number { - if (this._section instanceof cSnTrapez) + if (this._section instanceof cSnTrapez) { return this.drawSectionTrapez(); - if (this._section instanceof cSnRectang) + } + if (this._section instanceof cSnRectang) { return this.drawSectionRect(); - if (this._section instanceof cSnCirc) + } + if (this._section instanceof cSnCirc) { return this.drawSectionCirc(); - if (this._section instanceof cSnPuiss) + } + if (this._section instanceof cSnPuiss) { return this.drawSectionPara(); - throw "SectionCanvasComponent.drawSection() : type de section non pris en charge"; + } + throw new Error("SectionCanvasComponent.drawSection() : type de section non pris en charge"); } private sortLevels() { this._levels.sort((a, b) => { - if (a["val"] < b["val"]) + if (a["val"] < b["val"]) { return -1; - if (a["val"] > b["val"]) + } + if (a["val"] > b["val"]) { return 1; + } return 0; - }) + }); } private drawLevels(maxWidth: number) { @@ -318,18 +326,19 @@ export class SectionCanvasComponent { this._calcCanvas.resetLineDash(); this._calcCanvas.setLineWidth(1); - this._calcCanvas.setFont("12px sans- serif") - for (let l of this._levels) { - let y = l["val"]; - let col = l["rgb"]; + this._calcCanvas.setFont("12px sans- serif"); + for (const l of this._levels) { + const y = l["val"]; + const col = l["rgb"]; this._calcCanvas.setStrokeColor(col["r"], col["g"], col["b"]); this.drawSectionLine(0, y, maxWidth, y); this._calcCanvas.setFillColor(col["r"], col["g"], col["b"]); - if (left) + if (left) { this.drawText(l["label"], -0.1, y, "right"); - else + } else { this.drawText(l["label"], maxWidth + 0.1, y, "left"); + } left = !left; } } @@ -345,7 +354,7 @@ export class SectionCanvasComponent { private draw() { this.sortLevels(); this.drawFrame(); - let maxWidth = this.drawSection(); + const maxWidth = this.drawSection(); this.drawLevels(maxWidth); } } diff --git a/src/app/components/section-results/section-results.component.ts b/src/app/components/section-results/section-results.component.ts index f296b115b73fdb4931c4eb04cf92b2de36632b14..6c2d8dfc54ef4bf2c4fb16cc6536278f62c0b040 100644 --- a/src/app/components/section-results/section-results.component.ts +++ b/src/app/components/section-results/section-results.component.ts @@ -1,16 +1,16 @@ -import { Component, ViewChild, DoCheck } from '@angular/core'; +import { Component, ViewChild, DoCheck } from "@angular/core"; -import { acSection, Result, ResultElement } from 'jalhyd'; +import { acSection, Result, ResultElement } from "jalhyd"; -import { SectionCanvasComponent } from '../section-canvas/section-canvas.component'; -import { SectionResults } from '../../results/section-results'; -import { ApplicationSetupService } from '../../services/app-setup/app-setup.service'; -import { CalculatorResults } from '../../results/calculator-results'; -import { InternationalisationService } from '../../services/internationalisation/internationalisation.service'; +import { SectionCanvasComponent } from "../section-canvas/section-canvas.component"; +import { SectionResults } from "../../results/section-results"; +import { ApplicationSetupService } from "../../services/app-setup/app-setup.service"; +import { CalculatorResults } from "../../results/calculator-results"; +import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; @Component({ - selector: 'section-results', - templateUrl: './section-results.component.html', + selector: "section-results", + templateUrl: "./section-results.component.html", styles: [` .result_label { text-align: right; @@ -33,18 +33,32 @@ import { InternationalisationService } from '../../services/internationalisation ] }) export class SectionResultsComponent implements DoCheck { - /** - * résultats non mis en forme - */ - private _results: SectionResults; - - /** - * ResultElement mis en forme (symboles des variables traduits) - */ - private _resultElement: ResultElement; constructor(private appSetupService: ApplicationSetupService, private intlService: InternationalisationService) { } + public set results(rs: CalculatorResults[]) { + this._resultElement = undefined; + + this._results = undefined; + if (rs != undefined) { + for (const r of rs) { + if (r instanceof SectionResults) { + this._results = r; + break; + } + } + } + this.updateView(); + } + + private get hasResults(): boolean { + return this._results != undefined && this._results.hasResults; + } + + private get resultElement() { + return this._resultElement; + } + private static labelColors: { [key: string]: any; } = { "Hs": { r: 255, g: 0, b: 0 }, "Hsc": { r: 0, g: 0, b: 255 }, @@ -54,46 +68,46 @@ export class SectionResultsComponent implements DoCheck { "Yc": { r: 255, g: 128, b: 0 }, "Yco": { r: 255, g: 0, b: 255 }, }; + /** + * résultats non mis en forme + */ + private _results: SectionResults; - private _doUpdate: boolean = false; + /** + * ResultElement mis en forme (symboles des variables traduits) + */ + private _resultElement: ResultElement; + + private _doUpdate = false; @ViewChild(SectionCanvasComponent) private _sectionCanvas: SectionCanvasComponent; - public set results(rs: CalculatorResults[]) { - this._resultElement = undefined; - - this._results = undefined; - if (rs != undefined) - for (const r of rs) { - if (r instanceof SectionResults) { - this._results = r; - break; - } - } - this.updateView(); - } - public updateView() { - if (this._sectionCanvas != undefined) + if (this._sectionCanvas != undefined) { this._sectionCanvas.reset(); + } - if (this._results != undefined) + if (this._results != undefined) { this._doUpdate = this._results.hasResults; + } } /** * appelé pour gérer les changements non détectés par Angular */ public ngDoCheck() { - if (this._doUpdate) + if (this._doUpdate) { this._doUpdate = !this.updateResults(); + } } private isSectionLevel(s: string) { - for (const k in SectionResultsComponent.labelColors) - if (k === s) + for (const k in SectionResultsComponent.labelColors) { + if (k === s) { return true; + } + } return false; } @@ -109,8 +123,9 @@ export class SectionResultsComponent implements DoCheck { const er = this._results.result.getExtraResult(k); this._resultElement.addExtraResult(lbl, er); - if (this.isSectionLevel(k)) + if (this.isSectionLevel(k)) { this._sectionCanvas.addLevel(er, k + " = " + er.toFixed(nDigits), SectionResultsComponent.labelColors[k]); + } } this._sectionCanvas.section = this._results.section; @@ -119,14 +134,6 @@ export class SectionResultsComponent implements DoCheck { return false; } - private get hasResults(): boolean { - return this._results != undefined && this._results.hasResults; - } - - private get resultElement() { - return this._resultElement; - } - private getResultClass(i: number) { return "result_id_" + String(i & 1); } diff --git a/src/app/components/select-field-line/select-field-line.component.html b/src/app/components/select-field-line/select-field-line.component.html index f3e7ae806429ca653a341a374718f70a5e1295e0..55f88afa8060e1d625cd67f0f8466b2fa5fae19d 100644 --- a/src/app/components/select-field-line/select-field-line.component.html +++ b/src/app/components/select-field-line/select-field-line.component.html @@ -1,16 +1,16 @@ <div class="row"> <!-- titre --> <div class="col-12 col-sm-3"> - {{_select.label}} + {{ _select.label }} </div> <!-- liste déroulante --> <div class="btn-group col-12 col-sm-9" dropdown (click)="onSelect($event)"> <button dropdownToggle class="btn btn-primary dropdown-toggle waves-light my-1" type="button" mdbRippleRadius> - {{currentLabel}} + {{ currentLabel }} </button> <div class="dropdown-menu"> - <a class="dropdown-item" *ngFor="let e of entries" [value]=e>{{entryLabel(e)}}</a> + <a class="dropdown-item" *ngFor="let e of entries" [value]=e>{{ entryLabel(e) }}</a> </div> </div> </div> \ No newline at end of file diff --git a/src/app/components/select-field-line/select-field-line.component.ts b/src/app/components/select-field-line/select-field-line.component.ts index a544eed7d839c1ecd5f2f075d8ca599f0745cebf..8da3a93c203f70907b5e68ae4d5542d9dc3ed3a2 100644 --- a/src/app/components/select-field-line/select-field-line.component.ts +++ b/src/app/components/select-field-line/select-field-line.component.ts @@ -13,8 +13,9 @@ export class SelectFieldLineComponent extends GenericSelectComponent<SelectEntry private _select: SelectField; protected get entries(): SelectEntry[] { - if (this._select == undefined) + if (this._select == undefined) { return []; + } return this._select.entries; } diff --git a/src/app/error.module.ts b/src/app/error.module.ts index baf9b7e1c2a44cc35b9de25dc89d2b6fa63eadc2..4bdc1d3bbeda51bec71154732d164f75b97ad8d5 100644 --- a/src/app/error.module.ts +++ b/src/app/error.module.ts @@ -1,10 +1,10 @@ -import { Component, NgModule, ErrorHandler, Injectable } from '@angular/core'; +import { Component, NgModule, ErrorHandler, Injectable } from "@angular/core"; -import { ErrorService } from './services/error/error.service'; +import { ErrorService } from "./services/error/error.service"; @Component({ - selector: 'app-error-handler', - template: `<span style="color:red">{{errorText}}</span>` + selector: "app-error-handler", + template: `<span style="color:red">{{ errorText }}</span>` }) export class AppErrorHandler extends ErrorHandler { constructor(private errorService: ErrorService) { diff --git a/src/app/formulaire/definition/concrete/form-courbe-remous.ts b/src/app/formulaire/definition/concrete/form-courbe-remous.ts index f67df0d0bad7a6af51e35c75cd330a1dddfeb63d..12bf975997807b12280ed6bd180872c8aa8b55f0 100644 --- a/src/app/formulaire/definition/concrete/form-courbe-remous.ts +++ b/src/app/formulaire/definition/concrete/form-courbe-remous.ts @@ -70,8 +70,9 @@ export class FormulaireCourbeRemous extends FormulaireDefinition { switch (sender.id) { case "fs_section": this.replaceCurrentSessionNub(sender.properties); - for (const fs of this.allFieldsets) + for (const fs of this.allFieldsets) { fs.setSessionNub(this._currentSessionNub); + } this.reset(); break; diff --git a/src/app/formulaire/definition/concrete/form-lechapt-calmon.ts b/src/app/formulaire/definition/concrete/form-lechapt-calmon.ts index 04427e3db3008c31e8955cc00ea4364916731526..635c4029270d5a29c3ab02b08d535b6173add61c 100644 --- a/src/app/formulaire/definition/concrete/form-lechapt-calmon.ts +++ b/src/app/formulaire/definition/concrete/form-lechapt-calmon.ts @@ -36,7 +36,7 @@ export class FormulaireLechaptCalmon extends FormulaireDefinition implements Obs } /** - * gestion du clic sur les radios "paramètre fixé, à varier, à calculer" + * gestion du clic sur les radios "paramètre fixé, à varier, à calculer" */ public onRadioClick(info: string) { super.onRadioClick(info); @@ -64,8 +64,9 @@ export class FormulaireLechaptCalmon extends FormulaireDefinition implements Obs public update(sender: any, data: any) { // en cas de changement de valeur du select de matériau, effacement des résultats et MAJ des champs L,M,N if (sender instanceof SelectField) { - if (data.action == "select") + if (data.action == "select") { this.reset(); + } } } } diff --git a/src/app/formulaire/definition/concrete/form-parallel-structures.ts b/src/app/formulaire/definition/concrete/form-parallel-structures.ts index 5606c737ef3dc065100e0c395c42096a8d1b540c..1b47a27c0a7dc609216f3c465d42ee8442003fa5 100644 --- a/src/app/formulaire/definition/concrete/form-parallel-structures.ts +++ b/src/app/formulaire/definition/concrete/form-parallel-structures.ts @@ -77,17 +77,18 @@ export class FormulaireParallelStructure extends FormulaireDefinition { this.addStructureNub(sn.nub as Structure, after); res.setSessionNub(sn, false); - if (after !== undefined) + if (after !== undefined) { parent.kids.splice(after + 1, 0, res); - else + } else { parent.kids.push(res); + } this.resetResults(); return res; - } - else + } else { return super.createFieldset(parent, json, data); + } } protected initParse() { @@ -121,8 +122,7 @@ export class FormulaireParallelStructure extends FormulaireDefinition { this.fieldsetContainer.moveFieldsetUp(fs); this.resetResults(); - } - else super.moveFieldsetUp(fs); + } else { super.moveFieldsetUp(fs); } } public moveFieldsetDown(fs: FieldSet) { @@ -134,8 +134,7 @@ export class FormulaireParallelStructure extends FormulaireDefinition { this.fieldsetContainer.moveFieldsetDown(fs); this.resetResults(); - } - else super.moveFieldsetDown(fs); + } else { super.moveFieldsetDown(fs); } } public removeFieldset(fs: FieldSet) { @@ -147,8 +146,7 @@ export class FormulaireParallelStructure extends FormulaireDefinition { this.fieldsetContainer.removeFieldset(fs); this.resetResults(); - } - else super.removeFieldset(fs); + } else { super.removeFieldset(fs); } } protected completeParse(json: {}) { @@ -187,8 +185,9 @@ export class FormulaireParallelStructure extends FormulaireDefinition { private get fieldsetContainer(): FieldsetContainer { const n = this.getFormulaireNodeById("struct_container"); - if (n == undefined || !(n instanceof FieldsetContainer)) + if (n == undefined || !(n instanceof FieldsetContainer)) { throw new Error("l'élément 'struct_container' n'est pas du type FieldsetContainer"); + } return n as FieldsetContainer; } @@ -199,7 +198,7 @@ export class FormulaireParallelStructure extends FormulaireDefinition { "select": { [key: string]: string; }, "entry": { [key: string]: string; } } { - let select; // select + let select; // select let selectEntry; // entrée du select correspondant à la valeur de l'enum for (const k in conf) { @@ -217,13 +216,15 @@ export class FormulaireParallelStructure extends FormulaireDefinition { } } } - if (select !== undefined) + if (select !== undefined) { break; + } } } - if (select === undefined) + if (select === undefined) { return undefined; + } return { "select": select, "entry": selectEntry }; } @@ -235,9 +236,11 @@ export class FormulaireParallelStructure extends FormulaireDefinition { for (const k in conf) { const kid = conf[k]; if (kid.dep_exist !== undefined) { - for (const dep of kid.dep_exist) - if (dep.refid === refid && dep.refvalue === refvalue) + for (const dep of kid.dep_exist) { + if (dep.refid === refid && dep.refvalue === refvalue) { return kid; + } + } } } @@ -246,7 +249,7 @@ export class FormulaireParallelStructure extends FormulaireDefinition { /** * trouve une loi de débit compatible avec un type de structure dans un Fieldset en tenant compte des dépendances entre selects - * @param fs + * @param fs * @param structType */ private adjustLoiDebit(fs: FieldSet, structType: StructureType): Props { @@ -255,26 +258,30 @@ export class FormulaireParallelStructure extends FormulaireDefinition { // recherche du select "type de structure" const structSelect = this.findSelectWithEnum(fs.jsonConfig["fields"], "StructureType", StructureType[structType]); - if (structSelect === undefined) + if (structSelect === undefined) { throw new Error(`pas de select trouvé pour la propriété StructureType=${StructureType[structType]}`); + } // recherche du select dépendant (lois de débit) const loidebitSelect = this.findObjectWithDependency(fs.jsonConfig["fields"], structSelect.select.id, structSelect.entry.id); - if (loidebitSelect === undefined || loidebitSelect["type"] !== "select") + if (loidebitSelect === undefined || loidebitSelect["type"] !== "select") { throw new Error(`pas de select trouvé avec une dépendance au select 'type de structure' pour la valeur ${structSelect.select.id}=${structSelect.entry.id} (1)`); + } // liste des enums du select dépendant const loisDebit = []; - for (const e of loidebitSelect["select"]) + for (const e of loidebitSelect["select"]) { if (e.enum !== undefined) { const tmp = e.enum.split("."); loisDebit.push(LoiDebit[tmp[1]]); } + } - if (loisDebit.length === 0) + if (loisDebit.length === 0) { throw new Error(`pas de select trouvé avec une dépendance au select 'type de structure' pour la valeur ${structSelect.select.id}=${structSelect.entry.id} (2)`); + } res.setPropValue("loiDebit", StructureProperties.findCompatibleLoiDebit(structType, loisDebit)); @@ -295,8 +302,9 @@ export class FormulaireParallelStructure extends FormulaireDefinition { // si prop=type d'ouvrage, on prend la 1ère loi de débit compatible avec (spécifique aux ouvrages //), en tenant compte des dépendances. // (par ex, s'il existe un select de lois de débit dépendant du select de types d'ouvrage, on prend la 1ère entrée du select de lois de débit compatible) if (name === "structureType") { - if (!StructureProperties.isCompatibleValues(val, fs.properties.getPropValue("loiDebit"))) + if (!StructureProperties.isCompatibleValues(val, fs.properties.getPropValue("loiDebit"))) { return this.adjustLoiDebit(fs, val); + } } // si prop=loi débit, on prend un type d'ouvrage compatible // else if (name === "loiDebit") @@ -317,30 +325,34 @@ export class FormulaireParallelStructure extends FormulaireDefinition { * abonnement en tant qu'observateur des NgParameter des FieldSet contenus dans le FieldsetContainer */ private subscribeStructureInputFields(fs: FieldSet) { - for (const n of fs.allFormElements) - if (n instanceof NgParameter) + for (const n of fs.allFormElements) { + if (n instanceof NgParameter) { n.addObserver(this); + } + } } /** * abonnement en tant qu'observateur du SelectField des FieldSet contenus dans le FieldsetContainer */ private subscribeStructureSelectFields(fs: FieldSet) { - for (const n of fs.allFormElements) - if (n instanceof SelectField) + for (const n of fs.allFormElements) { + if (n instanceof SelectField) { n.addObserver(this); + } + } } // interface Observer public update(sender: any, data: any) { - if (sender instanceof FieldsetContainer) + if (sender instanceof FieldsetContainer) { switch (data.action) { case "newFieldset": this.reset(); this.subscribeStructureInputFields(data["fieldset"]); this.subscribeStructureSelectFields(data["fieldset"]); } - else if (sender instanceof FieldSet && data.action == "propertyChange") { + } else if (sender instanceof FieldSet && data.action == "propertyChange") { switch (sender.id) { case "fs_ouvrage": const props = this.adjustProperties(sender, data["name"], data["value"]); diff --git a/src/app/formulaire/definition/concrete/form-passe-bassin-dim.ts b/src/app/formulaire/definition/concrete/form-passe-bassin-dim.ts index bb7de04b6cf375f3e3aad38d2e96834e34ead84f..5236e6d6d513083a1b6e2f4a7703a8df07293643 100644 --- a/src/app/formulaire/definition/concrete/form-passe-bassin-dim.ts +++ b/src/app/formulaire/definition/concrete/form-passe-bassin-dim.ts @@ -33,7 +33,7 @@ export class FormulairePasseBassinDimensions extends FormulaireDefinition { } /** - * gestion du clic sur les radios "paramètre fixé, à varier, à calculer" + * gestion du clic sur les radios "paramètre fixé, à varier, à calculer" */ public onRadioClick(info: string) { super.onRadioClick(info); diff --git a/src/app/formulaire/definition/concrete/form-passe-bassin-puissance.ts b/src/app/formulaire/definition/concrete/form-passe-bassin-puissance.ts index ba57242df8937f4a065fa58c74fc5a9dc46199d3..cdaa2e16902991f33a976f85474db5cf8f6588f8 100644 --- a/src/app/formulaire/definition/concrete/form-passe-bassin-puissance.ts +++ b/src/app/formulaire/definition/concrete/form-passe-bassin-puissance.ts @@ -33,7 +33,7 @@ export class FormulairePasseBassinPuissance extends FormulaireDefinition { } /** - * gestion du clic sur les radios "paramètre fixé, à varier, à calculer" + * gestion du clic sur les radios "paramètre fixé, à varier, à calculer" */ public onRadioClick(info: string) { super.onRadioClick(info); diff --git a/src/app/formulaire/definition/concrete/form-regime-uniforme.ts b/src/app/formulaire/definition/concrete/form-regime-uniforme.ts index 64164746e23499c4052bc4e7b242617725367610..e821225d29039aca3b21c718a75c3e5bcb80f03e 100644 --- a/src/app/formulaire/definition/concrete/form-regime-uniforme.ts +++ b/src/app/formulaire/definition/concrete/form-regime-uniforme.ts @@ -47,7 +47,7 @@ export class FormulaireRegimeUniforme extends FormulaireDefinition implements Ob } /** - * gestion du clic sur les radios "paramètre fixé, à varier, à calculer" + * gestion du clic sur les radios "paramètre fixé, à varier, à calculer" */ public onRadioClick(info: string) { super.onRadioClick(info); @@ -80,8 +80,9 @@ export class FormulaireRegimeUniforme extends FormulaireDefinition implements Ob // changement de propriété du FieldSet contenant le select de choix du type de section if (sender instanceof FieldSet && sender.id === "fs_section" && data.action == "propertyChange") { this.replaceCurrentSessionNub(sender.properties); - for (const fs of this.allFieldsets) + for (const fs of this.allFieldsets) { fs.setSessionNub(this._currentSessionNub); + } this.reset(); } } diff --git a/src/app/formulaire/definition/concrete/form-section-parametree.ts b/src/app/formulaire/definition/concrete/form-section-parametree.ts index 6f3fa0391c21bfedfee2f5c1de7fe755abe4bd8a..1e5a9301e22e577c470d28e753ed9d003743aa76 100644 --- a/src/app/formulaire/definition/concrete/form-section-parametree.ts +++ b/src/app/formulaire/definition/concrete/form-section-parametree.ts @@ -39,7 +39,7 @@ export class FormulaireSectionParametree extends FormulaireDefinition { } /** - * gestion du clic sur les radios "paramètre fixé, à varier, à calculer" + * gestion du clic sur les radios "paramètre fixé, à varier, à calculer" */ public onRadioClick(info: string) { super.onRadioClick(info); @@ -70,8 +70,9 @@ export class FormulaireSectionParametree extends FormulaireDefinition { switch (sender.id) { case "fs_section": this.replaceCurrentSessionNub(sender.properties); - for (const fs of this.allFieldsets) + for (const fs of this.allFieldsets) { fs.setSessionNub(this._currentSessionNub); + } this.reset(); break; diff --git a/src/app/formulaire/definition/form-compute-courbe-remous.ts b/src/app/formulaire/definition/form-compute-courbe-remous.ts index 69f3a832a3ce2f1c39faeb372d16b568dbe0e307..ebd833cc027a1144eda7da408f1a9e7285cdbe8c 100644 --- a/src/app/formulaire/definition/form-compute-courbe-remous.ts +++ b/src/app/formulaire/definition/form-compute-courbe-remous.ts @@ -46,8 +46,8 @@ export class FormComputeCourbeRemous extends FormCompute { this.remousResults.hauteurCritique = Yc.resultElement; if (this.remousResults.extraParamSymbol) { this.remousResults.extraGraph = ["Hs", "Hsc", "Yf", "Yt", "Yco"].indexOf(this.remousResults.extraParamSymbol) === -1; - } - else + } else { this.remousResults.extraGraph = false; + } } } diff --git a/src/app/formulaire/definition/form-compute-parallel-structures.ts b/src/app/formulaire/definition/form-compute-parallel-structures.ts index 380f000fb4c87a172bf405c9abb9480ac838c368..1dd15b5c1906e241ae9e942f5192f1f05bebe676 100644 --- a/src/app/formulaire/definition/form-compute-parallel-structures.ts +++ b/src/app/formulaire/definition/form-compute-parallel-structures.ts @@ -29,7 +29,7 @@ export class FormComputeParallelStructures extends FormComputeFixedVar { */ private structureParents(p: NgParameter): [FieldsetContainer, FieldSet, number] { const parent1: FormulaireNode = p.parent; - if (parent1 !== undefined) + if (parent1 !== undefined) { if (parent1 instanceof FieldSet) { const parent2 = parent1.parent; if (parent2 instanceof FieldsetContainer) { @@ -37,6 +37,7 @@ export class FormComputeParallelStructures extends FormComputeFixedVar { return [parent2, parent1, fsIndex]; } } + } return [undefined, undefined, -1]; } @@ -46,17 +47,18 @@ export class FormComputeParallelStructures extends FormComputeFixedVar { */ protected getParameterRefid(p: NgParameter) { const [fsc, fs, i] = this.structureParents(p); - if (i == -1) + if (i == -1) { return super.getParameterRefid(p); + } return `${i}.${p.symbol}`; } protected setParameterValue(node: ComputeNode, p: NgParameter, val: number) { const [fsc, fs, i] = this.structureParents(p); - if (i == -1) - super.setParameterValue(node, p, val); // paramètre "normal" (pas un paramètre d'ouvrage) - else { + if (i == -1) { + super.setParameterValue(node, p, val); + } else { const n: ParallelStructure = node as ParallelStructure; const prm = n.structures[i].getParameter(p.symbol); prm.v = val; diff --git a/src/app/formulaire/definition/form-compute-section-parametree.ts b/src/app/formulaire/definition/form-compute-section-parametree.ts index 4578a4319d983e15e10f7f0c0f79fcde7ddfabf1..c31b941c14e9c6ab0c0476460411e58ddb81562a 100644 --- a/src/app/formulaire/definition/form-compute-section-parametree.ts +++ b/src/app/formulaire/definition/form-compute-section-parametree.ts @@ -43,13 +43,13 @@ export class FormComputeSectionParametree extends FormCompute { * @param varParam paramètre à varier */ private doComputeSectionVar(varParam: NgParameter) { - let computePrec: number = this._formBase.getParameterValue("Pr"); // précision de calcul - let nDigits = -Math.log10(computePrec); + const computePrec: number = this._formBase.getParameterValue("Pr"); // précision de calcul + const nDigits = -Math.log10(computePrec); this._formSectionResult.addSectionFixedParameters(false); // paramètre à calculer en fonction du paramètre à varier - let computedParamInfo = this._formSection.getSectionComputedParam(); + const computedParamInfo = this._formSection.getSectionComputedParam(); const sectNub: SectionParametree = this._formBase.currentSessionNub.nub as SectionParametree; const sect: acSection = sectNub.section; @@ -62,7 +62,7 @@ export class FormComputeSectionParametree extends FormCompute { const computedParam: NgParameter = this._paramService.createParameter(computedParamInfo.symbol, this._formBase); this._varResults.calculatedParameter = computedParam; - let compSymbol: string = computedParamInfo["symbol"]; + const compSymbol: string = computedParamInfo["symbol"]; this._varResults.result = this.runNubCalc(sectNub, computedParam, computePrec); this._varResults.graphTitle = computedParamInfo.symbol + " = f( " + varParam.symbol + " )"; @@ -70,7 +70,7 @@ export class FormComputeSectionParametree extends FormCompute { } protected compute() { - let varParam = this._formSection.getSectionVariatedParameter(); + const varParam = this._formSection.getSectionVariatedParameter(); if (varParam != undefined) { this.doComputeSectionVar(varParam); return; diff --git a/src/app/formulaire/definition/form-compute.ts b/src/app/formulaire/definition/form-compute.ts index 400f511f146920dcff9f6c4dedde5040c50994ca..63d5460cefeaebe46e5d95669dcaddbf9025572e 100644 --- a/src/app/formulaire/definition/form-compute.ts +++ b/src/app/formulaire/definition/form-compute.ts @@ -29,17 +29,21 @@ export abstract class FormCompute { let init: number; switch (computedParam.domain.domain) { case ParamDomainValue.ANY: - if (computedParam && computedParam.isDefined) + if (computedParam && computedParam.isDefined) { init = computedParam.getValue(); - if (init === undefined) + } + if (init === undefined) { init = 0; + } break; case ParamDomainValue.POS_NULL: - if (computedParam && computedParam.isDefined) + if (computedParam && computedParam.isDefined) { init = Math.max(computedParam.getValue(), 0); - if (init === undefined) + } + if (init === undefined) { init = 0; + } break; case ParamDomainValue.INTERVAL: @@ -47,17 +51,21 @@ export abstract class FormCompute { break; case ParamDomainValue.NOT_NULL: - if (computedParam && computedParam.isDefined) + if (computedParam && computedParam.isDefined) { init = computedParam.getValue(); - if (init === undefined || init === 0) + } + if (init === undefined || init === 0) { init = 1e-8; + } break; case ParamDomainValue.POS: - if (computedParam && computedParam.isDefined) + if (computedParam && computedParam.isDefined) { init = Math.max(computedParam.getValue(), 1e-8); - if (init === undefined) + } + if (init === undefined) { init = 1e-8; + } break; } diff --git a/src/app/formulaire/definition/form-def-fixedvar.ts b/src/app/formulaire/definition/form-def-fixedvar.ts index 9016a8a3081104112b212f1231f9c5af7f892f47..0f2a0d045847d4d668e6671194721a8a58c8c456 100644 --- a/src/app/formulaire/definition/form-def-fixedvar.ts +++ b/src/app/formulaire/definition/form-def-fixedvar.ts @@ -21,9 +21,11 @@ export class FormDefFixedVar { */ protected resetOtherRadio(me: NgParameter, except: ParamRadioConfig = undefined) { for (const p of this._formBase.allFormElements) { - if (p instanceof NgParameter) - if (p != me && p.radioState != except && p.radioState != ParamRadioConfig.LINK && p.radioConfig != ParamRadioConfig.FIX) + if (p instanceof NgParameter) { + if (p != me && p.radioState != except && p.radioState != ParamRadioConfig.LINK && p.radioConfig != ParamRadioConfig.FIX) { p.valueMode = ParamValueMode.SINGLE; + } + } } } @@ -34,7 +36,7 @@ export class FormDefFixedVar { * - 1 seul paramètre multivalué (VAR) à la fois (directement ou par liaison) * - plusieurs paramètres FIX à la fois possible * - plusieurs paramètres LINK à la fois possible si les 2 1ères règles sont respectées - * + * * analyse : * ancien état nouvel état action(s) * FIX VAR action1 @@ -44,7 +46,7 @@ export class FormDefFixedVar { * si paramètre lié CAL : si valeur unique : aucune * si valeur multiple : action1 * si paramètre lié LINK : recommencer ce cas avec le paramètre lié - * + * * VAR FIX aucune * VAR CAL action2 * VAR LINK si paramètre lié FIX : aucune @@ -52,7 +54,7 @@ export class FormDefFixedVar { * si paramètre lié CAL : si valeur unique : aucune * si valeur multiple : aucune * si paramètre lié LINK : recommencer ce cas avec le paramètre lié - * + * * CAL FIX action5 * CAL VAR action3 + action5 * CAL LINK si paramètre lié FIX : aucune @@ -80,13 +82,15 @@ export class FormDefFixedVar { break; case ParamValueMode.LINK: // nouvel état - if (sourceParam.paramDefinition.hasMultipleValues) + if (sourceParam.paramDefinition.hasMultipleValues) { this.resetOtherRadio(sourceParam, ParamRadioConfig.CAL); - else { + } else { const refParamValues = sourceParam.paramDefinition.referencedParamValues; - if (refParamValues !== undefined) // cad si on référence un paramètre et non un Result par ex - if (refParamValues.valueMode == ParamValueMode.LINK) - throw new Error(`références de paramètre en chaîne non pris en charge`); // cas à traiter + if (refParamValues !== undefined) { // cad si on référence un paramètre et non un Result par ex + if (refParamValues.valueMode == ParamValueMode.LINK) { + throw new Error(`références de paramètre en chaîne non pris en charge`); + } + } // cas à traiter } break; } @@ -102,8 +106,9 @@ export class FormDefFixedVar { case ParamValueMode.LINK: // nouvel état // mode du paramètre référencé const refParamValues = sourceParam.paramDefinition.referencedParamValues; - if (refParamValues.valueMode === ParamValueMode.LINK) - throw new Error(`références de paramètre en chaîne non pris en charge`) + if (refParamValues.valueMode === ParamValueMode.LINK) { + throw new Error(`références de paramètre en chaîne non pris en charge`); + } break; } break; @@ -134,28 +139,33 @@ export class FormDefFixedVar { // on vérifie qu'il y a au moins un paramètre "à calculer" et sinon, on prend le 1er qui est à "fixé" if (this._formBase.getDisplayedParamFromState(ParamRadioConfig.CAL) == undefined) { - let newCal: NgParameter = undefined; + let newCal: NgParameter; for (const p of this._formBase.allFormElements) { - if (p instanceof NgParameter) + if (p instanceof NgParameter) { if (p.radioConfig == ParamRadioConfig.CAL && p.radioState == ParamRadioConfig.FIX && p != sourceParam) { newCal = p; break; } - if (newCal != undefined) + } + if (newCal != undefined) { break; + } } - if (newCal != undefined) + if (newCal != undefined) { newCal.valueMode = ParamValueMode.CALCUL; + } } } private logParams() { console.log("----"); - for (const fe of this._formBase.allFormElements) - if (fe instanceof NgParameter) + for (const fe of this._formBase.allFormElements) { + if (fe instanceof NgParameter) { console.log(`${fe.paramDefinition.symbol} : ${ParamValueMode[fe.paramDefinition.valueMode]}`); + } + } } /** @@ -165,8 +175,8 @@ export class FormDefFixedVar { const param: NgParameter = info.param; // paramètre source de l'événement radio const old: ParamValueMode = info.oldValueMode; // ancien état (radio) - //this.logParams(); + // this.logParams(); this.resetRadiosAndResults(param, old); - //this.logParams(); + // this.logParams(); } } diff --git a/src/app/formulaire/definition/form-def-paramcalc.ts b/src/app/formulaire/definition/form-def-paramcalc.ts index de7d95b77ac5efcba949cb26594d2e4f8b36cd52..e4820672183758da2297decdb44825f845bd73fc 100644 --- a/src/app/formulaire/definition/form-def-paramcalc.ts +++ b/src/app/formulaire/definition/form-def-paramcalc.ts @@ -5,7 +5,7 @@ import { FormulaireDefinition } from "./form-definition"; import { FormDefFixedVar } from "./form-def-fixedvar"; import { NgParamInputComponent } from "../../components/ngparam-input/ngparam-input.component"; -/** +/** * gestion des formulaires avec "paramètre à calculer" (conduite distributrice, Lechapt-Calmon, régime uniforme, passes à bassin) */ export class FormDefParamToCalculate extends FormDefFixedVar { @@ -43,8 +43,9 @@ export class FormDefParamToCalculate extends FormDefFixedVar { */ private setDefault(except: NgParameter = undefined): NgParameter { const defaultParamCal: NgParameter = this._formBase.getParamFromSymbol(this._defaultCalculatedParam); - if (except === undefined || defaultParamCal.uid !== except.uid) + if (except === undefined || defaultParamCal.uid !== except.uid) { defaultParamCal.valueMode = ParamValueMode.CALCUL; + } return defaultParamCal; } @@ -71,11 +72,10 @@ export class FormDefParamToCalculate extends FormDefFixedVar { if (sourceParam.paramDefinition.hasMultipleValues) { super.resetOtherRadio(sourceParam); this.setDefault(); - } - else { + } else { // mode du paramètre référencé const refParamValues = sourceParam.paramDefinition.referencedParamValues; - if (refParamValues !== undefined) + if (refParamValues !== undefined) { switch (refParamValues.valueMode) { case ParamValueMode.MINMAX: case ParamValueMode.LISTE: @@ -87,6 +87,7 @@ export class FormDefParamToCalculate extends FormDefFixedVar { case ParamValueMode.LINK: throw new Error(`références de paramètre en chaîne non pris en charge`); // cas à traiter } + } } break; } diff --git a/src/app/formulaire/definition/form-def-section.ts b/src/app/formulaire/definition/form-def-section.ts index 2187473782af744075ec4f5be4759eb26869dd18..69fa4c92daa872d746a7245d409abd626a101bb3 100644 --- a/src/app/formulaire/definition/form-def-section.ts +++ b/src/app/formulaire/definition/form-def-section.ts @@ -55,8 +55,7 @@ export class FormDefSection { public afterParseFieldset(fs: FieldSet) { if (this.hasSectionNodeTypeSource) { // s'il existe un menu de choix de section dans la calculette const sel = fs.getFormulaireNodeById(this._sectionSourceId); - if (sel) // si le FieldSet contient le select de changement de type de section - { + if (sel) { // on abonne le formulaire aux propriétés du FieldSet pour MAJ du nub, reset du formulaire, ... fs.properties.addObserver(this._formBase); } diff --git a/src/app/formulaire/definition/form-result-fixedvar.ts b/src/app/formulaire/definition/form-result-fixedvar.ts index 695bc2059247e2fe753f826ab9bb94ce8cc56f53..04b248a83d70090cdfcd826cda530b8d38f1e3ff 100644 --- a/src/app/formulaire/definition/form-result-fixedvar.ts +++ b/src/app/formulaire/definition/form-result-fixedvar.ts @@ -37,13 +37,17 @@ export class FormResultFixedVar extends FormResult { } public addFixedParameters() { - for (const p of this._formBase.getDisplayedParamListFromState(ParamRadioConfig.FIX)) - if (p.symbol !== "Pr") + for (const p of this._formBase.getDisplayedParamListFromState(ParamRadioConfig.FIX)) { + if (p.symbol !== "Pr") { this._fixedResults.addFixedParameter(p); + } + } - for (const p of this._formBase.getDisplayedParamListFromState(ParamRadioConfig.LINK)) - if (!p.paramDefinition.hasMultipleValues) + for (const p of this._formBase.getDisplayedParamListFromState(ParamRadioConfig.LINK)) { + if (!p.paramDefinition.hasMultipleValues) { this._fixedResults.addFixedParameter(p); + } + } } public set graphType(t: GraphType) { @@ -60,8 +64,8 @@ export class FormResultFixedVar extends FormResult { public get results(): CalculatorResults[] { const res: CalculatorResults[] = []; - res.push(this._fixedResults) - res.push(this._varResults) + res.push(this._fixedResults); + res.push(this._varResults); return res; } } diff --git a/src/app/formulaire/definition/form-result-remous.ts b/src/app/formulaire/definition/form-result-remous.ts index 9709b6deba57b8464638e85d74fcaef63d43ad45..c54d0d6c47c51922d20fbef9d414a0a978cc531b 100644 --- a/src/app/formulaire/definition/form-result-remous.ts +++ b/src/app/formulaire/definition/form-result-remous.ts @@ -34,7 +34,7 @@ export class FormResultRemous extends FormResult { public get results(): CalculatorResults[] { const res: CalculatorResults[] = []; - res.push(this._remousResults) + res.push(this._remousResults); return res; } -} \ No newline at end of file +} diff --git a/src/app/formulaire/definition/form-result-section.ts b/src/app/formulaire/definition/form-result-section.ts index d023a8ee236896c9b9ea88d00aa57cf3031f3d91..0b828129e37bde7de751d534334dc6a844d63bcc 100644 --- a/src/app/formulaire/definition/form-result-section.ts +++ b/src/app/formulaire/definition/form-result-section.ts @@ -52,9 +52,11 @@ export class FormResultSection extends FormResult { } public addSectionFixedParameters(displaySymbol: boolean) { - for (let p of this._formBase.getDisplayedParamListFromState(ParamRadioConfig.FIX)) - if (p.symbol !== "Pr") + for (const p of this._formBase.getDisplayedParamListFromState(ParamRadioConfig.FIX)) { + if (p.symbol !== "Pr") { this._fixedResults.addFixedParameter(p); + } + } } public get hasResults(): boolean { @@ -65,9 +67,9 @@ export class FormResultSection extends FormResult { public get results(): CalculatorResults[] { const res: CalculatorResults[] = []; - res.push(this._fixedResults) - res.push(this._varResults) - res.push(this._sectionResults) + res.push(this._fixedResults); + res.push(this._varResults); + res.push(this._sectionResults); return res; } } diff --git a/src/app/formulaire/dependency/dependency.ts b/src/app/formulaire/dependency/dependency.ts index 8df53daef654a98e53318bc3b6040775dad56ebc..a7b8a4634e48fcfb248c8d471213a738a3b4e53e 100644 --- a/src/app/formulaire/dependency/dependency.ts +++ b/src/app/formulaire/dependency/dependency.ts @@ -1,7 +1,7 @@ import { FormulaireElement } from "../formulaire-element"; import { DependencyCondition } from "./dependency-condition"; -/** +/** * Dépendance entre un élément maître et un élément esclave * Si le maître vérifie une condition (masterCondition), alors la dépendance est appliquée à l'élément esclave, * cad que son affichage, sa valeur, ... sont modifiés @@ -22,9 +22,10 @@ export abstract class Dependency { private getMasterElement(id: string): FormulaireElement { let parentNode = this._slave.parent; while (parentNode != undefined) { - var res: FormulaireElement = parentNode.getFormulaireNodeById(id) as FormulaireElement; - if (res != undefined) + const res: FormulaireElement = parentNode.getFormulaireNodeById(id) as FormulaireElement; + if (res != undefined) { return res; + } parentNode = parentNode.parent; } return undefined; @@ -40,8 +41,9 @@ export abstract class Dependency { public apply() { const master: FormulaireElement = this.masterElement; - if (master && master.verifiesDependency(this)) + if (master && master.verifiesDependency(this)) { this._slave.applyDependency(this); + } } public toString(): string { diff --git a/src/app/formulaire/dependency/existence-dependency.ts b/src/app/formulaire/dependency/existence-dependency.ts index 0f8aecec3fa0bbecf96c5e7f7e0c5d8584df5749..2f1a17f24e70b83f76a8a86853bc13e0f4bd6166 100644 --- a/src/app/formulaire/dependency/existence-dependency.ts +++ b/src/app/formulaire/dependency/existence-dependency.ts @@ -1,7 +1,7 @@ import { Dependency } from "./dependency"; import { FormulaireElement } from "../formulaire-element"; -/** +/** * dépendance déterminant l'affichage de l'élément esclave */ export class ExistenceDependency extends Dependency { diff --git a/src/app/formulaire/dependency/value-dependency.ts b/src/app/formulaire/dependency/value-dependency.ts index 4f06d7d33c5fb26fa75ef35e8d32ef820c68778e..b94f9fc9bb6acda3ac142ca06a4047f4c13e9aca 100644 --- a/src/app/formulaire/dependency/value-dependency.ts +++ b/src/app/formulaire/dependency/value-dependency.ts @@ -2,7 +2,7 @@ import { Dependency } from "./dependency"; import { FormulaireElement } from "../formulaire-element"; import { ValueDependencyCondition } from "./value-dependency-condition"; -/** +/** * dépendance déterminant la valeur de l'élément esclave */ export class ValueDependency extends Dependency { diff --git a/src/app/formulaire/field.ts b/src/app/formulaire/field.ts index 99b2599df44c6225f10ee6d5de87f84fd4bf057e..d5f7c2df7f44ff88814ae3a882d6c62236df156b 100644 --- a/src/app/formulaire/field.ts +++ b/src/app/formulaire/field.ts @@ -10,10 +10,10 @@ export abstract class Field extends FormulaireElement { public abstract setValue(sender: any, val: any): void; private parse_value_dependencies(json: {}) { - for (let di in json) { - let d = json[di]; - let masterValue = d["refvalue"]; - let dep = new ValueDependency(this, d["refid"], masterValue); + for (const di in json) { + const d = json[di]; + const masterValue = d["refvalue"]; + const dep = new ValueDependency(this, d["refid"], masterValue); dep.slaveValue = d["value"]; this._dependencies.push(dep); } @@ -23,8 +23,9 @@ export abstract class Field extends FormulaireElement { super.parseDependencies(json); const dep = json["dep_value"]; - if (dep != undefined) + if (dep != undefined) { this.parse_value_dependencies(dep); + } } /** @@ -32,12 +33,13 @@ export abstract class Field extends FormulaireElement { */ public applyDependency(d: Dependency) { if (d instanceof ValueDependency) { - if (isNumber(d.slaveValue)) + if (isNumber(d.slaveValue)) { this.setValue(this, +d.slaveValue); - else + } else { this.setValue(this, d.slaveValue); - } - else + } + } else { super.applyDependency(d); + } } } diff --git a/src/app/formulaire/fieldset-container.ts b/src/app/formulaire/fieldset-container.ts index 4e2ec5b4a86f98bd454ed6e1908f9d033d036cb8..dd8881d8f1c32271ab60adb87127130429af9d81 100644 --- a/src/app/formulaire/fieldset-container.ts +++ b/src/app/formulaire/fieldset-container.ts @@ -9,7 +9,7 @@ export class FieldsetContainer extends FormulaireElement { private _localisation: StringMap; - public title: string + public title: string; constructor(parent: FormulaireNode) { super(parent); @@ -27,8 +27,9 @@ export class FieldsetContainer extends FormulaireElement { private getTemplateIndex(id: string): number { let i = 0; for (const t of this._templates) { - if (t.config["id"] == id) + if (t.config["id"] == id) { return i; + } i++; } throw new Error(`template ${id} non trouvé`); @@ -99,10 +100,13 @@ export class FieldsetContainer extends FormulaireElement { const templates = data as any[]; const templateNames: string[] = json["templates"]; - for (const t of templateNames) - for (const d of templates) - if (d.id == t) + for (const t of templateNames) { + for (const d of templates) { + if (d.id == t) { this.addTemplate(d); + } + } + } } public updateLocalisation(loc: StringMap = this._localisation) { @@ -116,7 +120,7 @@ export class FieldsetContainer extends FormulaireElement { * sérialisation en JSON */ public JSONserialise(): {} { - let res = {}; + const res = {}; res["id"] = this.id; res["elements"] = this.serialiseKids(); return { "fieldset_container": res }; @@ -126,17 +130,20 @@ export class FieldsetContainer extends FormulaireElement { const ind = this.getTemplateIndex(elements["id"]); const res: FieldSet = this.addFromTemplate(ind); const props = elements["props"]; - for (const k in props) - if (k !== "calcType" && k !== "nodeType") + for (const k in props) { + if (k !== "calcType" && k !== "nodeType") { res.setPropValue(k, props[k]); + } + } res.deserialiseJSON(elements); return res; } private deserialiseElement(element: {}) { const keys = Object.keys(element); - if (keys.length !== 1) + if (keys.length !== 1) { throw new Error(`session file : invalid fieldset object '${element}'`); + } switch (keys[0]) { case "fieldset": @@ -159,8 +166,9 @@ export class FieldsetContainer extends FormulaireElement { break; case "elements": - for (const e of elements[k]) + for (const e of elements[k]) { this.deserialiseElement(e); + } break; default: diff --git a/src/app/formulaire/fieldset.ts b/src/app/formulaire/fieldset.ts index cfcd138fa17a735385f5a5213e55c2fba338f5fe..2dc15da680fd3ca00152f0d0b51edcb7ea2b4d88 100644 --- a/src/app/formulaire/fieldset.ts +++ b/src/app/formulaire/fieldset.ts @@ -44,29 +44,34 @@ export class FieldSet extends FormulaireElement implements Observer { public setSessionNub(sn: SessionNub, update: boolean = true) { this._sessionNub = sn; this._props.setProps(sn.properties, this); - if (update) + if (update) { this.updateFields(); + } } private addField(f: Field) { - if (f == undefined) + if (f == undefined) { throw new Error("FieldSet.addField() : argument incorrect (undefined)"); + } this.kids.push(f); } public get hasInputs(): boolean { - for (const f of this.kids) - if (f instanceof NgParameter) + for (const f of this.kids) { + if (f instanceof NgParameter) { return true; + } + } return false; } public getInput(i: number): NgParameter { let n = 0; - for (let f of this.kids) { + for (const f of this.kids) { if (f instanceof NgParameter) { - if (n == i) + if (n == i) { return f; + } n++; } } @@ -74,23 +79,25 @@ export class FieldSet extends FormulaireElement implements Observer { } public get isValid(): boolean { - let res: boolean = true; + let res = true; for (const f of this.kids) { - if (f instanceof Field) - if (f.isDisplayed) + if (f instanceof Field) { + if (f.isDisplayed) { res = res && f.isValid; + } + } } return res; } private parse_check(json: {}): CheckField { - let res: CheckField = new CheckField(this); - res.parseConfig(json) + const res: CheckField = new CheckField(this); + res.parseConfig(json); return res; } private parse_select(json: {}): SelectField { - let res: SelectField = new SelectField(this); + const res: SelectField = new SelectField(this); res.parseConfig(json); res.addObserver(this); return res; @@ -135,21 +142,22 @@ export class FieldSet extends FormulaireElement implements Observer { default: const nt: string = json["nodeType"]; - let nodeType: ComputeNodeType = nt == undefined ? this.getPropValue("nodeType") : ComputeNodeType[nt]; + const nodeType: ComputeNodeType = nt == undefined ? this.getPropValue("nodeType") : ComputeNodeType[nt]; if (nodeType === this.getPropValue("nodeType")) { // si le nodeType du paramètre est le même que celui du fieldset try { - var nubParam: ParamDefinition = this.getNubParamFromSymbol(input_id); + const nubParam: ParamDefinition = this.getNubParamFromSymbol(input_id); + } catch (e) { } - catch (e) { - } - if (nubParam) + if (nubParam) { res = new NgParameter(nubParam, this); + } } } - if (res) + if (res) { res.parseConfig(json, { "radioConfig": default_radio_config }); + } return res; } @@ -162,8 +170,9 @@ export class FieldSet extends FormulaireElement implements Observer { if (field["type"] === "input") { const default_radio_config = this._jsonConfig["option"]; const param = this.parse_input(field, default_radio_config); - if (param) // potentiellement undefined car certaines définitions de FieldSet comportent des paramètres qui ne sont pas tous affichés en même temps (cf. ouvrages //) + if (param) { // potentiellement undefined car certaines définitions de FieldSet comportent des paramètres qui ne sont pas tous affichés en même temps (cf. ouvrages //) this.addField(param); + } } else if (field["type"] === "select") { const param = this.parse_select(field); this.addField(param); @@ -175,20 +184,23 @@ export class FieldSet extends FormulaireElement implements Observer { } private clearFields() { - for (const n of this.kids) + for (const n of this.kids) { n.removeObserver(this); + } this.clearKids(); } public updateLocalisation(loc?: StringMap) { - if (loc == undefined) + if (loc == undefined) { loc = this._localisation; - else + } else { this._localisation = loc; + } - if (loc) + if (loc) { super.updateLocalisation(loc); + } } /** @@ -222,8 +234,7 @@ export class FieldSet extends FormulaireElement implements Observer { sf3.setValue(se3); break; } - } - else if (this._confId === "fs_section") { + } else if (this._confId === "fs_section") { const sf: SelectField = this.getFormulaireNodeById("select_section") as SelectField; const nt: ComputeNodeType = this.getPropValue("nodeType"); const se = sf.getSelectedEntryFromValue(nt); @@ -251,11 +262,13 @@ export class FieldSet extends FormulaireElement implements Observer { this.setPropValue("nodeType", node_type); const st: string = json["defaultStructType"]; - if (st) - this.setPropValue("structureType", StructureType[st]) + if (st) { + this.setPropValue("structureType", StructureType[st]); + } const ld: string = json["defaultLoiDebit"]; - if (ld) - this.setPropValue("loiDebit", LoiDebit[ld]) + if (ld) { + this.setPropValue("loiDebit", LoiDebit[ld]); + } this.updateFields(); } @@ -272,11 +285,12 @@ export class FieldSet extends FormulaireElement implements Observer { case "input": case "select": case "check": - for (const k of this.kids) + for (const k of this.kids) { if (k.id == field["id"]) { k.parseDependencies(field); break; } + } break; } } @@ -285,18 +299,22 @@ export class FieldSet extends FormulaireElement implements Observer { } public getNodeParameter(symbol: string): NgParameter { - for (const p of this.kids) - if (p instanceof NgParameter) - if (p.isDisplayed && p.symbol === symbol) + for (const p of this.kids) { + if (p instanceof NgParameter) { + if (p.isDisplayed && p.symbol === symbol) { return p; + } + } + } return undefined; } public getNodeParameterValue(symbol: string): number { const p = this.getNodeParameter(symbol); - if (p == undefined) + if (p == undefined) { throw new Error(`FieldSet.getNodeParameterValue() : pas de paramètre ${symbol} trouvé`); + } switch (p.radioState) { case ParamRadioConfig.FIX: @@ -314,11 +332,12 @@ export class FieldSet extends FormulaireElement implements Observer { * @returns valeur courante du select sans le préfixe */ public getSelectedValue(selectFieldId: string): string { - for (const p of this.kids) + for (const p of this.kids) { if (p instanceof SelectField && p.isDisplayed && p.id === selectFieldId) { const value: string = p.getValue().value; return FormulaireElement.removePrefix(value, selectFieldId + "_"); } + } return undefined; } @@ -355,7 +374,7 @@ export class FieldSet extends FormulaireElement implements Observer { * sérialisation en JSON */ public JSONserialise(): {} { - let res = {}; + const res = {}; res["id"] = this.id; res["props"] = this._props.props; res["elements"] = this.serialiseKids(); @@ -376,8 +395,9 @@ export class FieldSet extends FormulaireElement implements Observer { private deserialiseElement(element: {}) { const keys = Object.keys(element); - if (keys.length !== 1) + if (keys.length !== 1) { throw new Error(`session file : invalid fieldset object '${element}'`); + } switch (keys[0]) { case "param": @@ -407,8 +427,9 @@ export class FieldSet extends FormulaireElement implements Observer { break; case "elements": - for (const e of elements[k]) + for (const e of elements[k]) { this.deserialiseElement(e); + } break; default: diff --git a/src/app/formulaire/form-iterator/abstract-node-iterator.ts b/src/app/formulaire/form-iterator/abstract-node-iterator.ts index c7d726faf34e5b8c09b7ae2ab30bcf561b2c184b..f089870064405dbbb87bed59d0600e04a4585281 100644 --- a/src/app/formulaire/form-iterator/abstract-node-iterator.ts +++ b/src/app/formulaire/form-iterator/abstract-node-iterator.ts @@ -6,18 +6,20 @@ import { FormulaireNode } from "../formulaire-node"; export class AbstractFormulaireNodeIterator<T extends FormulaireNode> { private _array: T[] = []; - private _index: number = 0; + private _index = 0; constructor(n: FormulaireNode) { this.flatten(n.kids, this._array); } private flatten(input: FormulaireNode[], out: FormulaireNode[]) { - for (let fe of input) { - if (this.isIterable(fe)) + for (const fe of input) { + if (this.isIterable(fe)) { out.push(fe); - if (this.isDeepIterator()) + } + if (this.isDeepIterator()) { this.flatten(fe.kids, out); + } } } diff --git a/src/app/formulaire/formulaire-element.ts b/src/app/formulaire/formulaire-element.ts index 600475342cfa1de3dcb7816354ee837575ecbb6f..6933766e0ac491e997304af136818297768afbc8 100644 --- a/src/app/formulaire/formulaire-element.ts +++ b/src/app/formulaire/formulaire-element.ts @@ -1,4 +1,4 @@ -import { FormulaireNode } from "./formulaire-node" +import { FormulaireNode } from "./formulaire-node"; import { StringMap } from "../stringmap"; import { Dependency } from "./dependency/dependency"; import { DependencyCondition, DependencyConditionType } from "./dependency/dependency-condition"; diff --git a/src/app/formulaire/formulaire-node.ts b/src/app/formulaire/formulaire-node.ts index aca8ea0c153d692e0330f4f3f614fde0de569a62..8d84e222d67e486335bc91ee8afb6152d608b96a 100644 --- a/src/app/formulaire/formulaire-node.ts +++ b/src/app/formulaire/formulaire-node.ts @@ -1,4 +1,4 @@ -import { JalhydObject, IObservable, Observer, Observable } from "jalhyd" +import { JalhydObject, IObservable, Observer, Observable } from "jalhyd"; /** * représentation sous forme d'arbre du formulaire et de ses éléments @@ -33,7 +33,7 @@ export abstract class FormulaireNode implements IObservable { this._parentNode = parent; this._kids = []; this._uid = JalhydObject.nextUID; - this._observable = new Observable() + this._observable = new Observable(); } get id(): string { @@ -60,13 +60,15 @@ export abstract class FormulaireNode implements IObservable { * cherche un FormulaireNode par son id de conf */ public getFormulaireNodeById(id: string): FormulaireNode { - if (this.id === id) + if (this.id === id) { return this; + } for (const k of this._kids) { const res = k.getFormulaireNodeById(id); - if (res !== undefined) + if (res !== undefined) { return res; + } } return undefined; @@ -76,13 +78,15 @@ export abstract class FormulaireNode implements IObservable { * cherche un FormulaireNode par son id numérique unique */ public getFormulaireNodeByUid(uid: number): FormulaireNode { - if (this.uid == uid) + if (this.uid == uid) { return this; + } for (const k of this._kids) { const res = k.getFormulaireNodeByUid(uid); - if (res !== undefined) + if (res !== undefined) { return res; + } } return undefined; @@ -96,8 +100,9 @@ export abstract class FormulaireNode implements IObservable { private kidIndex(kid: FormulaireNode): number { let n = 0; for (const k of this._kids) { - if (k._uid == kid._uid) + if (k._uid == kid._uid) { return n; + } n++; } @@ -146,8 +151,9 @@ export abstract class FormulaireNode implements IObservable { protected serialiseKids() { const elems = []; - for (const k of this.kids) + for (const k of this.kids) { elems.push(k.JSONserialise()); + } return elems; } diff --git a/src/app/formulaire/input-field.ts b/src/app/formulaire/input-field.ts index 933e2c626a48567c335c6807cb7abb916af457a8..744e2240c187c3b6380b4ee50dbf974cfac1769c 100644 --- a/src/app/formulaire/input-field.ts +++ b/src/app/formulaire/input-field.ts @@ -1,4 +1,4 @@ -import { Field } from "./field" +import { Field } from "./field"; export abstract class InputField extends Field { private _value: any; diff --git a/src/app/formulaire/ngparam.ts b/src/app/formulaire/ngparam.ts index 7faa80945cfd3a510238fd838f3faa866603a4b9..d814a3a27b402177f5d05450e9b65dd5b95b4c7d 100644 --- a/src/app/formulaire/ngparam.ts +++ b/src/app/formulaire/ngparam.ts @@ -29,19 +29,12 @@ export enum ParamRadioConfig { * boutons radio "paramètre fixé", "paramètre à varier" et "paramètre à calculer", "paramètre lié" */ LINK -}; +} /** * classe englobante de ParamDefinition (champs supplémentaires pour l'affichage, radio boutons, ...) */ export class NgParameter extends InputField implements Observer { - public unit: string; - public radioConfig: ParamRadioConfig; - - /** - * true si ce paramètre est celui par défaut dans un formulaire (cf. fichier de conf des calculettes, objet "options", champ "idCal") - */ - public isDefault: boolean = false; // archi bug du langage ! si on relit cette propriété sans l'avoir modifiée entre-temps, elle vaut undefined ! constructor(private _paramDef: ParamDefinition, parent: FormulaireNode) { super(parent); @@ -55,10 +48,6 @@ export class NgParameter extends InputField implements Observer { return this._paramDef.getDomain(); } - public getValue() { - return this._paramDef.v; - } - public set confId(id: string) { if (this._confId != undefined) { throw new Error(`NgParameter : l'identifiant de configuration est déjà défini (${this._confId})`); @@ -91,6 +80,106 @@ export class NgParameter extends InputField implements Observer { } } + get isDefined(): boolean { + return this._paramDef.isDefined; + } + + public get valueMode() { + return this._paramDef.valueMode; + } + + public set valueMode(m: ParamValueMode) { + // undefined si on clique en dehors du select après l'avoir ouvert (cad sans avoir fait de sélection) + // et au même niveau, cad à côté du bouton et non à côté du menu déroulant + if (m !== undefined && this._paramDef.valueMode !== m) { + this.unlinkParameter(); + this._paramDef.valueMode = m; + this.notifyObservers({ + "action": "valueModeChange", + "value": this._paramDef.getValue() + }); + } + } + + public get isMinMaxValid(): boolean { + return this._paramDef.isMinMaxValid; + } + + public get minValue() { + return this._paramValues.min; + } + + public set minValue(v: number) { + this._paramValues.min = v; + } + + public get maxValue() { + return this._paramValues.max; + } + + public set maxValue(v: number) { + this._paramValues.max = v; + } + + public get stepRefValue(): Pair { + return this._paramValues.stepRefValue; + } + + public get stepValue() { + return this._paramValues.step; + } + + public set stepValue(v: number) { + this._paramValues.step = v; + } + + public get valueList() { + return this._paramValues.valueList; + } + + public set valueList(l: number[]) { + this._paramValues.valueList = l; + } + + public get isValid() { + if (this.radioState === undefined) { + return false; + } + + return this._paramDef.isValid; + } + + public get valuesIterator(): NumberIterator { + return this._paramDef.valuesIterator; + } + public unit: string; + public radioConfig: ParamRadioConfig; + + /** + * true si ce paramètre est celui par défaut dans un formulaire (cf. fichier de conf des calculettes, objet "options", champ "idCal") + */ + public isDefault = false; // archi bug du langage ! si on relit cette propriété sans l'avoir modifiée entre-temps, elle vaut undefined ! + + private static getRadioConfig(s: string) { + if (s == "fix") { + return ParamRadioConfig.FIX; + } + + if (s == "var") { + return ParamRadioConfig.VAR; + } + + if (s == "cal") { + return ParamRadioConfig.CAL; + } + + throw new Error("invalid parameter radio configuration " + s); + } + + public getValue() { + return this._paramDef.v; + } + /** * notification envoyée après la modification de la valeur du paramètre */ @@ -120,7 +209,7 @@ export class NgParameter extends InputField implements Observer { * supprime un lien avec un paramètre */ private unlinkParameter() { - let o = asObservable(this._paramDef.referencedObject); + const o = asObservable(this._paramDef.referencedObject); if (this.valueMode === ParamValueMode.LINK) { this._paramDef.undefineReference(); if (o !== undefined) { @@ -157,37 +246,16 @@ export class NgParameter extends InputField implements Observer { } } - get isDefined(): boolean { - return this._paramDef.isDefined; - } - public checkValue(val: number) { this._paramDef.checkValue(val); } public checkList(l: number[]) { - for (let e of l) { + for (const e of l) { this.checkValue(e); } } - public get valueMode() { - return this._paramDef.valueMode; - } - - public set valueMode(m: ParamValueMode) { - // undefined si on clique en dehors du select après l'avoir ouvert (cad sans avoir fait de sélection) - // et au même niveau, cad à côté du bouton et non à côté du menu déroulant - if (m !== undefined && this._paramDef.valueMode !== m) { - this.unlinkParameter(); - this._paramDef.valueMode = m; - this.notifyObservers({ - "action": "valueModeChange", - "value": this._paramDef.getValue() - }); - } - } - public checkMin(min: number): boolean { return this._paramDef.checkMin(min); } @@ -196,94 +264,36 @@ export class NgParameter extends InputField implements Observer { return this._paramDef.checkMax(max); } - public get isMinMaxValid(): boolean { - return this._paramDef.isMinMaxValid; - } - - public get minValue() { - return this._paramValues.min; - } - - public set minValue(v: number) { - this._paramValues.min = v; - } - - public get maxValue() { - return this._paramValues.max; - } - - public set maxValue(v: number) { - this._paramValues.max = v; - } - public checkStep(step: number): boolean { return this._paramDef.checkStep(step); } - public get stepRefValue(): Pair { - return this._paramValues.stepRefValue; - } - - public get stepValue() { - return this._paramValues.step; - } - - public set stepValue(v: number) { - this._paramValues.step = v; - } - - public get valueList() { - return this._paramValues.valueList; - } - - public set valueList(l: number[]) { - this._paramValues.valueList = l; - } - - public get isValid() { - if (this.radioState === undefined) - return false; - - return this._paramDef.isValid; - } - - private static getRadioConfig(s: string) { - if (s == "fix") - return ParamRadioConfig.FIX; - - if (s == "var") - return ParamRadioConfig.VAR; - - if (s == "cal") - return ParamRadioConfig.CAL; - - throw "invalid parameter radio configuration " + s; - } - public parseConfig(json: {}, data?: {}) { const appSetupService: ApplicationSetupService = ServiceFactory.instance.applicationSetupService; const radioConfig: string = data["radioConfig"]; this._confId = json["id"]; this.unit = json["unit"]; - if (this.symbol == "Pr") - var val = appSetupService.computePrecision; - else + if (this.symbol == "Pr") { + const val = appSetupService.computePrecision; + } else { val = json["value"]; - if (val != undefined) + } + if (val != undefined) { this.setValue(this, +val); + } this.radioConfig = NgParameter.getRadioConfig(radioConfig); this.isDefault = false; // malgré le fait qu'il soit initialisé dans la déclaration de la classe NgParam à false, quand on relit sa valeur, il vaut undefined (merci Microsoft) } public verifiesDependency(d: Dependency): boolean { - if (super.verifiesDependency(d)) + if (super.verifiesDependency(d)) { return true; + } switch (d.masterCondition.type) { - case DependencyConditionType.HasValue: - { - let mc: ValueDependencyCondition = <ValueDependencyCondition>d.masterCondition; + case DependencyConditionType.HasValue: { + const mc: ValueDependencyCondition = <ValueDependencyCondition>d.masterCondition; return this.getValue() === mc.value; } @@ -291,16 +301,12 @@ export class NgParameter extends InputField implements Observer { return this.radioState == ParamRadioConfig.VAR; default: - throw "NgParameter.verifiesDependency() : type de condition '" + DependencyConditionType[d.masterCondition.type] + "' non pris en charge"; + throw new Error("NgParameter.verifiesDependency() : type de condition '" + DependencyConditionType[d.masterCondition.type] + "' non pris en charge"); } } - public get valuesIterator(): NumberIterator { - return this._paramDef.valuesIterator; - } - private paramValuesJSON(): any { - let res = {}; + const res = {}; const vm = this._paramDef.valueMode; res["mode"] = ParamValueMode[vm]; switch (vm) { @@ -325,7 +331,7 @@ export class NgParameter extends InputField implements Observer { * sérialisation en JSON */ public JSONserialise(): {} { - let res = {}; + const res = {}; res["id"] = this.id; res["values"] = this.paramValuesJSON(); return { "param": res }; diff --git a/src/app/formulaire/select-entry.ts b/src/app/formulaire/select-entry.ts index dc552ff9f6a52b09ba4f0625fa0f15f6781cc0bc..5d15f205f686139047ef4ed0e540b04b70053362 100644 --- a/src/app/formulaire/select-entry.ts +++ b/src/app/formulaire/select-entry.ts @@ -32,7 +32,7 @@ export class SelectEntry { * sérialisation en JSON */ public JSONserialise() { - let res = {}; + const res = {}; res["id"] = this.id; res["value"] = this._value; return res; diff --git a/src/app/formulaire/select-field.ts b/src/app/formulaire/select-field.ts index 916fee39c058dff6a2c0a6723517f2a470a0f7d7..d4a95b3387031cc4529da354227ce7bbf5a19d4d 100644 --- a/src/app/formulaire/select-field.ts +++ b/src/app/formulaire/select-field.ts @@ -24,14 +24,17 @@ export class SelectField extends Field { public addEntry(e: SelectEntry) { this._entries.push(e); - if (this._selectedEntry == undefined) + if (this._selectedEntry == undefined) { this._selectedEntry = e; + } } public getSelectedEntryFromValue(val: any): SelectEntry { - for (const se of this._entries) - if (se.value === val) + for (const se of this._entries) { + if (se.value === val) { return se; + } + } return undefined; } @@ -54,29 +57,31 @@ export class SelectField extends Field { } public getLabel() { - if (this._selectedEntry == undefined) + if (this._selectedEntry == undefined) { return undefined; + } return this._selectedEntry.label; } public verifiesDependency(d: Dependency): boolean { - if (super.verifiesDependency(d)) + if (super.verifiesDependency(d)) { return true; + } switch (d.masterCondition.type) { case DependencyConditionType.HasValue: - let mc: ValueDependencyCondition = <ValueDependencyCondition>d.masterCondition; + const mc: ValueDependencyCondition = <ValueDependencyCondition>d.masterCondition; return this._selectedEntry.id === mc.value; default: - throw "SelectField.verifiesDependency() : type de condition '" + DependencyConditionType[d.masterCondition.type] + "' non pris en charge"; + throw new Error("SelectField.verifiesDependency() : type de condition '" + DependencyConditionType[d.masterCondition.type] + "' non pris en charge"); } } public updateLocalisation(loc: StringMap) { super.updateLocalisation(loc); - for (let e of this._entries) { + for (const e of this._entries) { e.label = loc[e.id]; } } @@ -108,9 +113,9 @@ export class SelectField extends Field { default: throw new Error(`type d'enum ${tmp[0]} non pris en charge`); } - } - else if (v.value) + } else if (v.value) { val = v.value; + } const id = v["id"]; const e: SelectEntry = new SelectEntry(id, val); @@ -122,7 +127,7 @@ export class SelectField extends Field { * sérialisation en JSON */ public JSONserialise(): {} { - let res = {}; + const res = {}; res["id"] = this.id; res["selected_id"] = this._selectedEntry.id; return { "select": res }; @@ -140,11 +145,12 @@ export class SelectField extends Field { case "selected_id": const sel = elements[k]; - for (const e of this._entries) + for (const e of this._entries) { if (e.id === sel) { this._selectedEntry = e; break; } + } break; default: diff --git a/src/app/results/calculator-results.ts b/src/app/results/calculator-results.ts index be987f97425c0355e3c1cec675c3a6ad6e530349..935a2303534bdb080d81c1f03e15a6db8690342f 100644 --- a/src/app/results/calculator-results.ts +++ b/src/app/results/calculator-results.ts @@ -29,4 +29,4 @@ export abstract class CalculatorResults { * indique si il existe des résultats à afficher */ public abstract get hasResults(): boolean; -} \ No newline at end of file +} diff --git a/src/app/results/param-calc-results.ts b/src/app/results/param-calc-results.ts index dadbf0f384324721ae2e6c883ab7af52023a4f28..3c768a3da21161250948f828e647320dffee43c7 100644 --- a/src/app/results/param-calc-results.ts +++ b/src/app/results/param-calc-results.ts @@ -54,14 +54,16 @@ export abstract class CalculatedParamResults extends CalculatorResults { } public get hasResults(): boolean { - if (this._result == undefined) + if (this._result == undefined) { return false; + } return this._result.ok; } public get hasLog(): boolean { - if (this._result == undefined) + if (this._result == undefined) { return false; + } return this._result.hasLog; } diff --git a/src/app/results/remous-results.ts b/src/app/results/remous-results.ts index ec7d5ef9c09c35f803dc8e60f04bf48f4c992187..fdcdadd6971f3d225ff45881ccb3285a20ef1b45 100644 --- a/src/app/results/remous-results.ts +++ b/src/app/results/remous-results.ts @@ -123,12 +123,15 @@ export class RemousResults extends CalculatorResults { this._hasExtra = false; for (const re of this._result.resultElements) { - if (!this._hasFlu && re.getExtraResult("flu")) + if (!this._hasFlu && re.getExtraResult("flu")) { this._hasFlu = true; - if (!this._hasTor && re.getExtraResult("tor")) + } + if (!this._hasTor && re.getExtraResult("tor")) { this._hasTor = true; - if (!this._hasExtra && re.getExtraResult(this.extraParamSymbol)) + } + if (!this._hasExtra && re.getExtraResult(this.extraParamSymbol)) { this._hasExtra = true; + } } this._log.addLog(this._result.globalLog); @@ -137,13 +140,16 @@ export class RemousResults extends CalculatorResults { this._varResults.variatedParameter = new NgParameter(this._xValues, undefined); this._varResults.calculatedParameter = new NgParameter(new ParamDefinition("Ligne d'eau", ParamDomainValue.POS_NULL), undefined); this._varResults.result = this._result; - let keys = []; - if (this._hasFlu) + const keys = []; + if (this._hasFlu) { keys.push("flu"); - if (this._hasTor) + } + if (this._hasTor) { keys.push("tor"); - if (this._hasExtra) + } + if (this._hasExtra) { keys.push(this.extraParamSymbol); + } this._varResults.extraResultKeys = keys; this._varResults.update(true); } diff --git a/src/app/results/var-results.ts b/src/app/results/var-results.ts index 4a39c1c9a7f8812d3f70408d155963d64bd6fe08..4776f5d8837a41013655fb42cb618e8bf34f8064 100644 --- a/src/app/results/var-results.ts +++ b/src/app/results/var-results.ts @@ -117,25 +117,32 @@ export class VarResults extends CalculatedParamResults { } public update(displaySymbol: boolean) { - if (this._variableParamHeader === undefined) + if (this._variableParamHeader === undefined) { this._variableParamHeader = CalculatorResults.paramLabel(this.variatedParameter, displaySymbol); + } // valeurs du paramètre à calculer - for (const r of this._result.resultElements) + for (const r of this._result.resultElements) { this._yValues.push(r.vCalc); + } // clés des résultats supplémentaires - if (this._extraResultKeys.length === 0) - for (const re of this._result.resultElements) // re:ResultElement - for (const erk in re.extraResults) - if (!this._extraResultKeys.includes(erk)) + if (this._extraResultKeys.length === 0) { + for (const re of this._result.resultElements) { // re:ResultElement + for (const erk in re.extraResults) { + if (!this._extraResultKeys.includes(erk)) { this._extraResultKeys.push(erk); + } + } + } + } // entêtes des résultats supplémentaires const intlService = ServiceFactory.instance.internationalisationService; - for (const k of this._extraResultKeys) + for (const k of this._extraResultKeys) { this._extraResultHeaders.push(intlService.getExtraResLabel(k)); + } } } diff --git a/src/app/services/error/error.service.ts b/src/app/services/error/error.service.ts index 128ce234fcef7622d0c34702ec65938531463762..70dfcd798f74a05a192bd9e64d915a7ce3347bed 100644 --- a/src/app/services/error/error.service.ts +++ b/src/app/services/error/error.service.ts @@ -1,4 +1,4 @@ -import { Injectable } from '@angular/core'; +import { Injectable } from "@angular/core"; import { Observable } from "jalhyd"; diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 66dc6c198f9d0baba61f2461c02a3bd31c0a857f..54c0aa890ae39c1a76d0ca572aff294e3bc9165f 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -1,5 +1,5 @@ -import {map} from 'rxjs/operators'; +import {map} from "rxjs/operators"; import { Injectable } from "@angular/core"; import { Response } from "@angular/http"; import { Observable as rxObservable } from "rxjs"; @@ -52,7 +52,7 @@ export class FormulaireService extends Observable { } private loadLocalisation(calc: CalculatorType): Promise<any> { - const f: string = this.getConfigPathPrefix(calc) + this._intlService.currentLanguage.tag + ".json" + const f: string = this.getConfigPathPrefix(calc) + this._intlService.currentLanguage.tag + ".json"; const prom = this._httpService.httpGetRequestPromise(undefined, undefined, undefined, f); return prom.then((j) => { @@ -66,7 +66,7 @@ export class FormulaireService extends Observable { * @param localisation ensemble id-message traduit */ private updateFormulaireLocalisation(formId: number, localisation: StringMap) { - for (let f of this._formulaires) { + for (const f of this._formulaires) { if (f.uid === formId) { f.updateLocalisation(localisation); break; @@ -147,7 +147,7 @@ export class FormulaireService extends Observable { break; default: - throw new Error(`FormulaireService.newFormulaire() : type de calculette ${CalculatorType[ct]} non pris en charge`) + throw new Error(`FormulaireService.newFormulaire() : type de calculette ${CalculatorType[ct]} non pris en charge`); } f.defaultProperties["calcType"] = ct; @@ -164,7 +164,7 @@ export class FormulaireService extends Observable { const f: FormulaireDefinition = this.newFormulaire(ct); this._formulaires.push(f); - let prom: Promise<any> = this.loadConfig(ct); + const prom: Promise<any> = this.loadConfig(ct); return prom.then(s => { f.preparseConfig(JSON.parse(s)); return f; @@ -201,56 +201,68 @@ export class FormulaireService extends Observable { } public getFormulaireFromId(uid: number): FormulaireDefinition { - for (let f of this._formulaires) - if (f.uid === uid) + for (const f of this._formulaires) { + if (f.uid === uid) { return f; + } + } return undefined; } public getInputField(formId: number, elemId: string): InputField { const s = this.getFormulaireElementById(formId, elemId); - if (!(s instanceof InputField)) - throw "Form element with id '" + elemId + "' is not an input"; + if (!(s instanceof InputField)) { + throw new Error("Form element with id '" + elemId + "' is not an input"); + } return <InputField>s; } public getCheckField(formId: number, elemId: string): CheckField { const s = this.getFormulaireElementById(formId, elemId); - if (!(s instanceof CheckField)) + if (!(s instanceof CheckField)) { throw new Error("Form element with id '" + elemId + "' is not a checkbox"); + } return <CheckField>s; } public getSelectField(formId: number, elemId: string): SelectField { const s = this.getFormulaireElementById(formId, elemId); - if (!(s instanceof SelectField)) + if (!(s instanceof SelectField)) { throw new Error("Form element with id '" + elemId + "' is not a select"); + } return <SelectField>s; } private getFormulaireElementById(formId: number, elemId: string): FormulaireElement { - for (let f of this._formulaires) + for (const f of this._formulaires) { if (f.uid === formId) { const s = f.getFormulaireNodeById(elemId); - if (s !== undefined) + if (s !== undefined) { return s as FormulaireElement; + } } + } return undefined; } public getParamdefParentForm(prm: ParamDefinition): FormulaireDefinition { - for (const f of this._formulaires) - for (const p of f.allFormElements) - if (p instanceof NgParameter) - if (p.paramDefinition.uid === prm.uid) + for (const f of this._formulaires) { + for (const p of f.allFormElements) { + if (p instanceof NgParameter) { + if (p.paramDefinition.uid === prm.uid) { return f; + } + } + } + } return undefined; } public getConfigPathPrefix(ct: CalculatorType): string { - if (ct === undefined) - throw new Error("FormulaireService.getConfigPathPrefix() : invalid undefined CalculatorType") + if (ct === undefined) { + throw new Error("FormulaireService.getConfigPathPrefix() : invalid undefined CalculatorType"); + } switch (ct) { case CalculatorType.ConduiteDistributrice: @@ -287,7 +299,7 @@ export class FormulaireService extends Observable { return "app/calculators/cloisons/cloisons."; default: - throw new Error("FormulaireService.getConfigPathPrefix() : valeur de CalculatorType " + ct + " non implémentée") + throw new Error("FormulaireService.getConfigPathPrefix() : valeur de CalculatorType " + ct + " non implémentée"); } } @@ -330,8 +342,9 @@ export class FormulaireService extends Observable { public get currentFormHasResults(): boolean { const form = this.currentForm; - if (form !== undefined) + if (form !== undefined) { return form.hasResults; + } return false; } @@ -361,7 +374,7 @@ export class FormulaireService extends Observable { public loadSession(f: File, formInfos: any[]) { this.readSingleFile(f).then(s => { const session = JSON.parse(s); - for (const k in session) + for (const k in session) { switch (k) { case "session": this.deserialiseSession(session[k], formInfos); @@ -370,6 +383,7 @@ export class FormulaireService extends Observable { default: throw new Error(`session file : invalid key '${k}'`); } + } }).catch(err => { throw err; }); @@ -390,22 +404,25 @@ export class FormulaireService extends Observable { const session = JSON.parse(s); // liste des noms de calculettes - for (const k in session) + for (const k in session) { switch (k) { case "session": const sess = session[k]; const elems = sess["elements"]; - for (const e of elems) - for (const k in e) + for (const e of elems) { + for (const k in e) { if (k === "form") { const form = e[k]; res.push({ "uid": form["uid"], "title": form["id"] }); } + } + } break; default: throw new Error(`session file : invalid key '${k}'`); } + } return res; }); } @@ -425,16 +442,19 @@ export class FormulaireService extends Observable { private deserialiseSessionElement(element: {}, formInfos: any[]) { const keys = Object.keys(element); - if (keys.length !== 1) + if (keys.length !== 1) { throw new Error(`session file : invalid session object '${element}'`); + } switch (keys[0]) { case "form": const form = element[keys[0]]; - for (const i of formInfos) - if (i["uid"] === form["uid"] && i["selected"]) + for (const i of formInfos) { + if (i["uid"] === form["uid"] && i["selected"]) { this.deserialiseForm(form); + } + } break; default: @@ -443,16 +463,18 @@ export class FormulaireService extends Observable { } private deserialiseSession(elements: {}, formInfos: any[]) { - for (const ks in elements) + for (const ks in elements) { switch (ks) { case "elements": - for (const e of elements[ks]) + for (const e of elements[ks]) { this.deserialiseSessionElement(e, formInfos); + } break; default: throw new Error(`session file : invalid key '${ks}' in session object`); } + } } /** @@ -463,7 +485,7 @@ export class FormulaireService extends Observable { public getLinkableValues(p: NgParameter): any[] { const res: any[] = []; - if (p !== undefined) + if (p !== undefined) { for (const f of this._formulaires) { // nub associé au formulaire const sn = f.currentSessionNub; @@ -481,11 +503,11 @@ export class FormulaireService extends Observable { np["formTitle"] = f.calculatorName; res.push(np); } - } - catch (e) { + } catch (e) { // p.symbol n'existe pas dans le nub testé } } + } return res; } @@ -508,16 +530,20 @@ export class FormulaireService extends Observable { // ... on cherche s'il est affiché dans son parent let found = false; - if (parentForm !== undefined) - for (const fe of parentForm.allFormElements) - if (fe instanceof NgParameter) + if (parentForm !== undefined) { + for (const fe of parentForm.allFormElements) { + if (fe instanceof NgParameter) { if (fe.paramDefinition.uid === prm.uid) { found = true; break; } + } + } + } - if (!found) + if (!found) { values.splice(i, 1); + } } } diff --git a/src/app/services/param/param.service.ts b/src/app/services/param/param.service.ts index 8d935405c354b19cd8ee7715dbe4c31a134b5368..d915cd71219b1441855d8d8e260c253ca979a75b 100644 --- a/src/app/services/param/param.service.ts +++ b/src/app/services/param/param.service.ts @@ -20,7 +20,7 @@ export class ParamService { private createAccuracyParameter(): ParamDefinition { const d = new ParamDomain(ParamDomainValue.INTERVAL, 1e-10, 100); - const p = new ParamDefinition('Pr', d, this._appSetupService.computePrecision); + const p = new ParamDefinition("Pr", d, this._appSetupService.computePrecision); p.calculability = ParamCalculability.FREE; return p; }