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

ticket #47 : ajout d'un mode "liste de valeur" pour les paramètres à varier

- composants NgParamMinComponent, NgParamMaxComponent, NgParamStepComponent chacun dans leur fichier
- création d'un composant ValueListComponent pour gérer le "mode min/max/pas" et "liste de valeurs"
- NgParameter : ajout d'un enum pour indiquer le mode de génération des valeurs à varier
parent 6417b08c
No related branches found
No related tags found
1 merge request!7Resolve "Paramètres à varier : liste libre de paramètres"
......@@ -16,7 +16,11 @@ import { ApplicationSetupService } from "./services/app-setup/app-setup.service"
import { AppComponent } from './app.component';
import { NgParamInputComponent } from './components/ngparam-input/ngparam-input.component';
import { FieldSetComponent } from './components/field-set/field-set.component';
import { ParamFieldLineComponent, NgParamMinComponent, NgParamMaxComponent, NgParamStepComponent } from './components/param-field-line/param-field-line.component';
import { ParamFieldLineComponent } from './components/param-field-line/param-field-line.component';
import { NgParamMinComponent } from './components/param-values/ngparam-min.component';
import { NgParamMaxComponent } from './components/param-values/ngparam-max.component';
import { NgParamStepComponent } from './components/param-values/ngparam-step.component';
import { ParamValuesComponent, ValueListComponent } from './components/param-values/param-values.component';
import { SelectFieldLineComponent } from './components/select-field-line/select-field-line.component';
import { CheckFieldLineComponent } from './components/check-field-line/check-field-line.component';
// import { AlertDialog } from './components/alert-dialog/alert-dialog.component';
......@@ -62,6 +66,7 @@ const appRoutes: Routes = [
NgParamInputComponent,
FieldSetComponent,
ParamFieldLineComponent, NgParamMinComponent, NgParamMaxComponent, NgParamStepComponent,
ParamValuesComponent, ValueListComponent,
SelectFieldLineComponent, CheckFieldLineComponent,
LogComponent,
CalculatorListComponent,
......
......@@ -29,14 +29,4 @@
</div>
</div>
<div *ngIf="isRadioVarChecked" class="row">
<div class="col-12 col-sm-4">
<ngparam-min [title]="uitextValeurMini" (onChange)="onMinChanged($event)"></ngparam-min>
</div>
<div class="col-12 col-sm-4">
<ngparam-max [title]="uitextValeurMaxi" (onChange)="onMaxChanged($event)"></ngparam-max>
</div>
<div class="col-12 col-sm-4">
<ngparam-step [title]="uitextPasVariation" (onChange)="onStepChanged($event)"></ngparam-step>
</div>
</div>
\ No newline at end of file
<param-values *ngIf="isRadioVarChecked" [param]="_param"></param-values>
\ No newline at end of file
import { Component, ViewChild, Input, Output, DoCheck, EventEmitter } from "@angular/core";
import { NumericalString, ParamDomainValue, Pair } from "jalhyd";
import { Component, ViewChild, Input, Output, EventEmitter } from "@angular/core";
import { InternationalisationService } from "../../services/internationalisation/internationalisation.service";
import { NgParameter, ParamRadioConfig } from "../../formulaire/ngparam";
import { GenericInputComponent } from "../generic-input/generic-input.component";
@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;
}
}
@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;
}
}
@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;
}
}
@Component({
selector: "param-field-line",
templateUrl: "./param-field-line.component.html",
......@@ -244,142 +24,13 @@ export class NgParamStepComponent extends GenericInputComponent {
}`
]
})
export class ParamFieldLineComponent implements DoCheck {
export class ParamFieldLineComponent {
@Input("param")
private _param: NgParameter;
/**
* 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;
constructor(private intlService: InternationalisationService) {
}
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;
}
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();
}
}
/**
* 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 title(): string {
let t = "";
if (this._param.label != undefined)
......@@ -397,18 +48,6 @@ export class ParamFieldLineComponent implements DoCheck {
return this.intlService.localizeText("INFO_PARAMFIELD_PARAMVARIER");
}
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 uitextParamCalculer() {
return this.intlService.localizeText("INFO_PARAMFIELD_PARAMCALCULER");
}
......
......@@ -7,7 +7,7 @@ import { ParamService } from "../services/param/param.service";
import { InternationalisationService } from "../services/internationalisation/internationalisation.service";
import { ApplicationSetupService } from "../services/app-setup/app-setup.service";
import { Field } from "./field";
import { NgParameter, ParamRadioConfig } from "./ngparam";
import { NgParameter, ParamRadioConfig, ParamValueMode } from "./ngparam";
import { InputField } from "./input-field";
import { CheckField } from "./check-field";
import { SelectField } from "./select-field";
......@@ -1117,20 +1117,39 @@ export class FormulaireDefinition extends Observable {
this._fixVarResults.setVariableParamHeaderFromParameter(varParam, !rg);
this._fixVarResults.setVariableResultHeaderFromParameter(computedParam);
let min: number = +varParam.minValue;
let max: number = +varParam.maxValue;
let step: number = +varParam.stepValue;
switch (varParam.valueMode) {
case ParamValueMode.MINMAX:
let min: number = +varParam.minValue;
let max: number = +varParam.maxValue;
let step: number = +varParam.stepValue;
for (let val = min; val <= max; val += step) {
prms[varParam.symbol].v = val;
for (let val = min; val <= max; val += step) {
prms[varParam.symbol].v = val;
let res: Result = this.runNubCalc(nub, computedParam, computePrec);
if (res.ok) {
this._fixVarResults.addVarResult(val, res.vCalc);
}
else {
this._fixVarResults.addLogMessages(res.log);
}
let res: Result = this.runNubCalc(nub, computedParam, computePrec);
if (res.ok) {
this._fixVarResults.addVarResult(val, res.vCalc);
}
else {
this._fixVarResults.addLogMessages(res.log);
}
}
break;
case ParamValueMode.LISTE:
for (let val of varParam.valueList) {
prms[varParam.symbol].v = val;
let res: Result = this.runNubCalc(nub, computedParam, computePrec);
if (res.ok) {
this._fixVarResults.addVarResult(val, res.vCalc);
}
else {
this._fixVarResults.addLogMessages(res.log);
}
}
break;
}
this._fixVarResults.graphTitle = computedParam.symbol + " = f( " + varParam.symbol + " )";
......
......@@ -24,6 +24,21 @@ export enum ParamRadioConfig {
};
/**
* mode de génération des valeurs d'entrée lors d'un calcul avec plusieurs valeurs
*/
export enum ParamValueMode {
/**
* min, max, pas
*/
MINMAX,
/**
* liste de valeurs discrètes
*/
LISTE
}
/**
* classe englobante de ParamDefinition (champs supplémentaires pour l'affichage, radio boutons, ...)
*/
......@@ -35,6 +50,8 @@ export class NgParameter extends InputField {
public minValue: number; // valeur min dans le cas ParamRadioConfig.VAR
public maxValue: number; // valeur max dans le cas ParamRadioConfig.VAR
public stepValue: number; // pas de progression dans le cas ParamRadioConfig.VAR
public valueList: number[];
public valueMode: ParamValueMode = ParamValueMode.MINMAX;
constructor(private _paramDef: ParamDefinition, formId: number) {
super(_paramDef.computeNodeType, _paramDef.symbol, formId);
......
......@@ -14,8 +14,8 @@
<!-- ressources pour faire fonctionner le toggler de la navbar -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n"
crossorigin="anonymous"></script>
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"
crossorigin="anonymous"></script> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb"
crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn"
crossorigin="anonymous"></script>
......
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