diff --git a/README.md b/README.md index 54070a9d34681191a59d095548fc98f8a062d9b6..ac570727fdf5060fd9b44bda43ea8ffa68aba105 100644 --- a/README.md +++ b/README.md @@ -146,8 +146,9 @@ and then : Les ids utilisés doivent correspondre au symbole fourni à classe _BaseParam_ (1er paramètre du constructeur) Ne pas oublier de spécifier : - - - éventuellement le type de noeud de paramètres particuliers (objets comportant _"type":"input"_) avec le champ _"nodeType": "MaCalculetteBleue"_ + - é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. + + - éventuellement le type de noeud de paramètres particuliers (objets comportant _"type":"input"_) avec le champ _"nodeType": "MaCalculetteBleue"_ (par défaut, "_ComputeNodeType.None_") - dans _src/app/calculators/ma-calculette_ : @@ -167,8 +168,6 @@ and then : On peut soit composer la classe concrète directement avec ces classes, soient dériver ces dernières et composer avec. - - dans cette classe, surcharger la méthode _defaultProperties()_ (abstraite dans _FormulaireDefinition_) pour préciser le type de calculette (CalculatorType) et de noeud (ComputeNodeType) et éventuellement d'autres propriétés (cf. _FormulaireParallelStructure_). - * _src/locale/error_messages.<langue>.json_ : Ajouter un champ pour le titre de la calculette. Par exemple : _"INFO_MACALC_TITRE": "Ma calculette"_ diff --git a/src/app/calculators/regime-uniforme/regime-uniforme.config.json b/src/app/calculators/regime-uniforme/regime-uniforme.config.json index 7286a71d854c26253d79f644a1ee23f176901b13..0ef1396598aa2451def98876cfc22b23b3808f3e 100644 --- a/src/app/calculators/regime-uniforme/regime-uniforme.config.json +++ b/src/app/calculators/regime-uniforme/regime-uniforme.config.json @@ -152,6 +152,7 @@ }, { "type": "options", + "defaultNodeType": "SectionCercle", "idCal": "Q", "sectionSourceId": "fs_section" } diff --git a/src/app/calculators/remous/remous.config.json b/src/app/calculators/remous/remous.config.json index 289a274e1025d7b6fcda32c5556734efe79fba3c..592621d45ceafbaf28b1e91c907f114d5984796c 100644 --- a/src/app/calculators/remous/remous.config.json +++ b/src/app/calculators/remous/remous.config.json @@ -260,6 +260,7 @@ }, { "type": "options", + "defaultNodeType": "SectionPuissance", "sectionSourceId": "select_section", "targetSelectId": "select_target", "methodSelectId": "select_resolution" diff --git a/src/app/calculators/section-param/section-param.config.json b/src/app/calculators/section-param/section-param.config.json index 56ea1dd3cb265ab2e03c10c0fa9cd8689157168e..7c8a769ec32f0f93d9194b448edfa2958dc33587 100644 --- a/src/app/calculators/section-param/section-param.config.json +++ b/src/app/calculators/section-param/section-param.config.json @@ -274,6 +274,7 @@ }, { "type": "options", + "defaultNodeType": "SectionCercle", "sectionSourceId": "select_section", "targetSelectId": "select_target" } diff --git a/src/app/formulaire/definition/concrete/form-cond-distri.ts b/src/app/formulaire/definition/concrete/form-cond-distri.ts index c9e70be83fe041ed100de2532b4b64ff14f2303e..9229f2ce6e364acf9829ffde10c94f9e1cc40c77 100644 --- a/src/app/formulaire/definition/concrete/form-cond-distri.ts +++ b/src/app/formulaire/definition/concrete/form-cond-distri.ts @@ -23,10 +23,6 @@ export class FormulaireConduiteDistributrice extends FormulaireDefinition { this._formCompute = new FormComputeFixedVar(this, this._formResult); } - protected get defaultProperties(): {} { - return { "calcType": CalculatorType.ConduiteDistributrice, "nodeType": ComputeNodeType.None }; - } - protected initParse() { this._formParamCalc.initParse(); } diff --git a/src/app/formulaire/definition/concrete/form-courbe-remous.ts b/src/app/formulaire/definition/concrete/form-courbe-remous.ts index d67e9bf24054149d46a542a767382dd6d4ede2ab..c4653bbace083e3b72966a065e931accb31f74b2 100644 --- a/src/app/formulaire/definition/concrete/form-courbe-remous.ts +++ b/src/app/formulaire/definition/concrete/form-courbe-remous.ts @@ -27,11 +27,8 @@ export class FormulaireCourbeRemous extends FormulaireDefinition { this._formCompute = new FormComputeCourbeRemous(this, this._formSection, this._formResult); } - protected get defaultProperties(): {} { - return { "calcType": CalculatorType.CourbeRemous, "nodeType": ComputeNodeType.SectionPuissance }; - } - protected parseOptions(json: {}) { + super.parseOptions(json); this._formSection.parseOptions(json); // id du select configurant la méthode de résolution diff --git a/src/app/formulaire/definition/concrete/form-dever.ts b/src/app/formulaire/definition/concrete/form-dever.ts index f99c0ffb95c25ab86daf90f912ab4fa2f0f418cd..01543d811a6e4bcfe339a30468428352587a45f4 100644 --- a/src/app/formulaire/definition/concrete/form-dever.ts +++ b/src/app/formulaire/definition/concrete/form-dever.ts @@ -9,11 +9,4 @@ export class FormulaireDever extends FormulaireParallelStructure { constructor() { super(); } - - protected get defaultProperties(): {} { - return { - "calcType": CalculatorType.Dever, "nodeType": ComputeNodeType.None, - "structureType": StructureType.SeuilRectangulaire, "loiDebit": LoiDebit.WeirFree - }; - } } diff --git a/src/app/formulaire/definition/concrete/form-lechapt-calmon.ts b/src/app/formulaire/definition/concrete/form-lechapt-calmon.ts index 96d6fad59683bc4d6cc15cd03e1ce2d7eeac1c0d..04427e3db3008c31e8955cc00ea4364916731526 100644 --- a/src/app/formulaire/definition/concrete/form-lechapt-calmon.ts +++ b/src/app/formulaire/definition/concrete/form-lechapt-calmon.ts @@ -25,10 +25,6 @@ export class FormulaireLechaptCalmon extends FormulaireDefinition implements Obs this._formCompute = new FormComputeFixedVar(this, this._formResult); } - protected get defaultProperties(): {} { - return { "calcType": CalculatorType.LechaptCalmon, "nodeType": ComputeNodeType.None }; - } - protected initParse() { this._formParamCalc.initParse(); } diff --git a/src/app/formulaire/definition/concrete/form-parallel-structures.ts b/src/app/formulaire/definition/concrete/form-parallel-structures.ts index 64b83a279ce560209b0e082d6d5ec8400af48637..32bf51d115ce7cb60a4e231471dee9cf52e635fd 100644 --- a/src/app/formulaire/definition/concrete/form-parallel-structures.ts +++ b/src/app/formulaire/definition/concrete/form-parallel-structures.ts @@ -39,13 +39,6 @@ export class FormulaireParallelStructure extends FormulaireDefinition { this._formCompute = new FormComputeParallelStructures(this, this._formParallelStruct, this._formResult); } - protected get defaultProperties(): {} { - return { - "calcType": CalculatorType.ParallelStructure, "nodeType": ComputeNodeType.None, - "structureType": StructureType.SeuilRectangulaire, "loiDebit": LoiDebit.Cem88v - }; - } - private createStructNub(templ: FieldsetTemplate): SessionNub { // valeurs par défaut de CalculatorType, ComputeNodeType, StructureType, LoiDebit // !!! attention !!! pour l'instant, il doit y avoir cohérence entre ces valeurs et celles du fichier de conf @@ -96,6 +89,8 @@ export class FormulaireParallelStructure extends FormulaireDefinition { } protected parseOptions(json: {}) { + super.parseOptions(json); + // id du select configurant le type d'ouvrage this.__ouvrageSelectId = this.getOption(json, "ouvrageSelectId"); } 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 64a5141cdb1703b8f874265783afcd5b9dfff25c..bb7de04b6cf375f3e3aad38d2e96834e34ead84f 100644 --- a/src/app/formulaire/definition/concrete/form-passe-bassin-dim.ts +++ b/src/app/formulaire/definition/concrete/form-passe-bassin-dim.ts @@ -24,10 +24,6 @@ export class FormulairePasseBassinDimensions extends FormulaireDefinition { this._formCompute = new FormComputeFixedVar(this, this._formResult); } - protected get defaultProperties(): {} { - return { "calcType": CalculatorType.PabDimensions, "nodeType": ComputeNodeType.None }; - } - protected initParse() { this._formParamCalc.initParse(); } 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 31d2a86390c4ffa51a2822bfbabee50653ad66d5..ba57242df8937f4a065fa58c74fc5a9dc46199d3 100644 --- a/src/app/formulaire/definition/concrete/form-passe-bassin-puissance.ts +++ b/src/app/formulaire/definition/concrete/form-passe-bassin-puissance.ts @@ -24,10 +24,6 @@ export class FormulairePasseBassinPuissance extends FormulaireDefinition { this._formCompute = new FormComputeFixedVar(this, this._formResult); } - protected get defaultProperties(): {} { - return { "calcType": CalculatorType.PabPuissance, "nodeType": ComputeNodeType.None }; - } - protected initParse() { this._formParamCalc.initParse(); } diff --git a/src/app/formulaire/definition/concrete/form-regime-uniforme.ts b/src/app/formulaire/definition/concrete/form-regime-uniforme.ts index 50e7aeff7b5e5cc3f8f0eca81db18a7c88969f78..db3fd0e698109c5bdfe1fb55a1ef8e936ad96818 100644 --- a/src/app/formulaire/definition/concrete/form-regime-uniforme.ts +++ b/src/app/formulaire/definition/concrete/form-regime-uniforme.ts @@ -28,15 +28,16 @@ export class FormulaireRegimeUniforme extends FormulaireDefinition implements Ob this._formCompute = new FormComputeFixedVar(this, this._formResult); } - protected get defaultProperties(): {} { - return { "calcType": CalculatorType.RegimeUniforme, "nodeType": ComputeNodeType.SectionCercle }; - } + // protected get defaultProperties(): {} { + // return { "calcType": CalculatorType.RegimeUniforme, "nodeType": ComputeNodeType.SectionCercle }; + // } protected initParse() { this._formParamCalc.initParse(); } protected parseOptions(json: {}) { + super.parseOptions(json); this._formSection.parseOptions(json); } diff --git a/src/app/formulaire/definition/concrete/form-section-parametree.ts b/src/app/formulaire/definition/concrete/form-section-parametree.ts index 1f14c0f662e254bc5e3d81823e5e943f4362827d..6f3fa0391c21bfedfee2f5c1de7fe755abe4bd8a 100644 --- a/src/app/formulaire/definition/concrete/form-section-parametree.ts +++ b/src/app/formulaire/definition/concrete/form-section-parametree.ts @@ -29,11 +29,8 @@ export class FormulaireSectionParametree extends FormulaireDefinition { this._formCompute = new FormComputeSectionParametree(this, this._formSection, this._formSectionResult); } - protected get defaultProperties(): {} { - return { "calcType": CalculatorType.SectionParametree, "nodeType": ComputeNodeType.SectionCercle }; - } - protected parseOptions(json: {}) { + super.parseOptions(json); this._formSection.parseOptions(json); } diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index 1a43403007d74910984da7d1ad9fdb08868d2e56..c9d0506967eeb3b97296704e826bfa8125904d6b 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -30,6 +30,11 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs */ protected _currentSessionNub: SessionNub; + /** + * propriétés par défaut (lues si _currentSessionNub === undefined ) + */ + private _props = {}; + /** * fichier de configuration */ @@ -69,7 +74,9 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs return this._jsonConfig; } - protected abstract get defaultProperties(): {}; + public get defaultProperties() { + return this._props; + } public initSessionNub(props?: {}) { this._currentSessionNub = this.createSessionNub(props === undefined ? this.defaultProperties : props); @@ -79,6 +86,12 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs return this._currentSessionNub; } + public set currentSessionNub(n: SessionNub) { + if (this._props["calcType"] !== n.properties.getPropValue("calcType")) + throw new Error(`Nub ${n.properties["calcType"]} incompatible avec le formulaire ${this._calculatorName} (${this._props["calcType"]})`); + this._currentSessionNub = n; + } + private findNub(params: Props | {}) { return this._paramService.findSessionNub(params); } @@ -99,7 +112,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs } protected replaceCurrentSessionNub(params: Props) { - this._currentSessionNub = this._paramService.replaceSessionNub(this._currentSessionNub, params); + this.currentSessionNub = this._paramService.replaceSessionNub(this._currentSessionNub, params); } protected replaceSessionNub(sn: SessionNub, params: Props): SessionNub { @@ -128,6 +141,8 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs } protected parseOptions(json: {}) { + const dnt = json["defaultNodeType"]; + this._props["nodeType"] = dnt === undefined ? ComputeNodeType.None : ComputeNodeType[dnt]; } protected completeParse(json: {}) { @@ -196,7 +211,10 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs } } - public parseConfig(json: {}) { + /** + * 1ère passe d'analyse de la configuration + */ + public preparseConfig(json: {}) { this._jsonConfig = json; this.initParse(); @@ -213,13 +231,21 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs break; } } + } + + /** + * 2ème passe d'analyse de la configuration + */ + public parseConfig(json: {}) { + if (json !== undefined) + this._jsonConfig = json; // analyse des éléments du formulaire const templates: any[] = []; - for (let conf_index in json) { - const conf = json[conf_index]; + for (let conf_index in this._jsonConfig) { + const conf = this._jsonConfig[conf_index]; const type: string = conf["type"]; switch (type) { @@ -244,7 +270,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs } } - this.completeParse(json); + this.completeParse(this._jsonConfig); // console.log("-----"); @@ -257,7 +283,7 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs // logObject(this._fieldSets, "fieldsets"); // logObject(this._dependencies, "dependences"); - this.parseDependencies(json); + this.parseDependencies(this._jsonConfig); } public hasParameter(symbol: string): boolean { diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index 949e1a886eaf56501525e5ace0fcde7cba20cf62..c51afc628ef2d2cffca040d64eca6d3e7ef6db65 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -113,13 +113,9 @@ export class FormulaireService extends Observable { return this._intlService.localizeText(`INFO_${sCalculator}_TITRE`); } - private loadConfig(form: FormulaireDefinition, ct: CalculatorType): Promise<Response> { - let processData = function (s: string) { - form.parseConfig(JSON.parse(s)); - } - + public loadConfig(ct: CalculatorType): Promise<any> { let f: string = this.getConfigPathPrefix(ct) + "config.json" - return this._httpService.httpGetRequest(undefined, undefined, undefined, f, processData); + return this._httpService.httpGetRequest2(undefined, undefined, undefined, f); } private newFormulaire(ct: CalculatorType, jsonState?: {}): FormulaireDefinition { @@ -165,12 +161,7 @@ export class FormulaireService extends Observable { throw new Error(`FormulaireService.createFormulaire() : type de calculette ${ct} non pris en charge`) } - if (jsonState !== undefined) { - const props = jsonState["props"]; - f.initSessionNub(props); - } - else - f.initSessionNub(); + f.defaultProperties["calcType"] = ct; return f; } @@ -181,15 +172,26 @@ export class FormulaireService extends Observable { * @param jsonState */ public createFormulaire(ct: CalculatorType, jsonState?: {}): Promise<FormulaireDefinition> { - const f: FormulaireDefinition = this.newFormulaire(ct, jsonState); - - if (jsonState === undefined) - f.calculatorName = decode(this.getLocalisedTitleFromCalculatorType(ct) + " (" + f.uid + ")"); + const f: FormulaireDefinition = this.newFormulaire(ct); this._formulaires.push(f); - let prom: Promise<Response> = this.loadConfig(f, ct); - return prom.then(_ => { - if (jsonState !== undefined) + + let prom: Promise<any> = this.loadConfig(ct); + return prom.then(s => { + f.preparseConfig(JSON.parse(s)); + return f; + }).then(f => { + if (jsonState === undefined) { + f.calculatorName = decode(this.getLocalisedTitleFromCalculatorType(ct) + " (" + f.uid + ")"); + f.initSessionNub(); + } + else { f.deserialiseJSON(jsonState); + const props = jsonState["props"]; + f.initSessionNub(props); + } + return f; + }).then(f => { + f.parseConfig(undefined); return f; }).then(f => { this.loadUpdateFormulaireLocalisation(f); diff --git a/src/app/services/http/http.service.ts b/src/app/services/http/http.service.ts index 74c4dae34078347f8f320cabb67f5563dd3dd9c4..d99733819768f37ca84de58164ca27253acf517e 100644 --- a/src/app/services/http/http.service.ts +++ b/src/app/services/http/http.service.ts @@ -18,11 +18,17 @@ export class HttpService { return s1 + s2; } + /** + * construit, lance une requête GET et applique un callback sur le résultat + * @param processDataCallback callback en cas de succès + * @param errorCallback callback en cas d'erreur + * @see httpGetRequestResponse + */ public httpGetRequest(protocol: string, host: string, port: number, path: string, processDataCallback: (s: string) => void, errorCallback?: (err: any) => void, headers?: StringMap): Promise<Response> { - let resp: Observable<Response> = this.httpGetRequestResponse(protocol, host, port, path); + let resp: Observable<Response> = this.httpGetRequestResponse(protocol, host, port, path, headers); resp.map(res => res.text()) .subscribe( @@ -34,6 +40,22 @@ export class HttpService { return resp.toPromise(); } + /** + * construit et lance une requête GET + */ + public httpGetRequest2(protocol: string, host: string, port: number, path: string): Promise<any> { + let resp: Observable<Response> = this.httpGetRequestResponse(protocol, host, port, path); + return resp.map(res => res.text()).toPromise(); + } + + /** + * construit et lance une requête GET + * @param protocol type de protocole (http, ...) + * @param host nom d'hôte distant + * @param port numéro de port distant + * @param path chemin de la ressource + * @param headers entêtes de la requête + */ public httpGetRequestResponse(protocol: string, host: string, port: number, path: string, headers?: StringMap): Observable<Response> { let url: string; if (protocol != undefined)