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';
|
2024-02-09 21:46:05 +01:00
|
|
|
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-29 16:04:16 +01:00
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
2024-02-09 21:46:05 +01:00
|
|
|
import { FileTransformerService } from '@app/core/services/file-transformer/file-transformer.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';
|
2024-02-09 21:46:05 +01:00
|
|
|
import { ReferenceTypeService } from '@app/core/services/reference-type/reference-type.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';
|
2023-12-29 16:04:16 +01:00
|
|
|
import { CloneDmpDialogComponent } from '../../clone-dialog/dmp-clone-dialog.component';
|
2023-12-29 17:36:02 +01:00
|
|
|
import { DmpInvitationDialogComponent } from '../../invitation/dialog/dmp-invitation-dialog.component';
|
2024-02-09 21:46:05 +01:00
|
|
|
import { NewVersionDmpDialogComponent } from '../../new-version-dialog/dmp-new-version-dialog.component';
|
2024-03-01 09:54:02 +01:00
|
|
|
import { AppPermission } from '@app/core/common/enum/permission.enum';
|
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;
|
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-29 16:04:16 +01:00
|
|
|
private dmpService: DmpService,
|
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,
|
2024-02-09 21:46:05 +01:00
|
|
|
public referenceTypeService: ReferenceTypeService,
|
2023-12-29 16:04:16 +01:00
|
|
|
public fileTransformerService: FileTransformerService,
|
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
|
|
|
}
|
|
|
|
|
2023-12-29 17:36:02 +01:00
|
|
|
inviteToDmp() {
|
|
|
|
const dialogRef = this.dialog.open(DmpInvitationDialogComponent, {
|
|
|
|
// height: '250px',
|
|
|
|
// width: '700px',
|
|
|
|
autoFocus: false,
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
2024-03-01 17:50:46 +01:00
|
|
|
dmpId: this.dmp.id,
|
|
|
|
dmpName: this.dmp.label,
|
|
|
|
blueprint: this.dmp.blueprint
|
2023-12-29 17:36:02 +01:00
|
|
|
}
|
|
|
|
});
|
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-12-06 22:10:01 +01:00
|
|
|
viewVersions(dmp: Dmp) {
|
2024-03-14 10:41:32 +01:00
|
|
|
if (dmp.accessType == DmpAccessType.Public && dmp.status == DmpStatus.Finalized && !this.dmp.authorizationFlags?.some(x => x === AppPermission.EditDmp)) {
|
2023-12-06 22:10:01 +01:00
|
|
|
let url = this.router.createUrlTree(['/explore-plans/versions/', dmp.groupId]);
|
|
|
|
window.open(url.toString(), '_blank');
|
|
|
|
} else {
|
|
|
|
let url = this.router.createUrlTree(['/plans/versions/', dmp.groupId]);
|
|
|
|
window.open(url.toString(), '_blank');
|
|
|
|
}
|
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-12-29 16:04:16 +01:00
|
|
|
cloneClicked() {
|
|
|
|
const dialogRef = this.dialog.open(CloneDmpDialogComponent, {
|
|
|
|
maxWidth: '700px',
|
|
|
|
maxHeight: '80vh',
|
|
|
|
data: {
|
|
|
|
dmp: this.dmp
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe((result: Dmp) => {
|
|
|
|
if (result) {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.router.navigate(['/plans/edit/', result.id]);
|
|
|
|
}
|
|
|
|
});
|
2020-07-03 16:17:23 +02:00
|
|
|
}
|
|
|
|
|
2023-12-29 16:04:16 +01:00
|
|
|
newVersionClicked() {
|
|
|
|
const dialogRef = this.dialog.open(NewVersionDmpDialogComponent, {
|
|
|
|
maxWidth: '700px',
|
|
|
|
maxHeight: '80vh',
|
|
|
|
data: {
|
|
|
|
dmp: this.dmp
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe((result: Dmp) => {
|
|
|
|
if (result) {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-UPDATE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.router.navigate(['/plans/edit/', result.id]);
|
|
|
|
}
|
|
|
|
});
|
2020-10-09 12:04:38 +02:00
|
|
|
}
|
|
|
|
|
2023-12-05 21:36:00 +01:00
|
|
|
deleteClicked(id: Guid) {
|
2023-12-11 17:55:20 +01:00
|
|
|
this.lockService.checkLockStatus(Guid.parse(id.toString())).pipe(takeUntil(this._destroyed))
|
2020-07-24 16:40:53 +02:00
|
|
|
.subscribe(lockStatus => {
|
2024-03-21 08:46:18 +01:00
|
|
|
if (!lockStatus.status) {
|
2020-07-24 16:40:53 +02:00
|
|
|
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);
|
|
|
|
}
|
2024-04-05 16:49:20 +02:00
|
|
|
|
2024-03-22 16:22:12 +01:00
|
|
|
canEditDmp(dmp: Dmp): boolean {
|
2024-04-05 16:49:20 +02:00
|
|
|
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.EditDmp) || this.authentication.hasPermission(AppPermission.EditDmp)) && this.isPublic == false && this.dmp.belongsToCurrentTenant != false;
|
2024-03-22 16:22:12 +01:00
|
|
|
}
|
2020-07-03 16:17:23 +02:00
|
|
|
|
2024-03-01 09:54:02 +01:00
|
|
|
canCreateNewVersion(dmp: Dmp): boolean {
|
2024-04-05 16:49:20 +02:00
|
|
|
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.CreateNewVersionDmp) || this.authentication.hasPermission(AppPermission.CreateNewVersionDmp)) && this.isPublic == false && this.dmp.belongsToCurrentTenant != false;
|
2024-03-01 09:54:02 +01:00
|
|
|
}
|
2024-03-01 17:50:46 +01:00
|
|
|
|
|
|
|
canDeleteDmp(dmp: Dmp): boolean {
|
2024-04-05 16:49:20 +02:00
|
|
|
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.DeleteDmp) || this.authentication.hasPermission(AppPermission.DeleteDmp)) && this.isPublic == false && this.dmp.belongsToCurrentTenant != false;
|
2024-03-01 17:50:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
canCloneDmp(dmp: Dmp): boolean {
|
2024-03-14 10:41:32 +01:00
|
|
|
return this.dmp.authorizationFlags?.some(x => x === AppPermission.CloneDmp) || this.authentication.hasPermission(AppPermission.CloneDmp);
|
2024-03-01 17:50:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
canFinalizeDmp(dmp: Dmp): boolean {
|
2024-04-05 16:49:20 +02:00
|
|
|
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.FinalizeDmp) || this.authentication.hasPermission(AppPermission.FinalizeDmp)) && this.isPublic == false && this.dmp.belongsToCurrentTenant != false;
|
2024-03-01 17:50:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
canExportDmp(dmp: Dmp): boolean {
|
2024-03-14 10:41:32 +01:00
|
|
|
return this.dmp.authorizationFlags?.some(x => x === AppPermission.ExportDmp) || this.authentication.hasPermission(AppPermission.ExportDmp);
|
2024-03-01 17:50:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
canInviteDmpUsers(dmp: Dmp): boolean {
|
2024-04-05 16:49:20 +02:00
|
|
|
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.InviteDmpUsers) || this.authentication.hasPermission(AppPermission.InviteDmpUsers)) && this.isPublic == false && this.dmp.belongsToCurrentTenant != false;
|
2024-03-01 17:50:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
canAssignDmpUsers(dmp: Dmp): boolean {
|
2024-04-05 16:49:20 +02:00
|
|
|
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.AssignDmpUsers) || this.authentication.hasPermission(AppPermission.AssignDmpUsers)) && this.isPublic == false && this.dmp.belongsToCurrentTenant != false;
|
2024-03-01 17:50:46 +01:00
|
|
|
}
|
2019-04-25 16:04:54 +02:00
|
|
|
}
|