Skip to content
Snippets Groups Projects
Commit 62aedd0d authored by David Dorchies's avatar David Dorchies :zany_face:
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 { I18nService } from "../../services/internationalisation.service";
import { NgParameter, ParamRadioConfig } from "../../formulaire/elements/ngparam"; import { NgParameter, ParamRadioConfig } from "../../formulaire/elements/ngparam";
...@@ -19,7 +19,7 @@ import { ParamValuesComponent } from "../param-values/param-values.component"; ...@@ -19,7 +19,7 @@ import { ParamValuesComponent } from "../param-values/param-values.component";
"./param-field-line.component.scss" "./param-field-line.component.scss"
] ]
}) })
export class ParamFieldLineComponent implements OnChanges { export class ParamFieldLineComponent implements OnChanges, AfterViewInit {
constructor() { constructor() {
this.intlService = ServiceFactory.i18nService; this.intlService = ServiceFactory.i18nService;
...@@ -193,16 +193,17 @@ export class ParamFieldLineComponent implements OnChanges { ...@@ -193,16 +193,17 @@ export class ParamFieldLineComponent implements OnChanges {
*/ */
public hasRadioLink(): boolean { public hasRadioLink(): boolean {
if (this._formService.formulaires.length > 0 && !this.isParameterLinkTarget()) { if (this._formService.formulaires.length > 0 && !this.isParameterLinkTarget()) {
this._formService.getLinkableValues(this.param);
// au moins 2 modules de calcul ouverts // au moins 2 modules de calcul ouverts
if (this._formService.formulaires.length > 1) { 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 // ou un seul module de calcul "ouvrages parallèles" avec au moins 2 ouvrages
if (this._formService.formulaires[0].currentNub instanceof ParallelStructure) { if (this._formService.formulaires[0].currentNub instanceof ParallelStructure) {
const ps: ParallelStructure = this._formService.formulaires[0].currentNub; const ps: ParallelStructure = this._formService.formulaires[0].currentNub;
if (ps.structures.length > 1) { 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 { ...@@ -210,7 +211,7 @@ export class ParamFieldLineComponent implements OnChanges {
if (this._formService.formulaires[0].currentNub instanceof Pab) { if (this._formService.formulaires[0].currentNub instanceof Pab) {
const pab: Pab = this._formService.formulaires[0].currentNub; const pab: Pab = this._formService.formulaires[0].currentNub;
if (pab.children.length > 1) { 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 { ...@@ -359,6 +360,10 @@ export class ParamFieldLineComponent implements OnChanges {
this._ngParamInputComponent.showError = this.isRadioFixChecked; this._ngParamInputComponent.showError = this.isRadioFixChecked;
} }
public ngAfterViewInit() {
this._formService.getLinkableValues(this.param, true);
}
/** /**
* relit la valeur dans l'interface et met à jour le NgParameter * relit la valeur dans l'interface et met à jour le NgParameter
*/ */
......
...@@ -262,7 +262,7 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy { ...@@ -262,7 +262,7 @@ export class ParamLinkComponent implements OnChanges, Observer, OnDestroy {
let noMoreTarget = false; let noMoreTarget = false;
// liste des paramètres liables // liste des paramètres liables
if (this.param.valueMode === ParamValueMode.LINK) { 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; noMoreTarget = this._linkableParams.length === 0;
} else { } else {
this._linkableParams = []; this._linkableParams = [];
......
...@@ -29,6 +29,11 @@ export enum ParamRadioConfig { ...@@ -29,6 +29,11 @@ export enum ParamRadioConfig {
*/ */
export class NgParameter extends InputField implements Observer { 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 */ /** set to true to disable UI validation on this input */
private _allowEmpty = false; private _allowEmpty = false;
...@@ -41,8 +46,6 @@ export class NgParameter extends InputField implements Observer { ...@@ -41,8 +46,6 @@ export class NgParameter extends InputField implements Observer {
*/ */
private _radioConfig: ParamRadioConfig; private _radioConfig: ParamRadioConfig;
public disabled: boolean;
constructor(private _paramDef: ParamDefinition, parent: FormulaireNode) { constructor(private _paramDef: ParamDefinition, parent: FormulaireNode) {
super(parent); super(parent);
this._radioConfig = this.radioState; this._radioConfig = this.radioState;
......
...@@ -769,30 +769,35 @@ export class FormulaireService extends Observable { ...@@ -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 * Demande à la Session JalHYd la liste des paramètres/résultats pouvant être liés au
* paramètre fourni * paramètre fourni
*/ */
public getLinkableValues(p: NgParameter): LinkedValue[] { public getLinkableValues(p: NgParameter, update = false): LinkedValue[] {
let linkableValues: LinkedValue[] = []; let linkableValues: LinkedValue[] = [];
if (p) { if (p) {
linkableValues = Session.getInstance().getLinkableValues(p.paramDefinition); if (update || p.linkableValues === undefined) {
// join form names to ease usage linkableValues = Session.getInstance().getLinkableValues(p.paramDefinition);
for (let i = 0; i < linkableValues.length; i++) { // join form names to ease usage
const lv = linkableValues[i]; for (let i = 0; i < linkableValues.length; i++) {
for (const f of this._formulaires) { const lv = linkableValues[i];
if (f.currentNub) { for (const f of this._formulaires) {
if (f.currentNub.uid === lv.nub.uid) { if (f.currentNub) {
lv.meta["formTitle"] = f.calculatorName; if (f.currentNub.uid === lv.nub.uid) {
} else { lv.meta["formTitle"] = f.calculatorName;
// child structures ? } else {
for (const s of f.currentNub.getChildren()) { // child structures ?
if (s.uid === lv.nub.uid) { for (const s of f.currentNub.getChildren()) {
lv.meta["formTitle"] = f.calculatorName; 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; return linkableValues;
} }
...@@ -866,7 +871,7 @@ export class FormulaireService extends Observable { ...@@ -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 * s'il est du type régime uniforme ou courbe de remous
*/ */
public async generateParametricSectionForm(Y?: number): Promise<FormulaireDefinition> { 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