diff --git a/dmp-frontend/src/app/core/services/language/language.http.service.ts b/dmp-frontend/src/app/core/services/language/language.http.service.ts index 729b87297..a34317331 100644 --- a/dmp-frontend/src/app/core/services/language/language.http.service.ts +++ b/dmp-frontend/src/app/core/services/language/language.http.service.ts @@ -112,7 +112,7 @@ export class LanguageHttpService { nameof(x => x.code) ] }; - lookup.order = { items: [nameof(x => x.code)] }; + lookup.order = { items: [nameof(x => x.ordinal)] }; if (like) { lookup.like = this.filterService.transformLike(like); } return lookup; } diff --git a/dmp-frontend/src/app/ui/admin/notification-template/editor/notification-template-editor.component.html b/dmp-frontend/src/app/ui/admin/notification-template/editor/notification-template-editor.component.html index 89783a75d..34c7feed6 100644 --- a/dmp-frontend/src/app/ui/admin/notification-template/editor/notification-template-editor.component.html +++ b/dmp-frontend/src/app/ui/admin/notification-template/editor/notification-template-editor.component.html @@ -33,21 +33,24 @@
{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.NOTIFICATION-TYPE' | translate}} - + {{enumUtils.toNotificationTypeString(type)}} + {{formGroup.get('notificationType').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}}
{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.LANGUAGE' | translate}} - - - {{languageCode}} + + + {{language.code}} + {{formGroup.get('languageId').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}}
@@ -59,6 +62,7 @@ {{enumUtils.toNotificationTemplateKindString(kind)}} + {{formGroup.get('kind').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -70,6 +74,7 @@ {{enumUtils.toNotificationTemplateChannelString(channel)}} + {{formGroup.get('channel').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -81,12 +86,14 @@ {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.SUBJECT-TEXT' | translate}} + {{formGroup.get('value').get('subjectText').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}}
{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.SUBJECT-KEY' | translate}} + {{formGroup.get('value').get('subjectKey').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}}
@@ -114,6 +121,7 @@ [matChipInputAddOnBlur]="true" (matChipInputTokenEnd)="addChipListValues('subject', $event)"/> + {{formGroup.get('value').get('subjectFieldOptions').get('mandatory').getError('backendError').message}}

{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.OPTIONAL-TITLE' | translate}}

@@ -123,6 +131,7 @@ {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} + {{subjectOptions.get('key').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -134,6 +143,7 @@ {{enumUtils.toNotificationTemplateDataTypeString(type)}} + {{subjectOptions.get('type').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -141,6 +151,7 @@ {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} + {{subjectOptions.get('value').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}}
@@ -152,7 +163,7 @@
-
@@ -167,6 +178,7 @@ {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} + {{formGroup.get('value').get('subjectFieldOptions').get('formatting').getError('backendError').message}}
@@ -178,6 +190,7 @@ {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} + {{formGroup.get('value').get('subjectFieldOptions').get('formatting').getError('backendError').message}}
@@ -190,6 +203,7 @@ {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.BODY-KEY' | translate}} + {{formGroup.get('value').get('bodyKey').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -214,6 +228,7 @@ alignleft aligncenter alignright alignjustify | \ bullist numlist outdent indent | code | searchreplace | preview | removeformat | help | link | image' }" [formControl]="formGroup.get('value').get('bodyText')"> + {{formGroup.get('value').get('bodyText').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -240,6 +255,7 @@ [matChipInputAddOnBlur]="true" (matChipInputTokenEnd)="addChipListValues('body',$event)"/> + {{formGroup.get('value').get('bodyFieldOptions').get('mandatory').getError('backendError').message}}

{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.OPTIONAL-TITLE' | translate}}

@@ -249,6 +265,7 @@ {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} + {{bodyOptions.get('key').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -260,6 +277,7 @@ {{enumUtils.toNotificationTemplateDataTypeString(type)}} + {{bodyOptions.get('type').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}} @@ -267,6 +285,7 @@ {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} + {{bodyOptions.get('value').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}}
@@ -278,7 +297,7 @@
-
@@ -292,6 +311,7 @@ {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} + {{formGroup.get('value').get('bodyFieldOptions').get('formatting').getError('backendError').message}}
@@ -303,6 +323,7 @@ {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} + {{formGroup.get('value').get('bodyFieldOptions').get('formatting').getError('backendError').message}}
@@ -314,12 +335,14 @@

{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.ALLOW-ATTACHMENTS' | translate}} + {{formGroup.get('value').get('allowAttachments').getError('backendError').message}}

{{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.PRIORITY-KEY' | translate}} + {{formGroup.get('value').get('priorityKey').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}}
@@ -342,6 +365,7 @@ [matChipInputAddOnBlur]="true" (matChipInputTokenEnd)="addChipListValues('cc',$event)"/> + {{formGroup.get('value').get('cc').getError('backendError').message}}
@@ -352,6 +376,7 @@ {{enumUtils.toEmailOverrideModeString(emailOverrideMode)}} + {{formGroup.get('value').get('ccMode').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}}
@@ -374,6 +399,7 @@ [matChipInputAddOnBlur]="true" (matChipInputTokenEnd)="addChipListValues('bcc',$event)"/> + {{formGroup.get('value').get('bcc').getError('backendError').message}}
@@ -384,6 +410,7 @@ {{enumUtils.toEmailOverrideModeString(emailOverrideMode)}} + {{formGroup.get('value').get('bccMode').getError('backendError').message}} {{'GENERAL.VALIDATION.REQUIRED' | translate}}
@@ -406,6 +433,7 @@ [matChipInputAddOnBlur]="true" (matChipInputTokenEnd)="addChipListValues('extraDataKeys',$event)"/> + {{formGroup.get('value').get('extraDataKeys').getError('backendError').message}} diff --git a/dmp-frontend/src/app/ui/admin/notification-template/editor/notification-template-editor.component.ts b/dmp-frontend/src/app/ui/admin/notification-template/editor/notification-template-editor.component.ts index cca4177d3..ada536729 100644 --- a/dmp-frontend/src/app/ui/admin/notification-template/editor/notification-template-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/notification-template/editor/notification-template-editor.component.ts @@ -46,7 +46,7 @@ export class NotificationTemplateEditorComponent extends BaseEditor this.availableLanguageCodes = data.items, + data => this.languages = data.items, ); } @@ -141,7 +140,6 @@ export class NotificationTemplateEditorComponent extends BaseEditor(x => x.id),nameof(x => x.code)]) - .pipe(takeUntil(this._destroyed)) - .subscribe( - data => { - this.formGroup.get('languageId').patchValue(data.id); - } - ); - } - - subjectFieldOptionsSelectionChanged(matCheckBox: MatCheckboxChange){ if(matCheckBox.checked == true){ this.subjectFieldOptionsEnabled = true; @@ -332,9 +323,12 @@ export class NotificationTemplateEditorComponent extends BaseEditor { + const control = formGroup?.get(keyField); + control?.clearValidators(); + control?.addValidators(context.getValidation(keyField).validators); + }); + + NotificationFieldOptionsEditorModel.reapplyValidators({ + formGroup: formGroup?.get('subjectFieldOptions') as UntypedFormGroup, + rootPath: `${rootPath}subjectFieldOptions.`, + validationErrorModel: validationErrorModel + }); + + NotificationFieldOptionsEditorModel.reapplyValidators({ + formGroup: formGroup?.get('bodyFieldOptions') as UntypedFormGroup, + rootPath: `${rootPath}bodyFieldOptions.`, + validationErrorModel: validationErrorModel + }); + } } export class NotificationFieldOptionsEditorModel implements NotificationFieldOptionsPersist { @@ -181,7 +236,7 @@ export class NotificationFieldOptionsEditorModel implements NotificationFieldOpt public fromModel(item: NotificationFieldOptions): NotificationFieldOptionsEditorModel { if (item) { this.mandatory = item.mandatory; - if(item.optional) { item.optional.map(x => this.optional.push(new NotificationFieldInfoEditorModel().fromModel(x))); } + if(item.optional) { item.optional.map(x => this.optional.push(new NotificationFieldInfoEditorModel(this.validationErrorModel).fromModel(x))); } this.formatting = item.formatting; } return this; @@ -208,7 +263,7 @@ export class NotificationFieldOptionsEditorModel implements NotificationFieldOpt (item, index) => new NotificationFieldInfoEditorModel( this.validationErrorModel ).fromModel(item).buildForm({ - rootPath: `optional[${index}].` + rootPath: `${rootPath}optional[${index}].` }), context.getValidation('optional') ) ), @@ -231,6 +286,34 @@ export class NotificationFieldOptionsEditorModel implements NotificationFieldOpt return baseContext; } + static reapplyValidators(params: { + formGroup: UntypedFormGroup, + validationErrorModel: ValidationErrorModel, + rootPath: string + }): void { + + const { formGroup, rootPath, validationErrorModel } = params; + const context = NotificationFieldOptionsEditorModel.createValidationContext({ + rootPath, + validationErrorModel + }); + + ['mandatory', 'formatting'].forEach(keyField => { + const control = formGroup?.get(keyField); + control?.clearValidators(); + control?.addValidators(context.getValidation(keyField).validators); + }); + + (formGroup.get('optional') as FormArray).controls?.forEach( + (control, index) => NotificationFieldInfoEditorModel.reapplyValidators({ + formGroup: control as UntypedFormGroup, + rootPath: `${rootPath}optional[${index}].`, + validationErrorModel: validationErrorModel + } + ) + ); + } + } export class NotificationFieldInfoEditorModel implements NotificationFieldInfoPersist { @@ -287,4 +370,24 @@ export class NotificationFieldInfoEditorModel implements NotificationFieldInfoPe baseContext.validation = baseValidationArray; return baseContext; } + + static reapplyValidators(params: { + formGroup: UntypedFormGroup, + validationErrorModel: ValidationErrorModel, + rootPath: string + }): void { + + const { formGroup, rootPath, validationErrorModel } = params; + const context = NotificationFieldInfoEditorModel.createValidationContext({ + rootPath, + validationErrorModel + }); + + ['key', 'type', 'value'].forEach(keyField => { + const control = formGroup?.get(keyField); + control?.clearValidators(); + control?.addValidators(context.getValidation(keyField).validators); + }); + } + }