diff --git a/src/app/components/dialog-edit-param-computed/dialog-edit-param-computed.component.html b/src/app/components/dialog-edit-param-computed/dialog-edit-param-computed.component.html index 8e56fa40849187df03c20fdcd96a8221dc6c5008..e3a40065da10db038c0e6aebc7f63cf657bd19d2 100644 --- a/src/app/components/dialog-edit-param-computed/dialog-edit-param-computed.component.html +++ b/src/app/components/dialog-edit-param-computed/dialog-edit-param-computed.component.html @@ -7,8 +7,11 @@ </div> <div mat-dialog-actions [attr.align]="'end'"> - <button mat-raised-button [mat-dialog-close]="true" cdkFocusInitial> - {{ uitextClose }} + <button mat-raised-button color="primary" [mat-dialog-close]="true" cdkFocusInitial> + {{ uitextCancel }} + </button> + <button mat-raised-button color="warn" (click)="onValidate()"> + {{ uitextValidate }} </button> </div> diff --git a/src/app/components/dialog-edit-param-computed/dialog-edit-param-computed.component.ts b/src/app/components/dialog-edit-param-computed/dialog-edit-param-computed.component.ts index 9b372577156b5e3ffbeb377a4bd205dd9a29b40c..d971e1ea6851430ebe9cae41ded481c02ca89d6e 100644 --- a/src/app/components/dialog-edit-param-computed/dialog-edit-param-computed.component.ts +++ b/src/app/components/dialog-edit-param-computed/dialog-edit-param-computed.component.ts @@ -4,6 +4,8 @@ import { I18nService } from "../../services/internationalisation.service"; import { NgParameter } from "../../formulaire/elements/ngparam"; import { NgParamInputComponent } from "../ngparam-input/ngparam-input.component"; +import { ParamDefinition } from "jalhyd"; + @Component({ selector: "dialog-edit-param-computed", templateUrl: "dialog-edit-param-computed.component.html", @@ -22,11 +24,21 @@ export class DialogEditParamComputedComponent implements OnInit { private intlService: I18nService, @Inject(MAT_DIALOG_DATA) public data: any ) { - this.param = data.param; + // copy given parameter in a "fake" Ngparameter + const nP = data.param as NgParameter; + const p = nP.paramDefinition as ParamDefinition; + const pDef = new ParamDefinition(undefined, p.symbol, p.domain, p.unit, p.getValue(), p.family, p.visible); + this.param = new NgParameter(pDef, undefined); + this.param.setLabel(nP.label); + this.param.unit = nP.unit; + } + + public get uitextCancel(): string { + return this.intlService.localizeText("INFO_OPTION_CANCEL"); } - public get uitextClose() { - return this.intlService.localizeText("INFO_OPTION_CLOSE"); + public get uitextValidate(): string { + return this.intlService.localizeText("INFO_OPTION_VALIDATE"); } public get uitextEditParamComputedInitialValue() { @@ -36,4 +48,10 @@ export class DialogEditParamComputedComponent implements OnInit { public ngOnInit() { this._ngParamInputComponent.model = this.param; } + + public onValidate() { + this.dialogRef.close({ + value: this.param.getValue() + }); + } } diff --git a/src/app/components/param-computed/param-computed.component.ts b/src/app/components/param-computed/param-computed.component.ts index 43f2548b8e81bd70541f7bd77e243ab003253735..e1f9010718fe65e683d37fd444984d09757b5795 100644 --- a/src/app/components/param-computed/param-computed.component.ts +++ b/src/app/components/param-computed/param-computed.component.ts @@ -1,7 +1,7 @@ import { Component, Input } from "@angular/core"; import { MatDialog } from "@angular/material/dialog"; import { NgParameter } from "../../formulaire/elements/ngparam"; -import { ParamCalculability, Structure } from "jalhyd"; +import { ParamCalculability } from "jalhyd"; import { DialogEditParamComputedComponent } from "../dialog-edit-param-computed/dialog-edit-param-computed.component"; import { I18nService } from "../../services/internationalisation.service"; @@ -47,17 +47,23 @@ export class ParamComputedComponent { } public openDialog() { - // modification de la valeur initiale, sans avoir à remettre le mode de - // paramètre sur "fixé" - this.editInitialValueDialog.open( + // modification de la valeur initiale, sans avoir à remettre le mode de paramètre sur "fixé" + const dialogRef = this.editInitialValueDialog.open( DialogEditParamComputedComponent, { data: { param: this.param }, - autoFocus: false + autoFocus: false, + disableClose: true } ); + dialogRef.afterClosed().subscribe(result => { + if (result && result.value !== undefined) { + // use setInitValue() and not setValue() to prevent value mode from going back to SINGLE + this.param.paramDefinition.setInitValue(result.value); + } + }); } public get uitextEditInitialValue() { diff --git a/src/app/formulaire/elements/ngparam.ts b/src/app/formulaire/elements/ngparam.ts index 0a8baafb27a095b250258523f42b9b74504b1cd6..183c4e241df895a88255d8043c6efe40b694e344 100644 --- a/src/app/formulaire/elements/ngparam.ts +++ b/src/app/formulaire/elements/ngparam.ts @@ -287,6 +287,14 @@ export class NgParameter extends InputField implements Observer { } } + /** + * Trick method for overriding label; used in fake NgParameter such + * as the one in DialogEditParamComputedComponent + */ + public setLabel(l: string) { + this._label = l; + } + /** * Sets this parameter as the one to be computed */