Skip to content
Snippets Groups Projects
Commit d4de914c authored by francois.grand's avatar francois.grand
Browse files

ticket #47 : ajout du répertoire src/app/components/param-values/ oublié dans le commit précédent

parent b703c7e2
No related branches found
No related tags found
1 merge request!7Resolve "Paramètres à varier : liste libre de paramètres"
import { Component, Output, EventEmitter } from "@angular/core";
import { NumericalString, Pair } from "jalhyd";
import { GenericInputComponent } from "../generic-input/generic-input.component";
import { InternationalisationService } from "../../services/internationalisation/internationalisation.service";
@Component({
selector: "ngparam-max",
templateUrl: "../generic-input/generic-input.component.html"
})
export class NgParamMaxComponent extends GenericInputComponent {
/**
* valeur actuelle du maximum
*/
private _currentValue: number;
/**
* reférence (valeur maxi pour le maximum)
*/
private _refValue: Pair;
@Output()
private onChange = new EventEmitter<string>();
constructor(private intlService: InternationalisationService) {
super();
}
public set refValue(v: Pair) {
this._refValue = v;
}
protected getModelValue(): any {
return this._currentValue;
}
protected setModelValue(v: any) {
this._currentValue = v;
this.onChange.emit("value");
}
protected validateModelValue(v: any): { isValid: boolean, message: string } {
let msg = undefined;
let valid = false;
if (!this._refValue.intervalHasValue(v))
msg = "La valeur n'est pas dans " + this._refValue.toString();
else
valid = true;
return { isValid: valid, message: msg };
}
protected modelToUI(v: any): string {
if (typeof (v) == "number")
return String(v);
return undefined;
}
protected validateUIValue(ui: string): { isValid: boolean, message: string } {
let valid: boolean = false;
let msg: string = undefined;
let v: NumericalString = new NumericalString(ui);
if (!v.isNumerical)
msg = "Veuillez entrer une valeur numérique";
else
valid = true;
return { isValid: valid, message: msg };
}
protected uiToModel(ui: string) {
return +ui;
}
}
import { Component, Output, EventEmitter } from "@angular/core";
import { NumericalString, Pair } from "jalhyd";
import { GenericInputComponent } from "../generic-input/generic-input.component";
import { InternationalisationService } from "../../services/internationalisation/internationalisation.service";
@Component({
selector: "ngparam-min",
templateUrl: "../generic-input/generic-input.component.html"
})
export class NgParamMinComponent extends GenericInputComponent {
/**
* valeur actuelle du minimum
*/0.49999999995
private _currentValue: number;
/**
* reférence (valeur mini pour le minimum)
*/
private _refValue: Pair;
@Output()
private onChange = new EventEmitter<string>();
public isInit: boolean;
constructor(private intlService: InternationalisationService) {
super();
}
public set refValue(v: Pair) {
this._refValue = v;
}
protected getModelValue(): any {
return this._currentValue;
}
protected setModelValue(v: any) {
this._currentValue = v;
this.onChange.emit("value");
}
protected validateModelValue(v: any): { isValid: boolean, message: string } {
let msg = undefined;
let valid = false;
if (!this._refValue.intervalHasValue(v))
msg = "La valeur n'est pas dans " + this._refValue.toString();
else
valid = true;
return { isValid: valid, message: msg };
}
protected modelToUI(v: any): string {
if (typeof (v) == "number")
return String(v);
return undefined;
}
protected validateUIValue(ui: string): { isValid: boolean, message: string } {
let valid: boolean = false;
let msg: string = undefined;
let v: NumericalString = new NumericalString(ui);
if (!v.isNumerical)
msg = "Veuillez entrer une valeur numérique";
else
valid = true;
return { isValid: valid, message: msg };
}
protected uiToModel(ui: string): any {
return +ui;
}
}
import { Component, Output, EventEmitter } from "@angular/core";
import { NumericalString, Pair } from "jalhyd";
import { GenericInputComponent } from "../generic-input/generic-input.component";
import { InternationalisationService } from "../../services/internationalisation/internationalisation.service";
@Component({
selector: "ngparam-step",
templateUrl: "../generic-input/generic-input.component.html"
})
export class NgParamStepComponent extends GenericInputComponent {
/**
* valeur actuelle du pas
*/
private _currentValue: number;
/**
* reférence (valeur maxi pour le pas)
*/
private _refValue: Pair;
@Output()
private onChange = new EventEmitter<string>();
constructor(private intlService: InternationalisationService) {
super();
}
public set refValue(v: Pair) {
this._refValue = v;
}
protected getModelValue(): any {
return this._currentValue;
}
protected setModelValue(v: any) {
this._currentValue = v;
this.onChange.emit("value");
}
protected validateModelValue(v: any): { isValid: boolean, message: string } {
let msg = undefined;
let valid = false;
if (!this._refValue.intervalHasValue(v))
msg = "La valeur n'est pas dans " + this._refValue.toString();
else {
valid = v > 0;
if (!valid)
msg = "La valeur ne peut pas être <= 0";
}
return { isValid: valid, message: msg };
}
protected modelToUI(v: any): string {
if (typeof (v) == "number")
return String(v);
return "<invalid>";
}
protected validateUIValue(ui: string): { isValid: boolean, message: string } {
let valid: boolean = false;
let msg: string = undefined;
let v: NumericalString = new NumericalString(ui);
if (!v.isNumerical)
msg = "Veuillez entrer une valeur numérique";
else
valid = true;
return { isValid: valid, message: msg };
}
protected uiToModel(ui: string) {
return +ui;
}
}
<div class="row">
<div class="btn-group col-12 col-sm-3" dropdown (click)="onSelect($event)">
<button dropdownToggle class="btn btn-primary dropdown-toggle waves-light my-1" type="button" mdbRippleRadius>
{{currentLabel}}
</button>
<div class="dropdown-menu">
<a class="dropdown-item" *ngFor="let e of _valueModes" [value]=e.value>{{e.label}}</a>
</div>
</div>
<div *ngIf="!isList" class="col-12 col-sm-3">
<ngparam-min [title]="uitextValeurMini" (onChange)="onMinChanged($event)"></ngparam-min>
</div>
<div *ngIf="!isList" class="col-12 col-sm-3">
<ngparam-max [title]="uitextValeurMaxi" (onChange)="onMaxChanged($event)"></ngparam-max>
</div>
<div *ngIf="!isList" class="col-12 col-sm-3">
<ngparam-step [title]="uitextPasVariation" (onChange)="onStepChanged($event)"></ngparam-step>
</div>
<div *ngIf="isList" class="col-12 col-sm-9">
<value-list title="valeurs séparées par ';'" (onChange)="onListChanged($event)"></value-list>
</div>
</div>
\ No newline at end of file
import { Component, Input, Output, EventEmitter, ViewChild, DoCheck } from "@angular/core";
import { ParamDomainValue, Pair } from "jalhyd";
import { InternationalisationService } from "../../services/internationalisation/internationalisation.service";
import { NgParameter, ParamValueMode } from "../../formulaire/ngparam";
import { GenericInputComponent } from "../generic-input/generic-input.component";
import { NgParamMinComponent } from "./ngparam-min.component";
import { NgParamMaxComponent } from "./ngparam-max.component";
import { NgParamStepComponent } from "./ngparam-step.component";
@Component({
selector: "value-list",
templateUrl: "../generic-input/generic-input.component.html"
})
export class ValueListComponent extends GenericInputComponent {
@Output()
private onChange = new EventEmitter<string>();
public _list: number[];
public isInit;
constructor(private intlService: InternationalisationService) {
super();
this._list = [];
}
protected getModelValue(): any {
return this._list;
}
protected setModelValue(l: any) {
if (typeof (l) == "number") {
this._list = [];
this._list.push(l);
}
else
this._list = l;
this.onChange.emit("value");
}
protected validateModelValue(v: any): { isValid: boolean, message: string } {
let msg = undefined;
let valid = false;
if (v instanceof Array) {
valid = true;
for (let e of v) {
valid = valid && (typeof (e) == "number")
if (!valid) {
msg = "La valeur n'est pas une liste de nombres"
break;
}
}
}
return { isValid: valid, message: msg };
}
protected modelToUI(v: any): string {
let res = "";
for (let e of v) {
if (res != "")
res += ";";
res += String(e);
}
return res;
}
protected validateUIValue(ui: string): { isValid: boolean, message: string } {
let valid: boolean = false;
let msg: string = undefined;
let tmp: string[] = ui.split(";");
let res = true;
for (let v of tmp) {
let isnum = v != "" && (+v == +v);
res = res && isnum;
if (!res)
break;
}
if (!res)
msg = "Veuillez entrer une liste de nombres";
else
valid = true;
return { isValid: valid, message: msg };
}
protected uiToModel(ui: string) {
let tmp: string[] = ui.split(";");
let res = [];
for (let v of tmp)
res.push(+v);
return res;
}
}
@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 implements DoCheck {
@Input("param")
private _param: NgParameter;
/**
* true si liste de valeur, false si min/max/pas
*/
private _list: boolean;
private _valueModes = [];
/**
* 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;
constructor(private intlService: InternationalisationService) {
this._valueModes.push({ "value": ParamValueMode.MINMAX, "label": "Min/max" });
this._valueModes.push({ "value": ParamValueMode.LISTE, "label": "Liste" });
}
private getDefaultMin(): number {
switch (this._param.domain.domain) {
case ParamDomainValue.ANY:
case ParamDomainValue.NOT_NULL:
return -10;
default:
return this._param.domain.minValue;
}
}
private getDefaultMax(): number {
switch (this._param.domain.domain) {
case ParamDomainValue.INTERVAL:
return this._param.domain.maxValue;
default:
return 10;
}
}
private initMinMaxStep() {
// valeur pour min (celle déjà définie ou celle déduite du domaine de définition)
let min: number = this._param.minValue;
let ok = min != undefined
if (ok) {
try {
// on la vérifie
this._param.checkValue(min);
ok = true;
}
catch (e) {
ok = false;
}
}
if (!ok)
min = this.getDefaultMin();
// valeur pour max (celle déjà définie ou celle déduite du domaine de définition)
let max: number = this._param.maxValue;
ok = max != undefined
if (ok) {
try {
// on la vérifie
this._param.checkValue(max);
ok = true;
}
catch (e) {
ok = false;
}
}
if (!ok)
min = this.getDefaultMax();
this._minComponent.refValue = new Pair(this._param.domain.minValue, max);
this._minComponent.model = min;
this._maxComponent.refValue = new Pair(min, this._param.domain.maxValue);
this._maxComponent.model = max;
this.updateStepComponentRef();
let step = this._param.stepValue;
if (step == undefined)
step = (max - min) / 20;
if (min == -Infinity || max == Infinity)
step = 10;
this._stepComponent.model = step;
}
private onMinChanged(val: string) {
this.updateStepComponentRef();
this._maxComponent.refValue = new Pair(this._minComponent.model, this._param.domain.maxValue);
this._maxComponent.validateModel();
if (this._minComponent.validateModel())
this._param.minValue = this._minComponent.model;
}
private onMaxChanged(val: string) {
this.updateStepComponentRef();
this._minComponent.refValue = new Pair(this._param.domain.minValue, this._maxComponent.model);
this._minComponent.validateModel();
if (this._maxComponent.validateModel())
this._param.maxValue = this._maxComponent.model;
}
private onStepChanged(val: string) {
if (this._stepComponent.validateModel())
this._param.stepValue = this._stepComponent.model;
}
private onListChanged(val: string) {
if (this._listComponent.validateModel())
this._param.valueList = this._listComponent.model;
}
public ngDoCheck() {
// initialisation des champs min/max/step à l'apparition de ces contrôles
if (this._minComponent != undefined && !this._minComponent.isInit) {
this._minComponent.isInit = true;
this.initMinMaxStep();
}
if (this._listComponent != undefined && !this._listComponent.isInit) {
this._listComponent.isInit = true;
this._listComponent.model = [];
if (this._param.isDefined)
this._listComponent.model.push(this._param.getValue());
}
}
/**
* met à jour la valeur de référence du composant gérant le pas de variation
*/
private updateStepComponentRef() {
this._stepComponent.refValue = new Pair(1e-9, this._maxComponent.model - this._minComponent.model);
this._stepComponent.validateModel();
}
private get uitextValeurMini() {
return this.intlService.localizeText("INFO_PARAMFIELD_VALEURMINI");
}
private get uitextValeurMaxi() {
return this.intlService.localizeText("INFO_PARAMFIELD_VALEURMAXI");
}
private get uitextPasVariation() {
return this.intlService.localizeText("INFO_PARAMFIELD_PASVARIATION");
}
private get isList(): boolean {
return this._param.valueMode == ParamValueMode.LISTE;
}
/**
* valeur courante affichée dans le select
*/
private get currentLabel(): string {
// return this._list ? "Liste" : "Min/max/pas";
return ParamValueMode[this._param.valueMode];
}
private onSelect(event: any) {
// for (let a of event.target.attributes)
// if (a.name == "value") {
// var val = a.value;
// break;
// }
// // this._currentLabel = event.target.text;
// this._list = val == "list";
this._param.valueMode = event.target.value;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment