diff --git a/src/app/components/ngparam-input/ngparam-input.component.ts b/src/app/components/ngparam-input/ngparam-input.component.ts index abce24cdfbdc44650ae0a0e7f389f8115023d526..3db763c94d1fe1f7936e49bca44a89727cc4416f 100644 --- a/src/app/components/ngparam-input/ngparam-input.component.ts +++ b/src/app/components/ngparam-input/ngparam-input.component.ts @@ -115,6 +115,18 @@ export class NgParamInputComponent extends GenericInputComponent implements Obse this._tmp = data["value"]; this.updateAndValidateUI(); } + break; + + // changement de valueMode du paramètre ou de valeur à laquelle il est lié + case "valueModeChange": + case "valueLinkChange": + this._tmp = data["value"]; + this.updateAndValidateUI(); + break; } } + + public ngOnDestroy() { + this._paramDef.removeObserver(this); + } } diff --git a/src/app/components/param-link/param-link.component.ts b/src/app/components/param-link/param-link.component.ts index 0ce835b5d841758db870d9aea5263bc3793c558b..4ea99b759475163f760eae63b15cb487412167c8 100644 --- a/src/app/components/param-link/param-link.component.ts +++ b/src/app/components/param-link/param-link.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, Output, EventEmitter, OnChanges } from "@angular/core"; +import { Component, Input, Output, EventEmitter, OnChanges, OnDestroy } from "@angular/core"; import { NgParameter } from "../../formulaire/ngparam"; import { ServiceFactory } from "../../services/service-factory"; @@ -9,7 +9,8 @@ import { FormulaireService } from "../../services/formulaire/formulaire.service" selector: "param-link", templateUrl: "./param-link.component.html" }) -export class ParamLinkComponent implements OnChanges, Observer { +export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { + // paramètre géré (qui sera lié à une valeur, cad qui importe cette valeur) @Input("param") private _param: NgParameter; @@ -116,9 +117,17 @@ export class ParamLinkComponent implements OnChanges, Observer { } public ngOnChanges() { + if (this._param !== undefined) + this._param.removeObserver(this); + this._param.addObserver(this); + this.updateParamList(); } + public ngOnDestroy() { + this._param.removeObserver(this); + } + // interface Observer public update(sender: any, data: any) { diff --git a/src/app/formulaire/ngparam.ts b/src/app/formulaire/ngparam.ts index b48b72503ab6f44efc44161f43c106acf0df9485..fee5e2f71fe700b7115d54194472b7be177ebeb8 100644 --- a/src/app/formulaire/ngparam.ts +++ b/src/app/formulaire/ngparam.ts @@ -120,8 +120,15 @@ export class NgParameter extends InputField { * crée le lien avec un paramètre */ public linkToParameter(n: Nub, p: ParamDefinition) { - this.valueMode = ParamValueMode.LINK; - this.paramDefinition.defineReference(n, p.symbol); + const changed: boolean = this.paramDefinition.referencedObject !== n || this.paramDefinition.referenceDesc !== p.symbol; + if (changed) { + this.valueMode = ParamValueMode.LINK; + this._paramDef.defineReference(n, p.symbol); + this.notifyObservers({ + "action": "valueLinkChange", + "value": this._paramDef.getValue() + }); + } } get isDefined(): boolean { @@ -144,8 +151,13 @@ export class NgParameter extends InputField { 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) + if (m !== undefined && this._paramDef.valueMode !== m) { this._paramDef.valueMode = m; + this.notifyObservers({ + "action": "valueModeChange", + "value": this._paramDef.getValue() + }); + } } public checkMin(min: number): boolean {