Skip to content
Snippets Groups Projects
Commit 62aedd0d authored by David Dorchies's avatar David Dorchies
Browse files

fix(pab): input latency for big pab

- cache linkableValues in ngParam and compute its value only on AfterViewInit

Refs #660
parent 038c93bf
No related branches found
No related tags found
2 merge requests!275Release v4.19.0,!257Resolve "PAB: latence de saisie sur les grosses PAB"
Pipeline #172336 passed
import { Component, ViewChild, Input, Output, EventEmitter, OnChanges } from "@angular/core";
import { Component, ViewChild, Input, Output, EventEmitter, OnChanges, AfterViewInit } from "@angular/core";
import { I18nService } from "../../services/internationalisation.service";
import { NgParameter, ParamRadioConfig } from "../../formulaire/elements/ngparam";
......@@ -19,7 +19,7 @@ import { ParamValuesComponent } from "../param-values/param-values.component";
"./param-field-line.component.scss"
]
})
export class ParamFieldLineComponent implements OnChanges {
export class ParamFieldLineComponent implements OnChanges, AfterViewInit {
constructor() {
this.intlService = ServiceFactory.i18nService;
......@@ -193,16 +193,17 @@ export class ParamFieldLineComponent implements OnChanges {
*/
public hasRadioLink(): boolean {
if (this._formService.formulaires.length > 0 && !this.isParameterLinkTarget()) {
this._formService.getLinkableValues(this.param);
// au moins 2 modules de calcul ouverts
if (this._formService.formulaires.length > 1) {
return this._formService.getLinkableValues(this.param).length > 0;
return this.param.linkableValues.length > 0;
}
// ou un seul module de calcul "ouvrages parallèles" avec au moins 2 ouvrages
if (this._formService.formulaires[0].currentNub instanceof ParallelStructure) {
const ps: ParallelStructure = this._formService.formulaires[0].currentNub;
if (ps.structures.length > 1) {
return this._formService.getLinkableValues(this.param).length > 0;
return this.param.linkableValues.length > 0;
}
}
......@@ -210,7 +211,7 @@ export class ParamFieldLineComponent implements OnChanges {
if (this._formService.formulaires[0].currentNub instanceof Pab) {
const pab: Pab = this._formService.formulaires[0].currentNub;
if (pab.children.length > 1) {
return this._formService.getLinkableValues(this.param).length > 0;
return this.param.linkableValues.length > 0;
}
}
......@@ -359,6 +360,10 @@ export class ParamFieldLineComponent implements OnChanges {
this._ngParamInputComponent.showError = this.isRadioFixChecked;
}
public ngAfterViewInit() {
this._formService.getLinkableValues(this.param, true);
}
/**
* relit la valeur dans l'interface et met à jour le NgParameter
*/
......
......@@ -262,7 +262,7 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy {
let noMoreTarget = false;
// liste des paramètres liables
if (this.param.valueMode === ParamValueMode.LINK) {
this._linkableParams = this.formService.getLinkableValues(this.param);
this._linkableParams = this.formService.getLinkableValues(this.param, true);
noMoreTarget = this._linkableParams.length === 0;
} else {
this._linkableParams = [];
......
......@@ -29,6 +29,11 @@ export enum ParamRadioConfig {
*/
export class NgParameter extends InputField implements Observer {
/** cache of linkable values for this parameter */
public linkableValues: LinkedValue[];
public disabled: boolean;
/** set to true to disable UI validation on this input */
private _allowEmpty = false;
......@@ -41,8 +46,6 @@ export class NgParameter extends InputField implements Observer {
*/
private _radioConfig: ParamRadioConfig;
public disabled: boolean;
constructor(private _paramDef: ParamDefinition, parent: FormulaireNode) {
super(parent);
this._radioConfig = this.radioState;
......
......@@ -769,30 +769,35 @@ export class FormulaireService extends Observable {
* Demande à la Session JalHYd la liste des paramètres/résultats pouvant être liés au
* paramètre fourni
*/
public getLinkableValues(p: NgParameter): LinkedValue[] {
public getLinkableValues(p: NgParameter, update = false): LinkedValue[] {
let linkableValues: LinkedValue[] = [];
if (p) {
linkableValues = Session.getInstance().getLinkableValues(p.paramDefinition);
// join form names to ease usage
for (let i = 0; i < linkableValues.length; i++) {
const lv = linkableValues[i];
for (const f of this._formulaires) {
if (f.currentNub) {
if (f.currentNub.uid === lv.nub.uid) {
lv.meta["formTitle"] = f.calculatorName;
} else {
// child structures ?
for (const s of f.currentNub.getChildren()) {
if (s.uid === lv.nub.uid) {
lv.meta["formTitle"] = f.calculatorName;
if (update || p.linkableValues === undefined) {
linkableValues = Session.getInstance().getLinkableValues(p.paramDefinition);
// join form names to ease usage
for (let i = 0; i < linkableValues.length; i++) {
const lv = linkableValues[i];
for (const f of this._formulaires) {
if (f.currentNub) {
if (f.currentNub.uid === lv.nub.uid) {
lv.meta["formTitle"] = f.calculatorName;
} else {
// child structures ?
for (const s of f.currentNub.getChildren()) {
if (s.uid === lv.nub.uid) {
lv.meta["formTitle"] = f.calculatorName;
}
}
}
}
}
}
linkableValues = this.filterLinkableValues(linkableValues);
} else {
linkableValues = p.linkableValues;
}
}
linkableValues = this.filterLinkableValues(linkableValues);
p.linkableValues = linkableValues;
return linkableValues;
}
......@@ -866,7 +871,7 @@ export class FormulaireService extends Observable {
}
/**
* Génère un formulaire SectionParametree à partir du module courant
* Génère un formulaire SectionParametree à partir du module courant
* s'il est du type régime uniforme ou courbe de remous
*/
public async generateParametricSectionForm(Y?: number): Promise<FormulaireDefinition> {
......
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