2019-04-24 11:26:53 +02:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2019-04-25 11:03:22 +02:00
|
|
|
import { DmpListingModel } from '../../../core/model/dmp/dmp-listing';
|
|
|
|
import { EnumUtils } from '../../../core/services/utilities/enum-utils.service';
|
|
|
|
import { AuthService } from '../../../core/services/auth/auth.service';
|
|
|
|
import { DataTableRequest } from '../../../core/model/data-table/data-table-request';
|
|
|
|
import { DmpCriteria } from '../../../core/query/dmp/dmp-criteria';
|
|
|
|
import { DmpService } from '../../../core/services/dmp/dmp.service';
|
2019-04-26 18:08:51 +02:00
|
|
|
import { RecentActivityType } from '../../../core/common/enum/recent-activity-type';
|
|
|
|
import { Router } from '@angular/router';
|
2019-05-17 10:42:30 +02:00
|
|
|
import { Principal } from '../../../core/model/auth/Principal';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-06-04 13:34:30 +02:00
|
|
|
import { ConfirmationDialogComponent } from '../../../library/confirmation-dialog/confirmation-dialog.component';
|
|
|
|
import { MatDialog } from '@angular/material';
|
|
|
|
import { ExportMethodDialogComponent } from '../../../library/export-method-dialog/export-method-dialog.component';
|
|
|
|
import { BaseComponent } from '../../../core/common/base/base.component';
|
|
|
|
import { UiNotificationService, SnackBarNotificationLevel } from '../../../core/services/notification/ui-notification-service';
|
|
|
|
import * as FileSaver from 'file-saver';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2019-04-24 11:26:53 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-04-25 11:03:22 +02:00
|
|
|
selector: 'app-recent-edited-activity',
|
|
|
|
templateUrl: './recent-edited-activity.component.html',
|
|
|
|
styleUrls: ['./recent-edited-activity.component.css']
|
2019-04-24 11:26:53 +02:00
|
|
|
})
|
2019-06-04 13:34:30 +02:00
|
|
|
export class RecentEditedActivityComponent extends BaseComponent implements OnInit {
|
2019-04-25 11:03:22 +02:00
|
|
|
dmpActivities: DmpListingModel[];
|
2019-04-26 18:08:51 +02:00
|
|
|
recentActivityTypeEnum = RecentActivityType;
|
2019-04-24 11:26:53 +02:00
|
|
|
|
2019-04-25 11:03:22 +02:00
|
|
|
constructor(
|
2019-04-26 18:08:51 +02:00
|
|
|
private router: Router,
|
2019-04-25 11:03:22 +02:00
|
|
|
public enumUtils: EnumUtils,
|
|
|
|
private authentication: AuthService,
|
2019-05-17 10:42:30 +02:00
|
|
|
private dmpService: DmpService,
|
2019-06-04 13:34:30 +02:00
|
|
|
private language: TranslateService,
|
|
|
|
private dialog: MatDialog,
|
|
|
|
private uiNotificationService: UiNotificationService
|
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
2019-04-24 11:26:53 +02:00
|
|
|
|
2019-04-25 11:03:22 +02:00
|
|
|
ngOnInit() {
|
|
|
|
if (this.isAuthenticated()) {
|
2019-05-06 12:50:48 +02:00
|
|
|
const fields: Array<string> = ["-modified"];
|
2019-05-07 11:34:13 +02:00
|
|
|
const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(0, 5, { fields: fields });
|
2019-04-25 11:03:22 +02:00
|
|
|
dmpDataTableRequest.criteria = new DmpCriteria();
|
|
|
|
dmpDataTableRequest.criteria.like = "";
|
|
|
|
this.dmpService
|
|
|
|
.getPaged(dmpDataTableRequest, "listing")
|
|
|
|
.subscribe(response => {
|
|
|
|
this.dmpActivities = response.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public isAuthenticated(): boolean {
|
|
|
|
return !!this.authentication.current();
|
|
|
|
}
|
2019-04-24 11:26:53 +02:00
|
|
|
|
2019-06-04 13:34:30 +02:00
|
|
|
editClicked(dmp: DmpListingModel) {
|
|
|
|
this.router.navigate(['/plans/edit/' + dmp.id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
cloneClicked(dmp: DmpListingModel) {
|
|
|
|
this.router.navigate(['/plans/clone/' + dmp.id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteClicked(dmp: DmpListingModel) {
|
|
|
|
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.DELETE'),
|
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
this.dmpService.delete(dmp.id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
complete => { this.onCallbackSuccess() },
|
|
|
|
error => this.onDeleteCallbackError(error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
advancedClicked(dmp: DmpListingModel) {
|
|
|
|
const dialogRef = this.dialog.open(ExportMethodDialogComponent, {
|
2019-06-04 16:55:23 +02:00
|
|
|
maxWidth: '500px',
|
2019-06-04 13:34:30 +02:00
|
|
|
data: {
|
|
|
|
message: "Download as:",
|
|
|
|
XMLButton: "XML",
|
|
|
|
documentButton: "Document",
|
2019-06-04 16:55:23 +02:00
|
|
|
pdfButton: "PDF",
|
|
|
|
jsonButton: "JSON"
|
|
|
|
|
2019-06-04 13:34:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result == "pdf") {
|
|
|
|
this.downloadPDF(dmp.id);
|
|
|
|
} else if (result == "xml") {
|
|
|
|
this.downloadXml(dmp.id);
|
|
|
|
} else if (result == "doc") {
|
|
|
|
this.downloadDocx(dmp.id);
|
2019-06-04 16:55:23 +02:00
|
|
|
} else if (result == "json") {
|
|
|
|
this.downloadJson(dmp.id)
|
2019-06-04 13:34:30 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackSuccess(): void {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.router.navigate(['/plans']);
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteCallbackError(error) {
|
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
|
2019-04-26 18:08:51 +02:00
|
|
|
redirect(id: string, type: RecentActivityType) {
|
|
|
|
switch (type) {
|
|
|
|
case RecentActivityType.Project: {
|
|
|
|
this.router.navigate(["projects/edit/" + id]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case RecentActivityType.Dataset: {
|
|
|
|
this.router.navigate(["datasets/edit/" + id]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case RecentActivityType.Dmp: {
|
2019-06-13 13:38:33 +02:00
|
|
|
this.router.navigate(["plans/overview/" + id]);
|
2019-04-26 18:08:51 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
throw new Error("Unsupported Activity Type ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-14 10:21:24 +02:00
|
|
|
navigateToUrl() {
|
|
|
|
this.router.navigate(["plans/"]);
|
|
|
|
}
|
2019-05-17 10:42:30 +02:00
|
|
|
|
|
|
|
roleDisplay(value: any) {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
let role: number;
|
|
|
|
if (principal) {
|
|
|
|
value.forEach(element => {
|
|
|
|
if (principal.id === element.id) {
|
|
|
|
role = element.role;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (role === 0) {
|
|
|
|
return this.language.instant('DMP-LISTING.OWNER');
|
|
|
|
}
|
|
|
|
else if (role === 1) {
|
|
|
|
return this.language.instant('DMP-LISTING.MEMBER');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this.language.instant('DMP-LISTING.OWNER');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dmpProfileDisplay(value: any) {
|
|
|
|
if (value != null) {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "--";
|
|
|
|
}
|
|
|
|
}
|
2019-06-04 13:34:30 +02:00
|
|
|
|
|
|
|
downloadXml(id: string) {
|
|
|
|
this.dmpService.downloadXML(id)
|
|
|
|
.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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadDocx(id: string) {
|
|
|
|
this.dmpService.downloadDocx(id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/msword' });
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadPDF(id: string) {
|
|
|
|
this.dmpService.downloadPDF(id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/pdf' });
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-04 16:55:23 +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);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-06-04 13:34:30 +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;
|
|
|
|
}
|
2019-04-24 11:26:53 +02:00
|
|
|
}
|