diff --git a/e2e/calculate-linked-params.e2e-spec.ts b/e2e/calculate-linked-params.e2e-spec.ts index 56f8dd05fcb11caf5909a18f4d095c1495b90f45..12e68d423b9cdda3373f74cabd60824086cfb91e 100644 --- a/e2e/calculate-linked-params.e2e-spec.ts +++ b/e2e/calculate-linked-params.e2e-spec.ts @@ -304,4 +304,44 @@ describe("ngHyd − calculate with linked parameters", () => { expect(Number(volume)).toBeCloseTo(44.565, 3); }); + it(" − a link target parameter should not be able to link to another parameter", async () => { + debugger + // create 1st PAB-Chute + await navBar.clickNewCalculatorButton(); + await browser.sleep(200); + await listPage.clickMenuEntryForCalcType(12); + await browser.sleep(200); + + // upstream water level should not have link mode (only one calculator) + const Z1_1 = calcPage.getInputById("Z1"); + expect(await calcPage.inputHasLinkModeButton(Z1_1)).toBe(false); + + // create 2nd PAB-Chute + await navBar.clickNewCalculatorButton(); + await browser.sleep(200); + await listPage.clickMenuEntryForCalcType(12); + await browser.sleep(200); + + // back to 1st calculator + await navBar.clickCalculatorTab(0); + await browser.sleep(200); + + // upstream water level should have link mode (now there are 2 calculators) + expect(await calcPage.inputHasLinkModeButton(Z1_1)).toBe(true); + + // back to 2nd calculator + await navBar.clickCalculatorTab(1); + await browser.sleep(200); + + // link upstream water level in 2nd calculator to upstream water level in 1st one + const Z1_2 = calcPage.getInputById("Z1"); + await calcPage.setParamMode(Z1_2, "link"); + + // back to 1st calculator + await navBar.clickCalculatorTab(0); + await browser.sleep(200); + + // upstream water level should not have link mode (already a link target) + expect(await calcPage.inputHasLinkModeButton(Z1_1)).toBe(false); + }); }); diff --git a/e2e/calculator.po.ts b/e2e/calculator.po.ts index ed78fc4e299b9cc3de64efa3608c5159554658e8..af1e1803ce378ba967def9837500ece6da58a434 100644 --- a/e2e/calculator.po.ts +++ b/e2e/calculator.po.ts @@ -184,6 +184,14 @@ export class CalculatorPage { return await button.isPresent(); } + async inputHasLinkModeButton(input: ElementFinder) { + // get parent (div.container) + const container = await this.findParentContainer(input); + // find radio buttons + const button: ElementFinder = container.element(by.css("mat-button-toggle.radio_link > button")); + return await button.isPresent(); + } + /** * @returns true if "fixed mode" button linked to an input is selected */ diff --git a/jalhyd_branch b/jalhyd_branch index 0bd0de8433c44aa322701f9bf4b87ff6d54b525c..af02f54ce395c0a15d039b449fa00e9d42059486 100644 --- a/jalhyd_branch +++ b/jalhyd_branch @@ -1 +1 @@ -334-restructurer-lechapt-et-calmon-pour-de-nouvelles-lois-de-pertes-de-charge +341-un-parametre-cible-d-un-lien-ne-doit-pas-se-lier-a-un-autre-parametre diff --git a/src/app/components/param-field-line/param-field-line.component.html b/src/app/components/param-field-line/param-field-line.component.html index 641d9c4b026793c3f12900a2de31ee916068ff30..6cc879f86446cbcbdf0bf69e5e9bc0e6ec483072 100644 --- a/src/app/components/param-field-line/param-field-line.component.html +++ b/src/app/components/param-field-line/param-field-line.component.html @@ -41,6 +41,7 @@ <span fxHide.gt-xxs>C</span> </mat-button-toggle> + <!-- (click)="onRadioClick('link')" [checked]="isRadioLinkChecked" [disabled]="isRadioLinkDisabled"> --> <mat-button-toggle class="radio_link" value="radio_link" *ngIf="hasRadioLink()" (click)="onRadioClick('link')" [checked]="isRadioLinkChecked" [disabled]="! canExitCalcMode()"> <span fxHide.xxs>{{ uitextParamLie }}</span> diff --git a/src/app/components/param-field-line/param-field-line.component.ts b/src/app/components/param-field-line/param-field-line.component.ts index a64528e1fcab24d304caf2763e13ada2708894ad..2dbe5a3335f1a02e7b1c480ee157a8ad14a8aba4 100644 --- a/src/app/components/param-field-line/param-field-line.component.ts +++ b/src/app/components/param-field-line/param-field-line.component.ts @@ -4,7 +4,7 @@ import { I18nService } from "../../services/internationalisation.service"; import { NgParameter, ParamRadioConfig } from "../../formulaire/elements/ngparam"; import { NgParamInputComponent } from "../ngparam-input/ngparam-input.component"; import { ServiceFactory } from "../../services/service-factory"; -import { ParamValueMode, ParallelStructure, ParamCalculability, Pab } from "jalhyd"; +import { ParamValueMode, ParallelStructure, ParamCalculability, Pab, Session } from "jalhyd"; import { FormulaireService } from "../../services/formulaire.service"; import { ParamLinkComponent } from "../param-link/param-link.component"; import { ParamValuesComponent } from "../param-values/param-values.component"; @@ -192,7 +192,7 @@ export class ParamFieldLineComponent implements OnChanges { * calcule la présence du radio "paramètre lié" (importé d'un autre module de calcul) */ public hasRadioLink(): boolean { - if (this._formService.formulaires.length > 0) { + if (this._formService.formulaires.length > 0 && !this.isParameterLinkTarget()) { // au moins 2 modules de calcul ouverts if (this._formService.formulaires.length > 1) { return this._formService.getLinkableValues(this.param).length > 0; @@ -254,6 +254,20 @@ export class ParamFieldLineComponent implements OnChanges { return false; } + /** + * @returns true if parameter is a link target + */ + private isParameterLinkTarget(): boolean { + return Session.getInstance().isParameterLinkTarget(this.param.paramDefinition); + } + + /** + * compute link radio button "disabled" status + */ + public get isRadioLinkDisabled(): boolean { + return !this.canExitCalcMode() || this.isParameterLinkTarget(); + } + public get radioCalTitle(): string { if (this.isRadioCalDisabled) { return this.intlService.localizeText("INFO_PARAMFIELD_CANNOT_CALC_LINKS_LOOP");