diff --git a/README.md b/README.md index 2af2e1c504bf0ba772f8d8c654ea305d23991c51..4692536a011f4b9785e1844193e222fa557f22cf 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ and then : * Ajouter une valeur à l'enum _CalculatorType_ pour identifier le type de calculette (par ex _MaCalculette_). -* Compléter la méthode _NubFactory.createNub()_. +* Compléter la méthode _Session.createNub()_. ## ngHyd @@ -152,7 +152,7 @@ and then : - dans _src/app/calculators/ma-calculette_ : Créer _ma-calculette.config.json_ sur le modèle des autres. - Les ids utilisés doivent correspondre au symbole fourni à classe _BaseParam_ (1er paramètre du constructeur) + Les ids utilisés doivent correspondre au symbole fourni à classe _ParamDefinition_ (1er paramètre du constructeur) Ne pas oublier de spécifier : - éventuellement le type de noeud par défaut de la calculette dans les options avec le champ "_defaultNodeType_". Si ce champ est absent, sa valeur est "_ComputeNodeType.None_". Ce champ sert par ex pour les sections paramétrées à déterminer le type de section à afficher lors de la création de la calculette. diff --git a/jalhyd_branch b/jalhyd_branch index 1f7391f92b6a3792204e07e99f71f643cc35e7e1..bd388944e1091e13962974ce434774f09d31464e 100644 --- a/jalhyd_branch +++ b/jalhyd_branch @@ -1 +1 @@ -master +58-nettoyage-et-simplification-du-code diff --git a/package-lock.json b/package-lock.json index b064a6bfa4e54c461f1ec990477f39c9ac00bbca..9e1268ce06f2562df19427e00b7e6e4f994e5267 100644 --- a/package-lock.json +++ b/package-lock.json @@ -133,7 +133,7 @@ "dependencies": { "source-map": { "version": "0.5.6", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz", + "resolved": "http://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz", "integrity": "sha1-dc449SvwczxafwwRjYEzSiu19BI=", "dev": true }, @@ -1873,7 +1873,7 @@ }, "util": { "version": "0.10.3", - "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", + "resolved": "http://registry.npmjs.org/util/-/util-0.10.3.tgz", "integrity": "sha1-evsa/lCAUkZInj23/g7TeTNqwPk=", "dev": true, "requires": { @@ -4073,7 +4073,7 @@ }, "source-map": { "version": "0.2.0", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.2.0.tgz", + "resolved": "http://registry.npmjs.org/source-map/-/source-map-0.2.0.tgz", "integrity": "sha1-2rc/vPwrqBm03gO9b26qSBZLP50=", "dev": true, "optional": true, @@ -6716,7 +6716,7 @@ }, "resolve": { "version": "1.1.7", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", + "resolved": "http://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz", "integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=", "dev": true }, @@ -6921,7 +6921,7 @@ }, "jalhyd": { "version": "file:../jalhyd/jalhyd-1.0.0.tgz", - "integrity": "sha512-2/Os2o1wZUuPZqE6cdtyFpMr+13XGG2VXuwfIYwx4MqJKnvyKNIoBGpbo/t77ca+izUuh7n+SB1HxjK00fszQQ==" + "integrity": "sha512-ieqqCYVkbBnMqFCkVBnnfYH0ANM4VLpymdyRmcrN580L1WziUgQqFSmXNFXY4q/4TeAncO3R+2PeI79KrYHYMQ==" }, "jasmine": { "version": "2.8.0", @@ -7751,7 +7751,7 @@ }, "load-json-file": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", + "resolved": "http://registry.npmjs.org/load-json-file/-/load-json-file-1.1.0.tgz", "integrity": "sha1-lWkFcI1YtLq0wiYbBPWfMcmTdMA=", "dev": true, "requires": { @@ -8173,7 +8173,7 @@ }, "meow": { "version": "3.7.0", - "resolved": "https://registry.npmjs.org/meow/-/meow-3.7.0.tgz", + "resolved": "http://registry.npmjs.org/meow/-/meow-3.7.0.tgz", "integrity": "sha1-cstmi0JSKCkKu/qFaJJYcwioAfs=", "dev": true, "optional": true, @@ -8615,7 +8615,7 @@ "dependencies": { "semver": { "version": "5.3.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.3.0.tgz", + "resolved": "http://registry.npmjs.org/semver/-/semver-5.3.0.tgz", "integrity": "sha1-myzl094C0XxgEq0yaqa00M9U+U8=", "dev": true, "optional": true @@ -8713,7 +8713,7 @@ }, "supports-color": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "resolved": "http://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", "dev": true, "optional": true @@ -9172,7 +9172,7 @@ }, "os-locale": { "version": "1.4.0", - "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", + "resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz", "integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=", "dev": true, "optional": true, @@ -9436,7 +9436,7 @@ }, "parse-asn1": { "version": "5.1.1", - "resolved": "https://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.1.tgz", + "resolved": "http://registry.npmjs.org/parse-asn1/-/parse-asn1-5.1.1.tgz", "integrity": "sha512-KPx7flKXg775zZpnp9SxJlz00gTd4BmJ2yJufSc44gMCRrRQ7NSzAcSJQfifuOLgW6bEi+ftrALtsgALeB2Adw==", "dev": true, "requires": { @@ -9529,7 +9529,7 @@ }, "path-browserify": { "version": "0.0.0", - "resolved": "https://registry.npmjs.org/path-browserify/-/path-browserify-0.0.0.tgz", + "resolved": "http://registry.npmjs.org/path-browserify/-/path-browserify-0.0.0.tgz", "integrity": "sha1-oLhwcpquIUAFt9UDLsLLuw+0RRo=", "dev": true }, @@ -10271,7 +10271,7 @@ }, "raw-loader": { "version": "0.5.1", - "resolved": "https://registry.npmjs.org/raw-loader/-/raw-loader-0.5.1.tgz", + "resolved": "http://registry.npmjs.org/raw-loader/-/raw-loader-0.5.1.tgz", "integrity": "sha1-DD0L6u2KAclm2Xh793goElKpeao=", "dev": true }, @@ -10768,7 +10768,7 @@ "dependencies": { "source-map": { "version": "0.4.4", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "resolved": "http://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", "dev": true, "optional": true, @@ -10963,7 +10963,7 @@ }, "sha.js": { "version": "2.4.11", - "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", + "resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==", "dev": true, "requires": { @@ -11574,7 +11574,7 @@ }, "stream-browserify": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz", + "resolved": "http://registry.npmjs.org/stream-browserify/-/stream-browserify-2.0.1.tgz", "integrity": "sha1-ZiZu5fm9uZQKTkUUyvtDu3Hlyds=", "dev": true, "requires": { @@ -11622,7 +11622,7 @@ }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", + "resolved": "http://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", "dev": true, "requires": { @@ -11637,7 +11637,7 @@ }, "string_decoder": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", + "resolved": "http://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", "dev": true, "requires": { @@ -11772,13 +11772,13 @@ }, "sax": { "version": "0.5.8", - "resolved": "https://registry.npmjs.org/sax/-/sax-0.5.8.tgz", + "resolved": "http://registry.npmjs.org/sax/-/sax-0.5.8.tgz", "integrity": "sha1-1HLbIo6zMcJQaw6MFVJK25OdEsE=", "dev": true }, "source-map": { "version": "0.1.43", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz", + "resolved": "http://registry.npmjs.org/source-map/-/source-map-0.1.43.tgz", "integrity": "sha1-wkvBRspRfBRx9drL4lcbK3+eM0Y=", "dev": true, "requires": { @@ -11821,7 +11821,7 @@ }, "tar": { "version": "2.2.1", - "resolved": "https://registry.npmjs.org/tar/-/tar-2.2.1.tgz", + "resolved": "http://registry.npmjs.org/tar/-/tar-2.2.1.tgz", "integrity": "sha1-jk0qJWwOIYXGsYrWlK7JaLg8sdE=", "dev": true, "optional": true, @@ -12352,7 +12352,7 @@ }, "tty-browserify": { "version": "0.0.0", - "resolved": "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", + "resolved": "http://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz", "integrity": "sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=", "dev": true }, @@ -12754,7 +12754,7 @@ }, "vm-browserify": { "version": "0.0.4", - "resolved": "https://registry.npmjs.org/vm-browserify/-/vm-browserify-0.0.4.tgz", + "resolved": "http://registry.npmjs.org/vm-browserify/-/vm-browserify-0.0.4.tgz", "integrity": "sha1-XX6kW7755Kb/ZflUOOCofDV9WnM=", "dev": true, "requires": { @@ -12859,7 +12859,7 @@ }, "source-map": { "version": "0.4.4", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", + "resolved": "http://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", "integrity": "sha1-66T12pwNyZneaAMti092FzZSA2s=", "dev": true, "requires": { 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 f879a787b01580e72c5b0b0199826001cebc2598..8144f03d7d98e0861c8946980a46b773988e682d 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 @@ -1,19 +1,18 @@ // cf. https://blog.thoughtram.io/angular/2016/07/27/custom-form-controls-in-angular-2.html -import { Component, Input, forwardRef, OnInit, DoCheck, ChangeDetectorRef } from "@angular/core"; -import { ControlValueAccessor, NG_VALUE_ACCESSOR, NG_VALIDATORS, FormControl } from "@angular/forms"; +import { Component, ChangeDetectorRef } from "@angular/core"; -import { BaseParam, NumericalString, Message, ParamDomain, ParamDomainValue, Observable } from "jalhyd"; +import { NumericalString, Message, ParamDefinition, ParamDomain, ParamDomainValue, Observable } from "jalhyd"; -import { InternationalisationService, LanguageCode } from "../../services/internationalisation/internationalisation.service"; +import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; import { GenericInputComponent } from "../generic-input/generic-input.component"; export class NgBaseParam extends Observable { - private _param: BaseParam; + private _param: ParamDefinition; constructor(symb: string, d: ParamDomain | ParamDomainValue, val: number) { super(); - this._param = new BaseParam(symb, d, val); + this._param = new ParamDefinition(symb, d, val); } public get symbol() { diff --git a/src/app/components/generic-input/generic-input.component.ts b/src/app/components/generic-input/generic-input.component.ts index f392282fbf554d0d9403413e36b4b6a0cfd287be..e5513138b57a21d92d89b82c262a947ab8cfd775 100644 --- a/src/app/components/generic-input/generic-input.component.ts +++ b/src/app/components/generic-input/generic-input.component.ts @@ -360,7 +360,7 @@ export class TestInputComponent extends GenericInputComponent { // exemple où le modèle est une classe dont on ne gère qu'un membre -import { BaseParam } from "jalhyd"; +import { ParamDefinition } from "jalhyd"; @Component({ selector: "test2-input", @@ -376,7 +376,7 @@ export class Test2InputComponent extends GenericInputComponent { } // paramètre géré - private get _param(): BaseParam { + private get _param(): ParamDefinition { return this._model; } 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 ab389e306968b4905f20b2fde719057cfc451b58..65263d2c0f29ca9c8d3fa63c427784b25dd2b1c9 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 @@ -294,7 +294,7 @@ export class ParamFieldLineComponent implements OnChanges { // 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; + const ps: ParallelStructure = this._formService.formulaires[0].currentNub as ParallelStructure; if (ps.structures.length > 1) { return this._formService.filterLinkableValues(this._formService.getLinkableValues(this.param)).length > 0; } diff --git a/src/app/components/remous-results/remous-results.component.ts b/src/app/components/remous-results/remous-results.component.ts index bbcbd0e13170881424d4d5cd4184588e40fec287..290ae0548dcf768e0c49845303483651810f3d47 100644 --- a/src/app/components/remous-results/remous-results.component.ts +++ b/src/app/components/remous-results/remous-results.component.ts @@ -1,6 +1,6 @@ import { Component, ViewChild } from "@angular/core"; -import { ArrayReverseIterator, ResultElement, NumberIterator } from "jalhyd"; +import { ArrayReverseIterator, ResultElement, INumberIterator } from "jalhyd"; import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; import { LogComponent } from "../../components/log/log.component"; @@ -164,7 +164,7 @@ export class RemousResultsComponent { return false; } - private get abscisseIterator(): NumberIterator { + private get abscisseIterator(): INumberIterator { return this._remousResults.varResults.variatedParameter.paramDefinition.paramValues.getValuesIterator(); } diff --git a/src/app/formulaire/definition/concrete/form-cond-distri.ts b/src/app/formulaire/definition/concrete/form-cond-distri.ts index 9229f2ce6e364acf9829ffde10c94f9e1cc40c77..5f648a73a4482fee9d05dd42252d3497d16177d7 100644 --- a/src/app/formulaire/definition/concrete/form-cond-distri.ts +++ b/src/app/formulaire/definition/concrete/form-cond-distri.ts @@ -1,5 +1,4 @@ import { FormDefFixedVar } from "../form-def-fixedvar"; -import { CalculatorType, ComputeNodeType } from "jalhyd"; import { FormResultFixedVar } from "../form-result-fixedvar"; import { FormulaireDefinition } from "../form-definition"; import { CalculatorResults } from "../../../results/calculator-results"; @@ -7,7 +6,8 @@ import { FormDefParamToCalculate } from "../form-def-paramcalc"; import { FormComputeFixedVar } from "../form-compute-fixedvar"; export class FormulaireConduiteDistributrice extends FormulaireDefinition { - private _formFixedVar: FormDefFixedVar; + + // private _formFixedVar: FormDefFixedVar; private _formParamCalc: FormDefParamToCalculate; @@ -17,7 +17,7 @@ export class FormulaireConduiteDistributrice extends FormulaireDefinition { constructor() { super(); - this._formFixedVar = new FormDefFixedVar(this); + // this._formFixedVar = new FormDefFixedVar(this); this._formParamCalc = new FormDefParamToCalculate(this); this._formResult = new FormResultFixedVar(this, false); this._formCompute = new FormComputeFixedVar(this, this._formResult); diff --git a/src/app/formulaire/definition/concrete/form-courbe-remous.ts b/src/app/formulaire/definition/concrete/form-courbe-remous.ts index 12bf975997807b12280ed6bd180872c8aa8b55f0..2789da339cc20b63ed17e9c810c528ff3698e95b 100644 --- a/src/app/formulaire/definition/concrete/form-courbe-remous.ts +++ b/src/app/formulaire/definition/concrete/form-courbe-remous.ts @@ -1,4 +1,4 @@ -import { CalculatorType, ComputeNodeType, IObservable } from "jalhyd"; +import { IObservable } from "jalhyd"; import { FormResultRemous } from "../form-result-remous"; import { FormDefSection } from "../form-def-section"; @@ -66,12 +66,12 @@ export class FormulaireCourbeRemous extends FormulaireDefinition { // interface Observer update(sender: IObservable, data: any) { - if (sender instanceof FieldSet && data.action == "propertyChange") { + if (sender instanceof FieldSet && data.action === "propertyChange") { switch (sender.id) { case "fs_section": - this.replaceCurrentSessionNub(sender.properties); + this.replaceCurrentNub(sender.properties); for (const fs of this.allFieldsets) { - fs.setSessionNub(this._currentSessionNub); + fs.setNub(this._currentNub); } this.reset(); break; diff --git a/src/app/formulaire/definition/concrete/form-parallel-structures.ts b/src/app/formulaire/definition/concrete/form-parallel-structures.ts index 1b47a27c0a7dc609216f3c465d42ee8442003fa5..4d5697248f5612f0a8fa5eb16aa24ac64d12132a 100644 --- a/src/app/formulaire/definition/concrete/form-parallel-structures.ts +++ b/src/app/formulaire/definition/concrete/form-parallel-structures.ts @@ -1,4 +1,4 @@ -import { CalculatorType, ComputeNodeType, Structure, ParallelStructure, SessionNub, StructureType, LoiDebit, StructureProperties, Props } from "jalhyd"; +import { Structure, Nub, ParallelStructure, StructureType, LoiDebit, StructureProperties, Props } from "jalhyd"; import { FormulaireDefinition } from "../form-definition"; import { CalculatorResults } from "../../../results/calculator-results"; @@ -15,7 +15,8 @@ import { FieldsetTemplate } from "../../fieldset-template"; import { FormulaireNode } from "../../formulaire-node"; export class FormulaireParallelStructure extends FormulaireDefinition { - private _formFixedVar: FormDefFixedVar; + + // private _formFixedVar: FormDefFixedVar; private _formParallelStruct: FormDefParallelStructures; @@ -32,14 +33,14 @@ export class FormulaireParallelStructure extends FormulaireDefinition { constructor() { super(); - this._formFixedVar = new FormDefFixedVar(this); + // this._formFixedVar = new FormDefFixedVar(this); this._formParamCalc = new FormDefParamToCalculate(this); this._formResult = new FormResultFixedVar(this, false); this._formParallelStruct = new FormDefParallelStructures(); this._formCompute = new FormComputeParallelStructures(this, this._formParallelStruct, this._formResult); } - private createStructNub(templ: FieldsetTemplate): SessionNub { + private createStructNub(templ: FieldsetTemplate): Nub { // !!! attention !!! // Il doit y avoir cohérence dans le fichier de conf entre les valeurs defaultXXX et les valeurs possibles pour les select // cad valeur par défaut du 1er select (type d'ouvrage), du 2ème (loi de débit). @@ -51,7 +52,7 @@ export class FormulaireParallelStructure extends FormulaireDefinition { params["structureType"] = templ.defaultStructTypeFromConfig; params["loiDebit"] = templ.defaultLoiDebitFromConfig; - return this.createSessionNub(params); + return this.createNub(params); } /** @@ -64,7 +65,7 @@ export class FormulaireParallelStructure extends FormulaireDefinition { } private get parallelStructureNub(): ParallelStructure { - return this.currentSessionNub.nub as ParallelStructure; + return this.currentNub as ParallelStructure; } public createFieldset(parent: FormulaireNode, json: {}, data?: {}): FieldSet { @@ -74,8 +75,8 @@ export class FormulaireParallelStructure extends FormulaireDefinition { const res: FieldSet = new FieldSet(parent); const sn = this.createStructNub(data["template"]); - this.addStructureNub(sn.nub as Structure, after); - res.setSessionNub(sn, false); + this.addStructureNub(sn as Structure, after); + res.setNub(sn, false); if (after !== undefined) { parent.kids.splice(after + 1, 0, res); @@ -114,22 +115,22 @@ export class FormulaireParallelStructure extends FormulaireDefinition { } public moveFieldsetUp(fs: FieldSet) { - if (fs.sessionNub.nub instanceof Structure) { + if (fs.nub instanceof Structure) { // déplacement du nub - this._paramService.moveStructureNubUp(fs.sessionNub); - + fs.nub.parent.moveStructureUp(fs.nub); // déplacement du fieldset this.fieldsetContainer.moveFieldsetUp(fs); this.resetResults(); - } else { super.moveFieldsetUp(fs); } + } else { + super.moveFieldsetUp(fs); + } } public moveFieldsetDown(fs: FieldSet) { - if (fs.sessionNub.nub instanceof Structure) { + if (fs.nub instanceof Structure) { // déplacement du nub - this._paramService.moveStructureNubDown(fs.sessionNub); - + fs.nub.parent.moveStructureDown(fs.nub); // déplacement du fieldset this.fieldsetContainer.moveFieldsetDown(fs); @@ -138,9 +139,9 @@ export class FormulaireParallelStructure extends FormulaireDefinition { } public removeFieldset(fs: FieldSet) { - if (fs.sessionNub.nub instanceof Structure) { + if (fs.nub instanceof Structure) { // suppression du nub - this._paramService.deleteSessionNub(fs.sessionNub); + this._paramService.deleteNub(fs.nub); // suppression du fieldset this.fieldsetContainer.removeFieldset(fs); @@ -185,7 +186,7 @@ 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; @@ -266,6 +267,7 @@ export class FormulaireParallelStructure extends FormulaireDefinition { const loidebitSelect = this.findObjectWithDependency(fs.jsonConfig["fields"], structSelect.select.id, structSelect.entry.id); if (loidebitSelect === undefined || loidebitSelect["type"] !== "select") { + // tslint:disable-next-line:max-line-length 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)`); } @@ -280,6 +282,7 @@ export class FormulaireParallelStructure extends FormulaireDefinition { } if (loisDebit.length === 0) { + // tslint:disable-next-line:max-line-length 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)`); } @@ -299,8 +302,10 @@ export class FormulaireParallelStructure extends FormulaireDefinition { * @param val nouvelle valeur de la propriété */ private adjustProperties(fs: FieldSet, name: string, val: any): Props { - // 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) + // 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"))) { return this.adjustLoiDebit(fs, val); @@ -352,12 +357,12 @@ export class FormulaireParallelStructure extends FormulaireDefinition { 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"]); - const newNub = this.replaceSessionNub(sender.sessionNub, props); - sender.setSessionNub(newNub); + const newNub = this.replaceNub(sender.nub, props); + sender.setNub(newNub); this.reset(); break; } diff --git a/src/app/formulaire/definition/concrete/form-regime-uniforme.ts b/src/app/formulaire/definition/concrete/form-regime-uniforme.ts index e821225d29039aca3b21c718a75c3e5bcb80f03e..b7549d6764dfdb11b89f4b6e65f90b4871981aec 100644 --- a/src/app/formulaire/definition/concrete/form-regime-uniforme.ts +++ b/src/app/formulaire/definition/concrete/form-regime-uniforme.ts @@ -78,10 +78,10 @@ export class FormulaireRegimeUniforme extends FormulaireDefinition implements Ob update(sender: IObservable, data: any) { // 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); + if (sender instanceof FieldSet && sender.id === "fs_section" && data.action === "propertyChange") { + this.replaceCurrentNub(sender.properties); for (const fs of this.allFieldsets) { - fs.setSessionNub(this._currentSessionNub); + fs.setNub(this._currentNub); } 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 1e5a9301e22e577c470d28e753ed9d003743aa76..5b2e2bd2d29f3564f37d141ae3f8364fc464aea9 100644 --- a/src/app/formulaire/definition/concrete/form-section-parametree.ts +++ b/src/app/formulaire/definition/concrete/form-section-parametree.ts @@ -66,12 +66,12 @@ export class FormulaireSectionParametree extends FormulaireDefinition { update(sender: IObservable, data: any) { // changement de propriété du FieldSet contenant le select de choix du type de section - if (sender instanceof FieldSet && data.action == "propertyChange") { + if (sender instanceof FieldSet && data.action === "propertyChange") { switch (sender.id) { case "fs_section": - this.replaceCurrentSessionNub(sender.properties); + this.replaceCurrentNub(sender.properties); for (const fs of this.allFieldsets) { - fs.setSessionNub(this._currentSessionNub); + fs.setNub(this._currentNub); } 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 ebd833cc027a1144eda7da408f1a9e7285cdbe8c..6d996a2ab4af797a509ba2407534dc9d4f7f1080 100644 --- a/src/app/formulaire/definition/form-compute-courbe-remous.ts +++ b/src/app/formulaire/definition/form-compute-courbe-remous.ts @@ -18,7 +18,7 @@ export class FormComputeCourbeRemous extends FormCompute { } protected compute() { - const cr: CourbeRemous = this._formBase.currentSessionNub.nub as CourbeRemous; + const cr: CourbeRemous = this._formBase.currentNub as CourbeRemous; const prmCR: CourbeRemousParams = cr.parameters as CourbeRemousParams; const sect: acSection = prmCR.Sn; diff --git a/src/app/formulaire/definition/form-compute-fixedvar.ts b/src/app/formulaire/definition/form-compute-fixedvar.ts index 837e1eea9ba1a4cba24574539c6b7949f8c404de..873488018729347e8e215267e12933ac9a3eda7f 100644 --- a/src/app/formulaire/definition/form-compute-fixedvar.ts +++ b/src/app/formulaire/definition/form-compute-fixedvar.ts @@ -44,7 +44,7 @@ export class FormComputeFixedVar extends FormCompute { } protected compute() { - const nub: Nub = this._formBase.currentSessionNub.nub; + const nub: Nub = this._formBase.currentNub; let computePrec: number; if (this._formBase.hasParameter("Pr")) { computePrec = this._formBase.getParameterValue("Pr"); // précision de calcul diff --git a/src/app/formulaire/definition/form-compute-section-parametree.ts b/src/app/formulaire/definition/form-compute-section-parametree.ts index c31b941c14e9c6ab0c0476460411e58ddb81562a..5466762f0bad187cbcb20606afcf09461853ac23 100644 --- a/src/app/formulaire/definition/form-compute-section-parametree.ts +++ b/src/app/formulaire/definition/form-compute-section-parametree.ts @@ -1,12 +1,10 @@ -import { SectionParametree, acSection, ParamsEquation, ComputeNode, Result, ParamValueMode, Nub, ParamsSection, CalculatorType, SessionNub } from "jalhyd"; +import { SectionParametree, acSection } from "jalhyd"; import { FormCompute } from "./form-compute"; import { NgParameter } from "../ngparam"; import { FormResult } from "./form-result"; -import { Form } from "@angular/forms"; import { FormDefSection } from "./form-def-section"; import { FormResultSection } from "./form-result-section"; -import { InputField } from "../input-field"; import { FixedResults } from "../../results/fixed-results"; import { VarResults } from "../../results/var-results"; import { SectionResults } from "../../results/section-results"; @@ -51,7 +49,7 @@ export class FormComputeSectionParametree extends FormCompute { // paramètre à calculer en fonction du paramètre à varier const computedParamInfo = this._formSection.getSectionComputedParam(); - const sectNub: SectionParametree = this._formBase.currentSessionNub.nub as SectionParametree; + const sectNub: SectionParametree = this._formBase.currentNub as SectionParametree; const sect: acSection = sectNub.section; const prms = sectNub.parameters; @@ -71,12 +69,12 @@ export class FormComputeSectionParametree extends FormCompute { protected compute() { const varParam = this._formSection.getSectionVariatedParameter(); - if (varParam != undefined) { + if (varParam !== undefined) { this.doComputeSectionVar(varParam); return; } - const sectNub: SectionParametree = this._formBase.currentSessionNub.nub as SectionParametree; + const sectNub: SectionParametree = this._formBase.currentNub as SectionParametree; const sect: acSection = sectNub.section; this._sectionResults.section = sect; diff --git a/src/app/formulaire/definition/form-compute.ts b/src/app/formulaire/definition/form-compute.ts index 63d5460cefeaebe46e5d95669dcaddbf9025572e..6d9b33ea20285e770a68cf981789972c2b3eece5 100644 --- a/src/app/formulaire/definition/form-compute.ts +++ b/src/app/formulaire/definition/form-compute.ts @@ -1,4 +1,4 @@ -import { ParamValueMode, Nub, Result, ParamDomainValue, ParamDomain, SessionNub } from "jalhyd"; +import { Nub, Result, ParamDomainValue } from "jalhyd"; import { FormResult } from "./form-result"; import { FormulaireDefinition } from "./form-definition"; diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index ea579d10df796caa2a07c9dacaac8aa0b4d8a58b..0985db9573718d1191c0209954853ff407fce753 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -1,4 +1,4 @@ -import { CalculatorType, ComputeNodeType, ParamDefinition, SessionNub, Props, Observer } from "jalhyd"; +import { CalculatorType, ComputeNodeType, Nub, ParamDefinition, Props, Observer } from "jalhyd"; import { FormulaireElement } from "../formulaire-element"; import { NgParameter, ParamRadioConfig } from "../ngparam"; @@ -25,12 +25,12 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs private _calculatorName: string; /** - * SessionNub courant + * Nub courant */ - protected _currentSessionNub: SessionNub; + protected _currentNub: Nub; /** - * propriétés par défaut (lues si _currentSessionNub === undefined ) + * propriétés par défaut (lues si _currentNub === undefined ) */ private _props = {}; @@ -52,12 +52,12 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs } public get calculatorType(): CalculatorType { - const props = this._currentSessionNub === undefined ? this.defaultProperties : this._currentSessionNub.properties.props; + const props = this._currentNub === undefined ? this.defaultProperties : (this._currentNub.properties as Props).props; return props["calcType"]; } public get nodeType(): ComputeNodeType { - const props = this._currentSessionNub === undefined ? this.defaultProperties : this._currentSessionNub.properties.props; + const props = this._currentNub === undefined ? this.defaultProperties : (this._currentNub.properties as Props).props; return props["nodeType"]; } @@ -82,68 +82,39 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs return this._props; } - public initSessionNub(props?: {}) { - this._currentSessionNub = this.createSessionNub(props === undefined ? this.defaultProperties : props); + public initNub(props?: {}) { + this._currentNub = this.createNub(props === undefined ? this.defaultProperties : props); } - public get currentSessionNub(): SessionNub { - return this._currentSessionNub; + public get currentNub(): Nub { + return this._currentNub; } - public set currentSessionNub(n: SessionNub) { - if (this._props["calcType"] !== n.properties.getPropValue("calcType")) { + public set currentNub(n: Nub) { + const nubCalcType = (n.properties as Props).getPropValue("calcType"); + if (this._props["calcType"] !== nubCalcType) { throw new Error( `Nub ${n.properties["calcType"]} incompatible avec le formulaire ${this._calculatorName} (${this._props["calcType"]})` ); } - this._currentSessionNub = n; + this._currentNub = n; } - private findNub(params: Props | {}) { - return this._paramService.findSessionNub(params); + protected createNub(params: Props | {}): Nub { + const props = params instanceof Props ? params : new Props(params); + return this._paramService.createNub(props); } - protected createSessionNub(params: Props | {}): SessionNub { - return this._paramService.createSessionNub(params); + protected replaceCurrentNub(params: Props) { + this.currentNub = this._paramService.replaceNub(this._currentNub, params); } - /** - * @return le Nub associé à un type de noeud donné, le crée si nécessaire - * @param params paramètres de contexte de création du nub - */ - protected getSessionNub(params: Props | {}): SessionNub { - let res = this.findNub(params); - if (!res) { - res = this.createSessionNub(params); - } - return res; - } - - protected replaceCurrentSessionNub(params: Props) { - this.currentSessionNub = this._paramService.replaceSessionNub(this._currentSessionNub, params); - } - - protected replaceSessionNub(sn: SessionNub, params: Props): SessionNub { - return this._paramService.replaceSessionNub(sn, params); + protected replaceNub(sn: Nub, params: Props): Nub { + return this._paramService.replaceNub(sn, params); } - /** - * @return le paramètre d'un type de noeud - * @param symbol symbole du paramètre - * @param params paramètres de contexte de création du nub - */ - protected getNubParamFromSymbol(symbol: string, params: Props | {}): ParamDefinition { - const sessionNub: SessionNub = this.getSessionNub(params); - - if (sessionNub) { - return sessionNub.nub.getParameter(symbol); - } - - throw new Error(`FormulaireDefinition.getNubParamFromSymbol() : pas de Nub trouvé pour ${params}`); - } - - protected deleteSessionNub(sn: SessionNub) { - this._paramService.deleteSessionNub(sn); + protected deleteNub(sn: Nub) { + this._paramService.deleteNub(sn); } protected initParse() { @@ -171,7 +142,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs public createFieldset(parent: FormulaireNode, json: {}, data?: {}): FieldSet { const res: FieldSet = new FieldSet(parent); - res.setSessionNub(this._currentSessionNub, false); + res.setNub(this._currentNub, false); this.kids.push(res); return res; } @@ -292,7 +263,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs // console.log("-----"); - // for (const n of NubFactory.getInstance().sessionNubIterator) { + // for (const n of Session.getInstance().NubIterator) { // console.log(n.nub); // for (const p of n.nub.parameterIterator) // console.log(`${p.symbol} uid ${p.uid} props ${n.properties} mode ${p.valueMode} val ${p.uncheckedValue}`); @@ -300,7 +271,6 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs // logObject(this._fieldSets, "fieldsets"); // logObject(this._dependencies, "dependences"); - this.parseDependencies(this._jsonConfig); } @@ -489,7 +459,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs const res = {}; res["id"] = this.calculatorName; res["uid"] = this.uid; - res["props"] = this._currentSessionNub.properties.props; + res["props"] = (this._currentNub.properties as Props).props; res["elements"] = this.serialiseKids(); return { "form": res }; } diff --git a/src/app/formulaire/fieldset.ts b/src/app/formulaire/fieldset.ts index 97484a8186ee32ca3775923a9e3eeee675c32279..f69701b00eaa7adb0dfed353ebd4197b70b68520 100644 --- a/src/app/formulaire/fieldset.ts +++ b/src/app/formulaire/fieldset.ts @@ -1,4 +1,4 @@ -import { CalculatorType, ComputeNodeType, ParamDefinition, LoiDebit, StructureType, Props, SessionNub, Observer } from "jalhyd"; +import { CalculatorType, ComputeNodeType, ParamDefinition, LoiDebit, StructureType, Props, Observer, Nub } from "jalhyd"; import { FormulaireElement } from "./formulaire-element"; import { Field } from "./field"; @@ -13,9 +13,9 @@ import { FormulaireNode } from "./formulaire-node"; export class FieldSet extends FormulaireElement implements Observer { /** - * SessionNub associé + * Nub associé */ - private _sessionNub: SessionNub; + private _nub: Nub; /** * dictionnaire de traduction @@ -37,13 +37,13 @@ export class FieldSet extends FormulaireElement implements Observer { this._props = new Props(); } - public get sessionNub(): SessionNub { - return this._sessionNub; + public get nub(): Nub { + return this._nub; } - public setSessionNub(sn: SessionNub, update: boolean = true) { - this._sessionNub = sn; - this._props.setProps(sn.properties, this); + public setNub(sn: Nub, update: boolean = true) { + this._nub = sn; + this._props.setProps(sn.properties || new Props({}), this); if (update) { this.updateFields(); } @@ -116,7 +116,7 @@ export class FieldSet extends FormulaireElement implements Observer { } private getNubParamFromSymbol(symbol: string): ParamDefinition { - return this._sessionNub.nub.getParameter(symbol); + return this._nub.getParameter(symbol); } public get jsonConfig(): {} { @@ -206,7 +206,7 @@ export class FieldSet extends FormulaireElement implements Observer { } /** - * @param createOrUpdate true pour forcer la création d'un SessionNub + * @param createOrUpdate true pour forcer la création d'un Nub */ private updateFields() { this.clearFields(); diff --git a/src/app/formulaire/ngparam.ts b/src/app/formulaire/ngparam.ts index 4ea578ea0f72c8bb17b60a44649d5d4a7dc62e25..50125790a4fd68293ae9ae70ebc2d952eb698f0b 100644 --- a/src/app/formulaire/ngparam.ts +++ b/src/app/formulaire/ngparam.ts @@ -1,4 +1,4 @@ -import { ParamDefinition, Pair, ParamDomain, ParamValueMode, NumberIterator, Nub, Observer, asObservable } from "jalhyd"; +import { Interval, ParamDefinition, ParamDomain, ParamValueMode, INumberIterator, Nub, Observer, asObservable } from "jalhyd"; import { InputField } from "./input-field"; import { Dependency } from "./dependency/dependency"; @@ -6,7 +6,6 @@ import { DependencyConditionType } from "./dependency/dependency-condition"; import { ValueDependencyCondition } from "./dependency/value-dependency-condition"; import { ServiceFactory } from "../services/service-factory"; import { ApplicationSetupService } from "../services/app-setup/app-setup.service"; -import { StringMap } from "../stringmap"; import { FormulaireNode } from "./formulaire-node"; export enum ParamRadioConfig { @@ -121,7 +120,7 @@ export class NgParameter extends InputField implements Observer { this._paramValues.max = v; } - public get stepRefValue(): Pair { + public get stepRefValue(): Interval { return this._paramValues.stepRefValue; } @@ -149,7 +148,7 @@ export class NgParameter extends InputField implements Observer { return this._paramDef.isValid; } - public get valuesIterator(): NumberIterator { + public get valuesIterator(): INumberIterator { return this._paramDef.valuesIterator; } public unit: string; @@ -388,7 +387,7 @@ export class NgParameter extends InputField implements Observer { public update(sender: any, data: any) { switch (data["action"]) { - case "baseparamAfterValue": // changement de valeur envoyé par l'objet référencé + case "paramdefinitionAfterValue": // changement de valeur envoyé par l'objet référencé this.notifyValueModified(sender); break; } diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 385f056c856f350a64682474e09116e39bc9ed10..3fbec68f3b0a400e1edce4c870ba0d959934aca6 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -169,7 +169,7 @@ export class FormulaireService extends Observable { if (jsonState === undefined) { fi.calculatorName = decode(this.getLocalisedTitleFromCalculatorType(ct) + " (" + fi.uid + ")"); } - fi.initSessionNub(); + fi.initNub(); return fi; }).then(fi => { fi.parseConfig(undefined); @@ -485,17 +485,17 @@ export class FormulaireService extends Observable { if (p !== undefined) { for (const f of this._formulaires) { // nub associé au formulaire - const sn = f.currentSessionNub; + const sn = f.currentNub; try { // on vérifie que le paramètre en entrée appartient au nub - const np = sn.nub.getParameter(p.symbol); + const np = sn.getParameter(p.symbol); // si oui, on demande à exclure des valeurs retournées le résultat du même nom que le paramètre const exclude = np !== undefined ? p.paramDefinition.uid === np.uid : false; // valeurs liables - const ps = sn.getLinkableValues(p.paramDefinition, exclude); + const ps = sn.getLinkableValues(p.paramDefinition, undefined, exclude); for (const npp of ps) { npp["formTitle"] = f.calculatorName; res.push(npp); diff --git a/src/app/services/param/param.service.ts b/src/app/services/param/param.service.ts index d915cd71219b1441855d8d8e260c253ca979a75b..6e5362f391f07f5c3e99f459234c852ecebec92a 100644 --- a/src/app/services/param/param.service.ts +++ b/src/app/services/param/param.service.ts @@ -1,7 +1,6 @@ -import { ParamDomain, ParamDefinition, ParamDomainValue, ParamCalculability, NubFactory, SessionNub, Props } from "jalhyd"; +import { ParamDomain, ParamDefinition, ParamDomainValue, ParamCalculability, Session, Props, Nub } from "jalhyd"; import { NgParameter } from "../../formulaire/ngparam"; -import { FormulaireDefinition } from "../../formulaire/definition/form-definition"; import { Injectable } from "@angular/core"; import { ServiceFactory } from "../service-factory"; import { InternationalisationService } from "../internationalisation/internationalisation.service"; @@ -92,27 +91,16 @@ export class ParamService { return p; } - public createSessionNub(params: Props | {}): SessionNub { - return NubFactory.getInstance().createSessionNub(params); + public createNub(params: Props | {}): Nub { + const truc = Session.getInstance().createSessionNub(params); + return truc; } - public findSessionNub(params: Props | {}): SessionNub { - return NubFactory.getInstance().findSessionNub(params); + public replaceNub(sn: Nub, params: Props): Nub { + return Session.getInstance().replaceNub(sn, params); } - public replaceSessionNub(sn: SessionNub, params: Props): SessionNub { - return NubFactory.getInstance().replaceSessionNub(sn, params); - } - - public moveStructureNubUp(sn: SessionNub) { - NubFactory.getInstance().moveStructureNubUp(sn); - } - - public moveStructureNubDown(sn: SessionNub) { - NubFactory.getInstance().moveStructureNubDown(sn); - } - - public deleteSessionNub(sn: SessionNub) { - NubFactory.getInstance().deleteSessionNub(sn); + public deleteNub(sn: Nub) { + Session.getInstance().deleteNub(sn); } }