From c7a3b58019cbb05ae3bab986ae9c9ba654bd773c Mon Sep 17 00:00:00 2001 From: Diamantis Tziotzios Date: Fri, 12 Jan 2024 18:22:06 +0200 Subject: [PATCH] validator fixes --- .../description-template-type-editor.model.ts | 2 +- .../reference-type-editor.component.html | 18 +++--- .../editor/reference-type-editor.component.ts | 13 ++--- .../editor/reference-type-editor.model.ts | 55 ++++++++++--------- .../error-model/validation-error-model.ts | 26 ++++----- 5 files changed, 58 insertions(+), 56 deletions(-) diff --git a/dmp-frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.model.ts b/dmp-frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.model.ts index 6f280477b..6b47ba8fc 100644 --- a/dmp-frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.model.ts +++ b/dmp-frontend/src/app/ui/admin/description-types/editor/description-template-type-editor.model.ts @@ -44,7 +44,7 @@ export class DescriptionTemplateTypeEditorModel extends BaseEditorModel implemen const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'id', validators: [BackendErrorValidator(this.validationErrorModel, 'id')] }); - baseValidationArray.push({ key: 'name', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'RenameourceId')] }); + baseValidationArray.push({ key: 'name', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'name')] }); baseValidationArray.push({ key: 'status', validators: [Validators.required, BackendErrorValidator(this.validationErrorModel, 'status')] }); baseValidationArray.push({ key: 'hash', validators: [] }); diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.html b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.html index 29c1fdd99..afd96d71d 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.html +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.html @@ -35,10 +35,8 @@ {{'REFERENCE-TYPE-EDITOR.FIELDS.NAME' | translate}} - - {{formGroup.get('name').getError('backendError').message}} - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} + {{formGroup.get('name').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}
@@ -89,24 +87,24 @@ {{'REFERENCE-TYPE-EDITOR.FIELDS.LABEL' | translate}} - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} + {{field.get('label').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}
{{'REFERENCE-TYPE-EDITOR.FIELDS.DESCRIPTION' | translate}} - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} + {{field.get('description').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}
{{'REFERENCE-TYPE-EDITOR.FIELDS.CODE' | translate}} - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} + {{field.get('code').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}
diff --git a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts index 9b634f833..ba8a9fc32 100644 --- a/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/reference-type/editor/reference-type-editor.component.ts @@ -13,7 +13,7 @@ import { AppPermission } from '@app/core/common/enum/permission.enum'; import { ReferenceFieldDataType } from '@app/core/common/enum/reference-field-data-type'; import { ReferenceTypeExternalApiHTTPMethodType } from '@app/core/common/enum/reference-type-external-api-http-method-type'; import { ReferenceTypeSourceType } from '@app/core/common/enum/reference-type-source-type'; -import { ReferenceType, ReferenceTypePersist } from '@app/core/model/reference-type/reference-type'; +import { ReferenceType, ReferenceTypeDefinition, ReferenceTypePersist } from '@app/core/model/reference-type/reference-type'; import { AuthService } from '@app/core/services/auth/auth.service'; import { LoggingService } from '@app/core/services/logging/logging-service'; import { QueryParamsService } from '@app/core/services/utilities/query-params.service'; @@ -25,7 +25,7 @@ import { FilterService } from '@common/modules/text-filter/filter-service'; import { Guid } from '@common/types/guid'; import { TranslateService } from '@ngx-translate/core'; import { map, takeUntil } from 'rxjs/operators'; -import { DependencyPropertyEditorModel, QueryConfigEditorModel, ReferenceTypeEditorModel, ReferenceTypeFieldEditorModel, ReferenceTypeSourceBaseConfigurationEditorModel, ReferenceTypeSourceBaseDependencyEditorModel, ReferenceTypeStaticOptionEditorModel, ResultFieldsMappingConfigurationEditorModel } from './reference-type-editor.model'; +import { DependencyPropertyEditorModel, QueryConfigEditorModel, ReferenceTypeDefinitionEditorModel, ReferenceTypeEditorModel, ReferenceTypeFieldEditorModel, ReferenceTypeSourceBaseConfigurationEditorModel, ReferenceTypeSourceBaseDependencyEditorModel, ReferenceTypeStaticOptionEditorModel, ResultFieldsMappingConfigurationEditorModel } from './reference-type-editor.model'; import { ReferenceTypeEditorResolver } from './reference-type-editor.resolver'; import { ReferenceTypeEditorService } from './reference-type-editor.service'; @@ -172,9 +172,9 @@ export class ReferenceTypeEditorComponent extends BaseEditor new ReferenceTypeFieldEditorModel( this.validationErrorModel ).fromModel(item).buildForm({ - rootPath: `fields[${index}].` + rootPath: `[${index}].` }), context.getValidation('fields') ) ), @@ -182,9 +187,9 @@ export class ReferenceTypeFieldEditorModel implements ReferenceTypeFieldPersist const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'code', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}code`)] }); - baseValidationArray.push({ key: 'label', validators: [Validators.required,BackendErrorValidator(validationErrorModel, `${rootPath}label`)] }); + baseValidationArray.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}label`)] }); baseValidationArray.push({ key: 'description', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}description`)] }); - baseValidationArray.push({ key: 'dataType', validators: [Validators.required,BackendErrorValidator(validationErrorModel, `${rootPath}dataType`)] }); + baseValidationArray.push({ key: 'dataType', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}dataType`)] }); baseContext.validation = baseValidationArray; return baseContext; @@ -209,9 +214,9 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc auth: AuthenticationConfigurationEditorModel = new AuthenticationConfigurationEditorModel(); queries?: QueryConfigEditorModel[] = []; - options : ReferenceTypeStaticOptionEditorModel[] = []; + options: ReferenceTypeStaticOptionEditorModel[] = []; - dependencies : ReferenceTypeSourceBaseDependencyEditorModel[] = []; + dependencies: ReferenceTypeSourceBaseDependencyEditorModel[] = []; protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); @@ -234,18 +239,18 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc if (item.httpMethod) this.httpMethod = item.httpMethod; if (item.requestBody) this.requestBody = item.requestBody; if (item.filterType) this.filterType = item.filterType; - if (item.auth) this.auth = new AuthenticationConfigurationEditorModel().fromModel(item.auth); - if(item.queries) { item.queries.map(x => this.queries.push(new QueryConfigEditorModel().fromModel(x))); } - - if(item.options) { + if (item.auth) this.auth = new AuthenticationConfigurationEditorModel().fromModel(item.auth); + if (item.queries) { item.queries.map(x => this.queries.push(new QueryConfigEditorModel().fromModel(x))); } + + if (item.options) { item.options.map(x => this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel(x))); } else { - this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel({code: 'reference_id', value: undefined})); - this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel({code: 'label', value: undefined})); - this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel({code: 'description', value: undefined})); + this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel({ code: 'reference_id', value: undefined })); + this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel({ code: 'label', value: undefined })); + this.options.push(new ReferenceTypeStaticOptionEditorModel().fromModel({ code: 'description', value: undefined })); } - if(item.dependencies) { item.dependencies.map(x => this.dependencies.push(new ReferenceTypeSourceBaseDependencyEditorModel().fromModel(x))); } + if (item.dependencies) { item.dependencies.map(x => this.dependencies.push(new ReferenceTypeSourceBaseDependencyEditorModel().fromModel(x))); } } return this; } @@ -281,7 +286,7 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc requestBody: [{ value: this.requestBody, disabled: disabled }, context.getValidation('requestBody').validators], filterType: [{ value: this.filterType, disabled: disabled }, context.getValidation('filterType').validators], auth: this.auth.buildForm({ - rootPath: `auth.` + rootPath: `auth.` }), queries: this.formBuilder.array( (this.queries ?? []).map( @@ -323,9 +328,9 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc const baseContext: ValidationContext = new ValidationContext(); const baseValidationArray: Validation[] = new Array(); baseValidationArray.push({ key: 'type', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}type`)] }); - baseValidationArray.push({ key: 'key', validators: [Validators.required,BackendErrorValidator(validationErrorModel, `${rootPath}key`)] }); - baseValidationArray.push({ key: 'label', validators: [Validators.required,BackendErrorValidator(validationErrorModel, `${rootPath}label`)] }); - baseValidationArray.push({ key: 'ordinal', validators: [Validators.required,Validators.pattern("^[0-9]*$"), BackendErrorValidator(validationErrorModel, `${rootPath}ordinal`)] }); + baseValidationArray.push({ key: 'key', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}key`)] }); + baseValidationArray.push({ key: 'label', validators: [Validators.required, BackendErrorValidator(validationErrorModel, `${rootPath}label`)] }); + baseValidationArray.push({ key: 'ordinal', validators: [Validators.required, Validators.pattern("^[0-9]*$"), BackendErrorValidator(validationErrorModel, `${rootPath}ordinal`)] }); baseValidationArray.push({ key: 'url', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}url`)] }); baseValidationArray.push({ key: 'paginationPath', validators: [BackendErrorValidator(validationErrorModel, `${rootPath}paginationPath`)] }); @@ -348,7 +353,7 @@ export class ReferenceTypeSourceBaseConfigurationEditorModel implements Referenc export class ResultsConfigurationEditorModel implements ResultsConfigurationPersist { public resultsArrayPath: string; - public fieldsMapping: ResultFieldsMappingConfigurationEditorModel[] =[]; + public fieldsMapping: ResultFieldsMappingConfigurationEditorModel[] = []; protected formBuilder: UntypedFormBuilder = new UntypedFormBuilder(); @@ -358,11 +363,11 @@ export class ResultsConfigurationEditorModel implements ResultsConfigurationPers fromModel(item: ResultsConfiguration): ResultsConfigurationEditorModel { this.resultsArrayPath = item.resultsArrayPath; - if(item.fieldsMapping) { item.fieldsMapping.map(x => this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel(x))); } + if (item.fieldsMapping) { item.fieldsMapping.map(x => this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel(x))); } else { - this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel({code: 'reference_id', responsePath: undefined})); - this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel({code: 'label', responsePath: undefined})); - this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel({code: 'description', responsePath: undefined})); + this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel({ code: 'reference_id', responsePath: undefined })); + this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel({ code: 'label', responsePath: undefined })); + this.fieldsMapping.push(new ResultFieldsMappingConfigurationEditorModel().fromModel({ code: 'description', responsePath: undefined })); } return this; } @@ -391,7 +396,7 @@ export class ResultsConfigurationEditorModel implements ResultsConfigurationPers }), context.getValidation('fieldsMapping') ) ) - + }); } @@ -661,7 +666,7 @@ export class ReferenceTypeSourceBaseDependencyEditorModel implements ReferenceTy this.referenceTypeCode = item.referenceTypeCode; this.key = item.key; this.required = item.required; - if(item.properties) { item.properties.map(x => this.properties.push(new DependencyPropertyEditorModel().fromModel(x))); } + if (item.properties) { item.properties.map(x => this.properties.push(new DependencyPropertyEditorModel().fromModel(x))); } return this; } diff --git a/dmp-frontend/src/common/forms/validation/error-model/validation-error-model.ts b/dmp-frontend/src/common/forms/validation/error-model/validation-error-model.ts index 501335afa..a03ea232d 100644 --- a/dmp-frontend/src/common/forms/validation/error-model/validation-error-model.ts +++ b/dmp-frontend/src/common/forms/validation/error-model/validation-error-model.ts @@ -23,8 +23,8 @@ export class ValidationErrorModel implements Serializable let error: string; if (this.message && Array.isArray(this.message)) { for (const element of this.message) { - if (element.Key === propertyName) { - error = element.Value.join(', '); + if (element.key === propertyName) { + error = element.value.join(', '); break; } } @@ -38,10 +38,10 @@ export class ValidationErrorModel implements Serializable const errors = new Map(); if (this.message && Array.isArray(this.message)) { this.message.forEach(element => { - const match = element.Key.match(regExp); + const match = element.key.match(regExp); if (match && match.length >= 2) { const index = Number.parseInt(match[1]); - errors.set(index, element.Value.join(', ')); + errors.set(index, element.value.join(', ')); } }); } @@ -52,15 +52,15 @@ export class ValidationErrorModel implements Serializable if (this.message && Array.isArray(this.message)) { let exists = false; for (const element of this.message) { - if (element.Key === propertyName) { - if (!element.Value.includes(error)) { element.Value.push(error); } + if (element.key === propertyName) { + if (!element.value.includes(error)) { element.value.push(error); } exists = true; break; } } - if (!exists) { this.message.push({ Key: propertyName, Value: [error] }); } + if (!exists) { this.message.push({ key: propertyName, value: [error] }); } } else { - this.message = [{ Key: propertyName, Value: [error] }]; + this.message = [{ key: propertyName, value: [error] }]; } } @@ -68,7 +68,7 @@ export class ValidationErrorModel implements Serializable this.error = undefined; if (this.message && Array.isArray(this.message)) { this.message.forEach(element => { - element.Value.splice(0); + element.value.splice(0); }); } } @@ -76,8 +76,8 @@ export class ValidationErrorModel implements Serializable public clearPart(prefix: string) { if (this.message && Array.isArray(this.message)) { this.message.forEach(element => { - if (element && element.Key && element.Key.startsWith(prefix)) { - element.Value.splice(0); + if (element && element.key && element.key.startsWith(prefix)) { + element.value.splice(0); } }); } @@ -85,6 +85,6 @@ export class ValidationErrorModel implements Serializable } class ErrorMessageItem { - Key: string; - Value: Array = []; + key: string; + value: Array = []; }