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 @@
</mat-form-field>
<div *ngIf="isMinMax" class="min-max-step-container">
<form>
<form #minMaxForm="ngForm">
<mat-form-field>
<input matInput class="form-control" type="number" inputmode="numeric" name="min-value" step="0.01"
[placeholder]="uitextValeurMini" [(ngModel)]="minValue" #min="ngModel" name="min"
(input)="minMaxForm.controls.max.updateValueAndValidity()"
[appJalhydModelValidationMin]="param" required pattern="^-?([0-9]*\.)?([0-9]+[Ee]-?)?[0-9]+$">
<mat-error *ngIf="min.errors">
......@@ -36,6 +37,7 @@
<mat-form-field>
<input matInput class="form-control" type="number" inputmode="numeric" name="max-value" step="0.01"
[placeholder]="uitextValeurMaxi" [(ngModel)]="maxValue" #max="ngModel" name="max"
(input)="minMaxForm.controls.min.updateValueAndValidity()"
[appJalhydModelValidationMax]="param" required pattern="^-?([0-9]*\.)?([0-9]+[Ee]-?)?[0-9]+$">
<mat-error *ngIf="max.errors">
......@@ -51,6 +53,7 @@
<mat-form-field>
<input matInput class="form-control" type="number" inputmode="numeric" name="step-value" step="0.01"
[placeholder]="uitextPasVariation" [(ngModel)]="stepValue" #step="ngModel" name="step"
[appJalhydModelValidationStep]="param"
required pattern="^([0-9]*\.)?([0-9]+[Ee]-?)?[0-9]+$">
<mat-error *ngIf="step.errors">
......@@ -118,7 +121,7 @@
<div mat-dialog-actions [attr.align]="'end'">
<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 }}
</button>
</div>
......
import { MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog";
import { Inject, Component, OnInit } from "@angular/core";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { Inject, Component, OnInit, ViewChild } from "@angular/core";
import { FormBuilder, FormGroup, Validators, NgForm } from "@angular/forms";
import { I18nService } from "../../services/internationalisation.service";
import { NgParameter } from "../../formulaire/elements/ngparam";
......@@ -34,6 +34,7 @@ export class DialogEditParamValuesComponent implements OnInit {
/** current decimal separator */
public decimalSeparator: string;
/** form for values list */
public valuesListForm: FormGroup;
/** when true, shows the values chart instead of the edit form */
......@@ -42,6 +43,10 @@ export class DialogEditParamValuesComponent implements OnInit {
public chartData = {};
public chartOptions;
/** form for min/max/step values */
@ViewChild("minMaxForm", { static: false })
public minMaxForm: NgForm;
constructor(
public dialogRef: MatDialogRef<DialogEditParamValuesComponent>,
private intlService: I18nService,
......@@ -206,7 +211,12 @@ export class DialogEditParamValuesComponent implements OnInit {
public get numberOfValues(): number {
if (this.isMinMax) {
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) {
// min > max or something, silent fail
return 0;
......@@ -232,6 +242,11 @@ export class DialogEditParamValuesComponent implements OnInit {
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() {
// validate list values before switching views ?
if (! this.viewChart && this.param.valueMode === ParamValueMode.LISTE) {
......
......@@ -58,7 +58,7 @@ export class ParamValuesComponent implements AfterViewInit, Observer {
this.editValuesDialog.open(
DialogEditParamValuesComponent,
{
disableClose: false,
disableClose: true,
data: {
param: this.param
},
......
......@@ -144,13 +144,17 @@ export function jalhydModelValidatorMax(ngParam: NgParameter): ValidatorFn {
export function jalhydModelValidatorStep(ngParam: NgParameter): ValidatorFn {
return (control: AbstractControl): { [key: string]: any } | null => {
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) {
errorReturn = {
"jalhydModelStep": {
value: control.value,
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()
)
}
......
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