2019-05-08 11:53:23 +02:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
|
|
|
import { DatasetListingModel } from '../../../../core/model/dataset/dataset-listing';
|
2019-05-16 10:00:53 +02:00
|
|
|
import { Router } from '@angular/router';
|
2019-06-25 11:16:37 +02:00
|
|
|
import { DatasetStatus } from '../../../../core/common/enum/dataset-status';
|
2020-07-08 16:54:41 +02:00
|
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
|
|
import { DatasetWizardService } from '@app/core/services/dataset-wizard/dataset-wizard.service';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import * as FileSaver from 'file-saver';
|
2020-07-20 15:57:57 +02:00
|
|
|
import { DmpInvitationDialogComponent } from '@app/ui/dmp/invitation/dmp-invitation-dialog.component';
|
2020-07-08 16:54:41 +02:00
|
|
|
import { MatDialog } from '@angular/material';
|
|
|
|
import { DatasetCopyDialogueComponent } from '../../dataset-wizard/dataset-copy-dialogue/dataset-copy-dialogue.component';
|
|
|
|
import { FormControl } from '@angular/forms';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
|
|
|
import { UiNotificationService, SnackBarNotificationLevel } from '@app/core/services/notification/ui-notification-service';
|
|
|
|
import { ValidationErrorModel } from '@common/forms/validation/error-model/validation-error-model';
|
|
|
|
import { Principal } from '@app/core/model/auth/principal';
|
|
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
2020-07-22 10:23:20 +02:00
|
|
|
import { LockService } from '@app/core/services/lock/lock.service';
|
|
|
|
import { Role } from '@app/core/common/enum/role';
|
2020-07-22 13:26:49 +02:00
|
|
|
import { Location } from '@angular/common';
|
2019-05-08 11:53:23 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-dataset-listing-item-component',
|
|
|
|
templateUrl: './dataset-listing-item.component.html',
|
|
|
|
styleUrls: ['./dataset-listing-item.component.scss']
|
|
|
|
})
|
2020-07-08 16:54:41 +02:00
|
|
|
export class DatasetListingItemComponent extends BaseComponent implements OnInit {
|
2019-05-08 11:53:23 +02:00
|
|
|
|
|
|
|
@Input() dataset: DatasetListingModel;
|
|
|
|
@Input() showDivider: boolean = true;
|
2020-03-16 17:50:29 +01:00
|
|
|
@Input() isPublic: boolean = false;
|
2019-05-08 11:53:23 +02:00
|
|
|
@Output() onClick: EventEmitter<DatasetListingModel> = new EventEmitter();
|
|
|
|
|
2019-05-09 15:30:39 +02:00
|
|
|
isDraft: boolean;
|
2020-03-16 10:09:24 +01:00
|
|
|
isDeleted: boolean;
|
2020-07-22 10:23:20 +02:00
|
|
|
lockStatus: Boolean;
|
|
|
|
isUserOwner: boolean;
|
2019-05-08 11:53:23 +02:00
|
|
|
|
2020-07-08 16:54:41 +02:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
public enumUtils: EnumUtils,
|
|
|
|
private datasetWizardService: DatasetWizardService,
|
|
|
|
public dialog: MatDialog,
|
|
|
|
private language: TranslateService,
|
|
|
|
private authentication: AuthService,
|
2020-07-22 10:23:20 +02:00
|
|
|
private uiNotificationService: UiNotificationService,
|
2020-07-22 13:26:49 +02:00
|
|
|
private lockService: LockService,
|
|
|
|
private location: Location
|
2020-07-08 16:54:41 +02:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
2019-05-08 11:53:23 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
2020-03-16 10:09:24 +01:00
|
|
|
if (this.dataset.status === DatasetStatus.Draft) {
|
|
|
|
this.isDraft = true;
|
|
|
|
this.isDeleted = false;
|
2020-07-22 10:23:20 +02:00
|
|
|
this.checkLockStatus(this.dataset.id);
|
|
|
|
this.setIsUserOwner();
|
2020-07-08 16:54:41 +02:00
|
|
|
} else if (this.dataset.status === DatasetStatus.Deleted) {
|
|
|
|
this.isDeleted = true;
|
|
|
|
}
|
2020-03-16 10:09:24 +01:00
|
|
|
else {
|
|
|
|
this.isDraft = false;
|
|
|
|
this.isDeleted = false;
|
2020-07-22 10:23:20 +02:00
|
|
|
this.setIsUserOwner();
|
2020-07-08 16:54:41 +02:00
|
|
|
}
|
2019-05-08 11:53:23 +02:00
|
|
|
}
|
|
|
|
|
2020-07-22 10:23:20 +02:00
|
|
|
checkLockStatus(id: string) {
|
|
|
|
this.lockService.checkLockStatus(id).pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(lockStatus => this.lockStatus = lockStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
setIsUserOwner() {
|
|
|
|
if (this.dataset) {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
if (principal) this.isUserOwner = principal.id === this.dataset.users.find(x => x.role === Role.Owner).id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public isAuthenticated(): boolean {
|
|
|
|
return !(!this.authentication.current());
|
|
|
|
}
|
|
|
|
|
2020-03-16 17:50:29 +01:00
|
|
|
getItemLink(): string[] {
|
|
|
|
return this.isPublic ? [`/datasets/publicEdit/${this.dataset.id}`] : [`/datasets/edit/${this.dataset.id}`];
|
|
|
|
}
|
|
|
|
|
2020-03-17 11:44:37 +01:00
|
|
|
getDmpLink(): string[] {
|
2020-04-01 17:16:06 +02:00
|
|
|
return this.isPublic ? [`/explore-plans/publicOverview/${this.dataset.dmpId}`] : [`/plans/edit/${this.dataset.dmpId}`];
|
2020-03-17 11:44:37 +01:00
|
|
|
}
|
|
|
|
|
2020-07-08 16:54:41 +02:00
|
|
|
downloadPDF(dataset: DatasetListingModel): void {
|
|
|
|
this.datasetWizardService.downloadPDF(dataset.id as string)
|
|
|
|
.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);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadDOCX(dataset: DatasetListingModel): void {
|
|
|
|
this.datasetWizardService.downloadDOCX(dataset.id as string)
|
|
|
|
.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);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadXML(dataset: DatasetListingModel): void {
|
|
|
|
this.datasetWizardService.downloadXML(dataset.id as string)
|
|
|
|
.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;
|
|
|
|
}
|
|
|
|
|
2020-07-10 09:32:11 +02:00
|
|
|
openShareDialog(dmpRowId: any, dmpRowName: any) {
|
2020-07-08 16:54:41 +02:00
|
|
|
const dialogRef = this.dialog.open(DmpInvitationDialogComponent, {
|
|
|
|
// height: '250px',
|
|
|
|
// width: '700px',
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
dmpId: dmpRowId,
|
|
|
|
dmpName: dmpRowName
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
openDmpSearchDialogue(dataset: DatasetListingModel) {
|
|
|
|
const formControl = new FormControl();
|
|
|
|
const dialogRef = this.dialog.open(DatasetCopyDialogueComponent, {
|
|
|
|
width: '500px',
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
formControl: formControl,
|
|
|
|
datasetId: dataset.id,
|
2020-07-24 11:43:09 +02:00
|
|
|
datasetProfileId: dataset.profile.id,
|
2020-07-08 16:54:41 +02:00
|
|
|
datasetProfileExist: false,
|
|
|
|
confirmButton: this.language.instant('DATASET-WIZARD.DIALOGUE.COPY'),
|
|
|
|
cancelButton: this.language.instant('DATASET-WIZARD.DIALOGUE.CANCEL')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(result => {
|
|
|
|
if (result && result.datasetProfileExist) {
|
2020-07-24 11:43:09 +02:00
|
|
|
const newDmpId = result.formControl.value.id;
|
|
|
|
let url = this.router.createUrlTree(['/datasets/copy/', result.datasetId, { newDmpId: newDmpId }]);
|
|
|
|
window.open(url.toString(), '_blank');
|
2020-07-08 16:54:41 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
openConfirm(id: string): void {
|
|
|
|
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.datasetWizardService.delete(id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2020-07-22 10:23:20 +02:00
|
|
|
complete => this.onDeleteCallbackSuccess(),
|
|
|
|
error => this.onDeleteCallbackError(error)
|
2020-07-08 16:54:41 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-07-22 10:23:20 +02:00
|
|
|
reloadPage(): void {
|
2020-07-22 13:26:49 +02:00
|
|
|
const path = this.location.path();
|
2020-07-22 10:23:20 +02:00
|
|
|
this.router.navigateByUrl('/reload', { skipLocationChange: true }).then(() => {
|
2020-07-22 13:26:49 +02:00
|
|
|
this.router.navigate([path]);
|
2020-07-22 10:23:20 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteCallbackSuccess(): void {
|
2020-07-22 13:26:49 +02:00
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success);
|
2020-07-22 10:23:20 +02:00
|
|
|
this.reloadPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteCallbackError(error) {
|
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
|
2020-07-08 16:54:41 +02:00
|
|
|
}
|
|
|
|
|
2020-07-22 13:26:49 +02:00
|
|
|
onCallbackSuccess(id?: String): void {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
|
|
|
id ? this.router.navigate(['/reload']).then(() => { this.router.navigate(['/datasets', 'edit', id]); }) : this.router.navigate(['/datasets']);
|
|
|
|
}
|
2020-07-22 10:23:20 +02:00
|
|
|
|
2020-07-08 16:54:41 +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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 15:24:34 +02:00
|
|
|
isUserDatasetRelated() {
|
|
|
|
const principal: Principal = this.authentication.current();
|
|
|
|
let isRelated: boolean = false;
|
|
|
|
if (this.dataset && principal) {
|
|
|
|
this.dataset.users.forEach(element => {
|
|
|
|
if (element.id === principal.id) {
|
|
|
|
isRelated = true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return isRelated;
|
|
|
|
}
|
|
|
|
|
2020-07-22 10:23:20 +02:00
|
|
|
|
|
|
|
|
2020-07-08 16:54:41 +02:00
|
|
|
// onCallbackError(error: any) {
|
|
|
|
// this.setErrorModel(error.error);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// public setErrorModel(validationErrorModel: ValidationErrorModel) {
|
|
|
|
// Object.keys(validationErrorModel).forEach(item => {
|
|
|
|
// (<any>this.dataset.validationErrorModel)[item] = (<any>validationErrorModel)[item];
|
|
|
|
// });
|
|
|
|
// }
|
2019-05-08 11:53:23 +02:00
|
|
|
|
2019-10-23 17:36:29 +02:00
|
|
|
// grantClicked(dataset: DatasetListingModel) {
|
|
|
|
// this.router.navigate(['/grants/edit/' + dataset.grantId]);
|
|
|
|
// }
|
2019-05-16 10:00:53 +02:00
|
|
|
|
2019-10-23 17:36:29 +02:00
|
|
|
// itemClicked() {
|
|
|
|
// this.onClick.emit(this.dataset);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// datasetClicked(dataset: DatasetListingModel) {
|
|
|
|
// this.router.navigate(['/plans/edit/' + dataset.dmpId])
|
|
|
|
// }
|
2019-05-16 10:00:53 +02:00
|
|
|
|
2019-05-08 11:53:23 +02:00
|
|
|
}
|