2023-11-29 14:26:40 +01:00
|
|
|
import { Location } from '@angular/common';
|
|
|
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
2024-03-11 08:47:03 +01:00
|
|
|
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, Validators } from '@angular/forms';
|
2023-11-29 14:26:40 +01:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
|
import { Router } from '@angular/router';
|
2023-12-29 16:04:16 +01:00
|
|
|
import { DmpAccessType } from '@app/core/common/enum/dmp-access-type';
|
|
|
|
import { IsActive } from '@app/core/common/enum/is-active.enum';
|
|
|
|
import { Description } from '@app/core/model/description/description';
|
2023-11-29 14:26:40 +01:00
|
|
|
import { AuthService } from '@app/core/services/auth/auth.service';
|
2023-12-29 16:04:16 +01:00
|
|
|
import { DescriptionService } from '@app/core/services/description/description.service';
|
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
|
|
import { FileTransformerService } from '@app/core/services/file-transformer/file-transformer.service';
|
2023-11-29 14:26:40 +01: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-29 16:04:16 +01:00
|
|
|
import { ReferenceService } from '@app/core/services/reference/reference.service';
|
2023-11-29 14:26:40 +01:00
|
|
|
import { EnumUtils } from '@app/core/services/utilities/enum-utils.service';
|
|
|
|
import { FileUtils } from '@app/core/services/utilities/file-utils.service';
|
2023-12-29 17:36:02 +01:00
|
|
|
import { DmpInvitationDialogComponent } from '@app/ui/dmp/invitation/dialog/dmp-invitation-dialog.component';
|
2023-11-29 14:26:40 +01:00
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
2023-12-29 16:04:16 +01:00
|
|
|
import { Guid } from '@common/types/guid';
|
2023-11-29 14:26:40 +01:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import * as FileSaver from 'file-saver';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { DescriptionStatus } from '../../../../core/common/enum/description-status';
|
2023-12-01 18:18:41 +01:00
|
|
|
import { DescriptionCopyDialogComponent } from '../../description-copy-dialog/description-copy-dialog.component';
|
2024-03-15 13:13:55 +01:00
|
|
|
import { AppPermission } from '@app/core/common/enum/permission.enum';
|
2024-04-18 09:08:46 +02:00
|
|
|
import { FileTransformerEntityType } from '@app/core/common/enum/file-transformer-entity-type';
|
2023-11-29 14:26:40 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-description-listing-item-component',
|
|
|
|
templateUrl: './description-listing-item.component.html',
|
|
|
|
styleUrls: ['./description-listing-item.component.scss']
|
|
|
|
})
|
|
|
|
export class DescriptionListingItemComponent extends BaseComponent implements OnInit {
|
|
|
|
|
|
|
|
@Input() description: Description;
|
|
|
|
@Input() showDivider: boolean = true;
|
|
|
|
@Input() isPublic: boolean = false;
|
|
|
|
@Output() onClick: EventEmitter<Description> = new EventEmitter();
|
|
|
|
|
|
|
|
isDraft: boolean;
|
|
|
|
isDeleted: boolean;
|
|
|
|
isUserOwner: boolean;
|
2023-11-30 09:12:41 +01:00
|
|
|
descriptionStatusEnum = DescriptionStatus;
|
2024-04-18 09:08:46 +02:00
|
|
|
fileTransformerEntityTypeEnum = FileTransformerEntityType;
|
2023-11-30 09:12:41 +01:00
|
|
|
dmpAccessTypeEnum = DmpAccessType;
|
2024-03-15 13:13:55 +01:00
|
|
|
canDelete: boolean = false;
|
|
|
|
canEdit: boolean = false;
|
2024-03-22 16:22:12 +01:00
|
|
|
canInviteDmpUsers: boolean = false;
|
2023-11-29 14:26:40 +01:00
|
|
|
|
2023-12-19 17:09:09 +01:00
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
public enumUtils: EnumUtils,
|
|
|
|
private descriptionService: DescriptionService,
|
|
|
|
public dialog: MatDialog,
|
|
|
|
private language: TranslateService,
|
|
|
|
private authService: AuthService,
|
|
|
|
private uiNotificationService: UiNotificationService,
|
|
|
|
private lockService: LockService,
|
|
|
|
private location: Location,
|
|
|
|
private matomoService: MatomoService,
|
2023-12-01 18:18:41 +01:00
|
|
|
private fileUtils: FileUtils,
|
2023-12-29 16:04:16 +01:00
|
|
|
public dmpService: DmpService,
|
|
|
|
public referenceService: ReferenceService,
|
2024-02-09 21:46:05 +01:00
|
|
|
public referenceTypeService: ReferenceTypeService,
|
2024-03-11 08:47:03 +01:00
|
|
|
public fileTransformerService: FileTransformerService,
|
|
|
|
private fb: UntypedFormBuilder,
|
2023-11-29 14:26:40 +01:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.matomoService.trackPageView('Description Listing Item');
|
|
|
|
if (this.description.isActive === IsActive.Inactive) {
|
|
|
|
this.isDeleted = true;
|
|
|
|
} else if (this.description.status === DescriptionStatus.Draft) {
|
|
|
|
this.isDraft = true;
|
|
|
|
this.isDeleted = false;
|
|
|
|
this.setIsUserOwner();
|
|
|
|
} else {
|
|
|
|
this.isDraft = false;
|
|
|
|
this.isDeleted = false;
|
|
|
|
this.setIsUserOwner();
|
|
|
|
}
|
2024-03-15 13:13:55 +01:00
|
|
|
|
2024-04-05 16:49:20 +02:00
|
|
|
this.canDelete = (this.authService.hasPermission(AppPermission.DeleteDescription) ||
|
|
|
|
this.description.authorizationFlags?.some(x => x === AppPermission.DeleteDescription)) && this.description.belongsToCurrentTenant != false;
|
2024-03-15 13:13:55 +01:00
|
|
|
|
2024-04-05 16:49:20 +02:00
|
|
|
this.canEdit = (this.authService.hasPermission(AppPermission.EditDescription) ||
|
|
|
|
this.description.authorizationFlags?.some(x => x === AppPermission.EditDescription)) && this.description.belongsToCurrentTenant != false;
|
2024-03-15 13:13:55 +01:00
|
|
|
|
2024-04-05 16:49:20 +02:00
|
|
|
this.canInviteDmpUsers = (this.authService.hasPermission(AppPermission.InviteDmpUsers) ||
|
|
|
|
this.description.authorizationFlags?.some(x => x === AppPermission.InviteDmpUsers)) && this.description.belongsToCurrentTenant != false;
|
2024-03-22 16:22:12 +01:00
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setIsUserOwner() {
|
|
|
|
if (this.description) {
|
|
|
|
const principalId: string = this.authService.userId()?.toString();
|
|
|
|
//TODO: add user to description objects
|
|
|
|
//if (principalId) this.isUserOwner = !!this.description.users.find(x => (x.role === Role.Owner) && (principalId === x.id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-22 16:22:12 +01:00
|
|
|
isUserDMPRelated() {
|
|
|
|
const principalId: Guid = this.authService.userId();
|
|
|
|
return this.description.dmp.dmpUsers?.some(x => (x.user.id === principalId));
|
|
|
|
}
|
|
|
|
|
2023-11-29 14:26:40 +01:00
|
|
|
public isAuthenticated(): boolean {
|
|
|
|
return this.authService.currentAccountIsAuthenticated();
|
|
|
|
}
|
|
|
|
|
|
|
|
getItemLink(): string[] {
|
|
|
|
// return this.isPublic ? [`/descriptions/publicEdit/${this.description.id}`] : [`/descriptions/edit/${this.description.id}`];
|
2023-12-20 08:20:38 +01:00
|
|
|
return this.isPublic ? ['/descriptions/overview/public/' + this.description.id] : ['/descriptions/overview/' + this.description.id];
|
2023-11-29 14:26:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
getDmpLink(): string[] {
|
2023-12-20 08:20:38 +01:00
|
|
|
return this.isPublic ? [`/explore-plans/overview/public/${this.description.dmp.id}`] : [`/plans/edit/${this.description.dmp.id}`];
|
2023-11-29 14:26:40 +01:00
|
|
|
}
|
|
|
|
|
2023-12-19 17:09:09 +01:00
|
|
|
// downloadPDF(description: Description): void {
|
|
|
|
// this.descriptionService.downloadPDF(description.id.toString())
|
|
|
|
// .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'));
|
2023-12-18 11:55:19 +01:00
|
|
|
|
2023-12-19 17:09:09 +01:00
|
|
|
// FileSaver.saveAs(blob, filename);
|
|
|
|
// this.matomoService.trackDownload('descriptions', "pdf", description.id.toString());
|
|
|
|
// });
|
|
|
|
// }
|
2023-11-29 14:26:40 +01:00
|
|
|
|
2023-12-19 17:09:09 +01:00
|
|
|
download(description: Description, format: string): void {
|
|
|
|
this.descriptionService.download(description.id.toString(), format)
|
2023-12-18 11:55:19 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
2023-12-19 17:09:09 +01:00
|
|
|
const blob = new Blob([response.body], { type: 'application/octet-stream' });
|
2023-12-18 11:55:19 +01:00
|
|
|
const filename = this.fileUtils.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, filename);
|
2023-12-19 17:09:09 +01:00
|
|
|
this.matomoService.trackDownload('descriptions', format, description.id.toString());
|
2023-12-18 11:55:19 +01:00
|
|
|
});
|
2023-11-29 14:26:40 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
downloadXML(description: Description): void {
|
|
|
|
//TODO: add file transformer service
|
|
|
|
// this.descriptionService.downloadXML(description.id as string)
|
|
|
|
// .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'));
|
|
|
|
|
|
|
|
// FileSaver.saveAs(blob, filename);
|
|
|
|
// this.matomoService.trackDownload('descriptions', "xml", description.id);
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
2024-03-22 16:22:12 +01:00
|
|
|
openShareDialog() {
|
2023-11-29 14:26:40 +01:00
|
|
|
// TODO: This is a shared component. Put it in a seperate module.
|
|
|
|
const dialogRef = this.dialog.open(DmpInvitationDialogComponent, {
|
|
|
|
// height: '250px',
|
|
|
|
// width: '700px',
|
|
|
|
autoFocus: false,
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
2024-03-22 16:22:12 +01:00
|
|
|
dmpId: this.description.dmp.id,
|
|
|
|
dmpName: this.description.dmp.label,
|
|
|
|
blueprint: this.description.dmp.blueprint
|
2023-11-29 14:26:40 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-12-01 18:18:41 +01:00
|
|
|
copyToDmp(description: Description) {
|
2024-03-11 08:47:03 +01:00
|
|
|
const formGroup = this.fb.group({
|
|
|
|
dmpId: this.fb.control(null, Validators.required),
|
|
|
|
sectionId: this.fb.control(null, Validators.required),
|
|
|
|
})
|
2023-12-01 18:18:41 +01:00
|
|
|
const dialogRef = this.dialog.open(DescriptionCopyDialogComponent, {
|
|
|
|
width: '500px',
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
2024-03-11 08:47:03 +01:00
|
|
|
formGroup: formGroup,
|
2023-12-01 18:18:41 +01:00
|
|
|
descriptionId: description.id,
|
2023-12-04 18:37:52 +01:00
|
|
|
descriptionTemplate: description.descriptionTemplate,
|
2023-12-01 18:18:41 +01:00
|
|
|
descriptionProfileExist: false,
|
|
|
|
confirmButton: this.language.instant('DESCRIPTION-LISTING.COPY-DIALOG.COPY'),
|
|
|
|
cancelButton: this.language.instant('DESCRIPTION-LISTING.COPY-DIALOG.CANCEL')
|
|
|
|
}
|
|
|
|
});
|
2023-11-29 14:26:40 +01:00
|
|
|
|
2023-12-01 18:18:41 +01:00
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed))
|
2024-03-11 08:47:03 +01:00
|
|
|
.subscribe(formGroup => {
|
|
|
|
if (formGroup) {
|
|
|
|
this.router.navigate(['descriptions/edit/copy/' + description.id + '/' + formGroup.get('dmpId').value + '/' + formGroup.get('sectionId').value]);
|
2023-12-01 18:18:41 +01:00
|
|
|
}
|
|
|
|
});
|
2023-11-29 14:26:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteClicked(id: Guid) {
|
2023-12-11 17:55:20 +01:00
|
|
|
this.lockService.checkLockStatus(id).pipe(takeUntil(this._destroyed))
|
2023-11-29 14:26:40 +01:00
|
|
|
.subscribe(lockStatus => {
|
2024-03-21 08:46:18 +01:00
|
|
|
if (!lockStatus.status) {
|
2023-11-29 14:26:40 +01:00
|
|
|
this.openDeleteDialog(id);
|
|
|
|
} else {
|
|
|
|
this.openLockedByUserDialog();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
openDeleteDialog(id: Guid): 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.descriptionService.delete(id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
complete => this.onDeleteCallbackSuccess(),
|
|
|
|
error => this.onDeleteCallbackError(error)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
openLockedByUserDialog() {
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
maxWidth: '400px',
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
2023-12-01 18:18:41 +01:00
|
|
|
message: this.language.instant('DESCRIPTION-LISTING.LOCKED')
|
2023-11-29 14:26:40 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
reloadPage(): void {
|
|
|
|
const path = this.location.path();
|
|
|
|
this.router.navigateByUrl('/reload', { skipLocationChange: true }).then(() => {
|
|
|
|
this.router.navigate([path]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteCallbackSuccess(): void {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DELETE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.reloadPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
onDeleteCallbackError(error) {
|
|
|
|
this.uiNotificationService.snackBarNotification(error.error.message ? error.error.message : this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DELETE'), SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
}
|