2018-10-05 17:00:54 +02:00
|
|
|
import { DataSource } from '@angular/cdk/table';
|
2021-03-29 17:42:55 +02:00
|
|
|
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
2021-02-03 10:06:40 +01:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatPaginator, PageEvent } from '@angular/material/paginator';
|
|
|
|
import { MatSort } from '@angular/material/sort';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { ActivatedRoute, Params, Router } from '@angular/router';
|
2021-02-03 10:06:40 +01:00
|
|
|
import { DatasetStatus } from '@app/core/common/enum/dataset-status';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
|
|
|
import { DatasetListingModel } from '@app/core/model/dataset/dataset-listing';
|
|
|
|
import { DmpModel } from '@app/core/model/dmp/dmp';
|
|
|
|
import { DatasetProfileCriteria } from '@app/core/query/dataset-profile/dataset-profile-criteria';
|
|
|
|
import { DatasetProfileService } from '@app/core/services/dataset-profile/dataset-profile.service';
|
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
2020-12-14 18:28:13 +01:00
|
|
|
import { MatomoService } from '@app/core/services/matomo/matomo-service';
|
2021-03-29 17:42:55 +02:00
|
|
|
import { SnackBarNotificationLevel, UiNotificationService } from '@app/core/services/notification/ui-notification-service';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { DatasetProfileCriteriaComponent } from '@app/ui/admin/dataset-profile/listing/criteria/dataset-profile.component';
|
|
|
|
import { BreadcrumbItem } from '@app/ui/misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
2021-03-29 17:42:55 +02:00
|
|
|
import { ConfirmationDialogComponent } from '@common/modules/confirmation-dialog/confirmation-dialog.component';
|
2019-09-23 10:22:27 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2021-03-30 10:36:09 +02:00
|
|
|
import * as FileSaver from 'file-saver';
|
2019-09-23 10:22:27 +02:00
|
|
|
import { merge as observableMerge, Observable, of as observableOf } from 'rxjs';
|
|
|
|
import { map, startWith, switchMap, takeUntil } from 'rxjs/operators';
|
2021-02-03 10:06:40 +01:00
|
|
|
import { DialogConfirmationUploadDatasetProfiles } from './criteria/dialog-confirmation-upload-profile/dialog-confirmation-upload-profiles.component';
|
2018-02-06 14:56:33 +01:00
|
|
|
|
|
|
|
@Component({
|
2019-01-18 18:03:45 +01:00
|
|
|
selector: 'app-dataset-profile-listing-component',
|
|
|
|
templateUrl: 'dataset-profile-listing.component.html',
|
|
|
|
styleUrls: ['./dataset-profile-listing.component.scss']
|
2018-02-06 14:56:33 +01:00
|
|
|
})
|
2019-01-18 18:03:45 +01:00
|
|
|
export class DatasetProfileListingComponent extends BaseComponent implements OnInit {
|
2018-02-06 14:56:33 +01:00
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
@ViewChild(MatPaginator, { static: true }) _paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
|
|
@ViewChild(DatasetProfileCriteriaComponent, { static: true }) criteria: DatasetProfileCriteriaComponent;
|
2018-10-05 17:00:54 +02:00
|
|
|
|
2019-05-23 11:40:24 +02:00
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
2018-10-05 17:00:54 +02:00
|
|
|
dataSource: DatasetDataSource | null;
|
2020-05-08 17:27:16 +02:00
|
|
|
displayedColumns: String[] = ['label', 'description', 'created', 'status', 'actions'];
|
2018-10-05 17:00:54 +02:00
|
|
|
pageEvent: PageEvent;
|
|
|
|
titlePrefix: String;
|
|
|
|
dmpId: String;
|
2019-03-26 15:30:33 +01:00
|
|
|
itemId: string;
|
2021-03-30 10:36:09 +02:00
|
|
|
datasetStatusEnum = DatasetStatus;
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
constructor(
|
2019-01-18 18:03:45 +01:00
|
|
|
private datasetService: DatasetProfileService,
|
2018-10-05 17:00:54 +02:00
|
|
|
private router: Router,
|
2019-01-18 18:03:45 +01:00
|
|
|
private route: ActivatedRoute,
|
2019-03-26 15:30:33 +01:00
|
|
|
private dmpService: DmpService,
|
|
|
|
private language: TranslateService,
|
2020-12-14 18:28:13 +01:00
|
|
|
private uiNotificationService: UiNotificationService,
|
|
|
|
private httpClient: HttpClient,
|
2021-02-03 10:06:40 +01:00
|
|
|
private matomoService: MatomoService,
|
2021-03-29 17:42:55 +02:00
|
|
|
private dialog: MatDialog,
|
|
|
|
private datasetProfileService: DatasetProfileService,
|
2018-10-05 17:00:54 +02:00
|
|
|
) {
|
2018-11-27 18:33:17 +01:00
|
|
|
super();
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2020-12-14 18:28:13 +01:00
|
|
|
this.matomoService.trackPageView('Admin: Dataset Templates');
|
2018-11-27 18:33:17 +01:00
|
|
|
this.route.params
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe((params: Params) => {
|
2019-03-26 15:30:33 +01:00
|
|
|
if (params['dmpId']) {
|
|
|
|
this.dmpId = params['dmpId'];
|
|
|
|
if (this.dmpId != null) { this.setDmpTitle(this.dmpId); }
|
|
|
|
this.criteria.setCriteria(this.getDefaultCriteria());
|
|
|
|
this.refresh();
|
|
|
|
this.criteria.setRefreshCallback(() => this.refresh());
|
2019-05-23 11:40:24 +02:00
|
|
|
// this.breadCrumbs = Observable.of([{
|
|
|
|
// parentComponentName: null,
|
|
|
|
// label: this.language.instant('NAV-BAR.DATASET-TEMPLATES'),
|
|
|
|
// url: 'plans/edit/' + this.dmpId
|
|
|
|
// }]);
|
2019-03-26 15:30:33 +01:00
|
|
|
} else {
|
|
|
|
this.itemId = params['groupId'];
|
|
|
|
if (this.itemId) {
|
|
|
|
const datasetProfileLabel = this.route.snapshot.queryParams.groupLabel;
|
|
|
|
}
|
|
|
|
this.criteria.setCriteria(this.getDefaultCriteria());
|
|
|
|
this.refresh();
|
|
|
|
this.criteria.setRefreshCallback(() => this.refresh());
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([{
|
2019-05-23 11:40:24 +02:00
|
|
|
parentComponentName: null,
|
|
|
|
label: this.language.instant('NAV-BAR.DATASET-TEMPLATES'),
|
|
|
|
url: '/dataset-profiles'
|
|
|
|
}]);
|
2019-03-26 15:30:33 +01:00
|
|
|
}
|
2018-11-27 18:33:17 +01:00
|
|
|
});
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
setDmpTitle(dmpId: String) {
|
2019-09-23 10:17:03 +02:00
|
|
|
this.dmpService.getSingle(dmpId).pipe(map(data => data as DmpModel))
|
2018-11-27 18:33:17 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
2018-10-05 17:00:54 +02:00
|
|
|
.subscribe(data => {
|
|
|
|
this.titlePrefix = data.label;
|
2019-03-26 15:30:33 +01:00
|
|
|
}
|
2019-05-23 11:40:24 +02:00
|
|
|
);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
2019-03-26 15:30:33 +01:00
|
|
|
this.dataSource = new DatasetDataSource(this.datasetService, this._paginator, this.sort, this.criteria, this.itemId);
|
2021-04-27 22:33:30 +02:00
|
|
|
this._paginator.pageIndex = 0;
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rowClick(rowId: String) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['dataset-profiles/' + rowId]);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-03-26 15:30:33 +01:00
|
|
|
getDefaultCriteria(): DatasetProfileCriteria {
|
2018-10-16 13:11:15 +02:00
|
|
|
const defaultCriteria = new DatasetProfileCriteria();
|
2018-10-05 17:00:54 +02:00
|
|
|
return defaultCriteria;
|
|
|
|
}
|
|
|
|
|
2018-10-16 13:11:15 +02:00
|
|
|
clone(id: string) {
|
2019-01-18 18:03:45 +01:00
|
|
|
this.router.navigate(['dataset-profiles/clone/' + id]);
|
2018-10-16 13:11:15 +02:00
|
|
|
}
|
|
|
|
|
2019-03-26 15:30:33 +01:00
|
|
|
newVersion(id: string, label: string) {
|
|
|
|
this.router.navigate(['dataset-profiles/newversion/' + id]);
|
|
|
|
}
|
|
|
|
|
2023-04-09 12:21:08 +02:00
|
|
|
newVersionFromFile(id: string, label: string): void {
|
|
|
|
const dialogRef = this.dialog.open(DialogConfirmationUploadDatasetProfiles, {
|
|
|
|
width: '500px',
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
message: this.language.instant('DATASET-WIZARD.NEW-VERSION-FROM-FILE.NEW-VERSION-XML-FILE-TITLE', {datasetName: label}),
|
|
|
|
confirmButton: this.language.instant('DATASET-WIZARD.NEW-VERSION-FROM-FILE.NEW-VERSION-XML'),
|
|
|
|
cancelButton: this.language.instant('DATASET-WIZARD.NEW-VERSION-FROM-FILE.NEW-VERSION-XML-FILE-CANCEL'),
|
|
|
|
name: "",
|
|
|
|
file: FileList,
|
|
|
|
sucsess: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(data => {
|
|
|
|
if (data && data.sucsess && data.name != null && data.file != null) {
|
|
|
|
this.datasetService.uploadFile(data.file, data.name, id)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(_=>{
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('DATASET-WIZARD.NEW-VERSION-FROM-FILE.NEW-VERSION-XML-SUCCESSFUL'), SnackBarNotificationLevel.Success);
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
error=>{
|
|
|
|
this.uiNotificationService.snackBarNotification(error.message, SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-03-26 15:30:33 +01:00
|
|
|
viewVersions(rowId, rowLabel) {
|
|
|
|
this.router.navigate(['/dataset-profiles/versions/' + rowId], { queryParams: { groupLabel: rowLabel } });
|
|
|
|
}
|
2021-03-30 10:36:09 +02:00
|
|
|
downloadXML(datasetProfileId: string): void {
|
|
|
|
this.datasetProfileService.downloadXML(datasetProfileId)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'application/xml' });
|
|
|
|
const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition'));
|
|
|
|
|
|
|
|
FileSaver.saveAs(blob, filename);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
getFilenameFromContentDispositionHeader(header: string): string {
|
|
|
|
const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g);
|
|
|
|
|
|
|
|
const matches = header.match(regex);
|
|
|
|
let filename: string;
|
|
|
|
for (let i = 0; i < matches.length; i++) {
|
|
|
|
const match = matches[i];
|
|
|
|
if (match.includes('filename="')) {
|
|
|
|
filename = match.substring(10, match.length - 1);
|
|
|
|
break;
|
|
|
|
} else if (match.includes('filename=')) {
|
|
|
|
filename = match.substring(9);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filename;
|
|
|
|
}
|
2019-03-26 15:30:33 +01:00
|
|
|
|
2021-03-29 17:42:55 +02:00
|
|
|
deleteTemplate(id: string){
|
|
|
|
if(id){
|
|
|
|
const dialogRef = this.dialog.open(ConfirmationDialogComponent, {
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
message: this.language.instant('GENERAL.CONFIRMATION-DIALOG.DELETE-ITEM'),
|
|
|
|
confirmButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CONFIRM'),
|
|
|
|
cancelButton: this.language.instant('GENERAL.CONFIRMATION-DIALOG.ACTIONS.CANCEL'),
|
|
|
|
isDeleteConfirmation: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
//this.form.get('status').setValue(DatasetProfileEnum.DELETED);
|
|
|
|
this.datasetProfileService.delete(id, null)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(
|
|
|
|
complete => {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.SUCCESSFUL-DATASET-PROFILE-DELETE'), SnackBarNotificationLevel.Success);
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
error => {
|
|
|
|
this.onCallbackError(error);
|
|
|
|
if (error.error.statusCode == 674) {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant('GENERAL.SNACK-BAR.UNSUCCESSFUL-DATASET-PROFILE-DELETE'), SnackBarNotificationLevel.Error);
|
|
|
|
} else {
|
|
|
|
this.uiNotificationService.snackBarNotification(this.language.instant(error.message), SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onCallbackError(errorResponse: HttpErrorResponse) {
|
|
|
|
this.uiNotificationService.snackBarNotification(errorResponse.message, SnackBarNotificationLevel.Warning);
|
|
|
|
}
|
2018-10-05 17:00:54 +02:00
|
|
|
// makeItPublic(id: String) {
|
|
|
|
// debugger;
|
2018-11-27 18:33:17 +01:00
|
|
|
// this.datasetService.makeDatasetPublic(id).pipe(takeUntil(this._destroyed)).subscribe();
|
2018-10-05 17:00:54 +02:00
|
|
|
// }
|
2021-02-03 10:06:40 +01:00
|
|
|
|
|
|
|
openDialog(): void {
|
|
|
|
const dialogRef = this.dialog.open(DialogConfirmationUploadDatasetProfiles, {
|
|
|
|
width: '500px',
|
|
|
|
restoreFocus: false,
|
|
|
|
data: {
|
|
|
|
message: this.language.instant('DATASET-WIZARD.UPLOAD.UPLOAD-XML-FILE-TITLE'),
|
|
|
|
confirmButton: this.language.instant('DATASET-WIZARD.UPLOAD.UPLOAD-XML'),
|
|
|
|
cancelButton: this.language.instant('DATASET-WIZARD.UPLOAD.UPLOAD-XML-FILE-CANCEL'),
|
|
|
|
name: "",
|
|
|
|
file: FileList,
|
|
|
|
sucsess: false
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogRef.afterClosed().pipe(takeUntil(this._destroyed)).subscribe(data => {
|
|
|
|
if (data && data.sucsess && data.name != null && data.file != null) {
|
|
|
|
this.datasetService.uploadFile(data.file, data.name)
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
2021-03-31 17:31:57 +02:00
|
|
|
.subscribe(_=>{
|
|
|
|
this.uiNotificationService.snackBarNotification('Template successfully uploaded', SnackBarNotificationLevel.Success);
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
error=>{
|
|
|
|
this.uiNotificationService.snackBarNotification(error.message, SnackBarNotificationLevel.Error);
|
|
|
|
}
|
|
|
|
);
|
2021-02-03 10:06:40 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gets as a a pameter a number representing the status and returns the class that is applied
|
|
|
|
* to status-chip */
|
|
|
|
getStatusClass(status: DatasetStatus):string{
|
|
|
|
|
|
|
|
if(status == DatasetStatus.Finalized){
|
|
|
|
return 'status-chip-finalized'
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'status-chip-draft';
|
|
|
|
}
|
|
|
|
|
2018-02-06 14:56:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export class DatasetDataSource extends DataSource<DatasetListingModel> {
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
totalCount = 0;
|
|
|
|
|
|
|
|
constructor(
|
2019-01-18 18:03:45 +01:00
|
|
|
private _service: DatasetProfileService,
|
2018-10-05 17:00:54 +02:00
|
|
|
private _paginator: MatPaginator,
|
|
|
|
private _sort: MatSort,
|
2019-03-26 15:30:33 +01:00
|
|
|
private _criteria: DatasetProfileCriteriaComponent,
|
|
|
|
private itemId
|
2018-10-05 17:00:54 +02:00
|
|
|
) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(): Observable<DatasetListingModel[]> {
|
|
|
|
const displayDataChanges = [
|
|
|
|
this._paginator.page
|
|
|
|
//this._sort.matSortChange
|
|
|
|
];
|
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
return observableMerge(...displayDataChanges).pipe(
|
|
|
|
startWith(null),
|
|
|
|
switchMap(() => {
|
2018-10-05 17:00:54 +02:00
|
|
|
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
|
|
|
|
let fields: Array<string> = new Array();
|
|
|
|
if (this._sort.active) { fields = this._sort.direction === 'asc' ? ['+' + this._sort.active] : ['-' + this._sort.active]; }
|
2018-10-16 13:11:15 +02:00
|
|
|
const request = new DataTableRequest<DatasetProfileCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
|
2018-10-05 17:00:54 +02:00
|
|
|
request.criteria = this._criteria.criteria;
|
2020-01-20 17:11:35 +01:00
|
|
|
request.criteria.finalized = false;
|
2019-03-26 15:30:33 +01:00
|
|
|
if (this.itemId) {
|
|
|
|
request.criteria.groupIds = [this.itemId];
|
|
|
|
request.criteria.allVersions = true;
|
|
|
|
}
|
2018-10-05 17:00:54 +02:00
|
|
|
return this._service.getPaged(request);
|
2019-09-23 10:17:03 +02:00
|
|
|
}),
|
2018-10-05 17:00:54 +02:00
|
|
|
/*.catch((error: any) => {
|
|
|
|
this._snackBar.openFromComponent(SnackBarNotificationComponent, {
|
|
|
|
data: { message: 'GENERAL.SNACK-BAR.FORMS-BAD-REQUEST', language: this._languageService },
|
|
|
|
duration: 3000,
|
|
|
|
extraClasses: ['snackbar-warning']
|
|
|
|
});
|
|
|
|
//this._criteria.criteria.onCallbackError(error);
|
|
|
|
return Observable.of(null);
|
|
|
|
})*/
|
2019-09-23 10:17:03 +02:00
|
|
|
map(result => {
|
2018-10-05 17:00:54 +02:00
|
|
|
return result;
|
2019-09-23 10:17:03 +02:00
|
|
|
}),
|
|
|
|
map(result => {
|
2018-10-05 17:00:54 +02:00
|
|
|
if (!result) { return []; }
|
2021-04-27 22:33:30 +02:00
|
|
|
// if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
|
|
|
|
this.totalCount = result.totalCount;
|
2018-10-05 17:00:54 +02:00
|
|
|
return result.data;
|
2019-09-23 10:22:27 +02:00
|
|
|
}));
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
disconnect() {
|
|
|
|
// No-op
|
|
|
|
}
|
|
|
|
}
|