Skip to content
Snippets Groups Projects
Commit d6d35dcc authored by Mathias Chouet's avatar Mathias Chouet Committed by mathias.chouet
Browse files

Simplified custom select process

parent 98f88489
No related branches found
No related tags found
No related merge requests found
......@@ -33,9 +33,8 @@
{
"type": "options",
"selectIds": [ "select_target_result" ],
"targetNubSelectId": "select_target_nub",
"customSelectIds": [ "select_target_nub", "select_searched_param" ],
"targettedResultSelectId": "select_target_result",
"searchedParamSelectId": "select_searched_param",
"_help": "solveur.html"
}
]
\ No newline at end of file
......@@ -32,8 +32,7 @@
{
"type": "options",
"selectIds": [ "select_pab_jet_type", "select_species_list" ],
"targetPassSelectId": "select_target_pass",
"speciesListSelectId": "select_species_list",
"customSelectIds": [ "select_target_pass" ],
"help": "verification/verificateur.html"
}
]
......@@ -7,6 +7,7 @@ import { ParamRadioConfig, NgParameter } from "../elements/ngparam";
import { FieldSet } from "../elements/fieldset";
import { Nub, IObservable } from "jalhyd";
import { SelectFieldCustom } from '../elements/select-field-custom';
export class FormulaireFixedVar extends FormulaireDefinition {
......@@ -16,6 +17,9 @@ export class FormulaireFixedVar extends FormulaireDefinition {
/** ids of select fields */
private _selectIds: string[] = [];
/** ids of "custom" select fields */
private _customSelectIds: string[] = [];
constructor() {
super();
this._fixedResults = new FixedResults();
......@@ -70,21 +74,40 @@ export class FormulaireFixedVar extends FormulaireDefinition {
}
public afterParseFieldset(fs: FieldSet) {
// observe all select fields @see this.update()
// observe all Select fields @see this.update()
if (this._selectIds.length > 0) {
for (const sId of this._selectIds) {
const sel = fs.getFormulaireNodeById(sId);
if (sel) {
// Formulaire is listening to FieldSet properties (@TODO why not directly Select ?)
fs.properties.addObserver(this);
}
}
}
}
protected completeParse(firstNotif: boolean = true) {
super.completeParse(firstNotif);
// observe all CustomSelect fields @TODO move to afterParseFieldset ?
if (this._customSelectIds.length > 0) {
for (const csId of this._customSelectIds) {
const sel = this.getFormulaireNodeById(csId);
// Formulaire is listening to Select value
sel.addObserver(this);
if (firstNotif) {
// force 1st observation
(sel as SelectFieldCustom).notifyValueChanged();
}
}
}
}
protected parseOptions(json: {}) {
super.parseOptions(json);
// get ids of all select fields
this._selectIds = this.getOption(json, "selectIds") || [];
// get ids of all "custom" select fields
this._customSelectIds = this.getOption(json, "customSelectIds") || [];
}
protected compute() {
......
......@@ -52,6 +52,7 @@ export class FormulaireMacrorugoCompound extends FormulaireRepeatableFieldset {
}
protected completeParse(firstNotif: boolean = true) {
super.completeParse(firstNotif);
this.fieldsetContainer.addObserver(this);
if (firstNotif) {
this.updateApronState(this.currentNub.properties.getPropValue("inclinedApron"));
......
......@@ -93,7 +93,8 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
}
protected completeParse(firstNotif: boolean = true) {
this.subscribeFieldsetContainer();
super.completeParse(firstNotif);
this.fieldsetContainer.addObserver(this);
this.helpLinks = this._resultsHelpLinks;
}
......@@ -128,13 +129,6 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
}
}
/**
* abonnement en tant qu'observateur du FieldsetContainer
*/
private subscribeFieldsetContainer() {
this.fieldsetContainer.addObserver(this);
}
/**
* abonnement en tant qu'observateur des NgParameter des FieldSet contenus dans le FieldsetContainer
*/
......
......@@ -11,34 +11,18 @@ import { FieldSet } from "../elements/fieldset";
*/
export class FormulaireSolveur extends FormulaireFixedVar {
/** id of select configuring target Nub */
private _targetNubSelectId: string;
/** id of select configuring targetted result */
private _targettedResultSelectId: string;
/** id of select configuring searched param */
private _searchedParamSelectId: string;
protected parseOptions(json: {}) {
super.parseOptions(json);
this._targetNubSelectId = this.getOption(json, "targetNubSelectId");
this._targettedResultSelectId = this.getOption(json, "targettedResultSelectId");
this._searchedParamSelectId = this.getOption(json, "searchedParamSelectId");
}
protected completeParse(firstNotif: boolean = true) {
super.completeParse();
if (this._targetNubSelectId) {
const sel = this.getFormulaireNodeById(this._targetNubSelectId);
if (sel) {
sel.addObserver(this);
if (firstNotif) {
// force 1st observation
(sel as SelectFieldCustom).notifyValueChanged();
}
}
}
super.completeParse(firstNotif);
// even though this._targettedResultSelectId is a regular select, an extra action
// is needed: refresh searched parameter selector
if (this._targettedResultSelectId) {
const sel = this.getFormulaireNodeById(this._targettedResultSelectId);
if (sel) {
......@@ -49,17 +33,6 @@ export class FormulaireSolveur extends FormulaireFixedVar {
}
}
}
if (this._searchedParamSelectId) {
const sel = this.getFormulaireNodeById(this._searchedParamSelectId);
if (sel) {
sel.addObserver(this);
if (firstNotif) {
// force 1st observation
(sel as SelectFieldCustom).notifyValueChanged();
}
}
}
}
// interface Observer
......@@ -111,7 +84,7 @@ export class FormulaireSolveur extends FormulaireFixedVar {
inputXinit.notifyValueModified(this);
}
} else if (sender instanceof SelectField) {
if (sender.id === "select_target_result") {
if (sender.id === this._targettedResultSelectId) {
// refresh parameters selector
this.refreshParameterEntries();
}
......@@ -122,7 +95,7 @@ export class FormulaireSolveur extends FormulaireFixedVar {
* Re-populate searched parameter selector with fresh entries
*/
private refreshParameterEntries() {
const pSel = this.getFormulaireNodeById(this._searchedParamSelectId) as SelectFieldCustom;
const pSel = this.getFormulaireNodeById("select_searched_param") as SelectFieldCustom;
if (pSel) {
pSel.updateEntries();
// reflect changes in GUI
......
......@@ -2,39 +2,12 @@ import { IObservable, Nub, Verificateur } from "jalhyd";
import { SelectFieldCustom } from "../elements/select-field-custom";
import { FormulaireFixedVar } from "./form-fixedvar";
import { SelectField } from '../elements/select-field';
/**
* Formulaire pour les Vérificateurs
*/
export class FormulaireVerificateur extends FormulaireFixedVar {
/** id of select configuring target pass Nub */
private _targetPassSelectId: string;
/** id of select configuring list of species */
private _speciesListSelectId: string;
protected parseOptions(json: {}) {
super.parseOptions(json);
this._targetPassSelectId = this.getOption(json, "targetPassSelectId");
this._speciesListSelectId = this.getOption(json, "speciesListSelectId");
}
protected completeParse(firstNotif: boolean = true) {
super.completeParse();
if (this._targetPassSelectId) {
const sel = this.getFormulaireNodeById(this._targetPassSelectId);
if (sel) {
sel.addObserver(this);
if (firstNotif) {
// force 1st observation
(sel as SelectFieldCustom).notifyValueChanged();
}
}
}
}
// interface Observer
public update(sender: IObservable, data: any) {
......@@ -70,12 +43,12 @@ export class FormulaireVerificateur extends FormulaireFixedVar {
public onCalculatorInit() {
// refresh species list selector on each display, because Session might have gained new Espece nubs
console.log(">>>> speciesList avant rafraîchissement :", (this.currentNub as Verificateur).speciesList);
const pSel = this.getFormulaireNodeById(this._speciesListSelectId) as SelectField;
/* const pSel = this.getFormulaireNodeById(this._speciesListSelectId) as SelectField;
if (pSel) {
/* pSel.clearEntries();
pSel.parseConfig(); */
pSel.clearEntries();
pSel.parseConfig();
// (pSel.parent as FieldSet).updateFields()
}
} */
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment