2018-10-05 17:00:54 +02:00
|
|
|
import { DataSource } from '@angular/cdk/table';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
|
|
import { MatPaginator, MatSnackBar, MatSort, PageEvent } from '@angular/material';
|
|
|
|
import { ActivatedRoute, Params, Router } from '@angular/router';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2018-10-12 17:17:31 +02:00
|
|
|
import { Observable } from 'rxjs';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { BaseComponent } from '../../../core/common/base/base.component';
|
|
|
|
import { DataTableRequest } from '../../../core/model/data-table/data-table-request';
|
|
|
|
import { DatasetListingModel } from '../../../core/model/dataset/dataset-listing';
|
|
|
|
import { DatasetCriteria } from '../../../core/query/dataset/dataset-criteria';
|
|
|
|
import { DatasetService } from '../../../core/services/dataset/dataset.service';
|
|
|
|
import { DmpService } from '../../../core/services/dmp/dmp.service';
|
|
|
|
import { EnumUtils } from '../../../core/services/utilities/enum-utils.service';
|
|
|
|
import { BreadcrumbItem } from '../../misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCrumbComponent';
|
|
|
|
import { DatasetCriteriaComponent } from './criteria/dataset-criteria.component';
|
2017-12-15 16:33:18 +01:00
|
|
|
|
|
|
|
@Component({
|
2018-10-05 17:00:54 +02:00
|
|
|
selector: 'app-dataset-listing-component',
|
|
|
|
templateUrl: 'dataset-listing.component.html',
|
2019-01-18 18:03:45 +01:00
|
|
|
styleUrls: ['./dataset-listing.component.scss']
|
2017-12-15 16:33:18 +01:00
|
|
|
})
|
2018-11-27 18:33:17 +01:00
|
|
|
export class DatasetListingComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
|
2017-12-15 16:33:18 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
@ViewChild(MatPaginator) _paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort) sort: MatSort;
|
|
|
|
@ViewChild(DatasetCriteriaComponent) criteria: DatasetCriteriaComponent;
|
|
|
|
|
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
|
|
|
|
|
|
|
dataSource: DatasetDataSource | null;
|
2018-10-15 14:50:01 +02:00
|
|
|
displayedColumns: String[] = ['label', 'project', 'dmp', 'profile', 'status', 'description', 'created'];
|
2018-10-05 17:00:54 +02:00
|
|
|
pageEvent: PageEvent;
|
|
|
|
titlePrefix: String;
|
|
|
|
dmpId: string;
|
2019-04-09 09:29:43 +02:00
|
|
|
dmpSearchEnabled = true;
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private datasetService: DatasetService,
|
|
|
|
private router: Router,
|
|
|
|
private languageService: TranslateService,
|
2019-01-18 18:03:45 +01:00
|
|
|
private snackBar: MatSnackBar,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private dmpService: DmpService,
|
|
|
|
public enumUtils: EnumUtils
|
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() {
|
2018-11-27 18:33:17 +01:00
|
|
|
this.route.params
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(async (params: Params) => {
|
|
|
|
this.dmpId = params['dmpId'];
|
|
|
|
this.criteria.setRefreshCallback(() => this.refresh());
|
|
|
|
if (this.dmpId != null) {
|
2019-04-09 09:29:43 +02:00
|
|
|
this.dmpSearchEnabled = false;
|
2019-01-18 18:03:45 +01:00
|
|
|
const dmp = await this.dmpService.getSingle(this.dmpId).toPromise();
|
2019-04-09 09:29:43 +02:00
|
|
|
this.criteria.setCriteria(this.getDefaultCriteria(dmp));
|
|
|
|
this.refresh();
|
2019-01-18 18:03:45 +01:00
|
|
|
this.breadCrumbs = Observable.of([{ parentComponentName: 'DmpEditorComponent', label: dmp.label, url: 'plans/edit/' + this.dmpId }]);
|
2018-11-27 18:33:17 +01:00
|
|
|
if (params['dmpLabel'] !== undefined) {
|
|
|
|
this.titlePrefix = 'for ' + params['dmpLabel'];
|
|
|
|
}
|
|
|
|
} else {
|
2019-04-09 09:29:43 +02:00
|
|
|
this.criteria.setCriteria(this.getDefaultCriteria());
|
|
|
|
this.refresh();
|
2018-11-27 18:33:17 +01:00
|
|
|
this.breadCrumbs = Observable.of([]);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2018-11-27 18:33:17 +01:00
|
|
|
});
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
refresh() {
|
|
|
|
this.dataSource = new DatasetDataSource(this.datasetService, this._paginator, this.sort, this.languageService, this.snackBar, this.criteria, this.dmpId);
|
|
|
|
}
|
|
|
|
|
|
|
|
rowClick(rowId: String) {
|
|
|
|
this.router.navigate(['/datasets/edit/' + rowId]);
|
|
|
|
}
|
|
|
|
|
2019-04-15 11:34:12 +02:00
|
|
|
getDefaultCriteria(dmp: any = null): DatasetCriteria {
|
2018-10-05 17:00:54 +02:00
|
|
|
const defaultCriteria = new DatasetCriteria();
|
2019-04-15 11:34:12 +02:00
|
|
|
if (dmp != null) {
|
|
|
|
defaultCriteria.dmpIds.push(dmp);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
return defaultCriteria;
|
|
|
|
}
|
|
|
|
|
|
|
|
makeItPublic(id: String) {
|
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
|
|
|
}
|
2017-12-15 16:33:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export class DatasetDataSource extends DataSource<DatasetListingModel> {
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
totalCount = 0;
|
|
|
|
constructor(
|
|
|
|
private _service: DatasetService,
|
|
|
|
private _paginator: MatPaginator,
|
|
|
|
private _sort: MatSort,
|
|
|
|
private _languageService: TranslateService,
|
|
|
|
private _snackBar: MatSnackBar,
|
|
|
|
private _criteria: DatasetCriteriaComponent,
|
|
|
|
private dmpId: String
|
|
|
|
) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(): Observable<DatasetListingModel[]> {
|
|
|
|
const displayDataChanges = [
|
|
|
|
this._paginator.page
|
|
|
|
//this._sort.matSortChange
|
|
|
|
];
|
|
|
|
|
|
|
|
return Observable.merge(...displayDataChanges)
|
|
|
|
.startWith(null)
|
|
|
|
.switchMap(() => {
|
|
|
|
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]; }
|
|
|
|
const request = new DataTableRequest<DatasetCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
|
2019-04-09 09:29:43 +02:00
|
|
|
request.criteria = {
|
|
|
|
like: this._criteria.criteria.like,
|
|
|
|
status: this._criteria.criteria.status,
|
|
|
|
dmpIds: this._criteria.criteria.dmpIds ? this._criteria.criteria.dmpIds.map(x => x.id) : null,
|
|
|
|
tags: this._criteria.criteria.tags,
|
|
|
|
allVersions: this._criteria.criteria.allVersions
|
|
|
|
}
|
2018-10-05 17:00:54 +02:00
|
|
|
if (this.dmpId) { request.criteria.allVersions = true; }
|
|
|
|
return this._service.getPaged(request);
|
|
|
|
})
|
|
|
|
/*.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);
|
|
|
|
})*/
|
|
|
|
.map(result => {
|
2019-01-18 18:03:45 +01:00
|
|
|
result.data = result.data;
|
2018-10-05 17:00:54 +02:00
|
|
|
return result;
|
|
|
|
})
|
|
|
|
.map(result => {
|
|
|
|
return result;
|
|
|
|
})
|
|
|
|
.map(result => {
|
|
|
|
if (!result) { return []; }
|
|
|
|
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
|
|
|
|
return result.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
disconnect() {
|
|
|
|
// No-op
|
|
|
|
}
|
2018-05-28 11:50:42 +02:00
|
|
|
}
|