From e6ccb6b6469292d78de956652012a731e00aeb25 Mon Sep 17 00:00:00 2001 From: mariateresa Date: Wed, 12 Jun 2024 17:36:25 +0200 Subject: [PATCH] added validation messages and upated types --- .../facet-composer.component.html | 49 +++++++- .../facet-composer.component.ts | 118 +++++++++++++++--- 2 files changed, 149 insertions(+), 18 deletions(-) diff --git a/src/main/webapp/app/facet-composer/facet-composer.component.html b/src/main/webapp/app/facet-composer/facet-composer.component.html index 796240f..715973b 100644 --- a/src/main/webapp/app/facet-composer/facet-composer.component.html +++ b/src/main/webapp/app/facet-composer/facet-composer.component.html @@ -80,6 +80,7 @@ {{prop.label}} + {{checkForPropErrors(facetTemplate.key,ind,prop)}} @@ -90,7 +91,7 @@
type - + {{tp.value}} @@ -100,11 +101,51 @@ name - + value - + + {{checkForErrorsIn(facetTemplate.key,ind,i,'number')}} - + + value + + {{checkForErrorsIn(facetTemplate.key,ind,i,'boolean')}} + + + value + + {{checkForErrorsIn(facetTemplate.key,ind,i,'password')}} + + + value + + {{checkForErrorsIn(facetTemplate.key,ind,i,'datetime')}} + + + value + + {{checkForErrorsIn(facetTemplate.key,ind,i,'date')}} + + + value + + {{checkForErrorsIn(facetTemplate.key,ind,i,'text')}} + + + value + + {{checkForErrorsIn(facetTemplate.key,ind,i,'float')}} + + + + diff --git a/src/main/webapp/app/facet-composer/facet-composer.component.ts b/src/main/webapp/app/facet-composer/facet-composer.component.ts index 0e206ef..6038377 100644 --- a/src/main/webapp/app/facet-composer/facet-composer.component.ts +++ b/src/main/webapp/app/facet-composer/facet-composer.component.ts @@ -1,10 +1,12 @@ +/* eslint-disable no-labels */ +/* eslint-disable no-useless-escape */ /* eslint-disable @typescript-eslint/restrict-plus-operands */ /* eslint-disable @typescript-eslint/member-ordering */ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable no-console */ -import { CommonModule } from '@angular/common'; +import { CommonModule, DatePipe } from '@angular/common'; import { Component, Inject, OnInit } from '@angular/core'; -import { FormArray, FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; +import { AbstractControl, FormArray, FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; import { MAT_DIALOG_DATA, MatDialogModule, MatDialogRef } from '@angular/material/dialog'; import { IContextNode } from 'app/services/i-context-node'; import { IResource } from 'app/services/i-resource'; @@ -42,6 +44,7 @@ export class FacetComposerComponent implements OnInit { fieldsMap: Map; showPassword:boolean; + datePipe:DatePipe; // eslint-disable-next-line @typescript-eslint/member-ordering constructor(private guiService: FacetComposerService, private fb: FormBuilder, @@ -55,6 +58,7 @@ export class FacetComposerComponent implements OnInit { this.fieldsMap = new Map(); this.myForm = this.fb.group({}); this.showPassword = false; + this.datePipe = new DatePipe('en-US'); } @@ -73,7 +77,8 @@ export class FacetComposerComponent implements OnInit { optionTypes = [ { value: 'boolean'}, - { value: 'datetime-local'},//text + { value: 'date'},//text + { value: 'datetime'},//text { value: 'password'}, { value: 'float'},//text { value: 'number'}, @@ -81,6 +86,18 @@ export class FacetComposerComponent implements OnInit { ]; + +/* +*/ credentialTypes: string[] = ['username/password', 'clientId/secret', 'token/secret']; @@ -109,11 +126,16 @@ export class FacetComposerComponent implements OnInit { return this.fb.group({ deno: ['',Validators.required], val: ['',Validators.required], - tipo:['text'] + tipo:[''] }) } + get val():FormControl{ + return this.fb.control({ + }) + } + get props():FormGroup{ return this.fb.group({ }) @@ -129,7 +151,6 @@ export class FacetComposerComponent implements OnInit { return (this.getSingleFacetArray(denoFacet).controls[index]).get('extraProps') as FormArray; } - addExtraProp(denoFacet:string, index:number):void{ this.getExtraPropsArray(denoFacet, index).push(this.extraProp); } @@ -139,17 +160,29 @@ export class FacetComposerComponent implements OnInit { } updateExtraPropType(denoFacet:string, indexFct:number, index:number, newValue:string):void{ - console.debug('--------'); - console.debug(this.getExtraPropsArray(denoFacet, indexFct).controls[index].get('tipo')?.value); - console.debug(newValue); - console.debug('--------'); this.getExtraPropsArray(denoFacet, indexFct).controls[index].get('tipo')?.setValue(newValue); - console.debug('++++DOPO+++'); + const valFc:AbstractControl = this.getExtraPropsArray(denoFacet, indexFct).controls[index].get('val')!; if(newValue==='boolean'){ + valFc.setValue(''); + //valFc.addValidators(Validators.pattern('^\s*(true|false)\s*$')) + valFc.setValue('false'); // eslint-disable-next-line no-useless-escape - this.getExtraPropsArray(denoFacet, indexFct).controls[index].get('val')?.addValidators(Validators.pattern('^\s*(true|false)\s*$')) + valFc.setValidators([Validators.required,Validators.pattern('^\s*(true|false)\s*$')]); + } + if(newValue==='datetime'){ + valFc.setValue(''); + valFc.setValue(new Date().toISOString()); + const patt = '\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)'; + valFc.setValidators([Validators.required,Validators.pattern(patt)]); + } + if(newValue==='password'||newValue==='text'||newValue==='number'){ + valFc.setValue(''); + valFc.setValidators([Validators.required]); + } + if(newValue==='float'){ + valFc.setValue(''); + valFc.setValidators([Validators.required,Validators.pattern('^[-+]?[0-9]+\.[0-9]+$')]); } - console.debug(this.getExtraPropsArray(denoFacet, indexFct).controls[index].get('tipo')?.value); } addFacet(deno:string): void { @@ -158,6 +191,61 @@ export class FacetComposerComponent implements OnInit { singleFacetArray.push(this.createFacetGroup(icf,true)); } + + + + checkForErrors(valFc:AbstractControl, inputType:string): string{ + let errorMsg: string; + errorMsg=''; + + if(valFc.hasError('required')){ + errorMsg = 'The field must not be empty'; + } + if(valFc.hasError('pattern')){ + errorMsg = ''+ valFc.value+'is not a correct value'; + if(!this.checkIfEmpty(valFc.value)&& inputType==='float'){ + errorMsg = 'input is not a decimal number (use . as a separator)'; + } + if(!this.checkIfEmpty(valFc.value)&& inputType==='boolean'){ + errorMsg = 'please enter true or false'; + } + if(!this.checkIfEmpty(valFc.value)&& inputType==='datetime'){ + errorMsg = 'datetime provided is not in ISO format'; + } + if(!this.checkIfEmpty(valFc.value)&& inputType==='date'){ + errorMsg = 'date or date format is not correct'; + } + + } + return errorMsg; + } + + checkForPropErrors(denoFacet:string, indexFct:number, prop:IFacetProps):string{ + const abstractControl = this.getPropsGroup(denoFacet,indexFct).get(prop.name)!; + //TODO: usare questi campi per costruire la validazione: + //prop.validations + for(let i=0; i