Skip to content
Snippets Groups Projects
Commit 80cc2f39 authored by mathias.chouet's avatar mathias.chouet
Browse files

PreBarrage: show results corresponding to selected schema item

parent 28258c71
No related branches found
No related tags found
1 merge request!96WIP: Resolve "Simplifier les composants de résultats"
......@@ -35,22 +35,6 @@ export class PbResultsTableComponent extends ResultsComponentDirective {
super();
}
/* private getJetTypes(re: Result, vi: number): string {
// jet type for each device
const devices = re.sourceNub.getChildren();
const jetTypes: string[] = devices.map((device) => {
const jt = device.result.resultElements[vi].getValue("ENUM_StructureJetType");
let jetType = this.intlService.localizeText("INFO_ENUM_STRUCTUREJETTYPE_" + jt);
if (devices.length > 1) {
// evil HTML injection in table cell (simpler)
jetType = this.intlService.localizeText("INFO_LIB_FS_OUVRAGE") + " n°"
+ (device.findPositionInParent() + 1) + ": " + jetType;
}
return jetType;
});
return `<div class="inner-cell-line">` + jetTypes.join(`, </div><div class="inner-cell-line">`) + `</div>`;
} */
public set results(r: PrebarrageResults) {
this._pbResults = r;
console.log("Set results dans PBRTC !", r);
......
......@@ -112,7 +112,7 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
* @param name nom de la propriété qui vient de changer
* @param val nouvelle valeur de la propriété
*/
private adjustProperties(props: Props, name: string, val: any) {
protected adjustProperties(props: Props, name: string, val: any) {
if (name === "structureType") {
if (! StructureProperties.isCompatibleValues(
val, props.getPropValue("loiDebit"), this.currentNub as ParallelStructure
......@@ -138,7 +138,7 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
/**
* abonnement en tant qu'observateur des NgParameter des FieldSet contenus dans le FieldsetContainer
*/
private subscribeStructureInputFields(fs: FieldSet) {
protected subscribeStructureInputFields(fs: FieldSet) {
for (const n of fs.allFormElements) {
if (n instanceof NgParameter) {
n.addObserver(this);
......@@ -148,7 +148,7 @@ export class FormulaireParallelStructure extends FormulaireRepeatableFieldset {
/**
* abonnement en tant qu'observateur du SelectField des FieldSet contenus dans le FieldsetContainer
*/
private subscribeStructureSelectFields(fs: FieldSet) {
protected subscribeStructureSelectFields(fs: FieldSet) {
for (const n of fs.allFormElements) {
if (n instanceof SelectField) {
n.addObserver(this);
......
import { FormulaireParallelStructure } from "./form-parallel-structures";
import { SelectFieldNub } from "../elements/select-field-nub";
import { IObservable, Nub, PbCloison, PbBassin } from "jalhyd";
import { IObservable, Nub, PbCloison, PbBassin, Structure } from "jalhyd";
import { FieldSet } from '../elements/fieldset';
import { FormulaireNode } from '../elements/formulaire-node';
import { FieldsetContainer } from '../elements/fieldset-container';
export class FormulairePbCloison extends FormulaireParallelStructure {
......@@ -36,7 +39,31 @@ export class FormulairePbCloison extends FormulaireParallelStructure {
// interface Observer
public update(sender: IObservable, data: any) {
super.update(sender, data);
// do NOT call super.update() or "newFieldset" action will reset results
if (sender instanceof FieldsetContainer) {
switch (data.action) {
case "newFieldset":
// this.reset();
console.log("||| reset PAS NON PLUS :) |||");
this.subscribeStructureInputFields(data["fieldset"]);
this.subscribeStructureSelectFields(data["fieldset"]);
}
} else if (sender instanceof FieldSet && data.action === "propertyChange") {
switch (sender.id) {
case "fs_ouvrage":
const props = sender.properties;
// ensure loiDebit is set
props.setPropValue("loiDebit", data.value);
this.adjustProperties(props, data["name"], data["value"]);
// replace Structure Nub
const newNub = this.replaceNub((sender.nub as Structure), props);
sender.setNub(newNub);
// treat the fieldset as new to re-subscribe to Nub properties change events
this.afterParseFieldset(sender);
this.reset();
break;
}
}
if (sender instanceof SelectFieldNub) {
const nub = this._currentNub as PbCloison;
......@@ -72,4 +99,37 @@ export class FormulairePbCloison extends FormulaireParallelStructure {
}, this);
}
}
// do not reset results after adding fieldset (when switching results view
// from one wall to another, the form is rebuilt) @TODO anyway, we should
// reset when a fieldset is manually added from "input" (form) view
public createFieldset(parent: FormulaireNode, json: {}, data?: {}, nub?: Nub): FieldSet {
if (json["calcType"] === "Structure") {
// indice après lequel insérer le nouveau FieldSet
const after = data["after"];
const res: FieldSet = new FieldSet(parent);
let sn: Nub;
if (nub) { // use existing Nub (build interface based on model)
sn = nub;
} else {
sn = this.createChildNub(data["template"]);
this.currentNub.addChild(sn, after);
}
res.setNub(sn, false);
if (after !== undefined) {
parent.kids.splice(after + 1, 0, res);
} else {
parent.kids.push(res);
}
console.log("\\\ reset PAS ///");
// this.resetResults();
return res;
} else {
return super.createFieldset(parent, json, data);
}
}
}
......@@ -47,7 +47,6 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
public get results(): CalculatorResults[] {
// ensure help links are propagated
this._pbResults.helpLinks = this.helpLinks;
console.log("RENVOI", [ this.fixedResults, this._pbResults ]);
return [ this.fixedResults, this._pbResults ];
}
......@@ -120,7 +119,6 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
public nodeSelected(node: PbBassin | PbCloison) {
// store for results formatting
this._selectedItem = node;
this.reaffectResultComponents();
// show only the relevant form
if (node === undefined) {
......@@ -164,6 +162,7 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
}
this.showFormElements(wallForm);
}
this.reaffectResultComponents();
}
/**
......@@ -216,6 +215,10 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
this.pbResults.variatedParameters = varParams;
}
// cacher les résultats de la cloison
this.fixedResults.reset();
this.addFixedParameters();
// résultats selon l'objet sélectionné sur le schéma
if (this._selectedItem !== undefined && this._selectedItem instanceof PbCloison) {
// cacher les résultats de bassins
......@@ -228,10 +231,6 @@ export class FormulairePrebarrage extends FormulaireFixedVar {
this.fixedResults.calculatedParameter = computedParam;
}
} else {
// cacher les résultats de la cloison
this.fixedResults.reset();
this.addFixedParameters();
// afficher les résultats des bassins
this.pbResults.reset();
// résultat général du Nub (amont, aval, débit)
......
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