2019-12-11 15:51:03 +01:00
|
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
2019-09-23 10:17:03 +02:00
|
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
|
|
import { MatSort } from '@angular/material/sort';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { ActivatedRoute, Params, Router } from '@angular/router';
|
|
|
|
import { DataTableRequest } from '@app/core/model/data-table/data-table-request';
|
|
|
|
import { DatasetListingModel } from '@app/core/model/dataset/dataset-listing';
|
|
|
|
import { ExploreDatasetCriteriaModel } from '@app/core/query/explore-dataset/explore-dataset-criteria';
|
|
|
|
import { DatasetService } from '@app/core/services/dataset/dataset.service';
|
|
|
|
import { DmpService } from '@app/core/services/dmp/dmp.service';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
import { Observable, of as observableOf } from 'rxjs';
|
2018-11-27 18:33:17 +01:00
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2019-05-16 18:11:41 +02:00
|
|
|
import { BreadcrumbItem } from '../misc/breadcrumb/definition/breadcrumb-item';
|
2019-12-11 15:51:03 +01:00
|
|
|
import { IBreadCrumbComponent } from '../misc/breadcrumb/definition/IBreadCrumbComponent';
|
2018-08-30 13:09:36 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
2019-01-18 18:03:45 +01:00
|
|
|
selector: 'app-explore-dataset-listing-component',
|
|
|
|
templateUrl: 'explore-dataset-listing.component.html',
|
|
|
|
styleUrls: ['./explore-dataset-listing.component.scss'],
|
2018-08-30 13:09:36 +02:00
|
|
|
})
|
2019-05-16 18:11:41 +02:00
|
|
|
export class ExploreDatasetListingComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
|
2018-08-30 13:09:36 +02:00
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
@ViewChild(MatPaginator, { static: true }) _paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort, { static: false }) sort: MatSort;
|
2018-10-05 17:00:54 +02:00
|
|
|
|
2019-05-08 12:52:14 +02:00
|
|
|
totalCount: number;
|
|
|
|
listingItems: DatasetListingModel[] = [];
|
|
|
|
exploreDatasetCriteriaModel: ExploreDatasetCriteriaModel;
|
2019-05-16 18:11:41 +02:00
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
2019-06-11 10:25:32 +02:00
|
|
|
dmpId: string;
|
|
|
|
dmpSearchEnabled = true;
|
|
|
|
titlePrefix: String;
|
2018-10-05 17:00:54 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private datasetService: DatasetService,
|
2019-06-11 10:25:32 +02:00
|
|
|
private dmpService: DmpService,
|
2018-10-05 17:00:54 +02:00
|
|
|
private router: Router,
|
2019-06-11 10:25:32 +02:00
|
|
|
private route: ActivatedRoute,
|
2019-05-23 11:40:24 +02:00
|
|
|
private language: TranslateService,
|
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() {
|
2019-06-11 10:25:32 +02:00
|
|
|
this.route.params
|
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(async (params: Params) => {
|
|
|
|
const queryParams = this.route.snapshot.queryParams;
|
|
|
|
this.dmpId = queryParams['dmpId'];
|
|
|
|
if (this.dmpId != null) {
|
|
|
|
this.dmpSearchEnabled = false;
|
|
|
|
const dmp = await this.dmpService.getSinglePublic(this.dmpId).toPromise();
|
|
|
|
|
|
|
|
const fields: Array<string> = [];
|
|
|
|
const dmpDataTableRequest: DataTableRequest<ExploreDatasetCriteriaModel> = new DataTableRequest(0, this._paginator.pageSize, { fields: fields });
|
|
|
|
dmpDataTableRequest.criteria = new ExploreDatasetCriteriaModel();
|
|
|
|
dmpDataTableRequest.criteria.dmpIds.push(this.dmpId);
|
|
|
|
|
|
|
|
this.datasetService.getPublicPaged(dmpDataTableRequest).pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (!result) { return []; }
|
|
|
|
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
|
|
|
|
this.listingItems = result.data;
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
});
|
2019-05-16 18:11:41 +02:00
|
|
|
|
|
|
|
const breadCrumbs = [];
|
2019-05-23 11:40:24 +02:00
|
|
|
breadCrumbs.push({
|
|
|
|
parentComponentName: null,
|
|
|
|
label: this.language.instant('NAV-BAR.PUBLIC DATASETS'),
|
|
|
|
url: "/explore"
|
|
|
|
})
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf(breadCrumbs);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-06-11 10:25:32 +02:00
|
|
|
refresh(resetPages = false) {
|
2019-05-17 09:17:23 +02:00
|
|
|
if (this._paginator.pageSize === undefined) this._paginator.pageSize = 10;
|
2019-05-08 12:52:14 +02:00
|
|
|
const startIndex = this._paginator.pageIndex * this._paginator.pageSize;
|
|
|
|
let fields: Array<string> = new Array();
|
|
|
|
if (this.sort && this.sort.active) { fields = this.sort.direction === 'asc' ? ['+' + this.sort.active] : ['-' + this.sort.active]; }
|
|
|
|
const request = new DataTableRequest<ExploreDatasetCriteriaModel>(startIndex, this._paginator.pageSize, { fields: fields });
|
2019-05-08 13:09:44 +02:00
|
|
|
request.criteria = this.exploreDatasetCriteriaModel || this.getDefaultCriteria();
|
2019-05-08 12:52:14 +02:00
|
|
|
this.datasetService.getPublicPaged(request).pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
|
|
if (!result) { return []; }
|
|
|
|
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
|
|
|
|
this.listingItems = result.data;
|
|
|
|
});
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-10-23 17:36:29 +02:00
|
|
|
// rowClicked(dataset: DatasetListingModel) {
|
|
|
|
// this.router.navigate(['/datasets/publicEdit/' + dataset.id]);
|
|
|
|
// }
|
2018-10-05 17:00:54 +02:00
|
|
|
|
2019-05-08 12:52:14 +02:00
|
|
|
onCriteriaChange(event: ExploreDatasetCriteriaModel) {
|
|
|
|
this.exploreDatasetCriteriaModel = event;
|
2019-05-17 15:29:00 +02:00
|
|
|
this._paginator.pageIndex = 0;
|
2019-05-08 12:52:14 +02:00
|
|
|
this.refresh();
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
|
|
|
|
2019-05-08 13:09:44 +02:00
|
|
|
getDefaultCriteria(): ExploreDatasetCriteriaModel {
|
|
|
|
const defaultCriteria = new ExploreDatasetCriteriaModel();
|
2019-06-11 10:25:32 +02:00
|
|
|
// if (dmp != null) {
|
|
|
|
// defaultCriteria.dmpIds.push(dmp.id);
|
2019-05-08 13:09:44 +02:00
|
|
|
// }
|
2018-10-05 17:00:54 +02:00
|
|
|
return defaultCriteria;
|
|
|
|
}
|
2019-05-17 09:17:23 +02:00
|
|
|
|
|
|
|
pageThisEvent(event) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2019-05-15 10:09:42 +02:00
|
|
|
}
|