import { Component, OnInit } from '@angular/core'; import { FormArray, UntypedFormGroup } from '@angular/forms'; import { MatDialog } from '@angular/material/dialog'; import { ActivatedRoute, Router } from '@angular/router'; import { DmpBlueprintService } from '@app/core/services/dmp/dmp-blueprint.service'; import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service'; import { EnumUtils } from '@app/core/services/utilities/enum-utils.service'; // import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item'; import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; import { DatePipe } from '@angular/common'; import { DmpBlueprintExtraFieldDataType } from '@app/core/common/enum/dmp-blueprint-field-type'; import { DmpBlueprintSectionFieldCategory } from '@app/core/common/enum/dmp-blueprint-section-field-category'; import { DmpBlueprintStatus } from '@app/core/common/enum/dmp-blueprint-status'; import { DmpBlueprintSystemFieldType } from '@app/core/common/enum/dmp-blueprint-system-field-type'; import { IsActive } from '@app/core/common/enum/is-active.enum'; import { AppPermission } from '@app/core/common/enum/permission.enum'; import { DataTableRequest } from '@app/core/model/data-table/data-table-request'; import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile'; import { DmpBlueprint, DmpBlueprintPersist } from '@app/core/model/dmp-blueprint/dmp-blueprint'; import { DatasetProfileCriteria } from '@app/core/query/dataset-profile/dataset-profile-criteria'; import { AuthService } from '@app/core/services/auth/auth.service'; import { DmpService } from '@app/core/services/dmp/dmp.service'; import { LoggingService } from '@app/core/services/logging/logging-service'; import { MatomoService } from '@app/core/services/matomo/matomo-service'; import { FileUtils } from '@app/core/services/utilities/file-utils.service'; import { QueryParamsService } from '@app/core/services/utilities/query-params.service'; import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration'; import { BaseEditor } from '@common/base/base-editor'; import { FormService } from '@common/forms/form-service'; import { FormValidationErrorsDialogComponent } from '@common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component'; import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component'; import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service'; import { FilterService } from '@common/modules/text-filter/filter-service'; import { Guid } from '@common/types/guid'; import { TranslateService } from '@ngx-translate/core'; import * as FileSaver from 'file-saver'; import { Observable } from 'rxjs'; import { map, takeUntil } from 'rxjs/operators'; import { DescriptionTemplatesInSectionEditorModel, DmpBlueprintDefinitionSectionEditorModel, DmpBlueprintEditorModel, FieldInSectionEditorModel } from './dmp-blueprint-editor.model'; import { DmpBlueprintEditorResolver } from './dmp-blueprint-editor.resolver'; import { DmpBlueprintEditorService } from './dmp-blueprint-editor.service'; @Component({ selector: 'app-dmp-blueprint-editor-component', templateUrl: 'dmp-blueprint-editor.component.html', styleUrls: ['./dmp-blueprint-editor.component.scss'], providers: [DmpBlueprintEditorService] }) export class DmpBlueprintEditorComponent extends BaseEditor implements OnInit { isNew = true; isDeleted = false; formGroup: UntypedFormGroup = null; showInactiveDetails = false; selectedSystemFields: Array = []; dmpBlueprintSectionFieldCategory = DmpBlueprintSectionFieldCategory; dmpBlueprintSystemFieldType = DmpBlueprintSystemFieldType; public dmpBlueprintSystemFieldTypeEnum = this.enumUtils.getEnumValues(DmpBlueprintSystemFieldType); dmpBlueprintExtraFieldDataType = DmpBlueprintExtraFieldDataType; public dmpBlueprintExtraFieldDataTypeEnum = this.enumUtils.getEnumValues(DmpBlueprintExtraFieldDataType); blueprintsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration = { filterFn: this.filterDescriptionTempaltes.bind(this), initialItems: (excludedItems: any[]) => this.filterDescriptionTempaltes('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))), displayFn: (item: DatasetProfileModel) => item.label, titleFn: (item: DatasetProfileModel) => item.label, subtitleFn: (item: DatasetProfileModel) => item.description, popupItemActionIcon: 'visibility' }; protected get canDelete(): boolean { return !this.isDeleted && !this.isNew && this.hasPermission(this.authService.permissionEnum.DeleteDmpBlueprint); } protected get canSave(): boolean { return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditDmpBlueprint); } protected get canFinalize(): boolean { return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditDmpBlueprint); } private hasPermission(permission: AppPermission): boolean { return this.authService.hasPermission(permission) || this.editorModel?.permissions?.includes(permission); } constructor( // BaseFormEditor injected dependencies protected dialog: MatDialog, protected language: TranslateService, protected formService: FormService, protected router: Router, protected uiNotificationService: UiNotificationService, protected httpErrorHandlingService: HttpErrorHandlingService, protected filterService: FilterService, protected datePipe: DatePipe, protected route: ActivatedRoute, protected queryParamsService: QueryParamsService, // Rest dependencies. Inject any other needed deps here: public authService: AuthService, public enumUtils: EnumUtils, private dmpBlueprintService: DmpBlueprintService, private logger: LoggingService, private dmpBlueprintEditorService: DmpBlueprintEditorService, private fileUtils: FileUtils, private matomoService: MatomoService, private dmpService: DmpService ) { super(dialog, language, formService, router, uiNotificationService, httpErrorHandlingService, filterService, datePipe, route, queryParamsService); } ngOnInit(): void { this.matomoService.trackPageView('Admin: DMP Blueprints'); super.ngOnInit(); } getItem(itemId: Guid, successFunction: (item: DmpBlueprint) => void) { this.dmpBlueprintService.getSingle(itemId, DmpBlueprintEditorResolver.lookupFields()) .pipe(map(data => data as DmpBlueprint), takeUntil(this._destroyed)) .subscribe( data => successFunction(data), error => this.onCallbackError(error) ); } prepareForm(data: DmpBlueprint) { try { this.editorModel = data ? new DmpBlueprintEditorModel().fromModel(data) : new DmpBlueprintEditorModel(); this.isDeleted = data ? data.isActive === IsActive.Inactive : false; this.buildForm(); } catch (error) { this.logger.error('Could not parse dmpBlueprint item: ' + data + error); this.uiNotificationService.snackBarNotification(this.language.instant('COMMONS.ERRORS.DEFAULT'), SnackBarNotificationLevel.Error); } } buildForm() { this.formGroup = this.editorModel.buildForm(null, this.isDeleted || !this.authService.hasPermission(AppPermission.EditDmpBlueprint)); this.selectedSystemFields = this.selectedSystemFieldDisabled(); this.dmpBlueprintEditorService.setValidationErrorModel(this.editorModel.validationErrorModel); } refreshData(): void { this.getItem(this.editorModel.id, (data: DmpBlueprint) => this.prepareForm(data)); } refreshOnNavigateToData(id?: Guid): void { this.formGroup.markAsPristine(); let route = []; if (id === null) { route.push('../..'); } else if (this.isNew) { route.push('../' + id); } else { route.push('..'); } this.router.navigate(route, { queryParams: { 'lookup': this.queryParamsService.serializeLookup(this.lookupParams), 'lv': ++this.lv }, replaceUrl: true, relativeTo: this.route }); } persistEntity(onSuccess?: (response) => void): void { const formData = this.formService.getValue(this.formGroup.value) as DmpBlueprintPersist; this.dmpBlueprintService.persist(formData) .pipe(takeUntil(this._destroyed)).subscribe( complete => onSuccess ? onSuccess(complete) : this.onCallbackSuccess(complete), error => this.onCallbackError(error) ); } formSubmit(): void { this.formService.touchAllFormFields(this.formGroup); if (!this.isFormValid()) { return; } this.persistEntity(); } public delete() { const value = this.formGroup.value; if (value.id) { const dialogRef = this.dialog.open(ConfirmationDialogComponent, { maxWidth: '300px', data: { message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'), confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'), cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL') } }); dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { if (result) { this.dmpBlueprintService.delete(value.id).pipe(takeUntil(this._destroyed)) .subscribe( complete => this.onCallbackSuccess(), error => this.onCallbackError(error) ); } }); } } clearErrorModel() { this.editorModel.validationErrorModel.clear(); this.formService.validateAllFormFields(this.formGroup); } // // // Sections // // addSection(): void { const section: DmpBlueprintDefinitionSectionEditorModel = new DmpBlueprintDefinitionSectionEditorModel(); section.id = Guid.create(); section.ordinal = (this.formGroup.get('definition').get('sections') as FormArray).controls.length + 1; section.hasTemplates = false; (this.formGroup.get('definition').get('sections') as FormArray).push(section.buildForm()); //TODO: dtziotzios validation path } removeSection(sectionIndex: number): void { (this.formGroup.get('definition').get('sections') as FormArray).removeAt(sectionIndex); (this.formGroup.get('definition').get('sections') as FormArray).controls.forEach((section, index) => { section.get('ordinal').setValue(index + 1); }); } dropSections(event: CdkDragDrop) { const sectionsFormArray = (this.formGroup.get('definition').get('sections') as FormArray); moveItemInArray(sectionsFormArray.controls, event.previousIndex, event.currentIndex); sectionsFormArray.updateValueAndValidity(); sectionsFormArray.controls.forEach((section, index) => { section.get('ordinal').setValue(index + 1); }); } // // // Fields // // systemFieldDisabled(systemField: DmpBlueprintSystemFieldType) { return (this.formGroup.get('definition').get('sections') as FormArray)?.controls.some(x => (x.get('fields') as FormArray).controls.some(y => (y as UntypedFormGroup).get('systemFieldType')?.value === systemField)); // for (let section in (this.formGroup.get('definition').get('sections')as FormArray)?.controls) { // if (i != sectionIndex) { // for (let f of this.fieldsArray(i).controls) { // if ((f.get('category').value == FieldCategory.SYSTEM || f.get('category').value == 'SYSTEM') && f.get('type').value == systemField) { // return true; // } // } // } // i++; // } // return false; } selectedSystemFieldDisabled(): Array { return (this.formGroup.get('definition').get('sections') as FormArray)?.controls.flatMap(x => (x.get('fields') as FormArray).controls.map(y => (y as UntypedFormGroup).get('systemFieldType')?.value as DmpBlueprintSystemFieldType)); } addSystemField(sectionIndex: number, systemFieldType: DmpBlueprintSystemFieldType): void { const field: FieldInSectionEditorModel = new FieldInSectionEditorModel(); field.id = Guid.create(); field.ordinal = ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('fields') as FormArray).length + 1; field.category = DmpBlueprintSectionFieldCategory.SYSTEM; field.systemFieldType = systemFieldType; field.required = (systemFieldType == DmpBlueprintSystemFieldType.TEXT || systemFieldType == DmpBlueprintSystemFieldType.HTML_TEXT) ? true : false; ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('fields') as FormArray).push(field.buildForm()); //TODO: dtziotzios validation path } removeSystemField(sectionIndex: number, fieldIndex: number): void { const formArray = ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('fields') as FormArray); formArray.removeAt(fieldIndex); formArray.controls.forEach((section, index) => { section.get('ordinal').setValue(index + 1); }); } addExtraField(sectionIndex: number): void { const field: FieldInSectionEditorModel = new FieldInSectionEditorModel(); field.id = Guid.create(); field.ordinal = ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('fields') as FormArray).length + 1; field.category = DmpBlueprintSectionFieldCategory.EXTRA; ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('fields') as FormArray).push(field.buildForm()); //TODO: dtziotzios validation path } removeExtraField(sectionIndex: number, fieldIndex: number): void { const formArray = ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('fields') as FormArray); formArray.removeAt(fieldIndex); formArray.controls.forEach((section, index) => { section.get('ordinal').setValue(index + 1); }); } dropFields(event: CdkDragDrop, sectionIndex: number) { const fieldsFormArray = ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('fields') as FormArray); moveItemInArray(fieldsFormArray.controls, event.previousIndex, event.currentIndex); fieldsFormArray.updateValueAndValidity(); fieldsFormArray.controls.forEach((section, index) => { section.get('ordinal').setValue(index + 1); }); } // // // Autocomplete configuration // // filterDescriptionTempaltes(value: string): Observable { const request = new DataTableRequest(null, null, { fields: ['+label'] }); const criteria = new DatasetProfileCriteria(); criteria.like = value; request.criteria = criteria; return this.dmpService.searchDmpBlueprints(request); } onRemoveDescritionTemplate(event, sectionIndex: number) { const descriptionTemplateFormArray = (this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('descriptionTemplates') as FormArray; const foundIndex = descriptionTemplateFormArray.controls.findIndex(blueprint => blueprint.get('descriptionTemplateId').value === event.id); if (foundIndex !== -1) { descriptionTemplateFormArray.removeAt(foundIndex); } } onSelectDescritionTemplate(item, sectionIndex) { const descriptionTemplate: DescriptionTemplatesInSectionEditorModel = new DescriptionTemplatesInSectionEditorModel(); descriptionTemplate.id = Guid.create(); descriptionTemplate.descriptionTemplateId = item.id; descriptionTemplate.label = item.label; ((this.formGroup.get('definition').get('sections') as FormArray).at(sectionIndex).get('descriptionTemplates') as FormArray).push(descriptionTemplate.buildForm()); //TODO: dtziotzios validation path } // ngAfterViewInit() { // this.route.params // .pipe(takeUntil(this._destroyed)) // .subscribe((params: Params) => { // this.dmpBlueprintId = params['id']; // const cloneId = params['cloneid']; // if (this.dmpBlueprintId != null) { // this.isNew = false; // this.dmpBlueprintService.getSingleBlueprint(this.dmpBlueprintId).pipe(map(data => data as any)) // .pipe(takeUntil(this._destroyed)) // .subscribe(data => { // this.dmpBlueprintEditor = new DmpBlueprintEditor().fromModel(data); // this.formGroup = this.dmpBlueprintEditor.buildForm(); // this.buildSystemFields(); // this.fillDescriptionTemplatesInMultAutocomplete(); // if (this.dmpBlueprintEditor.status == DmpBlueprintStatus.Finalized) { // this.formGroup.disable(); // this.viewOnly = true // } // // this.breadCrumbs = observableOf([{ // // parentComponentName: 'DmpBlueprintListingComponent', // // label: this.language.instant('NAV-BAR.TEMPLATE'), // // url: '/dmp-blueprints/' + this.dmpBlueprintId // // }]); // }); // } else if (cloneId != null) { // this.isClone = true; // this.dmpBlueprintService.clone(cloneId).pipe(map(data => data as any), takeUntil(this._destroyed)) // .subscribe( // data => { // this.dmpBlueprintEditor = new DmpBlueprintEditor().fromModel(data); // this.dmpBlueprintEditor.id = null; // this.dmpBlueprintEditor.status = DmpBlueprintStatus.Draft; // this.formGroup = this.dmpBlueprintEditor.buildForm(); // this.buildSystemFields(); // this.fillDescriptionTemplatesInMultAutocomplete(); // }, // error => this.onCallbackError(error) // ); // } else { // this.dmpBlueprintEditorModel = new DmpBlueprintEditorModel(); // this.dmpBlueprintEditor = new DmpBlueprintEditor(); // setTimeout(() => { // // this.formGroup = this.dmpBlueprintModel.buildForm(); // // this.addField(); // this.dmpBlueprintEditor.status = DmpBlueprintStatus.Draft; // this.formGroup = this.dmpBlueprintEditor.buildForm(); // }); // // this.breadCrumbs = observableOf([{ // // parentComponentName: 'DmpBlueprintListingComponent', // // label: this.language.instant('NAV-BAR.TEMPLATE'), // // url: '/dmp-blueprints/' + this.dmpBlueprintId // // }]); // } // }); // } // buildSystemFields() { // const sections = this.sectionsArray().controls.length; // for (let i = 0; i < sections; i++) { // let systemFieldsInSection = new Array(); // this.fieldsArray(i).controls.forEach((field) => { // if ((field.get('category').value == FieldCategory.SYSTEM || field.get('category').value == 'SYSTEM')) { // systemFieldsInSection.push(this.fieldList.find(f => f.type == field.get('type').value).type); // } // }) // this.systemFieldListPerSection.push(systemFieldsInSection); // } // } // fillDescriptionTemplatesInMultAutocomplete() { // const sections = this.sectionsArray().controls.length; // for (let i = 0; i < sections; i++) { // let descriptionTemplatesInSection = new Array(); // this.descriptionTemplatesArray(i).controls.forEach((template) => { // descriptionTemplatesInSection.push({ id: template.value.descriptionTemplateId, label: template.value.label, description: "" }); // }) // this.descriptionTemplatesPerSection.push(descriptionTemplatesInSection); // } // } // checkForProfiles(event, sectionIndex: number) { // if (event.checked === false) { // this.descriptionTemplatesPerSection[sectionIndex] = new Array(); // this.descriptionTemplatesArray(sectionIndex).clear(); // } // } // sectionsArray(): UntypedFormArray { // //return this.dmpBlueprintsFormGroup.get('sections') as FormArray; // return this.formGroup.get('definition').get('sections') as UntypedFormArray; // } // fieldsArray(sectionIndex: number): UntypedFormArray { // return this.sectionsArray().at(sectionIndex).get('fields') as UntypedFormArray; // } // removeField(sectionIndex: number, fieldIndex: number): void { // this.fieldsArray(sectionIndex).removeAt(fieldIndex); // } // systemFieldsArray(sectionIndex: number): UntypedFormArray { // return this.sectionsArray().at(sectionIndex).get('systemFields') as UntypedFormArray; // } // initSystemField(systemField?: SystemFieldType): UntypedFormGroup { // return this.fb.group({ // id: this.fb.control(Guid.create().toString()), // type: this.fb.control(systemField), // label: this.fb.control(''), // placeholder: this.fb.control(''), // description: this.fb.control(''), // required: this.fb.control(true), // ordinal: this.fb.control('') // }); // } // addSystemField(sectionIndex: number, systemField?: SystemFieldType): void { // this.addField(sectionIndex, FieldCategory.SYSTEM, systemField); // } // transfromEnumToString(type: SystemFieldType): string { // return this.fieldList.find(f => f.type == type).label; // } // selectedFieldType(type: SystemFieldType, sectionIndex: number): void { // let index = this.systemFieldListPerSection[sectionIndex].indexOf(type); // if (index == -1) { // this.systemFieldListPerSection[sectionIndex].push(type); // this.addSystemField(sectionIndex, type); // } // else { // this.systemFieldListPerSection[sectionIndex].splice(index, 1); // this.removeSystemField(sectionIndex, type); // } // } // descriptionTemplatesArray(sectionIndex: number): UntypedFormArray { // return this.sectionsArray().at(sectionIndex).get('descriptionTemplates') as UntypedFormArray; // } // addDescriptionTemplate(descriptionTemplate, sectionIndex: number): void { // this.descriptionTemplatesArray(sectionIndex).push(this.fb.group({ // label: this.fb.control(descriptionTemplate.value) // })); // } // removeDescriptionTemplate(sectionIndex: number, templateIndex: number): void { // this.descriptionTemplatesArray(sectionIndex).removeAt(templateIndex); // } // extraFieldsArray(sectionIndex: number): UntypedFormArray { // return this.sectionsArray().at(sectionIndex).get('extraFields') as UntypedFormArray; // } // getExtraFieldTypes(): Number[] { // let keys: string[] = Object.keys(ExtraFieldType); // keys = keys.slice(0, keys.length / 2); // const values: Number[] = keys.map(Number); // return values; // } // getExtraFieldTypeValue(extraFieldType: ExtraFieldType): string { // switch (extraFieldType) { // case ExtraFieldType.TEXT: return 'Text'; // case ExtraFieldType.RICH_TEXT: return 'Rich Text'; // case ExtraFieldType.DATE: return 'Date'; // case ExtraFieldType.NUMBER: return 'Number'; // } // } // moveItemInFormArray(formArray: UntypedFormArray, fromIndex: number, toIndex: number): void { // const dir = toIndex > fromIndex ? 1 : -1; // const item = formArray.at(fromIndex); // for (let i = fromIndex; i * dir < toIndex * dir; i = i + dir) { // const current = formArray.at(i + dir); // formArray.setControl(i, current); // } // formArray.setControl(toIndex, item); // } // // clearForm(): void{ // // this.dmpBlueprintsFormGroup.reset(); // // } // // onPreviewTemplate(event, sectionIndex: number) { // // const dialogRef = this.dialog.open(DatasetPreviewDialogComponent, { // // width: '590px', // // minHeight: '200px', // // restoreFocus: false, // // data: { // // template: event // // }, // // panelClass: 'custom-modalbox' // // }); // // dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => { // // if (result) { // // let blueprints = this.sectionsArray().at(sectionIndex).get('descriptionTemplates').value;//this.formGroup.get('blueprints').value; // // const blueprint: DescriptionTemplatesInSectionEditor = new DescriptionTemplatesInSectionEditor(); // // blueprint.id = Guid.create().toString(); // // blueprint.descriptionTemplateId = event.id; // // blueprint.label = event.label; // // blueprints.push(blueprint.buildForm()); // // this.sectionsArray().at(sectionIndex).get('descriptionTemplates').setValue(blueprints);//this.formGroup.get('blueprints').setValue(blueprints); // // this.blueprintsAutoCompleteConfiguration = { // // filterFn: this.filterProfiles.bind(this), // // initialItems: (excludedItems: any[]) => this.filterProfiles('').pipe(map(result => result.filter(resultItem => (excludedItems || []).map(x => x.id).indexOf(resultItem.id) === -1))), // // displayFn: (item) => item['label'], // // titleFn: (item) => item['label'], // // subtitleFn: (item) => item['description'], // // popupItemActionIcon: 'visibility' // // }; // // } // // }); // // } checkValidity() { this.formService.touchAllFormFields(this.formGroup); if (!this.isFormValid()) { return false; } let errorMessages = []; if (!this.hasTitle()) { errorMessages.push("Title should be set."); } if (!this.hasDescription()) { errorMessages.push("Description should be set."); } if (!this.hasDescriptionTemplates()) { errorMessages.push("At least one section should have description templates."); } if (errorMessages.length > 0) { this.showValidationErrorsDialog(undefined, errorMessages); return false; } return true; } // formSubmit(): void { // if (this.checkValidity()) // this.onSubmit(); // } // public isFormValid() { // return this.formGroup.valid; // } hasTitle(): boolean { const dmpBlueprint: DmpBlueprintPersist = this.formGroup.value; return dmpBlueprint.definition.sections.some(section => section.fields.some(field => (field.category === DmpBlueprintSectionFieldCategory.SYSTEM || field.category as unknown === 'SYSTEM') && field.systemFieldType === DmpBlueprintSystemFieldType.TEXT)); } hasDescription(): boolean { const dmpBlueprint: DmpBlueprintPersist = this.formGroup.value; return dmpBlueprint.definition.sections.some(section => section.fields.some(field => (field.category === DmpBlueprintSectionFieldCategory.SYSTEM || field.category as unknown === 'SYSTEM') && field.systemFieldType === DmpBlueprintSystemFieldType.HTML_TEXT)); } hasDescriptionTemplates(): boolean { const dmpBlueprint: DmpBlueprintPersist = this.formGroup.value; return dmpBlueprint.definition.sections.some(section => section.hasTemplates == true); } private showValidationErrorsDialog(projectOnly?: boolean, errmess?: string[]) { const dialogRef = this.dialog.open(FormValidationErrorsDialogComponent, { disableClose: true, autoFocus: false, restoreFocus: false, data: { errorMessages: errmess, projectOnly: projectOnly }, }); } // onSubmit(): void { // this.dmpBlueprintService.createBlueprint(this.formGroup.value) // .pipe(takeUntil(this._destroyed)) // .subscribe( // complete => this.onCallbackSuccess(), // error => this.onCallbackError(error) // ); // } // onCallbackSuccess(): void { // this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success); // this.router.navigate(['/dmp-blueprints']); // } // onCallbackError(errorResponse: any) { // this.setErrorModel(errorResponse.error); // this.formService.validateAllFormFields(this.formGroup); // } // public setErrorModel(validationErrorModel: ValidationErrorModel) { // Object.keys(validationErrorModel).forEach(item => { // (this.dmpBlueprintEditor.validationErrorModel)[item] = (validationErrorModel)[item]; // }); // } public cancel(): void { this.router.navigate(['/dmp-blueprints']); } // // addField() { // // (this.formGroup.get('definition').get('fields')).push(new DmpBlueprintFieldEditorModel().buildForm()); // // } // // removeField(index: number) { // // (this.formGroup.get('definition').get('fields')).controls.splice(index, 1); // // } // getDmpBlueprintFieldDataTypeValues(): Number[] { // let keys: string[] = Object.keys(DmpBlueprintFieldDataType); // keys = keys.slice(0, keys.length / 2); // const values: Number[] = keys.map(Number); // return values; // } // getDmpBlueprintFieldDataTypeWithLanguage(fieldType: DmpBlueprintFieldDataType): string { // let result = ''; // this.language.get(this.enumUtils.toDmpBlueprintFieldDataTypeString(fieldType)) // .pipe(takeUntil(this._destroyed)) // .subscribe((value: string) => { // result = value; // }); // return result; // } // getDmpBlueprintFieldTypeValues(): Number[] { // let keys: string[] = Object.keys(DmpBlueprintType); // keys = keys.slice(0, keys.length / 2); // const values: Number[] = keys.map(Number); // return values; // } // getDmpBlueprintFieldTypeWithLanguage(blueprintType: DmpBlueprintType): string { // let result = ''; // this.language.get(this.enumUtils.toDmpBlueprintTypeString(blueprintType)) // .pipe(takeUntil(this._destroyed)) // .subscribe((value: string) => { // result = value; // }); // return result; // } // delete() { // this.dialog.open(ConfirmationDialogComponent, { // data: { // isDeleteConfirmation: true, // confirmButton: this.language.instant('DMP-BLUEPRINT-EDITOR.CONFIRM-DELETE-DIALOG.CONFIRM-BUTTON'), // cancelButton: this.language.instant("DMP-BLUEPRINT-EDITOR.CONFIRM-DELETE-DIALOG.CANCEL-BUTTON"), // message: this.language.instant("DMP-BLUEPRINT-EDITOR.CONFIRM-DELETE-DIALOG.MESSAGE") // } // }) // .afterClosed() // .subscribe( // confirmed => { // if (confirmed) { // if (this.formGroup.get('status').value == DmpBlueprintStatus.Draft) { // // this.formGroup.get('status').setValue(DmpBlueprintStatus.Deleted); // this.dmpBlueprintService.createBlueprint(this.formGroup.value) // .pipe(takeUntil(this._destroyed)) // .subscribe( // complete => this.onCallbackSuccess(), // error => this.onCallbackError(error) // ); // } // else { // // this.dmpBlueprintService.delete(this.dmpBlueprintId) // // .pipe(takeUntil(this._destroyed)) // // .subscribe( // // complete => this.onCallbackSuccess(), // // error => { // // if (error.error.statusCode == 674) { // // this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DMP-BLUEPRINT-DELETE'), SnackBarNotificationLevel.Error); // // } else { // // this.uiNotificationService.snackBarNotification(this.language.instant(error.message), SnackBarNotificationLevel.Error); // // } // // } // // ); // } // } // } // ) // } finalize() { if (this.checkValidity()) { this.formGroup.get('status').setValue(DmpBlueprintStatus.Finalized); this.formSubmit(); } } downloadXML(): void { const blueprintId = this.formGroup.get('id').value; if (blueprintId == null) return; this.dmpBlueprintService.downloadXML(blueprintId) .pipe(takeUntil(this._destroyed)) .subscribe(response => { const blob = new Blob([response.body], { type: 'application/xml' }); const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); FileSaver.saveAs(blob, filename); }); } }