From 7a6483caf82b836b495879bee33c2e031836b34a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Tue, 22 Mar 2022 09:27:34 +0100 Subject: [PATCH 1/5] feat: restore parameter value mode in case of cancel in variable values modification dialog refs #508 --- .../dialog-edit-param-values.component.html | 2 +- .../dialog-edit-param-values.component.ts | 10 +++++++++- .../param-field-line.component.ts | 16 +++++++++++++--- .../param-values/param-values.component.ts | 8 +++++++- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.html b/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.html index 5fc7c8482..beb23b46d 100644 --- a/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.html +++ b/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.html @@ -121,7 +121,7 @@ <div mat-dialog-actions [attr.align]="'end'"> <div> - <button id="btn-cancel" mat-raised-button color="primary" [mat-dialog-close]="true" cdkFocusInitial> + <button id="btn-cancel" mat-raised-button color="primary" (click)="onCancel()" cdkFocusInitial> {{ uitextCancel }} </button> <button mat-raised-button color="warn" (click)="onValidate()" [disabled]=" !isFormValid"> diff --git a/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts b/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts index d84c85459..a6cdcc650 100644 --- a/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts +++ b/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts @@ -282,6 +282,12 @@ export class DialogEditParamValuesComponent implements OnInit { return ret; } + public onCancel() { + this.dialogRef.close({ + cancelled: true + }); + } + public onValidate() { switch (this.param.valueMode) { case ParamValueMode.LISTE: @@ -294,7 +300,9 @@ export class DialogEditParamValuesComponent implements OnInit { this.data.param.setStepValue(this, this.param.stepValue); break; } - this.dialogRef.close(); + this.dialogRef.close({ + cancelled: false + }); } /** 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 f76d819c2..0e97c8b54 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 @@ -119,6 +119,12 @@ export class ParamFieldLineComponent implements OnChanges { private _formService: FormulaireService; + /** + * valeur du mode de paramètre avant clic sur un des radios, utilisé pour restaurer le mode en cas de cancel + * du dialogue de modification des valeurs en mode variable + */ + private oldValueMode: ParamValueMode; + /* * gestion des événements clic sur les radios : * envoi d'un message au composant parent @@ -236,7 +242,7 @@ export class ParamFieldLineComponent implements OnChanges { } public onRadioClick(option: string) { - const oldValue = this.param.valueMode; + this.oldValueMode = this.param.valueMode; switch (option) { case "fix": this.param.valueMode = ParamValueMode.SINGLE; @@ -245,7 +251,7 @@ export class ParamFieldLineComponent implements OnChanges { case "var": // prevent setting LISTE mode back to MINMAX if someone clicks "variable" again // after setting variable mode to LISTE - if (oldValue !== ParamValueMode.MINMAX && oldValue !== ParamValueMode.LISTE) { + if (this.oldValueMode !== ParamValueMode.MINMAX && this.oldValueMode !== ParamValueMode.LISTE) { this.param.valueMode = ParamValueMode.MINMAX; // min/max par défaut } if (this._paramValuesComponent) { @@ -273,7 +279,7 @@ export class ParamFieldLineComponent implements OnChanges { } this.radio.emit({ "param": this.param, - "oldValueMode": oldValue + "oldValueMode": this.oldValueMode }); // MAJ validité this.emitValidity(); @@ -306,6 +312,10 @@ export class ParamFieldLineComponent implements OnChanges { case "model": this.inputChange.emit(event); break; + + case "cancelvar": // cancel button clicked in DialogEditParamValuesComponent + this.param.valueMode = this.oldValueMode; + break; } } diff --git a/src/app/components/param-values/param-values.component.ts b/src/app/components/param-values/param-values.component.ts index 2a0ce5d3c..7a0d4f187 100644 --- a/src/app/components/param-values/param-values.component.ts +++ b/src/app/components/param-values/param-values.component.ts @@ -55,7 +55,7 @@ export class ParamValuesComponent implements AfterViewInit, Observer { public openDialog() { // modification des valeurs variables - this.editValuesDialog.open( + const dlgRef = this.editValuesDialog.open( DialogEditParamValuesComponent, { disableClose: true, @@ -66,6 +66,12 @@ export class ParamValuesComponent implements AfterViewInit, Observer { panelClass: "dialogMinWidth320px" } ); + dlgRef.afterClosed().toPromise().then(result => { + if (result.cancelled) + this.change.emit({ + action: "cancelvar" + }); + }); } public ngAfterViewInit() { -- GitLab From 6843eb43b5861393374d376bcf2926003c1ca66a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Tue, 22 Mar 2022 10:48:24 +0100 Subject: [PATCH 2/5] fix: allow validation button in DialogEditParamValuesComponent in chart view when in min/max mode refs #508 --- .../dialog-edit-param-values.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.html b/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.html index beb23b46d..c7b8d3803 100644 --- a/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.html +++ b/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.html @@ -124,7 +124,7 @@ <button id="btn-cancel" mat-raised-button color="primary" (click)="onCancel()" cdkFocusInitial> {{ uitextCancel }} </button> - <button mat-raised-button color="warn" (click)="onValidate()" [disabled]=" !isFormValid"> + <button mat-raised-button color="warn" (click)="onValidate()" [disabled]=" !isFormValid&&!viewChart"> {{ uitextValidate }} </button> </div> -- GitLab From 9d11df0cd7e9d650802b931e89827374eef486b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 23 Mar 2022 14:52:59 +0100 Subject: [PATCH 3/5] fix: set parameter radio config back when cancel button is clicked in variable values dialog refs #508 --- .../dialog-edit-param-values.component.ts | 2 +- .../param-field-line.component.ts | 16 +++++++++------- .../param-values/param-values.component.ts | 3 ++- src/app/formulaire/elements/ngparam.ts | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts b/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts index a6cdcc650..6a0a68d59 100644 --- a/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts +++ b/src/app/components/dialog-edit-param-values/dialog-edit-param-values.component.ts @@ -53,7 +53,7 @@ export class DialogEditParamValuesComponent implements OnInit { private fb: FormBuilder, @Inject(MAT_DIALOG_DATA) public data: any ) { - this.param = data.param.clone(); + this.param = data.param; // an explicit ReactiveForm is required for file input component const initialValue = (this.param.valueMode === ParamValueMode.LISTE ? this.valuesList : ""); this.valuesListForm = this.fb.group({ 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 0e97c8b54..2cdf93d1f 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 @@ -120,10 +120,10 @@ export class ParamFieldLineComponent implements OnChanges { private _formService: FormulaireService; /** - * valeur du mode de paramètre avant clic sur un des radios, utilisé pour restaurer le mode en cas de cancel - * du dialogue de modification des valeurs en mode variable + * sauvegarde de certaines propriétés du paramètre avant clic sur le radio "varier", utilisé pour + * restaurer le paramètre en cas de cancel du dialogue de modification des valeurs en mode variable */ - private oldValueMode: ParamValueMode; + private paramBackup: NgParameter; /* * gestion des événements clic sur les radios : @@ -242,16 +242,18 @@ export class ParamFieldLineComponent implements OnChanges { } public onRadioClick(option: string) { - this.oldValueMode = this.param.valueMode; + const oldValueMode = this.param.valueMode; switch (option) { case "fix": this.param.valueMode = ParamValueMode.SINGLE; break; case "var": + this.paramBackup = this.param.clone(); + // prevent setting LISTE mode back to MINMAX if someone clicks "variable" again // after setting variable mode to LISTE - if (this.oldValueMode !== ParamValueMode.MINMAX && this.oldValueMode !== ParamValueMode.LISTE) { + if (oldValueMode !== ParamValueMode.MINMAX && oldValueMode !== ParamValueMode.LISTE) { this.param.valueMode = ParamValueMode.MINMAX; // min/max par défaut } if (this._paramValuesComponent) { @@ -279,7 +281,7 @@ export class ParamFieldLineComponent implements OnChanges { } this.radio.emit({ "param": this.param, - "oldValueMode": this.oldValueMode + "oldValueMode": oldValueMode }); // MAJ validité this.emitValidity(); @@ -314,7 +316,7 @@ export class ParamFieldLineComponent implements OnChanges { break; case "cancelvar": // cancel button clicked in DialogEditParamValuesComponent - this.param.valueMode = this.oldValueMode; + this.param.setFrom(this.paramBackup); break; } } diff --git a/src/app/components/param-values/param-values.component.ts b/src/app/components/param-values/param-values.component.ts index 7a0d4f187..62a212791 100644 --- a/src/app/components/param-values/param-values.component.ts +++ b/src/app/components/param-values/param-values.component.ts @@ -67,10 +67,11 @@ export class ParamValuesComponent implements AfterViewInit, Observer { } ); dlgRef.afterClosed().toPromise().then(result => { - if (result.cancelled) + if (result.cancelled) { this.change.emit({ action: "cancelvar" }); + } }); } diff --git a/src/app/formulaire/elements/ngparam.ts b/src/app/formulaire/elements/ngparam.ts index 697667f6c..c18d7f308 100644 --- a/src/app/formulaire/elements/ngparam.ts +++ b/src/app/formulaire/elements/ngparam.ts @@ -46,6 +46,7 @@ export class NgParameter extends InputField implements Observer { const ret: NgParameter = new NgParameter(this._paramDef.clone(), this.parent); ret._allowEmpty = this._allowEmpty; ret.unit = this.unit; + ret.radioConfig = this.radioConfig; ret.disabled = this.disabled; return ret; } @@ -185,6 +186,9 @@ export class NgParameter extends InputField implements Observer { return this._paramDef; } + /** + * compute radio state from value mode + */ public get radioState() { switch (this._paramDef.valueMode) { case ParamValueMode.SINGLE: @@ -390,6 +394,16 @@ export class NgParameter extends InputField implements Observer { } } + /** + * assign given parameter to this + */ + public setFrom(p: NgParameter) { + this._allowEmpty = p._allowEmpty; + this.unit = p.unit; + this.radioConfig = p.radioConfig; + this._paramDef = p._paramDef; + } + /** * supprime un lien avec un paramètre */ -- GitLab From 1de703cec3ea9630a2adda679eb29b182f70ddb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Wed, 30 Mar 2022 12:43:39 +0200 Subject: [PATCH 4/5] fix: variable mode dialog opens when copying a structure In parallel structures, when: - set a structure parameter to variated mode - cancel dialog - copy structure a dialog opens. Now use object representation instead of clone to backup parameter before opening the variable mode dialog. refs #508 --- .../param-field-line.component.ts | 6 ++-- src/app/formulaire/elements/ngparam.ts | 33 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) 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 2cdf93d1f..a85aa6762 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 @@ -123,7 +123,7 @@ export class ParamFieldLineComponent implements OnChanges { * sauvegarde de certaines propriétés du paramètre avant clic sur le radio "varier", utilisé pour * restaurer le paramètre en cas de cancel du dialogue de modification des valeurs en mode variable */ - private paramBackup: NgParameter; + private paramBackup: any; /* * gestion des événements clic sur les radios : @@ -249,7 +249,7 @@ export class ParamFieldLineComponent implements OnChanges { break; case "var": - this.paramBackup = this.param.clone(); + this.paramBackup = this.param.objectRepresentation(); // prevent setting LISTE mode back to MINMAX if someone clicks "variable" again // after setting variable mode to LISTE @@ -316,7 +316,7 @@ export class ParamFieldLineComponent implements OnChanges { break; case "cancelvar": // cancel button clicked in DialogEditParamValuesComponent - this.param.setFrom(this.paramBackup); + this.param.loadObjectRepresentation(this.paramBackup); break; } } diff --git a/src/app/formulaire/elements/ngparam.ts b/src/app/formulaire/elements/ngparam.ts index c18d7f308..007814148 100644 --- a/src/app/formulaire/elements/ngparam.ts +++ b/src/app/formulaire/elements/ngparam.ts @@ -42,15 +42,6 @@ export class NgParameter extends InputField implements Observer { this.disabled = false; } - public clone(): NgParameter { - const ret: NgParameter = new NgParameter(this._paramDef.clone(), this.parent); - ret._allowEmpty = this._allowEmpty; - ret.unit = this.unit; - ret.radioConfig = this.radioConfig; - ret.disabled = this.disabled; - return ret; - } - /** * Returns a text preview of the current value(s), depending on the value mode * @param compact if true, will represent multiple values in a more compact way @@ -394,14 +385,22 @@ export class NgParameter extends InputField implements Observer { } } - /** - * assign given parameter to this - */ - public setFrom(p: NgParameter) { - this._allowEmpty = p._allowEmpty; - this.unit = p.unit; - this.radioConfig = p.radioConfig; - this._paramDef = p._paramDef; + public objectRepresentation(): any { + return { + prmDef: this.paramDefinition.objectRepresentation(), + allowEmpty: this._allowEmpty, + unit: this.unit, + radioConfig: this.radioConfig + } + } + + public loadObjectRepresentation(rep: any) { + if (this._paramDef.symbol === rep.prmDef.symbol) { + this._paramDef.loadObjectRepresentation(rep.prmDef); + this._allowEmpty = rep.allowEmpty; + this.unit = rep.unit; + this.radioConfig = rep.radioConfig; + } } /** -- GitLab From 1b3ba3abe013ba2356aa81fc7f3fccd618e0ef91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grand?= <francois.grand@inrae.fr> Date: Thu, 7 Apr 2022 10:21:57 +0200 Subject: [PATCH 5/5] test: check that parameter mode is set back to its previous value when min/max/list dialog is cancelled refs #508 --- e2e/reset-param-mode.e2e-spec.ts | 42 +++++++++++++++++++++++++++ e2e/variable-param-cancel.e2e-spec.ts | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 e2e/reset-param-mode.e2e-spec.ts diff --git a/e2e/reset-param-mode.e2e-spec.ts b/e2e/reset-param-mode.e2e-spec.ts new file mode 100644 index 000000000..7cc73c007 --- /dev/null +++ b/e2e/reset-param-mode.e2e-spec.ts @@ -0,0 +1,42 @@ +import { ListPage } from "./list.po"; +import { browser, by, element, ElementFinder } from "protractor"; +import { CalculatorPage } from "./calculator.po"; + +/** + * Parameter mode should be set to its previous mode (fixed/var/...) when cancel is pressed + * in variable mode edition dialog + */ +describe("ngHyd - check parameter mode is set to its previous value - ", () => { + let listPage: ListPage; + + beforeAll(async () => { + listPage = new ListPage(); + }); + + it("when min/max/list values dialog is cancelled", async () => { + // start page + await listPage.navigateTo(); + + // open PAB chute + await listPage.clickMenuEntryForCalcType(12); + + // click "calc" radio on Z1 parameter + const z1calcbtn = element(by.id("mat-button-toggle-3")); + await z1calcbtn.click(); + + // click "var" radio on Z1 parameter + const z1varbtn = element(by.id("mat-button-toggle-2")); + await z1varbtn.click(); + + // click cancel button + const cancelbtn = element(by.id("btn-cancel")); + await cancelbtn.click(); + await browser.sleep(200); + + // check Z1 var toggle is disabled + expect(await z1varbtn.getAttribute("ng-reflect-checked")).toBe("false"); + + // check Z1 calc toggle is enabled + expect(await z1calcbtn.getAttribute("ng-reflect-checked")).toBe("true"); + }); +}); diff --git a/e2e/variable-param-cancel.e2e-spec.ts b/e2e/variable-param-cancel.e2e-spec.ts index 750fdd160..abe96d8fe 100644 --- a/e2e/variable-param-cancel.e2e-spec.ts +++ b/e2e/variable-param-cancel.e2e-spec.ts @@ -12,7 +12,7 @@ describe("ngHyd - check cancel button for variable parameters - ", () => { listPage = new ListPage(); }); - fit("when min/max/list values dialog opens, a cancel button should be present", async () => { + it("when min/max/list values dialog opens, a cancel button should be present", async () => { // start page await listPage.navigateTo(); -- GitLab