An error occurred while loading the file. Please try again.
-
Guillaume Pasero authorede2cc1814
import { Component, Input, Output, EventEmitter, ViewChild, AfterViewChecked, OnChanges } from "@angular/core";
import { ParamValueMode } from "jalhyd";
import { InternationalisationService } from "../../services/internationalisation/internationalisation.service";
import { NgParameter } from "../../formulaire/ngparam";
import { NgParamMinComponent } from "./ngparam-min.component";
import { NgParamMaxComponent } from "./ngparam-max.component";
import { NgParamStepComponent } from "./ngparam-step.component";
import { BaseComponent } from "../base/base.component";
import { ValueListComponent } from "./value-list.component";
@Component({
selector: "param-values",
templateUrl: "./param-values.component.html",
styles: [
`.btn-on {
color:#505050;
border: 3px solid #505050;
background-color:white;
text-transform: uppercase;
font-size: 0.8em;
}`,
`.btn-off {
color:white;
border: 3px solid #505050;
background-color:#505050;
text-transform: uppercase;
font-size: 0.8em;
}`
]
})
export class ParamValuesComponent extends BaseComponent implements AfterViewChecked, OnChanges {
@Input()
private param: NgParameter;
private _valueModes = [];
/**
* true quand les champs du composant et de ses enfants sont initialisés
*/
private _initCompleted = false;
/**
* true si la valeur min est valide
*/
private _validMin = false;
/**
* true si la valeur max est valide
*/
private _validMax = false;
/**
* true si la valeur du pas est valide
*/
private _validStep = false;
/**
* true si la liste de valeurs est valide
*/
private _validList = false;
/**
* flag signalant qu'il faut initialiser le composant ValueListComponent (par ex quand on a sélectionné le mode "liste")
*/
private _doInitList = false;
/**
* flag signalant qu'il faut initialiser les composants min/max/pas
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
*/
private _doInitMinmax = false;
/**
* composant de saisie du minimum
*/
@ViewChild(NgParamMinComponent)
private _minComponent: NgParamMinComponent;
/**
* composant de saisie du maximum
*/
@ViewChild(NgParamMaxComponent)
private _maxComponent: NgParamMaxComponent;
/**
* composant de saisie du pas de variation
*/
@ViewChild(NgParamStepComponent)
private _stepComponent: NgParamStepComponent;
/**
* composant de saisie d'une liste de valeurs
*/
@ViewChild(ValueListComponent)
private _listComponent: ValueListComponent;
@Output()
private valid: EventEmitter<boolean>;
constructor(private intlService: InternationalisationService) {
super();
this._valueModes.push({ "value": ParamValueMode.MINMAX, "label": "Min/max" });
this._valueModes.push({ "value": ParamValueMode.LISTE, "label": "Liste" });
this.valid = new EventEmitter();
}
/**
* init des champs min/max/pas
*/
private initMinMaxStep() {
if (this.isMinMax && this._doInitMinmax) {
this._doInitMinmax = false;
// valeur pour min : celle déjà définie ou celle déduite de la valeur saisie
let min: number = this.param.minValue;
if (min === undefined) {
min = this.param.getValue() / 2;
}
// valeur pour max : celle déjà définie ou celle déduite de la valeur saisie
let max: number = this.param.maxValue;
if (max === undefined) {
max = this.param.getValue() * 2;
}
this.param.minValue = min;
this._minComponent.model = this.param;
this.param.maxValue = max;
this._maxComponent.model = this.param;
// valeur du pas
let step = this.param.stepValue;
if (step === undefined) {
step = (max - min) / 20;
}
this.param.stepValue = step;
this._stepComponent.model = this.param;