2019-04-25 16:04:54 +02:00
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
|
|
|
import { DmpListingModel } from '../../../../core/model/dmp/dmp-listing';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
2020-07-20 15:57:57 +02:00
|
|
|
import { DmpInvitationDialogComponent } from '../../invitation/dmp-invitation-dialog.component';
|
2019-05-15 08:57:10 +02:00
|
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
|
|
import { DatasetService } from '../../../../core/services/dataset/dataset.service';
|
2019-05-16 09:44:20 +02:00
|
|
|
import { AuthService } from '../../../../core/services/auth/auth.service';
|
2020-04-27 15:21:03 +02:00
|
|
|
import { Principal } from '../../../../core/model/auth/principal';
|
2019-05-16 09:44:20 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2019-06-25 11:16:37 +02:00
|
|
|
import { DmpStatus } from '../../../../core/common/enum/dmp-status';
|
2020-07-03 16:17:23 +02:00
|
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import * as FileSaver from 'file-saver';
|
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
|
|
|
import { UiNotificationService, SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service';
|
|
|
|
import { Role } from '@app/core/common/enum/role';
|
2019-04-25 16:04:54 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-dmp-listing-item-component',
|
|
|
|
templateUrl: './dmp-listing-item.component.html',
|
|
|
|
styleUrls: ['./dmp-listing-item.component.scss'],
|
|
|
|
})
|
2020-07-03 16:17:23 +02:00
|
|
|
export class DmpListingItemComponent extends BaseComponent implements OnInit {
|
2019-04-25 16:04:54 +02:00
|
|
|
|
|
|
|
@Input() dmp: DmpListingModel;
|
|
|
|
@Input() showDivider: boolean = true;
|
2020-04-01 17:16:06 +02:00
|
|
|
@Input() isPublic: boolean;
|
2019-04-25 16:04:54 +02:00
|
|
|
@Output() onClick: EventEmitter<DmpListingModel> = new EventEmitter();
|
|
|
|
|
2019-05-09 15:30:39 +02:00
|
|
|
isDraft: boolean;
|
2019-06-25 17:16:31 +02:00
|
|
|
isFinalized: boolean;
|
|
|
|
isPublished: boolean;
|
2019-05-09 15:30:39 +02:00
|
|
|
|
2019-05-16 09:44:20 +02:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
private dialog: MatDialog,
|
|
|
|
private authentication: AuthService,
|
2020-07-03 16:17:23 +02:00
|
|
|
public enumUtils: EnumUtils,
|
|
|
|
private dmpService: DmpService,
|
|
|
|
private language: TranslateService,
|
|
|
|
private uiNotificationService: UiNotificationService) {
|
|
|
|
super();
|
|
|
|
}
|
2019-04-25 16:04:54 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
2019-06-25 17:16:31 +02:00
|
|
|
if (this.dmp.status == DmpStatus.Draft) {
|
|
|
|
this.isDraft = true;
|
|
|
|
this.isFinalized = false;
|
|
|
|
this.isPublished = false;
|
|
|
|
}
|
|
|
|
else if (this.dmp.status == DmpStatus.Finalized) {
|
|
|
|
this.isDraft = false;
|
|
|
|
this.isFinalized = true;
|
|
|
|
this.isPublished = false;
|
|
|
|
if (this.dmp.public == true) { this.isPublished = true }
|
|
|
|
}
|
2019-04-25 16:04:54 +02:00
|
|
|
}
|
|
|
|
|
2019-05-08 10:37:44 +02:00
|
|
|
openShareDialog(rowId: any, rowName: any) {
|
|
|
|
const dialogRef = this.dialog.open(DmpInvitationDialogComponent, {
|
|
|
|
// height: '250px',
|
|
|
|
// width: '700px',
|
2019-09-27 10:09:29 +02:00
|
|
|
restoreFocus: false,
|
2019-05-08 10:37:44 +02:00
|
|
|
data: {
|
|
|
|
dmpId: rowId,
|
|
|
|
dmpName: rowName
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-05-22 15:52:55 +02:00
|
|
|
editClicked(dmpId: String) {
|
|
|
|
this.router.navigate(['/plans/edit/' + dmpId]);
|
|
|
|
}
|
|
|
|
|
2019-05-08 10:37:44 +02:00
|
|
|
addDataset(rowId: String) {
|
|
|
|
this.router.navigate(['/datasets/new/' + rowId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
showDatasets(rowId: String, rowLabel: String) {
|
|
|
|
this.router.navigate(['/datasets/dmp/' + rowId, { dmpLabel: rowLabel }]);
|
|
|
|
}
|
|
|
|
|
|
|
|
viewVersions(rowId: String, rowLabel: String) {
|
|
|
|
this.router.navigate(['/plans/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
|
|
|
|
}
|
2019-05-14 13:35:02 +02:00
|
|
|
|
2019-10-23 17:36:29 +02:00
|
|
|
// itemClicked() {
|
|
|
|
// this.onClick.emit(this.dmp);
|
|
|
|
// }
|
2019-05-14 13:35:02 +02:00
|
|
|
|
2019-10-23 17:36:29 +02:00
|
|
|
// grantClicked(grantId: String) {
|
|
|
|
// this.router.navigate(['/grants/edit/' + grantId]);
|
|
|
|
// }
|
2019-05-15 08:57:10 +02:00
|
|
|
|
2019-10-23 17:36:29 +02:00
|
|
|
// datasetClicked(dmpId: string) {
|
|
|
|
// this.router.navigate(['/plans/edit/' + dmpId], { queryParams: { tab: "datasetDescriptions" } });
|
|
|
|
// }
|
2019-05-16 09:44:20 +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) {
|
2020-07-08 16:54:41 +02:00
|
|
|
return this.language.instant('DMP-LISTING.OWNER');
|
2019-05-16 09:44:20 +02:00
|
|
|
}
|
|
|
|
else if (role === 1) {
|
2020-07-08 16:54:41 +02:00
|
|
|
return this.language.instant('DMP-LISTING.MEMBER');
|
2019-05-16 09:44:20 +02:00
|
|
|
}
|
|
|
|
else {
|
2020-07-08 16:54:41 +02:00
|
|
|
return this.language.instant('DMP-LISTING.OWNER');
|
2019-05-16 09:44:20 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-03 16:17:23 +02:00
|
|
|
|
|
|
|
cloneClicked(dmp: DmpListingModel) {
|
|
|
|
this.router.navigate(['/plans/clone/' + dmp.id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
newVersion(id: String, label: String) {
|
|
|
|
this.router.navigate(['/plans/new_version/' + id, { dmpLabel: label }]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteClicked(dmp: DmpListingModel) {
|
|
|
|
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) {
|
|
|
|
this.dmpService.delete(dmp.id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
complete => { this.onCallbackSuccess() },
|
|
|
|
error => this.onDeleteCallbackError(error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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']);
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteCallbackError(error) {
|
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
|
|
|
|
isUserOwner(activity: DmpListingModel): boolean {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
if (principal) return principal.id === activity.users.find(x => x.role === Role.Owner).id;
|
|
|
|
}
|
2019-04-25 16:04:54 +02:00
|
|
|
}
|