dialog-edit-param-values.component.ts 8.50 KiB
import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material";
import { Inject, Component, OnInit } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { I18nService } from "../../services/internationalisation/internationalisation.service";
import { NgParameter } from "../../formulaire/ngparam";
import { ParamValueMode } from "jalhyd";
import { sprintf } from "sprintf-js";
@Component({
    selector: "dialog-edit-param-values",
    templateUrl: "dialog-edit-param-values.component.html",
    styleUrls: ["dialog-edit-param-values.component.scss"]
export class DialogEditParamValuesComponent implements OnInit {
    /** the related parameter to change the "variable" value of */
    public param: NgParameter;
    /** available value modes (min / max, list) */
    public valueModes;
    /** available decimal separators */
    public decimalSeparators;
    /** current decimal separator */
    public decimalSeparator;
    public valuesListForm: FormGroup;
    constructor(
        public dialogRef: MatDialogRef<DialogEditParamValuesComponent>,
        private intlService: I18nService,
        private fb: FormBuilder,
        @Inject(MAT_DIALOG_DATA) public data: any
    ) {
        this.param = data.param;
        if (this.isListe) {
            console.log("PARAM LIST VALUE", this.param.valueList);
        // an explicit ReactiveForm is required for file input component
        this.valuesListForm = this.fb.group({
            file: [null, null]
        });
        this.valueModes = [
                value: ParamValueMode.MINMAX,
                label: this.intlService.localizeText("INFO_PARAMMODE_MINMAX")
                value: ParamValueMode.LISTE,
                label: this.intlService.localizeText("INFO_PARAMMODE_LIST")
        this.decimalSeparators = [
                label: this.intlService.localizeText("INFO_PARAMFIELD_PARAMVARIER_SEPARATEUR_POINT"),
                value: "."
                label: this.intlService.localizeText("INFO_PARAMFIELD_PARAMVARIER_SEPARATEUR_VIRGULE"),
                value: ","
        this.decimalSeparator = this.decimalSeparators[0].value;
    /** regular expression pattern for values list validation (depends on decimal separator) */
    public get valuesListPattern() {