2023-10-25 16:47:48 +02:00
|
|
|
import { Location } from '@angular/common';
|
|
|
|
import { HttpClient } from '@angular/common/http';
|
2019-04-25 16:04:54 +02:00
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
2023-10-06 10:10:53 +02:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
2023-10-25 16:47:48 +02:00
|
|
|
import { Router } from '@angular/router';
|
2023-12-04 16:56:12 +01:00
|
|
|
import { DmpAccessType } from '@app/core/common/enum/dmp-access-type';
|
|
|
|
import { DmpUserRole } from '@app/core/common/enum/dmp-user-role';
|
|
|
|
import { ReferenceType } from '@app/core/common/enum/reference-type';
|
|
|
|
import { Dmp } from '@app/core/model/dmp/dmp';
|
2023-10-25 16:47:48 +02:00
|
|
|
import { DmpBlueprintService } from '@app/core/services/dmp/dmp-blueprint.service';
|
2023-12-05 21:36:00 +01:00
|
|
|
import { DmpServiceNew } from '@app/core/services/dmp/dmp.service';
|
2023-10-25 16:47:48 +02:00
|
|
|
import { LockService } from '@app/core/services/lock/lock.service';
|
|
|
|
import { MatomoService } from '@app/core/services/matomo/matomo-service';
|
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
2023-12-04 16:56:12 +01:00
|
|
|
import { ReferenceService } from '@app/core/services/reference/reference.service';
|
2023-10-25 16:47:48 +02:00
|
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
|
|
import { FileUtils } from '@app/core/services/utilities/file-utils.service';
|
2020-07-03 16:17:23 +02:00
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
2023-10-25 16:47:48 +02:00
|
|
|
import { Guid } from '@common/types/guid';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2023-12-05 21:36:00 +01:00
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2023-10-25 16:47:48 +02:00
|
|
|
import { DmpStatus } from '../../../../core/common/enum/dmp-status';
|
|
|
|
import { AuthService } from '../../../../core/services/auth/auth.service';
|
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
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
@Input() dmp: Dmp;
|
2019-04-25 16:04:54 +02:00
|
|
|
@Input() showDivider: boolean = true;
|
2020-04-01 17:16:06 +02:00
|
|
|
@Input() isPublic: boolean;
|
2023-11-29 14:26:40 +01:00
|
|
|
@Output() onClick: EventEmitter<Dmp> = new EventEmitter();
|
2019-04-25 16:04:54 +02:00
|
|
|
|
2019-05-09 15:30:39 +02:00
|
|
|
isDraft: boolean;
|
2019-06-25 17:16:31 +02:00
|
|
|
isFinalized: boolean;
|
|
|
|
isPublished: boolean;
|
2023-11-29 14:26:40 +01:00
|
|
|
dmpStatusEnum = DmpStatus;
|
2023-12-01 18:18:41 +01:00
|
|
|
referenceTypeEnum = ReferenceType;
|
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,
|
2023-12-05 21:36:00 +01:00
|
|
|
private dmpService: DmpServiceNew,
|
2023-10-20 17:01:09 +02:00
|
|
|
private dmpBlueprintService: DmpBlueprintService,
|
2020-07-03 16:17:23 +02:00
|
|
|
private language: TranslateService,
|
2020-07-22 10:23:20 +02:00
|
|
|
private uiNotificationService: UiNotificationService,
|
2020-07-22 13:26:49 +02:00
|
|
|
private lockService: LockService,
|
2020-12-14 18:28:13 +01:00
|
|
|
private location: Location,
|
|
|
|
private httpClient: HttpClient,
|
2023-10-25 16:47:48 +02:00
|
|
|
private matomoService: MatomoService,
|
2023-12-01 18:18:41 +01:00
|
|
|
public referenceService: ReferenceService,
|
2023-10-25 16:47:48 +02:00
|
|
|
private fileUtils: FileUtils) {
|
2020-07-24 16:40:53 +02:00
|
|
|
super();
|
|
|
|
}
|
2019-04-25 16:04:54 +02:00
|
|
|
|
|
|
|
ngOnInit() {
|
2020-12-14 18:28:13 +01:00
|
|
|
this.matomoService.trackPageView('DMP Listing Item');
|
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;
|
2023-12-01 18:18:41 +01:00
|
|
|
if (this.dmp.status === DmpStatus.Finalized && this.dmp.accessType === DmpAccessType.Public) { this.isPublished = true }
|
2019-06-25 17:16:31 +02:00
|
|
|
}
|
2019-04-25 16:04:54 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 15:24:34 +02:00
|
|
|
public isAuthenticated(): boolean {
|
2023-10-11 16:53:12 +02:00
|
|
|
return this.authentication.currentAccountIsAuthenticated();
|
2020-07-23 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
2019-05-08 10:37:44 +02:00
|
|
|
openShareDialog(rowId: any, rowName: any) {
|
2023-12-01 18:18:41 +01:00
|
|
|
//TODO: add this.
|
|
|
|
// const dialogRef = this.dialog.open(DmpInvitationDialogComponent, {
|
|
|
|
// // height: '250px',
|
|
|
|
// // width: '700px',
|
|
|
|
// autoFocus: false,
|
|
|
|
// restoreFocus: false,
|
|
|
|
// data: {
|
|
|
|
// dmpId: rowId,
|
|
|
|
// dmpName: rowName
|
|
|
|
// }
|
|
|
|
// });
|
2019-05-08 10:37:44 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
showDatasets(rowId: String, rowLabel: String) {
|
|
|
|
this.router.navigate(['/datasets/dmp/' + rowId, { dmpLabel: rowLabel }]);
|
|
|
|
}
|
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
viewVersions(rowId: String, rowLabel: String, dmp: Dmp) {
|
|
|
|
// if (dmp.public && !this.isUserOwner(dmp)) {
|
|
|
|
// 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 } });
|
|
|
|
// } else {
|
|
|
|
// let url = this.router.createUrlTree(['/plans/versions/', rowId, { groupLabel: rowLabel }]);
|
|
|
|
// window.open(url.toString(), '_blank');
|
|
|
|
// // this.router.navigate(['/plans/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
|
|
|
|
// }
|
2019-05-08 10:37:44 +02:00
|
|
|
}
|
2019-05-14 13:35:02 +02:00
|
|
|
|
2020-07-23 15:24:34 +02:00
|
|
|
isUserDMPRelated() {
|
2023-12-01 18:18:41 +01:00
|
|
|
const principalId: Guid = this.authentication.userId();
|
2023-12-05 21:36:00 +01:00
|
|
|
return this.dmp.dmpUsers?.some(x => (x.user.id === principalId));
|
2020-07-23 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
cloneOrNewVersionClicked(dmp: Dmp, isNewVersion: boolean) {
|
|
|
|
// this.dmpService.getSingle(dmp.id).pipe(map(data => data as DmpModel))
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(data => {
|
|
|
|
// this.dmpModel = new DmpEditorModel();
|
|
|
|
// this.dmpModel.grant = new GrantTabModel();
|
|
|
|
// this.dmpModel.project = new ProjectFormModel();
|
|
|
|
// this.dmpModel.funder = new FunderFormModel();
|
|
|
|
// this.dmpModel.extraProperties = new ExtraPropertiesFormModel();
|
|
|
|
// this.dmpModel.fromModel(data);
|
|
|
|
// this.dmpModel.status = DmpStatus.Draft;
|
|
|
|
// this.dmpFormGroup = this.dmpModel.buildForm();
|
|
|
|
|
|
|
|
// if (!isNullOrUndefined(this.dmpFormGroup.get('profile').value)) {
|
|
|
|
// this.getBlueprintDefinition(Guid.parse(this.dmpFormGroup.get('profile').value), result => {
|
|
|
|
// this.checkForGrant(result.definition);
|
|
|
|
// this.checkForFunder(result.definition);
|
|
|
|
// this.checkForProject(result.definition);
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if (!isNewVersion) {
|
|
|
|
// this.dmpFormGroup.get('label').setValue(dmp.label + " New");
|
|
|
|
// }
|
|
|
|
// this.openCloneDialog(isNewVersion);
|
|
|
|
// });
|
2020-09-03 11:52:35 +02:00
|
|
|
}
|
|
|
|
|
2020-09-03 17:49:45 +02:00
|
|
|
openCloneDialog(isNewVersion: boolean) {
|
2023-12-01 18:18:41 +01:00
|
|
|
// TODO: fix this
|
|
|
|
// const dialogRef = this.dialog.open(CloneDialogComponent, {
|
|
|
|
// maxWidth: '700px',
|
|
|
|
// maxHeight: '80vh',
|
|
|
|
// data: {
|
|
|
|
// formGroup: this.dmpFormGroup,
|
|
|
|
// datasets: this.dmpFormGroup.get('datasets').value,
|
|
|
|
// isNewVersion: isNewVersion,
|
|
|
|
// confirmButton: this.language.instant('DMP-EDITOR.CLONE-DIALOG.SAVE'),
|
|
|
|
// cancelButton: this.language.instant('DMP-EDITOR.CLONE-DIALOG.CANCEL'),
|
|
|
|
// }
|
|
|
|
// });
|
2023-11-29 14:26:40 +01:00
|
|
|
// dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
// if (result) {
|
|
|
|
// if (!isNewVersion) {
|
|
|
|
// this.dmpService.clone(this.dmpFormGroup.getRawValue(), this.dmp.id)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(
|
|
|
|
// complete => this.onCloneOrNewVersionCallbackSuccess(complete),
|
|
|
|
// error => this.onCloneOrNewVersionCallbackError(error)
|
|
|
|
// );
|
|
|
|
// } else if (isNewVersion) {
|
|
|
|
// this.dmpService.newVersion(this.dmpFormGroup.getRawValue(), this.dmp.id)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(
|
|
|
|
// complete => this.onCloneOrNewVersionCallbackSuccess(complete),
|
|
|
|
// error => this.onCloneOrNewVersionCallbackError(error)
|
|
|
|
// );
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// });
|
2020-07-03 16:17:23 +02:00
|
|
|
}
|
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
downloadXml(id: Guid) {
|
2023-12-01 18:18:41 +01:00
|
|
|
// TODO: Add this
|
2023-11-29 14:26:40 +01:00
|
|
|
// this.dmpService.downloadXML(id)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(response => {
|
|
|
|
// const blob = new Blob([response.body], { type: 'application/xml' });
|
|
|
|
// const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
2020-07-03 16:17:23 +02:00
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
// FileSaver.saveAs(blob, filename);
|
|
|
|
// this.matomoService.trackDownload('dmps', "xml", id);
|
|
|
|
// });
|
2020-07-03 16:17:23 +02:00
|
|
|
}
|
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
downloadDocx(id: Guid) {
|
2023-12-01 18:18:41 +01:00
|
|
|
// TODO: Add this
|
2023-11-29 14:26:40 +01:00
|
|
|
// this.dmpService.downloadDocx(id)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(response => {
|
|
|
|
// const blob = new Blob([response.body], { type: 'application/msword' });
|
|
|
|
// const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
2020-07-03 16:17:23 +02:00
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
// FileSaver.saveAs(blob, filename);
|
|
|
|
// this.matomoService.trackDownload('dmps', "docx", id);
|
|
|
|
// });
|
2020-07-03 16:17:23 +02:00
|
|
|
}
|
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
downloadPDF(id: Guid) {
|
2023-12-01 18:18:41 +01:00
|
|
|
// TODO: Add this
|
2023-11-29 14:26:40 +01:00
|
|
|
// this.dmpService.downloadPDF(id)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(response => {
|
|
|
|
// const blob = new Blob([response.body], { type: 'application/pdf' });
|
|
|
|
// const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
2020-07-03 16:17:23 +02:00
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
// FileSaver.saveAs(blob, filename);
|
|
|
|
// this.matomoService.trackDownload('dmps', "pdf", id);
|
|
|
|
// });
|
2020-07-03 16:17:23 +02:00
|
|
|
}
|
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
downloadJson(id: Guid) {
|
2023-12-01 18:18:41 +01:00
|
|
|
// TODO: Add this
|
2023-11-29 14:26:40 +01:00
|
|
|
// this.dmpService.downloadJson(id)
|
|
|
|
// .pipe(takeUntil(this._destroyed))
|
|
|
|
// .subscribe(response => {
|
|
|
|
// const blob = new Blob([response.body], { type: 'application/json' });
|
|
|
|
// const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
// FileSaver.saveAs(blob, filename);
|
|
|
|
// this.matomoService.trackDownload('dmps', "json", id);
|
|
|
|
// }, async error => {
|
|
|
|
// this.onExportCallbackError(error);
|
|
|
|
// });
|
2020-10-09 12:04:38 +02:00
|
|
|
}
|
|
|
|
|
2023-12-01 18:18:41 +01:00
|
|
|
// async onExportCallbackError(error: any) {
|
|
|
|
// const errorJsonText = await error.error.text();
|
|
|
|
// const errorObj = JSON.parse(errorJsonText);
|
|
|
|
// this.uiNotificationService.snackBarNotification(errorObj.message, SnackBarNotificationLevel.Error);
|
|
|
|
// }
|
2020-07-03 16:17:23 +02:00
|
|
|
|
2023-12-05 21:36:00 +01:00
|
|
|
deleteClicked(id: Guid) {
|
|
|
|
this.lockService.checkLockStatus(id.toString()).pipe(takeUntil(this._destroyed))
|
2020-07-24 16:40:53 +02:00
|
|
|
.subscribe(lockStatus => {
|
|
|
|
if (!lockStatus) {
|
|
|
|
this.openDeleteDialog(id);
|
|
|
|
} else {
|
|
|
|
this.openLockedByUserDialog();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-12-05 21:36:00 +01:00
|
|
|
openDeleteDialog(id: Guid) {
|
2020-07-03 16:17:23 +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-03 16:17:23 +02:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
2020-07-22 10:23:20 +02:00
|
|
|
complete => this.onDeleteCallbackSuccess(),
|
2020-07-03 16:17:23 +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')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
isDraftDmp(activity: Dmp) {
|
2020-07-03 16:17:23 +02:00
|
|
|
return activity.status == DmpStatus.Draft;
|
|
|
|
}
|
|
|
|
|
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();
|
2020-07-03 16:17:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteCallbackError(error) {
|
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
|
2020-07-22 13:26:49 +02:00
|
|
|
onCallbackSuccess(): void {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.router.navigate(['/plans']);
|
|
|
|
}
|
|
|
|
|
2020-09-03 17:49:45 +02:00
|
|
|
onCloneOrNewVersionCallbackSuccess(cloneId: String): void {
|
2020-09-03 11:52:35 +02:00
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.router.navigate(['/plans/edit/', cloneId]);
|
|
|
|
}
|
|
|
|
|
2020-09-03 17:49:45 +02:00
|
|
|
onCloneOrNewVersionCallbackError(error: any) {
|
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Error);
|
2020-09-03 11:52:35 +02:00
|
|
|
}
|
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
isUserOwner(dmp: Dmp): boolean {
|
|
|
|
const principalId: Guid = this.authentication.userId();
|
2023-12-05 21:36:00 +01:00
|
|
|
if (principalId) return !!dmp.dmpUsers?.find(x => (x.role === DmpUserRole.Owner) && (principalId === x.id));
|
2020-07-03 16:17:23 +02:00
|
|
|
}
|
2019-04-25 16:04:54 +02:00
|
|
|
}
|