diff --git a/src/app/formulaire/check-field.ts b/src/app/formulaire/check-field.ts index a34d05a5ce295a5dcd4f873ba6e48c605e676854..cce27669e7ce6e3748b617894596048b8c79d90a 100644 --- a/src/app/formulaire/check-field.ts +++ b/src/app/formulaire/check-field.ts @@ -2,12 +2,13 @@ import { Field } from "./field"; import { Dependency } from "./dependency/dependency"; import { DependencyConditionType } from "./dependency/dependency-condition"; import { FormulaireDefinition } from "./definition/form-definition"; +import { FormulaireNode } from "./formulaire-node"; export class CheckField extends Field { private _value: boolean; - constructor() { - super(); + constructor(parent: FormulaireNode) { + super(parent); this._value = false; } diff --git a/src/app/formulaire/definition/form-compute-parallel-structures.ts b/src/app/formulaire/definition/form-compute-parallel-structures.ts index ce8ff3a10bcf4c525d72afd0048e7370a766c939..32f40244622b4e2cf6bcf70b416bd93e9011d89e 100644 --- a/src/app/formulaire/definition/form-compute-parallel-structures.ts +++ b/src/app/formulaire/definition/form-compute-parallel-structures.ts @@ -28,10 +28,10 @@ export class FormComputeParallelStructures extends FormComputeFixedVar { * ainsi que l'indice du FieldSet parent dans le FieldsetContainer */ private structureParents(p: NgParameter): [FieldsetContainer, FieldSet, number] { - const parent1: FormulaireNode = p.getDirectParent(this._formBase); + const parent1: FormulaireNode = p.parent; if (parent1 !== undefined) if (parent1 instanceof FieldSet) { - const parent2 = parent1.getDirectParent(this._formBase); + const parent2 = parent1.parent; if (parent2 instanceof FieldsetContainer) { const fsIndex = parent1.indexAsKid(this._formBase); return [parent2, parent1, fsIndex]; diff --git a/src/app/formulaire/definition/form-compute-section-parametree.ts b/src/app/formulaire/definition/form-compute-section-parametree.ts index 482da27e88c14abd99403f704df5ad7182ecd8b2..c21c8330fcd43a91e8bf50952485c14274a1016b 100644 --- a/src/app/formulaire/definition/form-compute-section-parametree.ts +++ b/src/app/formulaire/definition/form-compute-section-parametree.ts @@ -66,7 +66,7 @@ export class FormComputeSectionParametree extends FormCompute { this._varResults.variatedParameter = varParam; - const computedParam: NgParameter = this._paramService.createParameter(computedParamInfo.symbol); + const computedParam: NgParameter = this._paramService.createParameter(computedParamInfo.symbol, this._formBase); this._varResults.calculatedParameter = computedParam; let compSymbol: string = computedParamInfo["symbol"]; diff --git a/src/app/formulaire/definition/form-definition.ts b/src/app/formulaire/definition/form-definition.ts index 8a7ec372d5b0021c0bf8034f01279cda31ed97f0..3fdd028022205a3d8a43572f38d7e5a9a3c9b708 100644 --- a/src/app/formulaire/definition/form-definition.ts +++ b/src/app/formulaire/definition/form-definition.ts @@ -32,9 +32,8 @@ export abstract class FormulaireDefinition extends FormulaireNode { protected _paramService: ParamService; - constructor(calcType: CalculatorType, - ) { - super(); + constructor(calcType: CalculatorType) { + super(undefined); this._calcType = calcType; this._paramService = ServiceFactory.instance.paramService; } @@ -100,7 +99,7 @@ export abstract class FormulaireDefinition extends FormulaireNode { } private parse_fieldset(json: {}) { - const fs: FieldSet = new FieldSet(); + const fs: FieldSet = new FieldSet(this); this.kids.push(fs); fs.parseConfig(json, { "parentForm": this }); } @@ -122,7 +121,7 @@ export abstract class FormulaireDefinition extends FormulaireNode { case "template_container": for (const k of this.kids) if (k.id == conf["id"]) { - k.parseDependencies(conf, this); + k.parseDependencies(conf); break; } break; @@ -130,7 +129,7 @@ export abstract class FormulaireDefinition extends FormulaireNode { case "fieldset_template": for (const k of this.kids) if (k instanceof FieldsetContainer) - k.parseDependencies(conf, this); + k.parseDependencies(conf); break; } } diff --git a/src/app/formulaire/field.ts b/src/app/formulaire/field.ts index 36bf7c496c218f2ce65c36d185626377e891f9bb..44524d3f3eaad58a0f55c530d6a5d905c7859d01 100644 --- a/src/app/formulaire/field.ts +++ b/src/app/formulaire/field.ts @@ -8,10 +8,10 @@ export abstract class Field extends FormulaireElement { public abstract getValue(): any; public abstract setValue(sender: any, val: any): void; - private parse_value_dependencies(json: {}, parentNode: FormulaireNode) { + private parse_value_dependencies(json: {}) { for (let di in json) { let d = json[di]; - let masterField: FormulaireElement = parentNode.getFormulaireNodeById(d["refid"]) as FormulaireElement; + let masterField: FormulaireElement = this.parent.getFormulaireNodeById(d["refid"]) as FormulaireElement; if (masterField != undefined) { let masterValue = d["refvalue"]; let dep = new ValueDependency(masterField, masterValue); @@ -23,11 +23,11 @@ export abstract class Field extends FormulaireElement { } } - public parseDependencies(json: {}, parentNode: FormulaireNode) { - super.parseDependencies(json, parentNode); + public parseDependencies(json: {}) { + super.parseDependencies(json); const dep = json["dep_value"]; if (dep != undefined) - this.parse_value_dependencies(dep, parentNode); + this.parse_value_dependencies(dep); } } diff --git a/src/app/formulaire/fieldset-container.ts b/src/app/formulaire/fieldset-container.ts index 439c97c365e5d776c0d25ecb221afc30da482946..aa73266ee3547ccdb04b6bfa50c3e928b3f3717e 100644 --- a/src/app/formulaire/fieldset-container.ts +++ b/src/app/formulaire/fieldset-container.ts @@ -5,7 +5,7 @@ import { FieldSet } from "./fieldset"; import { FieldsetTemplate } from "./fieldset-template"; import { Dependency } from "./dependency/dependency"; import { StringMap } from "../stringmap"; -import { FormulaireDefinition } from "./definition/form-definition"; +import { FormulaireNode } from "./formulaire-node"; import { FormulaireParallelStructure } from "./definition/concrete/form-parallel-structures"; export class FieldsetContainer extends FormulaireElement { @@ -15,15 +15,11 @@ export class FieldsetContainer extends FormulaireElement { public title: string - constructor(private _parentForm: FormulaireDefinition) { - super(); + constructor(parent: FormulaireNode) { + super(parent); this._templates = []; } - public get parentForm() { - return this._parentForm; - } - private addTemplate(fst: FieldsetTemplate) { this._templates.push(new FieldsetTemplate(fst)); } @@ -41,7 +37,7 @@ export class FieldsetContainer extends FormulaireElement { const inst: FieldSet = templ.instantiateTemplate(this); if (inst.sessionNub.nub instanceof Structure) { - const psf = this.parentForm as FormulaireParallelStructure; + const psf = this.parent as FormulaireParallelStructure; psf.addStructureNub(inst.sessionNub.nub as Structure); } diff --git a/src/app/formulaire/fieldset-template.ts b/src/app/formulaire/fieldset-template.ts index a8db81d579249effe4ec4a4111ab9f11358e64c0..bc31026168e791ca54400c21c9479b9e763166c0 100644 --- a/src/app/formulaire/fieldset-template.ts +++ b/src/app/formulaire/fieldset-template.ts @@ -39,10 +39,9 @@ export class FieldsetTemplate { } public instantiateTemplate(cont: FieldsetContainer): FieldSet { - const res = new FieldSet(); - res.parent_fsc = cont; + const res = new FieldSet(cont); cont.addFieldset(res); - res.parseConfig(this._jsonConfig, { "parentForm": cont.parentForm, "createNub": true }); + res.parseConfig(this._jsonConfig, { "parentForm": cont.parent, "createNub": true }); return res; } } diff --git a/src/app/formulaire/fieldset.ts b/src/app/formulaire/fieldset.ts index 6097eb7fd979b2d2ecfdbdc0d70a8da6a5c8df5a..1ebb4e431d4abf10fe6307329af0ef35425ed485 100644 --- a/src/app/formulaire/fieldset.ts +++ b/src/app/formulaire/fieldset.ts @@ -13,6 +13,7 @@ import { FormulaireDefinition } from "./definition/form-definition"; import { Observer } from "../services/observer"; import { StringMap } from "../stringmap"; import { FieldsetContainer } from "./fieldset-container"; +import { FormulaireNode } from "./formulaire-node"; export class FieldSet extends FormulaireElement implements Observer { /** @@ -40,10 +41,8 @@ export class FieldSet extends FormulaireElement implements Observer { */ private _props: Props; - public parent_fsc: FieldsetContainer; // A VIRER - - constructor() { - super(); + constructor(parent: FormulaireNode) { + super(parent); this._props = new Props(); } @@ -92,13 +91,13 @@ export class FieldSet extends FormulaireElement implements Observer { } private parse_check(json: {}): CheckField { - let res: CheckField = new CheckField(); + let res: CheckField = new CheckField(this); res.parseConfig(json) return res; } private parse_select(json: {}): SelectField { - let res: SelectField = new SelectField(); + let res: SelectField = new SelectField(this); res.parseConfig(json); res.addObserver(this); return res; @@ -184,7 +183,7 @@ export class FieldSet extends FormulaireElement implements Observer { switch (input_id) { case "Pr": - var res: NgParameter = paramService.createParameter(input_id); + var res: NgParameter = paramService.createParameter(input_id, this); break; default: @@ -193,7 +192,7 @@ export class FieldSet extends FormulaireElement implements Observer { const nubParam: ParamDefinition = this.getNubParamFromSymbol(input_id); if (nubParam) - res = new NgParameter(nubParam); + res = new NgParameter(nubParam, this); } if (res) @@ -329,7 +328,7 @@ export class FieldSet extends FormulaireElement implements Observer { } public parseDependencies(json: {}) { - super.parseDependencies(json, this); + super.parseDependencies(json); for (const k1 in json) { if (k1 === "fields") { @@ -342,7 +341,7 @@ export class FieldSet extends FormulaireElement implements Observer { case "check": for (const k of this.kids) if (k.id == field["id"]) { - k.parseDependencies(field, this); + k.parseDependencies(field); break; } break; diff --git a/src/app/formulaire/formulaire-element.ts b/src/app/formulaire/formulaire-element.ts index 8f081c741021edc0d62a2ca54705c45746c01fc7..4f227999f1ebc9b2950a16fc9a774d1b20fd5f21 100644 --- a/src/app/formulaire/formulaire-element.ts +++ b/src/app/formulaire/formulaire-element.ts @@ -24,8 +24,8 @@ export abstract class FormulaireElement extends FormulaireNode { protected _dependencies: Dependency[] = []; - constructor() { - super(); + constructor(parent: FormulaireNode) { + super(parent); this._isDisplayed = true; } @@ -54,9 +54,8 @@ export abstract class FormulaireElement extends FormulaireNode { /** * analyse les dépendances d'existence * @param json configuration de la dépendance - * @param parentNode node parent dans lequel rechercher l'élément master (dont l'existence dépend) */ - private parse_existence_dependencies(json: {}, parentNode: FormulaireNode) { + private parse_existence_dependencies(json: {}) { for (let di in json) { let d = json[di]; let masterField: FormulaireElement = parentNode.getFormulaireNodeById(d["refid"]) as FormulaireElement; @@ -96,10 +95,10 @@ export abstract class FormulaireElement extends FormulaireNode { * @param json configuration de la dépendance * @param parentNode node parent dans lequel rechercher l'élément master (dont l'existence dépend) */ - public parseDependencies(json: {}, parentNode: FormulaireNode) { + public parseDependencies(json: {}) { const dep = json["dep_exist"]; if (dep != undefined) - this.parse_existence_dependencies(dep, parentNode); + this.parse_existence_dependencies(dep); } protected abstract verifyDependency(d: Dependency): boolean; diff --git a/src/app/formulaire/formulaire-node.ts b/src/app/formulaire/formulaire-node.ts index 7f76ed4f70dae57ccc780f2385b06ec31882608e..7957b5e0416b6246dda21310c2d462111f47cdfc 100644 --- a/src/app/formulaire/formulaire-node.ts +++ b/src/app/formulaire/formulaire-node.ts @@ -1,7 +1,5 @@ import { JalhydObject } from "jalhyd" -import { FormulaireDefinition } from "./definition/form-definition"; -import { DeepFormulaireNodeIterator } from "./form-iterator/deep-node-iterator"; import { IObservable, Observer, Observable } from "../services/observer"; /** @@ -18,6 +16,11 @@ export abstract class FormulaireNode implements IObservable { */ private _uid: number; + /** + * parent direct + */ + private _parentNode: FormulaireNode; + /** * enfants (utilisé entre autres pour FormulaireDefinition, FieldSet et FieldsetContainer) */ @@ -28,7 +31,8 @@ export abstract class FormulaireNode implements IObservable { */ private _observable: Observable; - constructor() { + constructor(parent: FormulaireNode) { + this._parentNode = parent; this._kids = []; this._uid = JalhydObject.nextUID; this._observable = new Observable() @@ -38,6 +42,10 @@ export abstract class FormulaireNode implements IObservable { return this._confId; } + public get parent() { + return this._parentNode; + } + public get kids(): FormulaireNode[] { return this._kids; } @@ -82,28 +90,6 @@ export abstract class FormulaireNode implements IObservable { return undefined; } - private hasDirectKid(n: FormulaireNode): boolean { - for (const k of this._kids) - if (k._uid == n._uid) - return true; - return false; - } - - /** - * retourne le parent direct de this - * @param root FormulaireNode racine dont on part pour rechercher le parent - */ - public getDirectParent(root: FormulaireNode): FormulaireNode { - if (root.hasDirectKid(this)) - return root; - - const it = new DeepFormulaireNodeIterator(root); - for (const n of it) - if (n.hasDirectKid(this)) - return n; - return undefined; - } - /** * retourne l'indice d'un FormulaireNode enfant dans la liste des enfants * @param kid FormulaireNode enfant dont on cherche l'indice @@ -126,11 +112,7 @@ export abstract class FormulaireNode implements IObservable { * @param root FormulaireNode racine dont on part pour rechercher le parent */ public indexAsKid(root: FormulaireNode): number { - // parent de this - const p = this.getDirectParent(root); - - // indice - return p.kidIndex(this); + return this._parentNode.kidIndex(this); } public abstract parseConfig(json: {}, data?: {}); @@ -140,7 +122,7 @@ export abstract class FormulaireNode implements IObservable { * @param json configuration de la dépendance * @param parentNode nod parent dans lequel rechercher l'élément master (dont l'existence dépend) */ - public abstract parseDependencies(json: {}, parentNode: FormulaireNode); + public abstract parseDependencies(json: {}); // interface IObservable diff --git a/src/app/formulaire/ngparam.ts b/src/app/formulaire/ngparam.ts index 580d8b6a9d79cb2c8368b1ef2c0bba3af23e04f3..4c464642c9cabc6df1ce2be43af6b85eda8f0bd5 100644 --- a/src/app/formulaire/ngparam.ts +++ b/src/app/formulaire/ngparam.ts @@ -8,6 +8,7 @@ import { FormulaireDefinition } from "./definition/form-definition"; 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 { /** @@ -38,8 +39,8 @@ export class NgParameter extends InputField { */ 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) { - super(); + constructor(private _paramDef: ParamDefinition, parent: FormulaireNode) { + super(parent); } get symbol(): string { diff --git a/src/app/formulaire/select-field.ts b/src/app/formulaire/select-field.ts index be8bc9581d98bafc1a0e7ad606c855d971490b96..e30c00373af1b7ac60c63a8807dbad192737a174 100644 --- a/src/app/formulaire/select-field.ts +++ b/src/app/formulaire/select-field.ts @@ -7,14 +7,15 @@ import { DependencyConditionType } from "./dependency/dependency-condition"; import { ValueDependencyCondition } from "./dependency/value-dependency-condition"; import { StringMap } from "../stringmap"; import { IObservable, Observable, Observer } from "../services/observer"; +import { FormulaireNode } from "./formulaire-node"; export class SelectField extends Field { private _entries: SelectEntry[]; private _selectedEntry: SelectEntry; - constructor() { - super(); + constructor(parent: FormulaireNode) { + super(parent); this._entries = []; } diff --git a/src/app/services/param/param.service.ts b/src/app/services/param/param.service.ts index 82290e17751a81e623ab4acdaf6568203fe0b9bb..6bcc6f831913534cea2bfd0cb6de8d8c342e4d86 100644 --- a/src/app/services/param/param.service.ts +++ b/src/app/services/param/param.service.ts @@ -6,6 +6,7 @@ import { Injectable } from "@angular/core"; import { ServiceFactory } from "../service-factory"; import { InternationalisationService } from "../internationalisation/internationalisation.service"; import { ApplicationSetupService } from "../app-setup/app-setup.service"; +import { FormulaireNode } from "../../formulaire/formulaire-node"; @Injectable() export class ParamService { @@ -29,15 +30,15 @@ export class ParamService { * @param calcType crée un NgParameter n'appartenant pas à un ComputeNode * @param symbol symbole du paramètre à créer */ - public createParameter(symbol: string): NgParameter { + public createParameter(symbol: string, parent: FormulaireNode): NgParameter { if (symbol === "Pr") { var prmDef: ParamDefinition = this.createAccuracyParameter(); - var p = new NgParameter(prmDef.clone()); + var p = new NgParameter(prmDef.clone(), parent); p.confId = "Pr"; } else { const dom = new ParamDomain(ParamDomainValue.POS_NULL); - p = new NgParameter(new ParamDefinition(symbol, dom)); + p = new NgParameter(new ParamDefinition(symbol, dom), parent); p.confId = symbol; switch (symbol) {