From 5da3c4f9b984b106339595289654916e2cff1dd6 Mon Sep 17 00:00:00 2001 From: amentis Date: Fri, 1 Mar 2024 09:38:11 +0200 Subject: [PATCH] refactor tenant, notification-template ui editors --- ...tion-template-field-options.component.html | 92 ++++++++ ...tion-template-field-options.component.scss | 0 ...cation-template-field-options.component.ts | 127 +++++++++++ ...otification-template-editor.component.html | 200 ++---------------- .../notification-template-editor.component.ts | 104 --------- .../notification-template-editor.model.ts | 10 - .../notification-template.module.ts | 4 +- .../source/tenant-source.component.html | 83 ++++++++ .../source/tenant-source.component.scss | 18 ++ .../editor/source/tenant-source.component.ts | 99 +++++++++ .../editor/tenant-editor.component.html | 180 ++-------------- .../tenant/editor/tenant-editor.component.ts | 135 +----------- .../tenant/editor/tenant-editor.model.ts | 18 +- .../src/app/ui/admin/tenant/tenant.module.ts | 4 +- 14 files changed, 459 insertions(+), 615 deletions(-) create mode 100644 dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.html create mode 100644 dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.scss create mode 100644 dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.ts create mode 100644 dmp-frontend/src/app/ui/admin/tenant/editor/source/tenant-source.component.html create mode 100644 dmp-frontend/src/app/ui/admin/tenant/editor/source/tenant-source.component.scss create mode 100644 dmp-frontend/src/app/ui/admin/tenant/editor/source/tenant-source.component.ts diff --git a/dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.html b/dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.html new file mode 100644 index 000000000..78f5278f9 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.html @@ -0,0 +1,92 @@ +
+ + {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.MANDATORY' | translate}} + + + {{field}} + + + + + {{form.get('mandatory').getError('backendError').message}} + +
+

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

+
+
+
+ + {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} + + {{options.get('key').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.DATA-TYPE' | translate}} + + + {{enumUtils.toNotificationTemplateDataTypeString(type)}} + + + {{options.get('type').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} + + {{options.get('value').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+ +
+
+
+
+
+ +
+
+
+

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

+
+ + {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} + + + + {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} + + {{form.get('formatting').getError('backendError').message}} + +
+
+
+ + {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} + + + + {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} + + {{form.get('formatting').getError('backendError').message}} + +
+
\ No newline at end of file diff --git a/dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.scss b/dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.ts b/dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.ts new file mode 100644 index 000000000..6653ddc78 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/notification-template/editor/field-options/notification-template-field-options.component.ts @@ -0,0 +1,127 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { UntypedFormArray } from '@angular/forms'; +import { NotificationDataType } from '@app/core/common/enum/notification-data-type'; +import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; +import { BaseComponent } from '@common/base/base.component'; +import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; +import { NotificationFieldInfoEditorModel, NotificationFieldOptionsEditorModel } from '../notification-template-editor.model'; +import { MatChipEditedEvent, MatChipInputEvent } from '@angular/material/chips'; +import { COMMA, ENTER } from '@angular/cdk/keycodes'; + +@Component({ + selector: 'app-notification-template-field-options-component', + templateUrl: 'notification-template-field-options.component.html', + styleUrls: ['./notification-template-field-options.component.scss'] +}) +export class NotificationTemplateFieldOptionsComponent extends BaseComponent implements OnInit { + + @Input() form; + @Input() validationErrorModel: ValidationErrorModel = null; + @Input() validationRootPath: string = null; + @Input() mandatoryFields: string[] = []; + @Input() formatting: { [key: string]: string } = {}; + + public notificationDataTypeEnum = this.enumUtils.getEnumValues(NotificationDataType); + readonly separatorKeysCodes: number[] = [ENTER, COMMA]; + + constructor( + public enumUtils: EnumUtils, + ) { super(); } + + ngOnInit() { + } + + addChipListValues(event: MatChipInputEvent){ + this.mandatoryFields = this.add(event, this.mandatoryFields); + } + + editChipListValues(event: MatChipEditedEvent, field: string){ + this.mandatoryFields = this.edit(field, this.mandatoryFields, event); + this.editFormmattingKey(field, event.value.trim()); + } + + removeChipListValues(field: string){ + this.mandatoryFields = this.remove(field, this.mandatoryFields); + this.deleteFormattingItem(field); + } + + add(event: MatChipInputEvent, values: string[]) { + const value = (event.value || '').trim(); + + if (value) values.push(value) + event.chipInput!.clear(); + return values; + + } + + remove(field: string, values: string[]) { + const index = values.indexOf(field); + + if (index >= 0) values.splice(index, 1); + return values; + } + + edit(field: string, values: string[], event: MatChipEditedEvent) { + const value = event.value.trim(); + + if (!value) { + values = this.remove(field, values); + return values; + } + + const index = values.indexOf(field); + if (index >= 0) values[index] = value + + return values; + } + + //options fields + + addOptionalItem() { + const formArray = (this.form.get('optional') as UntypedFormArray); + const optional: NotificationFieldInfoEditorModel = new NotificationFieldInfoEditorModel(this.validationErrorModel); + + formArray.push(optional.buildForm({ rootPath: this.validationRootPath + 'optional[' + formArray.length + '].' })); + } + + removeSubjectOptionalItem(optionalIndex: number): void { + const key = (this.form.get('optional') as UntypedFormArray).at(optionalIndex).get("key").value; + this.deleteFormattingItem(key); + + (this.form.get('optional') as UntypedFormArray).removeAt(optionalIndex); + + //Reapply validators + NotificationFieldOptionsEditorModel.reapplyValidators( + { + formGroup: this.form, + validationErrorModel: this.validationErrorModel, + rootPath: this.validationRootPath + } + ); + this.form.get('optional').markAsDirty(); + } + + // subject formatting + insertFormattingItem(key: string, value: string){ + this.formatting[key] = value; + this.form.get('formatting').setValue(this.formatting); + } + + formattingValueChange(event: Event, key: string){ + this.formatting[key] = (event.target as HTMLInputElement).value; + this.form.get('formatting').setValue(this.formatting); + } + + editFormmattingKey(oldKey: string, newKey: string){ + this.insertFormattingItem(newKey, this.formatting[oldKey]); + this.deleteFormattingItem(oldKey); + } + + deleteFormattingItem(key:string){ + if (key in this.formatting) { + delete this.formatting[key]; + this.form.get('formatting').setValue(this.formatting); + } + } + +} 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 34c7feed6..407433c65 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 @@ -102,99 +102,14 @@
-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.MANDATORY' | translate}} - - - {{field}} - - - - - {{formGroup.get('value').get('subjectFieldOptions').get('mandatory').getError('backendError').message}} - -
-

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

-
-
-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} - - {{subjectOptions.get('key').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.DATA-TYPE' | translate}} - - - {{enumUtils.toNotificationTemplateDataTypeString(type)}} - - - {{subjectOptions.get('type').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} - - {{subjectOptions.get('value').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
- -
-
-
-
-
- -
-
-
-

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

-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} - - - - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} - - {{formGroup.get('value').get('subjectFieldOptions').get('formatting').getError('backendError').message}} - -
-
-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} - - - - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} - - {{formGroup.get('value').get('subjectFieldOptions').get('formatting').getError('backendError').message}} - -
-
-
+ + +
@@ -236,98 +151,13 @@
-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.MANDATORY' | translate}} - - - {{field}} - - - - - {{formGroup.get('value').get('bodyFieldOptions').get('mandatory').getError('backendError').message}} - -
-

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

-
-
-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} - - {{bodyOptions.get('key').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.DATA-TYPE' | translate}} - - - {{enumUtils.toNotificationTemplateDataTypeString(type)}} - - - {{bodyOptions.get('type').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} - - {{bodyOptions.get('value').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
- -
-
-
-
-
- -
-
-

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

-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} - - - - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} - - {{formGroup.get('value').get('bodyFieldOptions').get('formatting').getError('backendError').message}} - -
-
-
- - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.KEY' | translate}} - - - - {{'NOTIFICATION-SERVICE.NOTIFICATION-TEMPLATE-EDITOR.FIELDS.VALUE' | translate}} - - {{formGroup.get('value').get('bodyFieldOptions').get('formatting').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 ada536729..ddc868b0f 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 @@ -252,10 +252,6 @@ export class NotificationTemplateEditorComponent extends BaseEditor + {{label}} + + +
+
+
+
+ {{'TENANT-EDITOR.FIELDS.SOURCE' | translate}} {{sourceIndex + 1}} +
+
+ +
+
+
+
+ + {{'TENANT-EDITOR.FIELDS.URL' | translate}} + + {{source.get('url').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'TENANT-EDITOR.FIELDS.ISSUER-URL' | translate}} + + {{source.get('issuerUrl').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'TENANT-EDITOR.FIELDS.CLIENT-ID' | translate}} + + {{source.get('clientId').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'TENANT-EDITOR.FIELDS.CLIENT-SECRET' | translate}} + + {{source.get('clientSecret').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'TENANT-EDITOR.FIELDS.SCOPE' | translate}} + + {{source.get('scope').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+ + {{'TENANT-EDITOR.FIELDS.CODES' | translate}} + + + {{code}} + + + + + {{source.get('codes').getError('backendError').message}} + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + +
+
+
+
\ No newline at end of file diff --git a/dmp-frontend/src/app/ui/admin/tenant/editor/source/tenant-source.component.scss b/dmp-frontend/src/app/ui/admin/tenant/editor/source/tenant-source.component.scss new file mode 100644 index 000000000..186cc7dc6 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/tenant/editor/source/tenant-source.component.scss @@ -0,0 +1,18 @@ +.action-btn { + border-radius: 30px; + background-color: var(--secondary-color); + border: 1px solid transparent; + padding-left: 2em; + padding-right: 2em; + box-shadow: 0px 3px 6px #1E202029; + + transition-property: background-color, color; + transition-duration: 200ms; + transition-delay: 50ms; + transition-timing-function: ease-in-out; + &:disabled{ + background-color: #CBCBCB; + color: #FFF; + border: 0px; + } +} \ No newline at end of file diff --git a/dmp-frontend/src/app/ui/admin/tenant/editor/source/tenant-source.component.ts b/dmp-frontend/src/app/ui/admin/tenant/editor/source/tenant-source.component.ts new file mode 100644 index 000000000..c5ce43c93 --- /dev/null +++ b/dmp-frontend/src/app/ui/admin/tenant/editor/source/tenant-source.component.ts @@ -0,0 +1,99 @@ +import { Component, Input, OnInit } from '@angular/core'; +import { UntypedFormArray } from '@angular/forms'; +import { MatChipEditedEvent, MatChipInputEvent } from '@angular/material/chips'; +import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; +import { BaseComponent } from '@common/base/base.component'; +import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model'; +import { TenantDepositConfigEditorModel, TenantEditorModel, TenantSourceEditorModel } from '../tenant-editor.model'; + +@Component({ + selector: 'app-tenant-source-component', + templateUrl: 'tenant-source.component.html', + styleUrls: ['./tenant-source.component.scss'] +}) +export class TenantSourceComponent extends BaseComponent implements OnInit { + + @Input() form; + @Input() validationErrorModel: ValidationErrorModel = null; + @Input() validationRootPath: string = null; + @Input() codes: Map; + @Input() label: string = null; + + constructor( + public enumUtils: EnumUtils, + ) { super(); } + + ngOnInit() { + } + + // + // source + // + addSource(): void { + const formArray = this.form.get('sources') as UntypedFormArray; + this.codes.set(formArray.length, []); + const source: TenantSourceEditorModel = new TenantSourceEditorModel(this.validationErrorModel); + formArray.push(source.buildForm({ rootPath: this.validationRootPath + 'sources[' + formArray.length + '].' })); + } + + removeSource(sourceIndex: number): void { + this.codes.delete((this.form.get('sources') as UntypedFormArray).length); + (this.form.get('sources') as UntypedFormArray).removeAt(sourceIndex); + + // Reapply validators + TenantDepositConfigEditorModel.reapplySourcesFieldsValidators( + { + formArray: this.form.get('sources') as UntypedFormArray, + validationErrorModel: this.validationErrorModel, + rootPath: this.validationRootPath + } + ) + this.form.get('sources').markAsDirty(); + } + + // source codes + + addCode(event: MatChipInputEvent, key: number): void { + const value = (event.value || '').trim(); + + if (value){ + const values = this.codes.get(key); + values.push(value); + this.codes.set(key, values); + } + event.chipInput!.clear(); + } + + removeCode(code: string, key: number): void { + const values = this.codes.get(key); + if (values){ + const index = values.indexOf(code); + + if (index >= 0) { + values.splice(index, 1); + this.codes.set(key, values); + } + } + } + + editCode(code: string, event: MatChipEditedEvent, key: number) { + const values = this.codes.get(key); + if (values){ + const value = event.value.trim(); + + // Remove code if it no longer has a value + if (!value) { + this.removeCode(code, key); + return; + } + + const index = values.indexOf(code); + if (index >= 0) { + values[index] = value; + this.codes.set(key, values); + } + } + } + + +} diff --git a/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.component.html b/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.component.html index 77382a90d..134366881 100644 --- a/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.component.html +++ b/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.component.html @@ -57,174 +57,22 @@
-

- {{'TENANT-EDITOR.FIELDS.DEPOSIT' | translate}} - -

-
-
-
-
- {{'TENANT-EDITOR.FIELDS.SOURCE' | translate}} {{sourceIndex + 1}} -
-
- -
-
-
-
- - {{'TENANT-EDITOR.FIELDS.URL' | translate}} - - {{source.get('url').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'TENANT-EDITOR.FIELDS.ISSUER-URL' | translate}} - - {{source.get('issuerUrl').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'TENANT-EDITOR.FIELDS.CLIENT-ID' | translate}} - - {{source.get('clientId').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'TENANT-EDITOR.FIELDS.CLIENT-SECRET' | translate}} - - {{source.get('clientSecret').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'TENANT-EDITOR.FIELDS.SCOPE' | translate}} - - {{source.get('scope').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'TENANT-EDITOR.FIELDS.CODES' | translate}} - - - {{code}} - - - - - {{source.get('codes').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
-
-
+ +
-

- {{'TENANT-EDITOR.FIELDS.FILE-TRANSFORMERS' | translate}} - -

-
-
-
-
- {{'TENANT-EDITOR.FIELDS.SOURCE' | translate}} {{sourceIndex + 1}} -
-
- -
-
-
-
- - {{'TENANT-EDITOR.FIELDS.URL' | translate}} - - {{source.get('url').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'TENANT-EDITOR.FIELDS.ISSUER-URL' | translate}} - - {{source.get('issuerUrl').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'TENANT-EDITOR.FIELDS.CLIENT-ID' | translate}} - - {{source.get('clientId').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'TENANT-EDITOR.FIELDS.CLIENT-SECRET' | translate}} - - {{source.get('clientSecret').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'TENANT-EDITOR.FIELDS.SCOPE' | translate}} - - {{source.get('scope').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
- - {{'TENANT-EDITOR.FIELDS.CODES' | translate}} - - - {{code}} - - - - - {{source.get('codes').getError('backendError').message}} - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
-
-
-
+ +
diff --git a/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.component.ts b/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.component.ts index 113a351ef..74f9b277b 100644 --- a/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.component.ts +++ b/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.component.ts @@ -27,8 +27,7 @@ import { TranslateService } from '@ngx-translate/core'; import { map, takeUntil } from 'rxjs/operators'; import { TenantEditorResolver } from './tenant-editor.resolver'; import { TenantEditorService } from './tenant-editor.service'; -import { TenantEditorModel, TenantSourceEditorModel } from './tenant-editor.model'; -import { MatChipEditedEvent, MatChipInputEvent } from '@angular/material/chips'; +import { TenantEditorModel } from './tenant-editor.model'; @Component({ @@ -188,137 +187,5 @@ export class TenantEditorComponent extends BaseEditor this.formService.validateAllFormFields(this.formGroup); } - // - // deposit source - // - addDepositSource(): void { - this.depositCodes.set((this.formGroup.get('config').get('deposit').get('sources') as FormArray).length, []); - (this.formGroup.get('config').get('deposit').get('sources') as FormArray).push(this.editorModel.createChildDeposit((this.formGroup.get('config').get('deposit').get('sources') as FormArray).length)); - } - - removeDepositSource(sourceIndex: number): void { - this.depositCodes.delete((this.formGroup.get('config').get('deposit').get('sources') as FormArray).length); - (this.formGroup.get('config').get('deposit').get('sources') as FormArray).removeAt(sourceIndex); - - //Reapply validators - TenantEditorModel.reApplyDepositSourcesValidators( - { - formGroup: this.formGroup, - validationErrorModel: this.editorModel.validationErrorModel - } - ) - this.formGroup.get('config').get('deposit').get('sources').markAsDirty(); - } - - // deposit source codes - - addDepositCode(event: MatChipInputEvent, key: number): void { - const value = (event.value || '').trim(); - - if (value){ - const values = this.depositCodes.get(key); - values.push(value); - this.depositCodes.set(key, values); - } - event.chipInput!.clear(); - } - - removeDepositCode(code: string, key: number): void { - const values = this.depositCodes.get(key); - if (values){ - const index = values.indexOf(code); - - if (index >= 0) { - values.splice(index, 1); - this.depositCodes.set(key, values); - } - } - } - - editDepositCode(code: string, event: MatChipEditedEvent, key: number) { - const values = this.depositCodes.get(key); - if (values){ - const value = event.value.trim(); - - // Remove code if it no longer has a value - if (!value) { - this.removeDepositCode(code, key); - return; - } - - const index = values.indexOf(code); - if (index >= 0) { - values[index] = value; - this.depositCodes.set(key, values); - } - } - } - - // - // fileTransformers source - // - addFileSource(): void { - this.fileTransformersCodes.set((this.formGroup.get('config').get('fileTransformers').get('sources') as FormArray).length, []); - (this.formGroup.get('config').get('fileTransformers').get('sources') as FormArray).push(this.editorModel.createChildFileTransformer((this.formGroup.get('config').get('fileTransformers').get('sources') as FormArray).length)); - } - - removeFileSource(sourceIndex: number): void { - this.fileTransformersCodes.delete((this.formGroup.get('config').get('fileTransformers').get('sources') as FormArray).length); - (this.formGroup.get('config').get('fileTransformers').get('sources') as FormArray).removeAt(sourceIndex); - - //Reapply validators - TenantEditorModel.reApplyFileTransformerSourcesValidators( - { - formGroup: this.formGroup, - validationErrorModel: this.editorModel.validationErrorModel - } - ) - this.formGroup.get('config').get('fileTransformers').get('sources').markAsDirty(); - } - - // fileTransformers source codes - - addFileCode(event: MatChipInputEvent, key: number): void { - const value = (event.value || '').trim(); - - if (value){ - const values = this.fileTransformersCodes.get(key); - values.push(value); - this.fileTransformersCodes.set(key, values); - } - event.chipInput!.clear(); - } - - removeFileCode(code: string, key: number): void { - const values = this.fileTransformersCodes.get(key); - if (values){ - const index = values.indexOf(code); - - if (index >= 0) { - values.splice(index, 1); - this.fileTransformersCodes.set(key, values); - } - } - } - - editFileCode(code: string, event: MatChipEditedEvent, key:number) { - const values = this.fileTransformersCodes.get(key); - if (values){ - const value = event.value.trim(); - - // Remove code if it no longer has a value - if (!value) { - this.removeFileCode(code, key); - return; - } - - const index = values.indexOf(code); - if (index >= 0) { - values[index] = value; - this.fileTransformersCodes.set(key, values); - } - } - } - } diff --git a/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.model.ts b/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.model.ts index fc410e564..8b23f0401 100644 --- a/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.model.ts +++ b/dmp-frontend/src/app/ui/admin/tenant/editor/tenant-editor.model.ts @@ -56,11 +56,6 @@ export class TenantEditorModel extends BaseEditorModel implements TenantPersist return baseContext; } - createChildDeposit(index: number): UntypedFormGroup { - const deposit: TenantSourceEditorModel = new TenantSourceEditorModel(this.validationErrorModel); - return deposit.buildForm({ rootPath: 'config.deposit.sources[' + index + '].' }); - } - static reApplyDepositSourcesValidators(params: { formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, @@ -75,11 +70,6 @@ export class TenantEditorModel extends BaseEditorModel implements TenantPersist }); } - createChildFileTransformer(index: number): UntypedFormGroup { - const deposit: TenantSourceEditorModel = new TenantSourceEditorModel(this.validationErrorModel); - return deposit.buildForm({ rootPath: 'config.fileTransformers.sources[' + index + '].' }); - } - static reApplyFileTransformerSourcesValidators(params: { formGroup: UntypedFormGroup, validationErrorModel: ValidationErrorModel, @@ -186,8 +176,8 @@ export class TenantDepositConfigEditorModel implements TenantDepositConfigPersis this.validationErrorModel ).fromModel(item).buildForm({ rootPath: `${rootPath}sources[${index}].` - }), context.getValidation('sources') - ) + }) + ), context.getValidation('sources') ), }); } @@ -258,8 +248,8 @@ export class TenantFileTransformersConfigEditorModel implements TenantFileTransf this.validationErrorModel ).fromModel(item).buildForm({ rootPath: `${rootPath}sources[${index}].` - }), context.getValidation('sources') - ) + }) + ), context.getValidation('sources') ), }); } diff --git a/dmp-frontend/src/app/ui/admin/tenant/tenant.module.ts b/dmp-frontend/src/app/ui/admin/tenant/tenant.module.ts index 79e6dceb0..766f819f0 100644 --- a/dmp-frontend/src/app/ui/admin/tenant/tenant.module.ts +++ b/dmp-frontend/src/app/ui/admin/tenant/tenant.module.ts @@ -14,6 +14,7 @@ import { TenantEditorComponent } from './editor/tenant-editor.component'; import { TenantListingComponent } from './listing/tenant-listing.component'; import { TenantListingFiltersComponent } from "./listing/filters/tenant-listing-filters.component"; import { RichTextEditorModule } from '@app/library/rich-text-editor/rich-text-editor.module'; +import { TenantSourceComponent } from './editor/source/tenant-source.component'; @NgModule({ imports: [ @@ -33,7 +34,8 @@ import { RichTextEditorModule } from '@app/library/rich-text-editor/rich-text-ed declarations: [ TenantEditorComponent, TenantListingComponent, - TenantListingFiltersComponent + TenantListingFiltersComponent, + TenantSourceComponent ] }) export class TenantModule { }