diff --git a/src/app/components/param-link/param-link.component.ts b/src/app/components/param-link/param-link.component.ts index 4ccaf65e116fefa76f1b6bafe6eaa596431b71af..0ce835b5d841758db870d9aea5263bc3793c558b 100644 --- a/src/app/components/param-link/param-link.component.ts +++ b/src/app/components/param-link/param-link.component.ts @@ -2,13 +2,14 @@ import { Component, Input, Output, EventEmitter, OnChanges } from "@angular/core import { NgParameter } from "../../formulaire/ngparam"; import { ServiceFactory } from "../../services/service-factory"; -import { ParamValueMode } from "jalhyd"; +import { ParamValueMode, Observer } from "jalhyd"; +import { FormulaireService } from "../../services/formulaire/formulaire.service"; @Component({ selector: "param-link", templateUrl: "./param-link.component.html" }) -export class ParamLinkComponent implements OnChanges { +export class ParamLinkComponent implements OnChanges, Observer { @Input("param") private _param: NgParameter; @@ -31,8 +32,12 @@ export class ParamLinkComponent implements OnChanges { */ private _linkableParams: any[]; + private _formService: FormulaireService; + constructor() { this.onValid = new EventEmitter(); + this._formService = ServiceFactory.instance.formulaireService; + this._formService.addObserver(this); } /** @@ -94,13 +99,35 @@ export class ParamLinkComponent implements OnChanges { } } - public ngOnChanges() { - this._linkableParams = ServiceFactory.instance.formulaireService.getLinkableParameters(this._param); + private updateParamList() { + // liste des paramètres liables + this._linkableParams = this._formService.getLinkableParameters(this._param); + + // initialisation de l'indice courant if (this._linkableParams.length > 0) { - this.linkTo(0); + if (this._currentIndex === -1) + this.linkTo(0); this._message = undefined; } - else + else { + this._currentIndex = -1; this._message = "Aucun paramètre compatible trouvé"; + } + } + + public ngOnChanges() { + this.updateParamList(); + } + + // interface Observer + + public update(sender: any, data: any) { + if (sender instanceof FormulaireService) { + switch (data["action"]) { + case "createForm": + this.updateParamList(); + break; + } + } } }