argos/dmp-frontend/src/app/ui/dmp/listing/listing-item/dmp-listing-item.component.ts

252 lines
9.4 KiB
TypeScript
Raw Normal View History

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 { 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';
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';
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';
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;
@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
isDraft: boolean;
isFinalized: boolean;
isPublished: boolean;
2023-11-29 14:26:40 +01:00
dmpStatusEnum = DmpStatus;
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,
private dmpBlueprintService: DmpBlueprintService,
2020-07-03 16:17:23 +02:00
private language: TranslateService,
private uiNotificationService: UiNotificationService,
2020-07-22 13:26:49 +02:00
private lockService: LockService,
private location: Location,
private httpClient: HttpClient,
2023-10-25 16:47:48 +02:00
private matomoService: MatomoService,
public referenceService: ReferenceService,
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) {
super();
}
2019-04-25 16:04:54 +02:00
ngOnInit() {
this.matomoService.trackPageView('DMP Listing Item');
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.status === DmpStatus.Finalized && this.dmp.accessType === DmpAccessType.Public) { this.isPublished = true }
}
2019-04-25 16:04:54 +02:00
}
public isAuthenticated(): boolean {
2023-10-11 16:53:12 +02:00
return this.authentication.currentAccountIsAuthenticated();
}
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
}
isUserDMPRelated() {
const principalId: Guid = this.authentication.userId();
2023-12-05 21:36:00 +01:00
return this.dmp.dmpUsers?.some(x => (x.user.id === principalId));
}
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]);
}
});
}
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))
.subscribe(lockStatus => {
if (!lockStatus.status) {
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) {
this.dmpService.delete(id)
2020-07-03 16:17:23 +02:00
.pipe(takeUntil(this._destroyed))
.subscribe(
complete => this.onDeleteCallbackSuccess(),
2020-07-03 16:17:23 +02:00
error => this.onDeleteCallbackError(error)
);
}
});
}
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;
}
reloadPage(): void {
2020-07-22 13:26:49 +02:00
const path = this.location.path();
this.router.navigateByUrl('/reload', { skipLocationChange: true }).then(() => {
2020-07-22 13:26:49 +02:00
this.router.navigate([path]);
});
}
onDeleteCallbackSuccess(): void {
2020-07-22 13:26:49 +02:00
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success);
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-03-22 16:22:12 +01:00
canEditDmp(dmp: Dmp): boolean {
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.EditDmp) || this.authentication.hasPermission(AppPermission.EditDmp)) && this.isPublic == false;
}
2020-07-03 16:17:23 +02:00
2024-03-01 09:54:02 +01:00
canCreateNewVersion(dmp: Dmp): boolean {
2024-03-14 10:41:32 +01:00
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.CreateNewVersionDmp) || this.authentication.hasPermission(AppPermission.CreateNewVersionDmp)) && this.isPublic == false;
2024-03-01 09:54:02 +01:00
}
2024-03-01 17:50:46 +01:00
canDeleteDmp(dmp: Dmp): boolean {
2024-03-14 10:41:32 +01:00
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.DeleteDmp) || this.authentication.hasPermission(AppPermission.DeleteDmp)) && this.isPublic == 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-03-14 10:41:32 +01:00
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.FinalizeDmp) || this.authentication.hasPermission(AppPermission.FinalizeDmp)) && this.isPublic == 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-03-14 10:41:32 +01:00
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.InviteDmpUsers) || this.authentication.hasPermission(AppPermission.InviteDmpUsers)) && this.isPublic == false;
2024-03-01 17:50:46 +01:00
}
canAssignDmpUsers(dmp: Dmp): boolean {
2024-03-14 10:41:32 +01:00
return (this.dmp.authorizationFlags?.some(x => x === AppPermission.AssignDmpUsers) || this.authentication.hasPermission(AppPermission.AssignDmpUsers)) && this.isPublic == false;
2024-03-01 17:50:46 +01:00
}
2019-04-25 16:04:54 +02:00
}