Skip to content
Snippets Groups Projects
Commit eba93408 authored by Dorchies David's avatar Dorchies David
Browse files

Merge branch...

Merge branch '385-saisie-parametre-qui-varie-message-d-erreur-persistant-sur-le-champ-min' into 'master'

Resolve "Saisie paramètre qui varie: message d'erreur persistant sur le champ min"

Closes #385

See merge request !83
parents 84431e71 59f1012e
No related branches found
No related tags found
1 merge request!83Resolve "Saisie paramètre qui varie: message d'erreur persistant sur le champ min"
Pipeline #137841 passed
188-solveur-pouvoir-cibler-un-resultat-complementaire-eventuellement-sur-un-seul-nub master
...@@ -17,10 +17,11 @@ ...@@ -17,10 +17,11 @@
</mat-form-field> </mat-form-field>
<div *ngIf="isMinMax" class="min-max-step-container"> <div *ngIf="isMinMax" class="min-max-step-container">
<form> <form #minMaxForm="ngForm">
<mat-form-field> <mat-form-field>
<input matInput class="form-control" type="number" inputmode="numeric" name="min-value" step="0.01" <input matInput class="form-control" type="number" inputmode="numeric" name="min-value" step="0.01"
[placeholder]="uitextValeurMini" [(ngModel)]="minValue" #min="ngModel" name="min" [placeholder]="uitextValeurMini" [(ngModel)]="minValue" #min="ngModel" name="min"
(input)="minMaxForm.controls.max.updateValueAndValidity()"
[appJalhydModelValidationMin]="param" required pattern="^-?([0-9]*\.)?([0-9]+[Ee]-?)?[0-9]+$"> [appJalhydModelValidationMin]="param" required pattern="^-?([0-9]*\.)?([0-9]+[Ee]-?)?[0-9]+$">
<mat-error *ngIf="min.errors"> <mat-error *ngIf="min.errors">
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
<mat-form-field> <mat-form-field>
<input matInput class="form-control" type="number" inputmode="numeric" name="max-value" step="0.01" <input matInput class="form-control" type="number" inputmode="numeric" name="max-value" step="0.01"
[placeholder]="uitextValeurMaxi" [(ngModel)]="maxValue" #max="ngModel" name="max" [placeholder]="uitextValeurMaxi" [(ngModel)]="maxValue" #max="ngModel" name="max"
(input)="minMaxForm.controls.min.updateValueAndValidity()"
[appJalhydModelValidationMax]="param" required pattern="^-?([0-9]*\.)?([0-9]+[Ee]-?)?[0-9]+$"> [appJalhydModelValidationMax]="param" required pattern="^-?([0-9]*\.)?([0-9]+[Ee]-?)?[0-9]+$">
<mat-error *ngIf="max.errors"> <mat-error *ngIf="max.errors">
...@@ -51,6 +53,7 @@ ...@@ -51,6 +53,7 @@
<mat-form-field> <mat-form-field>
<input matInput class="form-control" type="number" inputmode="numeric" name="step-value" step="0.01" <input matInput class="form-control" type="number" inputmode="numeric" name="step-value" step="0.01"
[placeholder]="uitextPasVariation" [(ngModel)]="stepValue" #step="ngModel" name="step" [placeholder]="uitextPasVariation" [(ngModel)]="stepValue" #step="ngModel" name="step"
[appJalhydModelValidationStep]="param"
required pattern="^([0-9]*\.)?([0-9]+[Ee]-?)?[0-9]+$"> required pattern="^([0-9]*\.)?([0-9]+[Ee]-?)?[0-9]+$">
<mat-error *ngIf="step.errors"> <mat-error *ngIf="step.errors">
...@@ -118,7 +121,7 @@ ...@@ -118,7 +121,7 @@
<div mat-dialog-actions [attr.align]="'end'"> <div mat-dialog-actions [attr.align]="'end'">
<div *ngIf="isMinMax || viewChart"> <div *ngIf="isMinMax || viewChart">
<button mat-raised-button [mat-dialog-close]="true" cdkFocusInitial> <button mat-raised-button [mat-dialog-close]="true" [disabled]="minMaxFormInvalid" cdkFocusInitial>
{{ uitextClose }} {{ uitextClose }}
</button> </button>
</div> </div>
......
import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog"; import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog";
import { Inject, Component, OnInit } from "@angular/core"; import { Inject, Component, OnInit, ViewChild } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from "@angular/forms"; import { FormBuilder, FormGroup, Validators, NgForm } from "@angular/forms";
import { I18nService } from "../../services/internationalisation.service"; import { I18nService } from "../../services/internationalisation.service";
import { NgParameter } from "../../formulaire/elements/ngparam"; import { NgParameter } from "../../formulaire/elements/ngparam";
...@@ -34,6 +34,7 @@ export class DialogEditParamValuesComponent implements OnInit { ...@@ -34,6 +34,7 @@ export class DialogEditParamValuesComponent implements OnInit {
/** current decimal separator */ /** current decimal separator */
public decimalSeparator: string; public decimalSeparator: string;
/** form for values list */
public valuesListForm: FormGroup; public valuesListForm: FormGroup;
/** when true, shows the values chart instead of the edit form */ /** when true, shows the values chart instead of the edit form */
...@@ -42,6 +43,10 @@ export class DialogEditParamValuesComponent implements OnInit { ...@@ -42,6 +43,10 @@ export class DialogEditParamValuesComponent implements OnInit {
public chartData = {}; public chartData = {};
public chartOptions; public chartOptions;
/** form for min/max/step values */
@ViewChild("minMaxForm", { static: false })
public minMaxForm: NgForm;
constructor( constructor(
public dialogRef: MatDialogRef<DialogEditParamValuesComponent>, public dialogRef: MatDialogRef<DialogEditParamValuesComponent>,
private intlService: I18nService, private intlService: I18nService,
...@@ -206,7 +211,12 @@ export class DialogEditParamValuesComponent implements OnInit { ...@@ -206,7 +211,12 @@ export class DialogEditParamValuesComponent implements OnInit {
public get numberOfValues(): number { public get numberOfValues(): number {
if (this.isMinMax) { if (this.isMinMax) {
try { try {
return this.param.paramDefinition.getInferredValuesList().length; // .getInferredValuesList().length is too slow when nb values > 1000
if (this.param.paramDefinition.step === 0) {
return 0;
} else {
return Math.max(0, Math.ceil((this.param.paramDefinition.max - this.param.paramDefinition.min) / this.param.paramDefinition.step) + 1);
}
} catch (e) { } catch (e) {
// min > max or something, silent fail // min > max or something, silent fail
return 0; return 0;
...@@ -232,6 +242,11 @@ export class DialogEditParamValuesComponent implements OnInit { ...@@ -232,6 +242,11 @@ export class DialogEditParamValuesComponent implements OnInit {
this.param.setValueList(this, vals); this.param.setValueList(this, vals);
} }
/** returns true if min/max/step form is invalid */
public get minMaxFormInvalid(): boolean {
return this.minMaxForm === undefined || ! this.minMaxForm.valid;
}
public toggleViewChart() { public toggleViewChart() {
// validate list values before switching views ? // validate list values before switching views ?
if (! this.viewChart && this.param.valueMode === ParamValueMode.LISTE) { if (! this.viewChart && this.param.valueMode === ParamValueMode.LISTE) {
......
...@@ -58,7 +58,7 @@ export class ParamValuesComponent implements AfterViewInit, Observer { ...@@ -58,7 +58,7 @@ export class ParamValuesComponent implements AfterViewInit, Observer {
this.editValuesDialog.open( this.editValuesDialog.open(
DialogEditParamValuesComponent, DialogEditParamValuesComponent,
{ {
disableClose: false, disableClose: true,
data: { data: {
param: this.param param: this.param
}, },
......
...@@ -144,13 +144,17 @@ export function jalhydModelValidatorMax(ngParam: NgParameter): ValidatorFn { ...@@ -144,13 +144,17 @@ export function jalhydModelValidatorMax(ngParam: NgParameter): ValidatorFn {
export function jalhydModelValidatorStep(ngParam: NgParameter): ValidatorFn { export function jalhydModelValidatorStep(ngParam: NgParameter): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } | null => { return (control: AbstractControl): { [key: string]: any } | null => {
let errorReturn = null; // no error, everything OK let errorReturn = null; // no error, everything OK
const result = ngParam.checkMinMaxStep(control.value); // @WARNING remplacement du contrôle complet de min/max/step par une
// simple vérification que le pas est positif
// const result = ngParam.checkMinMaxStep(control.value);
const result = (control.value > 0);
if (! result) { if (! result) {
errorReturn = { errorReturn = {
"jalhydModelStep": { "jalhydModelStep": {
value: control.value, value: control.value,
message: sprintf( message: sprintf(
ServiceFactory.instance.i18nService.localizeText("ERROR_MINMAXSTEP_STEP"), // ServiceFactory.instance.i18nService.localizeText("ERROR_MINMAXSTEP_STEP"),
ServiceFactory.instance.i18nService.localizeText("ERROR_PARAM_MUST_BE_POSITIVE"),
ngParam.stepRefValue.toString() ngParam.stepRefValue.toString()
) )
} }
......
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