minor fix in public datasets page

This commit is contained in:
Diamantis Tziotzios 2019-05-08 14:09:44 +03:00
parent c6fe54badf
commit c23531d69b
1 changed files with 8 additions and 26 deletions

View File

@ -1,14 +1,12 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatPaginator, MatSort } from '@angular/material';
import { ActivatedRoute, Params, Router } from '@angular/router';
import { Router } from '@angular/router';
import { takeUntil } from 'rxjs/operators';
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 { ExploreDatasetCriteriaModel } from '../../core/query/explore-dataset/explore-dataset-criteria';
import { DatasetService } from '../../core/services/dataset/dataset.service';
import { DmpService } from '../../core/services/dmp/dmp.service';
@Component({
@ -21,35 +19,19 @@ export class ExploreDatasetListingComponent extends BaseComponent implements OnI
@ViewChild(MatPaginator) _paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
titlePrefix: String;
dmpId: string;
totalCount: number;
dmpSearchEnabled = true;
listingItems: DatasetListingModel[] = [];
exploreDatasetCriteriaModel: ExploreDatasetCriteriaModel;
constructor(
private datasetService: DatasetService,
private router: Router,
private route: ActivatedRoute,
private dmpService: DmpService,
) {
super();
}
ngOnInit() {
this.route.params
.pipe(takeUntil(this._destroyed))
.subscribe(async (params: Params) => {
this.dmpId = params['dmpId'];
this.refresh();
if (this.dmpId != null) {
const dmp = await this.dmpService.getSingle(this.dmpId).toPromise();
if (params['dmpLabel'] !== undefined) {
this.titlePrefix = 'for ' + params['dmpLabel'];
}
}
});
}
refresh() {
@ -57,7 +39,7 @@ export class ExploreDatasetListingComponent extends BaseComponent implements OnI
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 });
request.criteria = this.exploreDatasetCriteriaModel;
request.criteria = this.exploreDatasetCriteriaModel || this.getDefaultCriteria();
this.datasetService.getPublicPaged(request).pipe(takeUntil(this._destroyed)).subscribe(result => {
if (!result) { return []; }
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
@ -75,11 +57,11 @@ export class ExploreDatasetListingComponent extends BaseComponent implements OnI
this.refresh();
}
getDefaultCriteria(dmpId: String): DatasetCriteria {
const defaultCriteria = new DatasetCriteria();
if (dmpId != null) {
defaultCriteria.dmpIds.push(dmpId);
}
getDefaultCriteria(): ExploreDatasetCriteriaModel {
const defaultCriteria = new ExploreDatasetCriteriaModel();
// if (dmpId != null) {
// defaultCriteria.dmpIds.push(dmpId);
// }
return defaultCriteria;
}
}