2019-01-24 16:30:23 +01:00
|
|
|
import { Component, OnInit, ViewContainerRef } from '@angular/core';
|
2019-07-01 11:35:09 +02:00
|
|
|
import { FormGroup, FormControl, FormArray } from '@angular/forms';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { MatDialog, MatSnackBar } from '@angular/material';
|
|
|
|
import { ActivatedRoute, Params, Router } from '@angular/router';
|
2018-10-05 17:00:54 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2018-11-27 18:33:17 +01:00
|
|
|
import * as FileSaver from 'file-saver';
|
2018-10-12 17:17:31 +02:00
|
|
|
import { Observable } from 'rxjs';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2019-01-24 16:30:23 +01:00
|
|
|
import { ValidationErrorModel } from '../../../common/forms/validation/error-model/validation-error-model';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { BaseComponent } from '../../../core/common/base/base.component';
|
|
|
|
import { DmpStatus } from '../../../core/common/enum/dmp-status';
|
|
|
|
import { Status } from '../../../core/common/enum/Status';
|
2019-02-13 14:44:08 +01:00
|
|
|
import { DataTableRequest } from '../../../core/model/data-table/data-table-request';
|
|
|
|
import { DmpProfileDefinition } from '../../../core/model/dmp-profile/dmp-profile';
|
|
|
|
import { DmpProfileListing } from '../../../core/model/dmp-profile/dmp-profile-listing';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { DmpModel } from '../../../core/model/dmp/dmp';
|
|
|
|
import { UserModel } from '../../../core/model/user/user';
|
|
|
|
import { BaseCriteria } from '../../../core/query/base-criteria';
|
2019-02-13 14:44:08 +01:00
|
|
|
import { DmpProfileCriteria } from '../../../core/query/dmp/dmp-profile-criteria';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { ProjectCriteria } from '../../../core/query/project/project-criteria';
|
2019-01-24 16:30:23 +01:00
|
|
|
import { RequestItem } from '../../../core/query/request-item';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { DmpProfileService } from '../../../core/services/dmp/dmp-profile.service';
|
|
|
|
import { DmpService } from '../../../core/services/dmp/dmp.service';
|
|
|
|
import { ExternalSourcesService } from '../../../core/services/external-sources/external-sources.service';
|
2019-01-24 16:30:23 +01:00
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '../../../core/services/notification/ui-notification-service';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { ProjectService } from '../../../core/services/project/project.service';
|
2019-02-13 14:44:08 +01:00
|
|
|
import { ConfirmationDialogComponent } from '../../../library/confirmation-dialog/confirmation-dialog.component';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { LanguageResolverService } from '../../../services/language-resolver/language-resolver.service';
|
|
|
|
import { BreadcrumbItem } from '../../misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCrumbComponent';
|
|
|
|
import { DmpEditorModel } from './dmp-editor.model';
|
2019-07-01 11:35:09 +02:00
|
|
|
import { DmpFinalizeDialogComponent, DmpFinalizeDialogInput } from './dmp-finalize-dialog/dmp-finalize-dialog.component';
|
2019-04-26 16:05:15 +02:00
|
|
|
import { AuthService } from '../../../core/services/auth/auth.service';
|
2019-05-23 17:48:54 +02:00
|
|
|
import { ExportMethodDialogComponent } from '../../../library/export-method-dialog/export-method-dialog.component';
|
2019-05-28 09:49:09 +02:00
|
|
|
import { UserInfoListingModel } from '../../../core/model/user/user-info-listing';
|
2019-06-12 15:01:55 +02:00
|
|
|
import { ProjectTabModel } from './project-tab/project-tab-model';
|
2019-06-21 15:55:38 +02:00
|
|
|
import { DatasetListingModel } from '../../../core/model/dataset/dataset-listing';
|
2017-12-14 18:13:28 +01:00
|
|
|
|
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
selector: 'app-dmp-editor-component',
|
|
|
|
templateUrl: 'dmp-editor.component.html',
|
2019-01-18 18:03:45 +01:00
|
|
|
styleUrls: ['./dmp-editor.component.scss']
|
2017-12-14 18:13:28 +01:00
|
|
|
})
|
2019-01-24 16:30:23 +01:00
|
|
|
export class DmpEditorComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
|
2017-12-18 11:01:22 +01:00
|
|
|
|
2019-05-21 15:42:28 +02:00
|
|
|
editMode = true;
|
|
|
|
// editMode = false;
|
2017-12-21 10:16:46 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
|
|
|
isNew = true;
|
2019-04-26 16:05:15 +02:00
|
|
|
isPublic = false;
|
2019-06-25 15:02:54 +02:00
|
|
|
isFinalized = false;
|
2019-01-18 18:03:45 +01:00
|
|
|
dmp: DmpEditorModel;
|
2018-10-05 17:00:54 +02:00
|
|
|
formGroup: FormGroup = null;
|
|
|
|
|
|
|
|
createNewVersion;
|
2019-01-18 18:03:45 +01:00
|
|
|
associatedUsers: Array<UserModel>;
|
2019-05-28 09:49:09 +02:00
|
|
|
people: Array<UserInfoListingModel>;
|
2019-02-13 14:44:08 +01:00
|
|
|
filteredOptions: DmpProfileListing[];
|
|
|
|
selectedDmpProfileDefinition: DmpProfileDefinition;
|
|
|
|
DynamicDmpFieldResolverComponent: any;
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
constructor(
|
2019-01-18 18:03:45 +01:00
|
|
|
private dmpProfileService: DmpProfileService,
|
|
|
|
private dmpService: DmpService,
|
2018-10-05 17:00:54 +02:00
|
|
|
private projectService: ProjectService,
|
|
|
|
private externalSourcesService: ExternalSourcesService,
|
|
|
|
private route: ActivatedRoute,
|
2019-01-18 18:03:45 +01:00
|
|
|
private snackBar: MatSnackBar,
|
|
|
|
private router: Router,
|
|
|
|
private language: TranslateService,
|
|
|
|
private _service: DmpService,
|
|
|
|
private dialog: MatDialog,
|
2018-10-05 17:00:54 +02:00
|
|
|
private _viewContainerRef: ViewContainerRef,
|
2019-01-24 11:46:29 +01:00
|
|
|
public languageResolverService: LanguageResolverService,
|
2019-04-26 16:05:15 +02:00
|
|
|
private uiNotificationService: UiNotificationService,
|
|
|
|
private authService: AuthService,
|
2018-10-05 17:00:54 +02:00
|
|
|
) {
|
2018-11-27 18:33:17 +01:00
|
|
|
super();
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-01-24 16:30:23 +01:00
|
|
|
ngOnInit() {
|
2018-11-27 18:33:17 +01:00
|
|
|
this.route.params
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe((params: Params) => {
|
|
|
|
const itemId = params['id'];
|
2019-01-24 11:46:29 +01:00
|
|
|
const projectId = params['projectId'];
|
2019-04-26 16:05:15 +02:00
|
|
|
const publicId = params['publicId'];
|
2018-11-27 18:33:17 +01:00
|
|
|
|
|
|
|
const projectRequestItem: RequestItem<ProjectCriteria> = new RequestItem();
|
|
|
|
projectRequestItem.criteria = new ProjectCriteria();
|
|
|
|
const organisationRequestItem: RequestItem<BaseCriteria> = new RequestItem();
|
|
|
|
organisationRequestItem.criteria = new BaseCriteria();
|
|
|
|
|
2019-05-28 09:49:09 +02:00
|
|
|
// this.projectAutoCompleteConfiguration = {
|
|
|
|
// filterFn: this.searchProject.bind(this),
|
|
|
|
// initialItems: (extraData) => this.searchProject(''),
|
|
|
|
// displayFn: (item) => item['label'],
|
|
|
|
// titleFn: (item) => item['label']
|
|
|
|
// };
|
2018-11-27 18:33:17 +01:00
|
|
|
if (itemId != null) {
|
|
|
|
this.isNew = false;
|
2019-01-18 18:03:45 +01:00
|
|
|
this.dmpService.getSingle(itemId).map(data => data as DmpModel)
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(async data => {
|
2019-06-12 15:01:55 +02:00
|
|
|
this.dmp = new DmpEditorModel();
|
|
|
|
this.dmp.project = new ProjectTabModel();
|
|
|
|
this.dmp.fromModel(data);
|
2019-01-18 18:03:45 +01:00
|
|
|
this.formGroup = this.dmp.buildForm();
|
2019-05-23 17:48:54 +02:00
|
|
|
//this.registerFormEventsForDmpProfile(this.dmp.definition);
|
2019-06-25 15:02:54 +02:00
|
|
|
if (!this.editMode || this.dmp.status === Status.Inactive) {
|
|
|
|
this.isFinalized = true;
|
|
|
|
this.formGroup.disable();
|
|
|
|
}
|
2019-05-16 18:11:41 +02:00
|
|
|
if (this.isAuthenticated) {
|
2019-05-21 15:42:28 +02:00
|
|
|
// if (!this.isAuthenticated) {
|
2019-05-22 11:52:53 +02:00
|
|
|
const breadCrumbs = [];
|
2019-05-23 11:40:24 +02:00
|
|
|
breadCrumbs.push({
|
|
|
|
parentComponentName: null,
|
2019-06-07 13:03:10 +02:00
|
|
|
label: this.language.instant('NAV-BAR.MY-DMPS'),
|
2019-05-23 11:40:24 +02:00
|
|
|
url: "/plans"
|
|
|
|
});
|
2019-06-07 13:03:10 +02:00
|
|
|
breadCrumbs.push({
|
2019-06-07 17:21:09 +02:00
|
|
|
parentComponentName: 'DmpListingComponent',
|
|
|
|
label: this.dmp.label,
|
|
|
|
url: '/plans/edit/' + this.dmp.id,
|
|
|
|
// notFoundResolver: [await this.projectService.getSingle(this.dmp.project.id).map(x => ({ label: x.label, url: '/projects/edit/' + x.id }) as BreadcrumbItem).toPromise()]
|
|
|
|
}
|
2019-04-26 16:05:15 +02:00
|
|
|
);
|
2019-05-22 11:52:53 +02:00
|
|
|
this.breadCrumbs = Observable.of(breadCrumbs);
|
2019-04-26 16:05:15 +02:00
|
|
|
}
|
2018-11-27 18:33:17 +01:00
|
|
|
this.associatedUsers = data.associatedUsers;
|
2019-05-28 09:49:09 +02:00
|
|
|
this.people = data.users;
|
2018-11-27 18:33:17 +01:00
|
|
|
});
|
2019-01-24 11:46:29 +01:00
|
|
|
} else if (projectId != null) {
|
|
|
|
this.isNew = true;
|
2019-06-12 15:01:55 +02:00
|
|
|
this.projectService.getSingle(projectId).map(data => data as ProjectTabModel)
|
2019-01-24 11:46:29 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(data => {
|
|
|
|
this.dmp = new DmpEditorModel();
|
2019-06-12 15:01:55 +02:00
|
|
|
this.dmp.project = new ProjectTabModel();
|
2019-01-24 11:46:29 +01:00
|
|
|
this.dmp.project = data;
|
|
|
|
this.formGroup = this.dmp.buildForm();
|
2019-05-23 17:48:54 +02:00
|
|
|
//this.registerFormEventsForDmpProfile();
|
2019-01-24 11:46:29 +01:00
|
|
|
this.formGroup.get('project').disable();
|
|
|
|
this.registerFormEventsForNewItem();
|
|
|
|
});
|
2019-04-26 16:05:15 +02:00
|
|
|
} else if (publicId != null) {
|
|
|
|
this.isNew = false;
|
|
|
|
this.isPublic = true;
|
|
|
|
this.dmpService.getSinglePublic(publicId).map(data => data as DmpModel)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(async data => {
|
2019-06-12 15:01:55 +02:00
|
|
|
this.dmp = new DmpEditorModel();
|
|
|
|
this.dmp.project = new ProjectTabModel();
|
|
|
|
this.dmp.fromModel(data);
|
2019-04-26 16:05:15 +02:00
|
|
|
this.formGroup = this.dmp.buildForm();
|
2019-05-23 17:48:54 +02:00
|
|
|
//this.registerFormEventsForDmpProfile(this.dmp.definition);
|
2019-04-26 16:05:15 +02:00
|
|
|
if (!this.editMode || this.dmp.status === Status.Inactive) { this.formGroup.disable(); }
|
2019-06-11 10:25:32 +02:00
|
|
|
// if (!this.isAuthenticated) {
|
2019-06-21 15:55:38 +02:00
|
|
|
const breadcrumbs = [];
|
2019-06-25 15:02:54 +02:00
|
|
|
breadcrumbs.push({ parentComponentName: null, label: this.language.instant('NAV-BAR.PUBLIC-DMPS').toUpperCase(), url: '/plans' });
|
2019-06-21 15:55:38 +02:00
|
|
|
breadcrumbs.push({ parentComponentName: null, label: this.dmp.label, url: '/plans/publicEdit/' + this.dmp.id });
|
|
|
|
this.breadCrumbs = Observable.of(breadcrumbs);
|
|
|
|
// this.breadCrumbs = Observable.of([
|
|
|
|
// {
|
|
|
|
// parentComponentName: 'DmpListingComponent',
|
|
|
|
// label: this.language.instant('NAV-BAR.MY-DMPS'),
|
|
|
|
// url: 'plans',
|
|
|
|
// notFoundResolver: [await this.projectService.getSingle(this.dmp.project.id).map(x => ({ label: x.label, url: '/projects/edit/' + x.id }) as BreadcrumbItem).toPromise()]
|
|
|
|
// }]
|
|
|
|
// );
|
|
|
|
this.associatedUsers = data.associatedUsers;
|
2019-06-11 10:25:32 +02:00
|
|
|
// }
|
2019-04-26 16:05:15 +02:00
|
|
|
});
|
2018-11-27 18:33:17 +01:00
|
|
|
} else {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.dmp = new DmpEditorModel();
|
2019-06-12 15:01:55 +02:00
|
|
|
this.dmp.project = new ProjectTabModel();
|
2019-01-24 11:46:29 +01:00
|
|
|
this.formGroup = this.dmp.buildForm();
|
|
|
|
this.registerFormEventsForNewItem();
|
2019-06-07 13:03:10 +02:00
|
|
|
if (this.isAuthenticated) {
|
2019-06-26 17:34:43 +02:00
|
|
|
this.language.get('NAV-BAR.MY-DMPS').pipe(takeUntil(this._destroyed)).subscribe(x => {
|
|
|
|
this.breadCrumbs = Observable.of([
|
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: x,
|
|
|
|
url: '/plans'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
parentComponentName: null,
|
|
|
|
label: "CREATE NEW DMP",
|
|
|
|
url: "/plans/new"
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
})
|
2019-06-07 13:03:10 +02:00
|
|
|
}
|
2018-11-27 18:33:17 +01:00
|
|
|
}
|
|
|
|
});
|
2019-01-24 11:46:29 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
this.route
|
|
|
|
.queryParams
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
2018-10-05 17:00:54 +02:00
|
|
|
.subscribe(params => {
|
|
|
|
this.createNewVersion = params['clone'];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-04-26 16:05:15 +02:00
|
|
|
isAuthenticated() {
|
|
|
|
return this.authService.current() != null;
|
|
|
|
}
|
2019-02-13 14:44:08 +01:00
|
|
|
|
|
|
|
registerFormEventsForNewItem() {
|
2019-01-24 11:46:29 +01:00
|
|
|
this.breadCrumbs = Observable.of([
|
|
|
|
{
|
|
|
|
parentComponentName: 'DmpListingComponent',
|
2019-06-07 13:03:10 +02:00
|
|
|
label: this.language.instant('NAV-BAR.MY-DMPS'),
|
2019-02-13 14:44:08 +01:00
|
|
|
url: 'plans',
|
2019-01-24 11:46:29 +01:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2019-02-14 13:14:44 +01:00
|
|
|
dmpProfileSearch(query: string) {
|
2019-02-13 14:44:08 +01:00
|
|
|
let fields: Array<string> = new Array();
|
|
|
|
var request = new DataTableRequest<DmpProfileCriteria>(0, 10, { fields: fields });
|
|
|
|
request.criteria = new DmpProfileCriteria();
|
|
|
|
return this.dmpProfileService.getPaged(request).map(x => x.data);
|
|
|
|
}
|
|
|
|
|
2019-05-28 09:49:09 +02:00
|
|
|
// searchProject(query: string) {
|
|
|
|
// const projectRequestItem: RequestItem<ProjectCriteria> = new RequestItem();
|
|
|
|
// projectRequestItem.criteria = new ProjectCriteria();
|
|
|
|
// projectRequestItem.criteria.like = query;
|
|
|
|
// return this.projectService.getWithExternal(projectRequestItem);
|
|
|
|
// }
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
formSubmit(): void {
|
|
|
|
//this.touchAllFormFields(this.formGroup);
|
|
|
|
if (!this.isFormValid()) { return; }
|
|
|
|
this.onSubmit();
|
|
|
|
}
|
|
|
|
|
|
|
|
public isFormValid() {
|
|
|
|
return this.formGroup.valid;
|
|
|
|
}
|
|
|
|
|
|
|
|
onSubmit(): void {
|
2019-01-24 11:46:29 +01:00
|
|
|
this.dmpService.createDmp(this.formGroup.getRawValue())
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-06-07 17:21:09 +02:00
|
|
|
complete => this.onCallbackSuccess(),
|
|
|
|
error => this.onCallbackError(error)
|
2018-11-27 18:33:17 +01:00
|
|
|
);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackSuccess(): void {
|
2019-01-24 11:46:29 +01:00
|
|
|
this.uiNotificationService.snackBarNotification(this.isNew ? this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-CREATION') : this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/plans']);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackError(error: any) {
|
|
|
|
this.setErrorModel(error.error);
|
|
|
|
//this.validateAllFormFields(this.formGroup);
|
|
|
|
}
|
|
|
|
|
2019-01-21 12:14:20 +01:00
|
|
|
public setErrorModel(validationErrorModel: ValidationErrorModel) {
|
|
|
|
Object.keys(validationErrorModel).forEach(item => {
|
|
|
|
(<any>this.dmp.validationErrorModel)[item] = (<any>validationErrorModel)[item];
|
2018-10-05 17:00:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-21 15:42:28 +02:00
|
|
|
public cancel(id: String): void {
|
2019-06-21 15:55:38 +02:00
|
|
|
if (id != null) {
|
|
|
|
this.router.navigate(['/plans/overview/' + id]);
|
|
|
|
} else {
|
|
|
|
this.router.navigate(['/plans']);
|
|
|
|
}
|
2019-05-30 16:40:32 +02:00
|
|
|
}
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
public invite(): void {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/invite/' + this.dmp.id]);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-01-24 16:30:23 +01:00
|
|
|
public delete(): void {
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
maxWidth: '300px',
|
|
|
|
data: {
|
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
|
2019-06-14 10:21:24 +02:00
|
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.DELETE'),
|
2019-06-26 11:24:06 +02:00
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
|
|
|
isDeleteConfirmation: true
|
2019-01-24 16:30:23 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
this.dmpService.delete(this.dmp.id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2019-06-07 17:21:09 +02:00
|
|
|
complete => { this.onCallbackSuccess() },
|
|
|
|
error => this.onDeleteCallbackError(error)
|
2019-01-24 16:30:23 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2019-03-05 12:21:04 +01:00
|
|
|
onDeleteCallbackError(error) {
|
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
|
2019-02-15 15:19:07 +01:00
|
|
|
}
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
displayWith(item: any) {
|
|
|
|
if (!item) { return null; }
|
|
|
|
return item['label'];
|
|
|
|
}
|
|
|
|
|
|
|
|
redirectToProject() {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['projects/edit/' + this.dmp.project.id]);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
redirectToDatasets() {
|
2019-04-22 11:35:50 +02:00
|
|
|
this.router.navigate(['datasets'], { queryParams: { dmpId: this.dmp.id } });
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
newVersion(id: String, label: String) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/plans/new_version/' + id, { dmpLabel: label }]);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
clone(id: String) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/plans/clone/' + id]);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2018-10-11 13:22:03 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
viewVersions(rowId: String, rowLabel: String) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['/plans/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2018-10-09 10:28:44 +02:00
|
|
|
|
2019-05-23 17:48:54 +02:00
|
|
|
advancedClicked() {
|
|
|
|
const dialogRef = this.dialog.open(ExportMethodDialogComponent, {
|
2019-06-04 16:55:23 +02:00
|
|
|
maxWidth: '500px',
|
2019-05-23 17:48:54 +02:00
|
|
|
data: {
|
|
|
|
message: "Download as:",
|
|
|
|
XMLButton: "XML",
|
|
|
|
documentButton: "Document",
|
2019-06-04 16:04:04 +02:00
|
|
|
pdfButton: "PDF",
|
|
|
|
jsonButton: "JSON"
|
2019-05-23 17:48:54 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result == "pdf") {
|
|
|
|
this.downloadPDF(this.dmp.id);
|
|
|
|
} else if (result == "xml") {
|
|
|
|
this.downloadXml(this.dmp.id);
|
|
|
|
} else if (result == "doc") {
|
|
|
|
this.downloadDocx(this.dmp.id);
|
2019-06-04 16:04:04 +02:00
|
|
|
} else if (result == "json") {
|
|
|
|
this.downloadJson(this.dmp.id)
|
2019-05-23 17:48:54 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-10-09 10:28:44 +02:00
|
|
|
downloadXml(id: string) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.dmpService.downloadXML(id)
|
2018-11-27 18:33:17 +01:00
|
|
|
.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);
|
|
|
|
});
|
2018-10-09 10:28:44 +02:00
|
|
|
}
|
|
|
|
|
2018-10-19 09:35:35 +02:00
|
|
|
downloadDocx(id: string) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.dmpService.downloadDocx(id)
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
2019-02-06 11:46:14 +01:00
|
|
|
const blob = new Blob([response.body], { type: 'application/msword' });
|
2018-11-27 18:33:17 +01:00
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
2018-10-19 09:35:35 +02:00
|
|
|
}
|
|
|
|
|
2018-10-22 09:48:56 +02:00
|
|
|
downloadPDF(id: string) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.dmpService.downloadPDF(id)
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
2019-02-06 11:46:14 +01:00
|
|
|
const blob = new Blob([response.body], { type: 'application/pdf' });
|
2018-11-27 18:33:17 +01:00
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
2018-10-22 09:48:56 +02:00
|
|
|
}
|
|
|
|
|
2019-06-04 16:04:04 +02:00
|
|
|
downloadJson(id: string) {
|
|
|
|
this.dmpService.downloadJson(id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/json' });
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-10-09 10:28:44 +02:00
|
|
|
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;
|
|
|
|
}
|
2018-10-11 13:22:03 +02:00
|
|
|
|
|
|
|
public enableForm() {
|
2019-01-18 18:03:45 +01:00
|
|
|
if (this.formGroup.get('status').value !== DmpStatus.Finalized) {
|
2018-10-12 10:22:23 +02:00
|
|
|
this.editMode = true;
|
|
|
|
this.formGroup.enable();
|
|
|
|
}
|
2019-02-14 13:14:44 +01:00
|
|
|
//else {
|
|
|
|
// this.dmpService.unlock(this.formGroup.get('id').value)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(x => {
|
|
|
|
// this.editMode = true;
|
|
|
|
// this.formGroup.get('status').patchValue(DmpStatus.Draft);
|
|
|
|
// this.formGroup.enable();
|
|
|
|
// });
|
|
|
|
// }
|
2018-10-11 13:22:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public disableForm() {
|
|
|
|
this.editMode = false;
|
|
|
|
this.formGroup.disable();
|
|
|
|
}
|
|
|
|
|
|
|
|
saveAndFinalize() {
|
2019-07-01 11:35:09 +02:00
|
|
|
|
|
|
|
const dialogInputModel: DmpFinalizeDialogInput = {
|
|
|
|
dmpLabel: this.formGroup.get('label').value,
|
|
|
|
dmpDescription: this.formGroup.get('description').value,
|
|
|
|
datasets: this.formGroup.get('datasets').value.map(x => {
|
|
|
|
return { label: x.label, id: x.id, status: x.status };
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-01-18 18:03:45 +01:00
|
|
|
const dialogRef = this.dialog.open(DmpFinalizeDialogComponent, {
|
2019-06-21 15:55:38 +02:00
|
|
|
maxWidth: '500px',
|
2018-10-11 13:22:03 +02:00
|
|
|
data: {
|
2019-07-01 11:35:09 +02:00
|
|
|
dialogInputModel: dialogInputModel,
|
2019-06-21 15:55:38 +02:00
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.FINALIZE-ITEM'),
|
|
|
|
confirmButton: this.language.instant('DMP-FINALISE-DIALOG.SUBMIT'),
|
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
2018-10-11 13:22:03 +02:00
|
|
|
}
|
|
|
|
});
|
2019-07-01 11:35:09 +02:00
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result && !result.cancelled) {
|
|
|
|
this.formGroup.get('status').setValue(DmpStatus.Finalized);
|
|
|
|
this.formGroup.get('datasetsToBeFinalized').setValue(result.datasetsToBeFinalized);
|
|
|
|
this.formSubmit();
|
|
|
|
dialogRef.close();
|
|
|
|
}
|
|
|
|
});
|
2018-10-11 13:22:03 +02:00
|
|
|
}
|
2018-05-28 11:50:42 +02:00
|
|
|
}
|