2020-07-01 17:25:16 +02:00
|
|
|
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
|
|
|
|
import { MatDialog } from '@angular/material';
|
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { RecentActivityType } from '@app/core/common/enum/recent-activity-type';
|
|
|
|
import { Principal } from '@app/core/model/auth/principal';
|
|
|
|
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
|
|
|
import { DmpListingModel } from '@app/core/model/dmp/dmp-listing';
|
|
|
|
import { DmpCriteria } from '@app/core/query/dmp/dmp-criteria';
|
|
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
|
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import * as FileSaver from 'file-saver';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2020-07-20 15:57:57 +02:00
|
|
|
import { DmpInvitationDialogComponent } from '@app/ui/dmp/invitation/dmp-invitation-dialog.component';
|
2020-07-01 17:25:16 +02:00
|
|
|
import { DmpStatus } from '@app/core/common/enum/dmp-status';
|
|
|
|
import { DatasetService } from '@app/core/services/dataset/dataset.service';
|
|
|
|
import { DatasetListingModel } from '@app/core/model/dataset/dataset-listing';
|
|
|
|
import { Role } from '@app/core/common/enum/role';
|
2020-07-10 15:52:35 +02:00
|
|
|
import { FormBuilder, FormControl } from '@angular/forms';
|
2020-07-13 12:01:03 +02:00
|
|
|
import { RecentActivityOrder } from '@app/core/common/enum/recent-activity-order';
|
2020-07-22 13:26:49 +02:00
|
|
|
import { Location } from '@angular/common';
|
2020-07-23 11:35:08 +02:00
|
|
|
import { LockService } from '@app/core/services/lock/lock.service';
|
2020-07-01 17:25:16 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-recent-edited-dmp-activity',
|
|
|
|
templateUrl: './recent-edited-dmp-activity.component.html',
|
|
|
|
styleUrls: ['./recent-edited-dmp-activity.component.css']
|
|
|
|
})
|
|
|
|
export class RecentEditedDmpActivityComponent extends BaseComponent implements OnInit {
|
|
|
|
|
|
|
|
@Output() totalCountDmps: EventEmitter<any> = new EventEmitter();
|
|
|
|
|
|
|
|
dmpActivities: DmpListingModel[];
|
|
|
|
datasetActivities: DatasetListingModel[];
|
|
|
|
recentActivityTypeEnum = RecentActivityType;
|
|
|
|
isDraft: boolean;
|
|
|
|
|
|
|
|
totalCount: number;
|
2020-07-10 15:52:35 +02:00
|
|
|
startIndex: number = 0;
|
2020-07-01 17:25:16 +02:00
|
|
|
pageSize: number = 5;
|
2020-07-10 15:52:35 +02:00
|
|
|
public formGroup = new FormBuilder().group({
|
2020-07-13 12:01:03 +02:00
|
|
|
like: new FormControl(),
|
|
|
|
order: new FormControl()
|
2020-07-10 15:52:35 +02:00
|
|
|
});
|
2020-07-01 17:25:16 +02:00
|
|
|
|
2020-07-13 12:01:03 +02:00
|
|
|
order = RecentActivityOrder;
|
|
|
|
|
2020-07-01 17:25:16 +02:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
public enumUtils: EnumUtils,
|
|
|
|
private authentication: AuthService,
|
|
|
|
private dmpService: DmpService,
|
|
|
|
private datasetService: DatasetService,
|
|
|
|
private language: TranslateService,
|
|
|
|
private dialog: MatDialog,
|
2020-07-22 13:26:49 +02:00
|
|
|
private uiNotificationService: UiNotificationService,
|
2020-07-23 11:35:08 +02:00
|
|
|
private location: Location,
|
|
|
|
private lockService: LockService
|
2020-07-01 17:25:16 +02:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
if (this.isAuthenticated()) {
|
2020-07-13 12:01:03 +02:00
|
|
|
// const fields: Array<string> = ["-modified"];
|
|
|
|
this.formGroup.get('order').setValue(this.order.MODIFIED);
|
|
|
|
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
|
2020-07-01 17:25:16 +02:00
|
|
|
const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(0, 5, { fields: fields });
|
|
|
|
dmpDataTableRequest.criteria = new DmpCriteria();
|
|
|
|
dmpDataTableRequest.criteria.like = "";
|
|
|
|
this.dmpService
|
|
|
|
.getPaged(dmpDataTableRequest, "listing")
|
|
|
|
.subscribe(response => {
|
|
|
|
this.dmpActivities = response.data;
|
|
|
|
this.totalCount = response.totalCount;
|
2020-07-10 15:52:35 +02:00
|
|
|
this.totalCountDmps.emit(this.dmpActivities.length);
|
|
|
|
// this.totalCount < this.pageSize ? this.totalCountDmps.emit(response.totalCount) : this.totalCountDmps.emit(this.pageSize);
|
2020-07-02 18:34:27 +02:00
|
|
|
// this.totalCountDmps.emit(this.totalCount);
|
2020-07-01 17:25:16 +02:00
|
|
|
// this.dmpActivities.forEach(dmpActivity => {
|
|
|
|
// const recentActivity: RecentActivity = {
|
|
|
|
// activityData: dmpActivity,
|
|
|
|
// activityType: RecentActivityType.Dmp
|
|
|
|
// };
|
|
|
|
// this.allRecentActivities.push(recentActivity)
|
|
|
|
// })
|
|
|
|
});
|
2020-07-10 15:52:35 +02:00
|
|
|
this.formGroup.get('like').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => this.refresh());
|
2020-07-13 12:01:03 +02:00
|
|
|
this.formGroup.get('order').valueChanges
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(x => this.refresh());
|
2020-07-01 17:25:16 +02:00
|
|
|
|
|
|
|
// const datasetDataTableRequest: DataTableRequest<DatasetCriteria> = new DataTableRequest(0, 5, { fields: fields });
|
|
|
|
// datasetDataTableRequest.criteria = new DatasetCriteria();
|
|
|
|
// datasetDataTableRequest.criteria.like = "";
|
|
|
|
// this.datasetService
|
|
|
|
// .getPaged(datasetDataTableRequest)
|
|
|
|
// .subscribe(response => {
|
|
|
|
// this.datasetActivities = response.data;
|
|
|
|
// this.datasetActivities.forEach(datasetActivity => {
|
|
|
|
// const recentActivity: RecentActivity = {
|
|
|
|
// activityData: datasetActivity,
|
|
|
|
// activityType: RecentActivityType.Dataset
|
|
|
|
// };
|
|
|
|
// this.allRecentActivities.push(recentActivity)
|
|
|
|
// })
|
|
|
|
// });
|
2020-07-10 15:52:35 +02:00
|
|
|
}
|
2020-07-01 17:25:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public isAuthenticated(): boolean {
|
|
|
|
return !!this.authentication.current();
|
|
|
|
}
|
|
|
|
|
|
|
|
isUserOwner(activity: DmpListingModel): boolean {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
if (principal) return principal.id === activity.users.find(x => x.role === Role.Owner).id;
|
|
|
|
}
|
|
|
|
|
|
|
|
editClicked(dmp: DmpListingModel) {
|
|
|
|
this.router.navigate(['/plans/edit/' + dmp.id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
cloneClicked(dmp: DmpListingModel) {
|
2020-07-22 10:23:20 +02:00
|
|
|
let url = this.router.createUrlTree(['/plans/clone/', dmp.id]);
|
|
|
|
window.open(url.toString(), '_blank');
|
2020-07-01 17:25:16 +02:00
|
|
|
}
|
|
|
|
|
2020-07-24 16:40:53 +02:00
|
|
|
deleteClicked(id: string) {
|
|
|
|
this.lockService.checkLockStatus(id).pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(lockStatus => {
|
|
|
|
if (!lockStatus) {
|
|
|
|
this.openDeleteDialog(id);
|
|
|
|
} else {
|
|
|
|
this.openLockedByUserDialog();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
openDeleteDialog(id: string) {
|
2020-07-01 17:25:16 +02:00
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
maxWidth: '300px',
|
|
|
|
restoreFocus: false,
|
|
|
|
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'),
|
|
|
|
isDeleteConfirmation: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
2020-07-24 16:40:53 +02:00
|
|
|
this.dmpService.delete(id)
|
2020-07-01 17:25:16 +02:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2020-07-22 13:26:49 +02:00
|
|
|
complete => this.onDeleteCallbackSuccess(),
|
2020-07-01 17:25:16 +02:00
|
|
|
error => this.onDeleteCallbackError(error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-24 16:40:53 +02:00
|
|
|
openLockedByUserDialog() {
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
maxWidth: '400px',
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
message: this.language.instant('DMP-EDITOR.ACTIONS.LOCK')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-01 17:25:16 +02:00
|
|
|
openShareDialog(rowId: any, rowName: any) {
|
|
|
|
const dialogRef = this.dialog.open(DmpInvitationDialogComponent, {
|
|
|
|
// height: '250px',
|
|
|
|
// width: '700px',
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
dmpId: rowId,
|
|
|
|
dmpName: rowName
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
isDraftDmp(activity: DmpListingModel) {
|
|
|
|
return activity.status == DmpStatus.Draft;
|
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackSuccess(): void {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.router.navigate(['/plans']);
|
|
|
|
}
|
|
|
|
|
2020-07-22 13:26:49 +02:00
|
|
|
reloadPage(): void {
|
|
|
|
const path = this.location.path();
|
|
|
|
this.router.navigateByUrl('/reload', { skipLocationChange: true }).then(() => {
|
|
|
|
this.router.navigate([path]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteCallbackSuccess(): void {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.reloadPage();
|
|
|
|
}
|
|
|
|
|
2020-07-01 17:25:16 +02:00
|
|
|
onDeleteCallbackError(error) {
|
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
|
|
|
|
redirect(id: string, type: RecentActivityType) {
|
|
|
|
switch (type) {
|
|
|
|
case RecentActivityType.Grant: {
|
|
|
|
this.router.navigate(["grants/edit/" + id]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case RecentActivityType.Dataset: {
|
|
|
|
this.router.navigate(["datasets/edit/" + id]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case RecentActivityType.Dmp: {
|
|
|
|
this.router.navigate(["plans/overview/" + id]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
throw new Error("Unsupported Activity Type ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// navigateToUrl() {
|
|
|
|
// this.router.navigate(["plans/"]);
|
|
|
|
// }
|
|
|
|
|
|
|
|
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 "--";
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
newVersion(id: String, label: String) {
|
2020-07-27 10:52:42 +02:00
|
|
|
let url = this.router.createUrlTree(['/plans/new_version/', id, { dmpLabel: label }]);
|
|
|
|
window.open(url.toString(), '_blank');
|
2020-07-01 17:25:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
viewVersions(rowId: String, rowLabel: String, activity: DmpListingModel) {
|
2020-07-27 10:52:42 +02:00
|
|
|
if (activity.public && !this.isUserOwner(activity)) {
|
|
|
|
let url = this.router.createUrlTree(['/explore-plans/versions/', rowId, { groupLabel: rowLabel }]);
|
|
|
|
window.open(url.toString(), '_blank');
|
|
|
|
// this.router.navigate(['/explore-plans/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
|
2020-07-01 17:25:16 +02:00
|
|
|
} else {
|
2020-07-27 10:52:42 +02:00
|
|
|
let url = this.router.createUrlTree(['/plans/versions/', rowId, { groupLabel: rowLabel }]);
|
|
|
|
window.open(url.toString(), '_blank');
|
|
|
|
// this.router.navigate(['/plans/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
|
2020-07-01 17:25:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-10 15:52:35 +02:00
|
|
|
refresh(): void {
|
2020-07-13 12:01:03 +02:00
|
|
|
// const fields: Array<string> = ["-modified"];
|
|
|
|
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
|
2020-07-10 15:52:35 +02:00
|
|
|
this.startIndex = 0;
|
|
|
|
const dmpDataTableRequest: DataTableRequest<DmpCriteria> = new DataTableRequest(this.startIndex, this.pageSize, { fields: fields });
|
|
|
|
dmpDataTableRequest.criteria = new DmpCriteria();
|
|
|
|
dmpDataTableRequest.criteria.like = this.formGroup.get("like").value;
|
|
|
|
this.dmpService
|
|
|
|
.getPaged(dmpDataTableRequest, "listing")
|
|
|
|
.subscribe(response => {
|
|
|
|
this.dmpActivities = response.data;
|
|
|
|
this.totalCount = response.totalCount;
|
|
|
|
this.totalCountDmps.emit(this.dmpActivities.length);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-01 17:25:16 +02:00
|
|
|
public loadMore() {
|
2020-07-10 15:52:35 +02:00
|
|
|
this.startIndex = this.startIndex + this.pageSize;
|
2020-07-13 12:01:03 +02:00
|
|
|
// const fields: Array<string> = ["-modified"];
|
|
|
|
const fields: Array<string> = ["-" + this.formGroup.get('order').value];
|
2020-07-01 17:25:16 +02:00
|
|
|
const request = new DataTableRequest<DmpCriteria>(this.startIndex, this.pageSize, { fields: fields });
|
|
|
|
|
|
|
|
request.criteria = new DmpCriteria();
|
2020-07-10 15:52:35 +02:00
|
|
|
request.criteria.like = this.formGroup.get("like").value ? this.formGroup.get("like").value : "";
|
2020-07-01 17:25:16 +02:00
|
|
|
|
|
|
|
this.dmpService.getPaged(request, "listing").pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (!result) { return []; }
|
|
|
|
this.dmpActivities = this.dmpActivities.concat(result.data);
|
2020-07-10 15:52:35 +02:00
|
|
|
this.totalCountDmps.emit(this.dmpActivities.length);
|
2020-07-01 17:25:16 +02:00
|
|
|
});
|
2020-07-02 18:34:27 +02:00
|
|
|
|
2020-07-01 17:25:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// advancedClicked(dmp: DmpListingModel) {
|
|
|
|
// const dialogRef = this.dialog.open(ExportMethodDialogComponent, {
|
|
|
|
// maxWidth: '500px',
|
|
|
|
// data: {
|
|
|
|
// message: "Download as:",
|
|
|
|
// XMLButton: "XML",
|
|
|
|
// documentButton: "Document",
|
|
|
|
// pdfButton: "PDF",
|
|
|
|
// jsonButton: "JSON"
|
|
|
|
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// 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);
|
|
|
|
// } else if (result == "json") {
|
|
|
|
// this.downloadJson(dmp.id)
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
}
|