Commit bdf531b2 authored by Mathias Chouet's avatar Mathias Chouet 🍝
Browse files

Fix #143 Paramètre lié dans le même module: le changement de nom n'est pas répercuté

parent 2402cba1
......@@ -2,10 +2,10 @@ import { Component, Input, Output, EventEmitter, OnChanges, OnDestroy } from "@a
import { NgParameter } from "../../formulaire/ngparam";
import { ServiceFactory } from "../../services/service-factory";
import { ParamValueMode, Observer, Structure } from "jalhyd";
import { ParamValueMode, Observer, Structure, ParallelStructure } from "jalhyd";
import { FormulaireService } from "../../services/formulaire/formulaire.service";
import { I18nService } from "../../services/internationalisation/internationalisation.service";
import { ApplicationSetupService } from "../../services/app-setup/app-setup.service";
import { FormulaireDefinition } from "../../formulaire/definition/form-definition";
@Component({
selector: "param-link",
......@@ -222,11 +222,27 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy {
public update(sender: any, data: any) {
if (sender instanceof FormulaireService) {
switch (data["action"]) {
switch (data.action) {
// scan newly created form for available linkable params
case "createForm":
this.updateParamList();
break;
case "formNameChanged":
const f = data.form as FormulaireDefinition;
for (const lp of this._linkableParams) {
if (
lp.nub.uid === f.currentNub.uid
|| ( // repeatable structure inside parent module
lp.nub.parent instanceof ParallelStructure
&& lp.nub.parent.uid === f.currentNub.uid
)
) {
// update <select> option
lp.formTitle = data.value;
}
}
break;
}
}
}
......
......@@ -12,6 +12,7 @@ import { DeepFieldsetIterator } from "../form-iterator/deep-fieldset-iterator";
import { DeepFormulaireElementIterator } from "../form-iterator/deep-element-iterator";
import { TopFormulaireElementIterator } from "../form-iterator/top-element-iterator";
import { CalculatorResults } from "../../results/calculator-results";
import { ServiceFactory } from "../../services/service-factory";
/**
* classe de base pour tous les formulaires
......@@ -73,6 +74,8 @@ export abstract class FormulaireDefinition extends FormulaireNode implements Obs
"action": "nameChanged",
"name": name
}, this);
// convenient trick to notify param-link components
ServiceFactory.instance.formulaireService.propagateFormNameChange(this, name);
}
public get jsonConfig(): {} {
......
......@@ -241,15 +241,26 @@ export class FormulaireService extends Observable {
return this.loadUpdateFormulaireLocalisation(f);
}).then(fi => {
fi.applyDependencies();
this.notifyObservers(
{
"action": "createForm",
"form": fi
});
this.notifyObservers({
"action": "createForm",
"form": fi
});
return fi;
});
}
/**
* Trick to notify param-link components that parent form name changed
* @TODO find a way to make param-link components directly observe FormDefinition
*/
public propagateFormNameChange(f: FormulaireDefinition, name: string) {
this.notifyObservers({
"action": "formNameChanged",
"form": f,
"value": name
});
}
public getFormulaireFromId(uid: string): FormulaireDefinition {
for (const f of this._formulaires) {
if (f.uid === uid) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment