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

357 lines
16 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 { ReferenceType } from '@app/core/common/enum/reference-type';
2023-10-25 16:47:48 +02:00
import { DescriptionTemplatesInSection, DmpBlueprint, DmpBlueprintDefinition, DmpBlueprintDefinitionSection, FieldInSection } from '@app/core/model/dmp-blueprint/dmp-blueprint';
2023-12-04 16:56:12 +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';
2020-07-03 16:17:23 +02:00
import { DmpService } 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';
import { map, takeUntil } from 'rxjs/operators';
import { nameof } from 'ts-simple-nameof';
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;
@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;
referenceTypeEnum = ReferenceType;
constructor(
private router: Router,
private dialog: MatDialog,
private authentication: AuthService,
2020-07-03 16:17:23 +02:00
public enumUtils: EnumUtils,
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,
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();
}
2019-05-08 10:37:44 +02:00
openShareDialog(rowId: any, rowName: any) {
//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
}
isUserDMPRelated() {
const principalId: Guid = this.authentication.userId();
return this.dmp.dmpUsers.some(x => (x.user.id === principalId));
}
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
}
2023-10-24 17:00:11 +02:00
private getBlueprintDefinition(blueprintId: Guid, successFunction) {
this.dmpBlueprintService.getSingle(blueprintId, [
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.id)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.label)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.description)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.ordinal)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.hasTemplates)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.id)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.category)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.dataType)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.systemFieldType)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.label)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.placeholder)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.description)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.required)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.fields), nameof<FieldInSection>(x => x.ordinal)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.id)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.descriptionTemplateId)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.label)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.minMultiplicity)].join('.'),
[nameof<DmpBlueprint>(x => x.definition), nameof<DmpBlueprintDefinition>(x => x.sections), nameof<DmpBlueprintDefinitionSection>(x => x.descriptionTemplates), nameof<DescriptionTemplatesInSection>(x => x.maxMultiplicity)].join('.'),
]
)
2023-10-25 16:47:48 +02:00
.pipe(map(data => data as DmpBlueprint), takeUntil(this._destroyed))
.subscribe(
data => successFunction(data),
);
2023-10-24 17:00:11 +02:00
}
2020-09-03 17:49:45 +02:00
openCloneDialog(isNewVersion: boolean) {
// 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) {
// 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) {
// 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) {
// 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) {
// 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);
// });
}
// 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
deleteClicked(id: string) {
this.lockService.checkLockStatus(id).pipe(takeUntil(this._destroyed))
.subscribe(lockStatus => {
if (!lockStatus) {
this.openDeleteDialog(id);
} else {
this.openLockedByUserDialog();
}
});
}
openDeleteDialog(id: string) {
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);
}
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();
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
}