775 lines
32 KiB
TypeScript
775 lines
32 KiB
TypeScript
|
|
||
|
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 { 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 { DescriptionTemplateStatus } from '@app/core/common/enum/description-template-status';
|
||
|
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 { DescriptionTemplate } from '@app/core/model/description-template/description-template';
|
||
|
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 { DescriptionTemplateEditorResolver } from './description-template-editor.resolver';
|
||
|
import { DescriptionTemplateEditorService } from './description-template-editor.service';
|
||
|
import { DescriptionTemplateEditorModel } from './description-template-editor.model';
|
||
|
import { DescriptionTemplateService } from '@app/core/services/description-template/description-template.service';
|
||
|
import { DescriptionTemplatePersist } from '@app/core/model/description-template/description-template-persist';
|
||
|
|
||
|
|
||
|
@Component({
|
||
|
selector: 'app-description-template-editor-component',
|
||
|
templateUrl: 'description-template-editor.component.html',
|
||
|
styleUrls: ['./description-template-editor.component.scss'],
|
||
|
providers: [DescriptionTemplateEditorService]
|
||
|
})
|
||
|
export class DescriptionTemplateEditorComponent extends BaseEditor<DescriptionTemplateEditorModel, DescriptionTemplate> implements OnInit {
|
||
|
|
||
|
isNew = true;
|
||
|
isDeleted = false;
|
||
|
formGroup: UntypedFormGroup = null;
|
||
|
showInactiveDetails = false;
|
||
|
// selectedSystemFields: Array<DescriptionTemplateSystemFieldType> = [];
|
||
|
// descriptionTemplateSectionFieldCategory = DescriptionTemplateSectionFieldCategory;
|
||
|
// descriptionTemplateSystemFieldType = DescriptionTemplateSystemFieldType;
|
||
|
// public descriptionTemplateSystemFieldTypeEnum = this.enumUtils.getEnumValues(DescriptionTemplateSystemFieldType);
|
||
|
// descriptionTemplateExtraFieldDataType = DescriptionTemplateExtraFieldDataType;
|
||
|
// public descriptionTemplateExtraFieldDataTypeEnum = this.enumUtils.getEnumValues(DescriptionTemplateExtraFieldDataType);
|
||
|
|
||
|
// 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.DeleteDescriptionTemplate);
|
||
|
}
|
||
|
|
||
|
protected get canSave(): boolean {
|
||
|
return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditDescriptionTemplate);
|
||
|
}
|
||
|
|
||
|
protected get canFinalize(): boolean {
|
||
|
return !this.isDeleted && this.hasPermission(this.authService.permissionEnum.EditDescriptionTemplate);
|
||
|
}
|
||
|
|
||
|
|
||
|
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 descriptionTemplateService: DescriptionTemplateService,
|
||
|
private logger: LoggingService,
|
||
|
private descriptionTemplateEditorService: DescriptionTemplateEditorService,
|
||
|
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: DescriptionTemplate) => void) {
|
||
|
this.descriptionTemplateService.getSingle(itemId, DescriptionTemplateEditorResolver.lookupFields())
|
||
|
.pipe(map(data => data as DescriptionTemplate), takeUntil(this._destroyed))
|
||
|
.subscribe(
|
||
|
data => successFunction(data),
|
||
|
error => this.onCallbackError(error)
|
||
|
);
|
||
|
}
|
||
|
|
||
|
prepareForm(data: DescriptionTemplate) {
|
||
|
try {
|
||
|
this.editorModel = data ? new DescriptionTemplateEditorModel().fromModel(data) : new DescriptionTemplateEditorModel();
|
||
|
this.isDeleted = data ? data.isActive === IsActive.Inactive : false;
|
||
|
this.buildForm();
|
||
|
} catch (error) {
|
||
|
this.logger.error('Could not parse descriptionTemplate 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.EditDescriptionTemplate));
|
||
|
//this.selectedSystemFields = this.selectedSystemFieldDisabled();
|
||
|
this.descriptionTemplateEditorService.setValidationErrorModel(this.editorModel.validationErrorModel);
|
||
|
if (this.editorModel.status == DescriptionTemplateStatus.Finalized) {
|
||
|
this.formGroup.disable();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
refreshData(): void {
|
||
|
this.getItem(this.editorModel.id, (data: DescriptionTemplate) => 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 DescriptionTemplatePersist;
|
||
|
|
||
|
this.descriptionTemplateService.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.descriptionTemplateService.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: DescriptionTemplateDefinitionSectionEditorModel = new DescriptionTemplateDefinitionSectionEditorModel();
|
||
|
// 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<string[]>) {
|
||
|
// 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: DescriptionTemplateSystemFieldType) {
|
||
|
// 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 == DescriptionTemplateSectionFieldCategory.SYSTEM) && f.get('type').value == systemField) {
|
||
|
// // return true;
|
||
|
// // }
|
||
|
// // }
|
||
|
// // }
|
||
|
// // i++;
|
||
|
// // }
|
||
|
// // return false;
|
||
|
// }
|
||
|
|
||
|
// selectedSystemFieldDisabled(): Array<DescriptionTemplateSystemFieldType> {
|
||
|
// 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 DescriptionTemplateSystemFieldType));
|
||
|
// }
|
||
|
|
||
|
// addSystemField(sectionIndex: number, systemFieldType: DescriptionTemplateSystemFieldType): 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 = DescriptionTemplateSectionFieldCategory.SYSTEM;
|
||
|
// field.systemFieldType = systemFieldType;
|
||
|
// field.required = (systemFieldType == DescriptionTemplateSystemFieldType.TEXT || systemFieldType == DescriptionTemplateSystemFieldType.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 = DescriptionTemplateSectionFieldCategory.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<string[]>, 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<DatasetProfileModel[]> {
|
||
|
// const request = new DataTableRequest<DatasetProfileCriteria>(null, null, { fields: ['+label'] });
|
||
|
// const criteria = new DatasetProfileCriteria();
|
||
|
// criteria.like = value;
|
||
|
// request.criteria = criteria;
|
||
|
// return this.dmpService.searchDescriptionTemplates(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.descriptionTemplateId = params['id'];
|
||
|
// const cloneId = params['cloneid'];
|
||
|
|
||
|
// if (this.descriptionTemplateId != null) {
|
||
|
// this.isNew = false;
|
||
|
// this.descriptionTemplateService.getSingleBlueprint(this.descriptionTemplateId).pipe(map(data => data as any))
|
||
|
// .pipe(takeUntil(this._destroyed))
|
||
|
// .subscribe(data => {
|
||
|
// this.descriptionTemplateEditor = new DescriptionTemplateEditor().fromModel(data);
|
||
|
// this.formGroup = this.descriptionTemplateEditor.buildForm();
|
||
|
// this.buildSystemFields();
|
||
|
// this.fillDescriptionTemplatesInMultAutocomplete();
|
||
|
// if (this.descriptionTemplateEditor.status == DescriptionTemplateStatus.Finalized) {
|
||
|
// this.formGroup.disable();
|
||
|
// this.viewOnly = true
|
||
|
// }
|
||
|
// // this.breadCrumbs = observableOf([{
|
||
|
// // parentComponentName: 'DescriptionTemplateListingComponent',
|
||
|
// // label: this.language.instant('NAV-BAR.TEMPLATE'),
|
||
|
// // url: '/description-templates/' + this.descriptionTemplateId
|
||
|
// // }]);
|
||
|
// });
|
||
|
// } else if (cloneId != null) {
|
||
|
// this.isClone = true;
|
||
|
// this.descriptionTemplateService.clone(cloneId).pipe(map(data => data as any), takeUntil(this._destroyed))
|
||
|
// .subscribe(
|
||
|
// data => {
|
||
|
// this.descriptionTemplateEditor = new DescriptionTemplateEditor().fromModel(data);
|
||
|
// this.descriptionTemplateEditor.id = null;
|
||
|
// this.descriptionTemplateEditor.status = DescriptionTemplateStatus.Draft;
|
||
|
// this.formGroup = this.descriptionTemplateEditor.buildForm();
|
||
|
// this.buildSystemFields();
|
||
|
// this.fillDescriptionTemplatesInMultAutocomplete();
|
||
|
// },
|
||
|
// error => this.onCallbackError(error)
|
||
|
// );
|
||
|
// } else {
|
||
|
// this.descriptionTemplateEditorModel = new DescriptionTemplateEditorModel();
|
||
|
// this.descriptionTemplateEditor = new DescriptionTemplateEditor();
|
||
|
// setTimeout(() => {
|
||
|
// // this.formGroup = this.descriptionTemplateModel.buildForm();
|
||
|
// // this.addField();
|
||
|
// this.descriptionTemplateEditor.status = DescriptionTemplateStatus.Draft;
|
||
|
// this.formGroup = this.descriptionTemplateEditor.buildForm();
|
||
|
// });
|
||
|
// // this.breadCrumbs = observableOf([{
|
||
|
// // parentComponentName: 'DescriptionTemplateListingComponent',
|
||
|
// // label: this.language.instant('NAV-BAR.TEMPLATE'),
|
||
|
// // url: '/description-templates/' + this.descriptionTemplateId
|
||
|
// // }]);
|
||
|
// }
|
||
|
// });
|
||
|
|
||
|
// }
|
||
|
|
||
|
// 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 == DescriptionTemplateSectionFieldCategory.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<DatasetProfileModel>();
|
||
|
// 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<DatasetProfileModel>();
|
||
|
// this.descriptionTemplatesArray(sectionIndex).clear();
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
|
||
|
|
||
|
// sectionsArray(): UntypedFormArray {
|
||
|
// //return this.descriptionTemplatesFormGroup.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.descriptionTemplatesFormGroup.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 descriptionTemplate: DescriptionTemplatePersist = this.formGroup.value;
|
||
|
// return descriptionTemplate.definition.sections.some(section => section.fields.some(field => (field.category === DescriptionTemplateSectionFieldCategory.SYSTEM || field.category as unknown === DescriptionTemplateSectionFieldCategory.SYSTEM) && field.systemFieldType === DescriptionTemplateSystemFieldType.TEXT));
|
||
|
// }
|
||
|
|
||
|
// hasDescription(): boolean {
|
||
|
// const descriptionTemplate: DescriptionTemplatePersist = this.formGroup.value;
|
||
|
// return descriptionTemplate.definition.sections.some(section => section.fields.some(field => (field.category === DescriptionTemplateSectionFieldCategory.SYSTEM || field.category as unknown === DescriptionTemplateSectionFieldCategory.SYSTEM) && field.systemFieldType === DescriptionTemplateSystemFieldType.HTML_TEXT));
|
||
|
// }
|
||
|
|
||
|
// hasDescriptionTemplates(): boolean {
|
||
|
// const descriptionTemplate: DescriptionTemplatePersist = this.formGroup.value;
|
||
|
// return descriptionTemplate.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.descriptionTemplateService.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(['/description-templates']);
|
||
|
// }
|
||
|
|
||
|
// onCallbackError(errorResponse: any) {
|
||
|
// this.setErrorModel(errorResponse.error);
|
||
|
// this.formService.validateAllFormFields(this.formGroup);
|
||
|
// }
|
||
|
|
||
|
// public setErrorModel(validationErrorModel: ValidationErrorModel) {
|
||
|
// Object.keys(validationErrorModel).forEach(item => {
|
||
|
// (<any>this.descriptionTemplateEditor.validationErrorModel)[item] = (<any>validationErrorModel)[item];
|
||
|
// });
|
||
|
// }
|
||
|
|
||
|
public cancel(): void {
|
||
|
this.router.navigate(['/description-templates']);
|
||
|
}
|
||
|
|
||
|
// // addField() {
|
||
|
// // (<FormArray>this.formGroup.get('definition').get('fields')).push(new DescriptionTemplateFieldEditorModel().buildForm());
|
||
|
// // }
|
||
|
|
||
|
// // removeField(index: number) {
|
||
|
// // (<FormArray>this.formGroup.get('definition').get('fields')).controls.splice(index, 1);
|
||
|
// // }
|
||
|
|
||
|
// getDescriptionTemplateFieldDataTypeValues(): Number[] {
|
||
|
// let keys: string[] = Object.keys(DescriptionTemplateFieldDataType);
|
||
|
// keys = keys.slice(0, keys.length / 2);
|
||
|
// const values: Number[] = keys.map(Number);
|
||
|
// return values;
|
||
|
// }
|
||
|
|
||
|
// getDescriptionTemplateFieldDataTypeWithLanguage(fieldType: DescriptionTemplateFieldDataType): string {
|
||
|
// let result = '';
|
||
|
// this.language.get(this.enumUtils.toDescriptionTemplateFieldDataTypeString(fieldType))
|
||
|
// .pipe(takeUntil(this._destroyed))
|
||
|
// .subscribe((value: string) => {
|
||
|
// result = value;
|
||
|
// });
|
||
|
// return result;
|
||
|
// }
|
||
|
|
||
|
// getDescriptionTemplateFieldTypeValues(): Number[] {
|
||
|
// let keys: string[] = Object.keys(DescriptionTemplateType);
|
||
|
// keys = keys.slice(0, keys.length / 2);
|
||
|
// const values: Number[] = keys.map(Number);
|
||
|
// return values;
|
||
|
// }
|
||
|
|
||
|
// getDescriptionTemplateFieldTypeWithLanguage(blueprintType: DescriptionTemplateType): string {
|
||
|
// let result = '';
|
||
|
// this.language.get(this.enumUtils.toDescriptionTemplateTypeString(blueprintType))
|
||
|
// .pipe(takeUntil(this._destroyed))
|
||
|
// .subscribe((value: string) => {
|
||
|
// result = value;
|
||
|
// });
|
||
|
// return result;
|
||
|
// }
|
||
|
|
||
|
// delete() {
|
||
|
// this.dialog.open(ConfirmationDialogComponent, {
|
||
|
// data: {
|
||
|
// isDeleteConfirmation: true,
|
||
|
// confirmButton: this.language.instant('DESCRIPTION-TEMPLATE-EDITOR.CONFIRM-DELETE-DIALOG.CONFIRM-BUTTON'),
|
||
|
// cancelButton: this.language.instant("DESCRIPTION-TEMPLATE-EDITOR.CONFIRM-DELETE-DIALOG.CANCEL-BUTTON"),
|
||
|
// message: this.language.instant("DESCRIPTION-TEMPLATE-EDITOR.CONFIRM-DELETE-DIALOG.MESSAGE")
|
||
|
// }
|
||
|
// })
|
||
|
// .afterClosed()
|
||
|
// .subscribe(
|
||
|
// confirmed => {
|
||
|
// if (confirmed) {
|
||
|
// if (this.formGroup.get('status').value == DescriptionTemplateStatus.Draft) {
|
||
|
// // this.formGroup.get('status').setValue(DescriptionTemplateStatus.Deleted);
|
||
|
// this.descriptionTemplateService.createBlueprint(this.formGroup.value)
|
||
|
// .pipe(takeUntil(this._destroyed))
|
||
|
// .subscribe(
|
||
|
// complete => this.onCallbackSuccess(),
|
||
|
// error => this.onCallbackError(error)
|
||
|
// );
|
||
|
// }
|
||
|
// else {
|
||
|
// // this.descriptionTemplateService.delete(this.descriptionTemplateId)
|
||
|
// // .pipe(takeUntil(this._destroyed))
|
||
|
// // .subscribe(
|
||
|
// // complete => this.onCallbackSuccess(),
|
||
|
// // error => {
|
||
|
// // if (error.error.statusCode == 674) {
|
||
|
// // this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DESCRIPTION-TEMPLATE-DELETE'), SnackBarNotificationLevel.Error);
|
||
|
// // } else {
|
||
|
// // this.uiNotificationService.snackBarNotification(this.language.instant(error.message), SnackBarNotificationLevel.Error);
|
||
|
// // }
|
||
|
// // }
|
||
|
// // );
|
||
|
// }
|
||
|
// }
|
||
|
// }
|
||
|
// )
|
||
|
|
||
|
// }
|
||
|
|
||
|
// finalize() {
|
||
|
// if (this.checkValidity()) {
|
||
|
// this.formGroup.get('status').setValue(DescriptionTemplateStatus.Finalized);
|
||
|
// this.formSubmit();
|
||
|
// }
|
||
|
// }
|
||
|
|
||
|
// downloadXML(): void {
|
||
|
// const blueprintId = this.formGroup.get('id').value;
|
||
|
// if (blueprintId == null) return;
|
||
|
// this.descriptionTemplateService.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);
|
||
|
// });
|
||
|
// }
|
||
|
}
|