658 lines
25 KiB
TypeScript
658 lines
25 KiB
TypeScript
|
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
|
|
import { HttpClient } from '@angular/common/http';
|
|
import { AfterViewInit, Component } from '@angular/core';
|
|
import { UntypedFormArray, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
import { ActivatedRoute, Params, Router } from '@angular/router';
|
|
import { DmpBlueprintFieldDataType } from '@app/core/common/enum/dmp-blueprint-field-type';
|
|
import { DmpBlueprintStatus } from '@app/core/common/enum/dmp-blueprint-status';
|
|
import { DmpBlueprintType } from '@app/core/common/enum/dmp-blueprint-type';
|
|
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
|
import { DatasetProfileModel } from '@app/core/model/dataset/dataset-profile';
|
|
import { DmpBlueprint, ExtraFieldType, FieldCategory, SystemFieldType } from '@app/core/model/dmp/dmp-blueprint/dmp-blueprint';
|
|
import { DatasetProfileCriteria } from '@app/core/query/dataset-profile/dataset-profile-criteria';
|
|
import { ConfigurationService } from '@app/core/services/configuration/configuration.service';
|
|
import { DmpBlueprintService } from '@app/core/services/dmp/dmp-blueprint.service';
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
import { MatomoService } from '@app/core/services/matomo/matomo-service';
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
import { MultipleAutoCompleteConfiguration } from '@app/library/auto-complete/multiple/multiple-auto-complete-configuration';
|
|
import { DmpBlueprintExternalAutoCompleteFieldDataEditorModel } from '@app/ui/admin/dmp-blueprint/editor/external-autocomplete/dmp-blueprint-external-autocomplete-field-editor.model';
|
|
// import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
|
|
import { isNullOrUndefined } from '@app/utilities/enhancers/utils';
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
import { FormService } from '@common/forms/form-service';
|
|
import { FormValidationErrorsDialogComponent } from '@common/forms/form-validation-errors-dialog/form-validation-errors-dialog.component';
|
|
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
|
import { Guid } from '@common/types/guid';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
import * as FileSaver from 'file-saver';
|
|
import { Observable, of as observableOf } from 'rxjs';
|
|
import { map, takeUntil } from 'rxjs/operators';
|
|
import { DescriptionTemplatesInSectionEditor, DmpBlueprintEditor, FieldInSectionEditor, SectionDmpBlueprintEditor } from './dmp-blueprint-editor.model';
|
|
import { DmpBlueprintEditorModel } from './dmp-profile-editor.model';
|
|
|
|
|
|
@Component({
|
|
selector: 'app-dmp-blueprint-editor-component',
|
|
templateUrl: 'dmp-blueprint-editor.component.html',
|
|
styleUrls: ['./dmp-blueprint-editor.component.scss']
|
|
})
|
|
export class DmpBlueprintEditorComponent extends BaseComponent implements AfterViewInit {
|
|
|
|
isNew = true;
|
|
isClone = false;
|
|
viewOnly = false;
|
|
dmpBlueprintEditorModel = new DmpBlueprintEditorModel();
|
|
dmpBlueprintEditor = new DmpBlueprintEditor();
|
|
formGroup: UntypedFormGroup = null;
|
|
host: string;
|
|
dmpBlueprintId: string;
|
|
// breadCrumbs: Observable<BreadcrumbItem[]>;
|
|
|
|
dmpBlueprintsFormGroup: UntypedFormGroup = null;
|
|
|
|
blueprintsAutoCompleteConfiguration: MultipleAutoCompleteConfiguration;
|
|
|
|
fieldList = [
|
|
{ label: 'Title', type: SystemFieldType.TEXT },
|
|
{ label: 'Description', type: SystemFieldType.HTML_TEXT },
|
|
{ label: 'Researchers', type: SystemFieldType.RESEARCHERS },
|
|
{ label: 'Organizations', type: SystemFieldType.ORGANIZATIONS },
|
|
{ label: 'Language', type: SystemFieldType.LANGUAGE },
|
|
{ label: 'Contact', type: SystemFieldType.CONTACT },
|
|
{ label: 'Funder', type: SystemFieldType.FUNDER },
|
|
{ label: 'Grant', type: SystemFieldType.GRANT },
|
|
{ label: 'Project', type: SystemFieldType.PROJECT },
|
|
{ label: 'License', type: SystemFieldType.LICENSE },
|
|
{ label: 'Access Rights', type: SystemFieldType.ACCESS_RIGHTS }
|
|
];
|
|
systemFieldListPerSection: Array<Array<any>> = new Array();
|
|
descriptionTemplatesPerSection: Array<Array<DatasetProfileModel>> = new Array<Array<DatasetProfileModel>>();
|
|
|
|
constructor(
|
|
private dmpBlueprintService: DmpBlueprintService,
|
|
private _service: DmpService,
|
|
private route: ActivatedRoute,
|
|
private router: Router,
|
|
private language: TranslateService,
|
|
private enumUtils: EnumUtils,
|
|
private uiNotificationService: UiNotificationService,
|
|
private formService: FormService,
|
|
private fb: UntypedFormBuilder,
|
|
private configurationService: ConfigurationService,
|
|
private httpClient: HttpClient,
|
|
private matomoService: MatomoService,
|
|
private dialog: MatDialog
|
|
) {
|
|
super();
|
|
this.host = configurationService.server;
|
|
}
|
|
|
|
ngAfterViewInit() {
|
|
this.matomoService.trackPageView('Admin: DMP Profile Edit');
|
|
|
|
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'
|
|
};
|
|
|
|
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<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();
|
|
}
|
|
}
|
|
|
|
filterProfiles(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._service.searchDmpBlueprints(request);
|
|
}
|
|
|
|
sectionsArray(): UntypedFormArray {
|
|
//return this.dmpBlueprintsFormGroup.get('sections') as FormArray;
|
|
return this.formGroup.get('definition').get('sections') as UntypedFormArray;
|
|
}
|
|
|
|
addSection(): void {
|
|
const section: SectionDmpBlueprintEditor = new SectionDmpBlueprintEditor();
|
|
section.id = Guid.create().toString();
|
|
section.ordinal = this.sectionsArray().length + 1;
|
|
section.hasTemplates = false;
|
|
this.sectionsArray().push(section.buildForm());
|
|
this.systemFieldListPerSection.push(new Array());
|
|
}
|
|
|
|
removeSection(sectionIndex: number): void {
|
|
this.systemFieldListPerSection.splice(sectionIndex, 1);
|
|
this.sectionsArray().removeAt(sectionIndex);
|
|
this.sectionsArray().controls.forEach((section, index) => {
|
|
section.get('ordinal').setValue(index + 1);
|
|
});
|
|
}
|
|
|
|
fieldsArray(sectionIndex: number): UntypedFormArray {
|
|
return this.sectionsArray().at(sectionIndex).get('fields') as UntypedFormArray;
|
|
}
|
|
|
|
addField(sectionIndex: number, fieldCategory: FieldCategory, fieldType?: number): void {
|
|
const field: FieldInSectionEditor = new FieldInSectionEditor();
|
|
field.id = Guid.create().toString();
|
|
field.ordinal = this.fieldsArray(sectionIndex).length + 1;
|
|
field.category = fieldCategory;
|
|
if (!isNullOrUndefined(fieldType)) {
|
|
field.type = fieldType
|
|
}
|
|
field.required = (!isNullOrUndefined(fieldType) && (fieldType == 0 || fieldType == 1)) ? true : false;
|
|
this.fieldsArray(sectionIndex).push(field.buildForm());
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
systemFieldDisabled(systemField: SystemFieldType, sectionIndex: number) {
|
|
let i = 0;
|
|
for (let s in this.sectionsArray().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;
|
|
}
|
|
|
|
removeSystemFieldWithIndex(sectionIndex: number, fieldIndex: number): void {
|
|
let type: SystemFieldType = this.fieldsArray(sectionIndex).at(fieldIndex).get('type').value;
|
|
let index = this.systemFieldListPerSection[sectionIndex].indexOf(type);
|
|
this.systemFieldListPerSection[sectionIndex] = this.systemFieldListPerSection[sectionIndex].filter(types => types != type);
|
|
this.fieldsArray(sectionIndex).removeAt(fieldIndex);
|
|
}
|
|
|
|
removeSystemField(sectionIndex: number, systemField: SystemFieldType): void {
|
|
let i = 0;
|
|
for (let f of this.fieldsArray(sectionIndex).controls) {
|
|
if ((f.get('category').value == FieldCategory.SYSTEM || f.get('category').value == 'SYSTEM') && f.get('type').value == systemField) {
|
|
this.fieldsArray(sectionIndex).removeAt(i);
|
|
return;
|
|
}
|
|
i++;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
addExtraField(sectionIndex: number): void {
|
|
this.addField(sectionIndex, FieldCategory.EXTRA);
|
|
}
|
|
|
|
removeExtraField(sectionIndex: number, fieldIndex: number): void {
|
|
this.fieldsArray(sectionIndex).removeAt(fieldIndex);
|
|
}
|
|
|
|
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';
|
|
}
|
|
}
|
|
|
|
drop(event: CdkDragDrop<string[]>, sectionIndex: number) {
|
|
moveItemInArray(this.fieldsArray(sectionIndex).controls, event.previousIndex, event.currentIndex);
|
|
moveItemInArray(this.fieldsArray(sectionIndex).value, event.previousIndex, event.currentIndex);
|
|
}
|
|
|
|
dropSections(event: CdkDragDrop<string[]>) {
|
|
moveItemInArray(this.sectionsArray().controls, event.previousIndex, event.currentIndex);
|
|
moveItemInArray(this.sectionsArray().value, event.previousIndex, event.currentIndex);
|
|
this.sectionsArray().controls.forEach((section, index) => {
|
|
section.get('ordinal').setValue(index + 1);
|
|
});
|
|
}
|
|
|
|
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();
|
|
// }
|
|
|
|
onRemoveTemplate(event, sectionIndex: number) {
|
|
const blueprints = this.descriptionTemplatesArray(sectionIndex).controls;
|
|
const foundIndex = blueprints.findIndex(blueprint => blueprint.get('descriptionTemplateId').value === event.id);
|
|
foundIndex !== -1 && this.descriptionTemplatesArray(sectionIndex).removeAt(foundIndex);
|
|
}
|
|
|
|
// 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'
|
|
// };
|
|
// }
|
|
// });
|
|
// }
|
|
|
|
onOptionSelected(item, sectionIndex) {
|
|
const blueprint: DescriptionTemplatesInSectionEditor = new DescriptionTemplatesInSectionEditor();
|
|
blueprint.id = Guid.create().toString();
|
|
blueprint.descriptionTemplateId = item.id;
|
|
blueprint.label = item.label;
|
|
this.descriptionTemplatesArray(sectionIndex).push(blueprint.buildForm());
|
|
}
|
|
|
|
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: DmpBlueprint = this.formGroup.value;
|
|
return dmpBlueprint.definition.sections.some(section => section.fields.some(field => (field.category === FieldCategory.SYSTEM || field.category as unknown === 'SYSTEM') && field.type === SystemFieldType.TEXT));
|
|
}
|
|
|
|
hasDescription(): boolean {
|
|
const dmpBlueprint: DmpBlueprint = this.formGroup.value;
|
|
return dmpBlueprint.definition.sections.some(section => section.fields.some(field => (field.category === FieldCategory.SYSTEM || field.category as unknown === 'SYSTEM') && field.type === SystemFieldType.HTML_TEXT));
|
|
}
|
|
|
|
hasDescriptionTemplates(): boolean {
|
|
const dmpBlueprint: DmpBlueprint = 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 => {
|
|
(<any>this.dmpBlueprintEditor.validationErrorModel)[item] = (<any>validationErrorModel)[item];
|
|
});
|
|
}
|
|
|
|
public cancel(): void {
|
|
this.router.navigate(['/dmp-blueprints']);
|
|
}
|
|
|
|
// addField() {
|
|
// (<FormArray>this.formGroup.get('definition').get('fields')).push(new DmpBlueprintFieldEditorModel().buildForm());
|
|
// }
|
|
|
|
// removeField(index: number) {
|
|
// (<FormArray>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.onSubmit();
|
|
}
|
|
}
|
|
|
|
downloadXML(): void {
|
|
this.dmpBlueprintService.downloadXML(this.dmpBlueprintId)
|
|
.pipe(takeUntil(this._destroyed))
|
|
.subscribe(response => {
|
|
const blob = new Blob([response.body], { type: 'application/xml' });
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
});
|
|
}
|
|
|
|
|
|
getFilenameFromContentDispositionHeader(header: string): string {
|
|
const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);
|
|
|
|
const matches = header.match(regex);
|
|
let filename: string;
|
|
for (let i = 0; i < matches.length; i++) {
|
|
const match = matches[i];
|
|
if (match.includes('filename="')) {
|
|
filename = match.substring(10, match.length - 1);
|
|
break;
|
|
} else if (match.includes('filename=')) {
|
|
filename = match.substring(9);
|
|
break;
|
|
}
|
|
}
|
|
return filename;
|
|
}
|
|
|
|
isExternalAutocomplete(formGroup: UntypedFormGroup) {
|
|
if (formGroup.get('dataType').value == DmpBlueprintFieldDataType.ExternalAutocomplete) {
|
|
this.addControl(formGroup);
|
|
return true;
|
|
} else {
|
|
this.removeControl(formGroup);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
addControl(formGroup: UntypedFormGroup) {
|
|
if (formGroup.get('dataType').value == 3)
|
|
formGroup.addControl('externalAutocomplete', new DmpBlueprintExternalAutoCompleteFieldDataEditorModel().buildForm());
|
|
}
|
|
|
|
removeControl(formGroup: UntypedFormGroup) {
|
|
if (formGroup.get('dataType').value != 3)
|
|
formGroup.removeControl('externalAutocomplete');
|
|
}
|
|
}
|