dialog-edit-param-values.component.ts 13.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";
import { ApplicationSetupService } from "../../services/app-setup/app-setup.service";
@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: { value: ParamValueMode; label: string; }[];
    /** available decimal separators */
    public decimalSeparators: { label: string; value: string; }[];
    /** current decimal separator */
    public decimalSeparator: string;
    public valuesListForm: FormGroup;
    /** when true, shows the values chart instead of the edit form */
    public viewChart = false;
    // chart config
    public chartData = {};
    public chartOptions;
    constructor(
        public dialogRef: MatDialogRef<DialogEditParamValuesComponent>,
        private intlService: I18nService,
        private appSetupService: ApplicationSetupService,
        private fb: FormBuilder,
        @Inject(MAT_DIALOG_DATA) public data: any
    ) {
        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({
            file: [""],
            valuesList: [ initialValue,
                    Validators.required
                    // Validators.pattern(new RegExp(this.valuesListPattern)) // behaves weirdly
        });
        // available options for select controls
        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"),