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 { Component, OnInit, ViewChild } from '@angular/core';
import { MatPaginator, MatSort } from '@angular/material'; import { MatPaginator, MatSort } from '@angular/material';
import { ActivatedRoute, Params, Router } from '@angular/router'; import { Router } from '@angular/router';
import { takeUntil } from 'rxjs/operators'; import { takeUntil } from 'rxjs/operators';
import { BaseComponent } from '../../core/common/base/base.component'; import { BaseComponent } from '../../core/common/base/base.component';
import { DataTableRequest } from '../../core/model/data-table/data-table-request'; import { DataTableRequest } from '../../core/model/data-table/data-table-request';
import { DatasetListingModel } from '../../core/model/dataset/dataset-listing'; 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 { ExploreDatasetCriteriaModel } from '../../core/query/explore-dataset/explore-dataset-criteria';
import { DatasetService } from '../../core/services/dataset/dataset.service'; import { DatasetService } from '../../core/services/dataset/dataset.service';
import { DmpService } from '../../core/services/dmp/dmp.service';
@Component({ @Component({
@ -21,35 +19,19 @@ export class ExploreDatasetListingComponent extends BaseComponent implements OnI
@ViewChild(MatPaginator) _paginator: MatPaginator; @ViewChild(MatPaginator) _paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
titlePrefix: String;
dmpId: string;
totalCount: number; totalCount: number;
dmpSearchEnabled = true;
listingItems: DatasetListingModel[] = []; listingItems: DatasetListingModel[] = [];
exploreDatasetCriteriaModel: ExploreDatasetCriteriaModel; exploreDatasetCriteriaModel: ExploreDatasetCriteriaModel;
constructor( constructor(
private datasetService: DatasetService, private datasetService: DatasetService,
private router: Router, private router: Router,
private route: ActivatedRoute,
private dmpService: DmpService,
) { ) {
super(); super();
} }
ngOnInit() { 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() { refresh() {
@ -57,7 +39,7 @@ export class ExploreDatasetListingComponent extends BaseComponent implements OnI
let fields: Array<string> = new Array(); let fields: Array<string> = new Array();
if (this.sort && this.sort.active) { fields = this.sort.direction === 'asc' ? ['+' + this.sort.active] : ['-' + this.sort.active]; } 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 }); 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 => { this.datasetService.getPublicPaged(request).pipe(takeUntil(this._destroyed)).subscribe(result => {
if (!result) { return []; } if (!result) { return []; }
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; } if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
@ -75,11 +57,11 @@ export class ExploreDatasetListingComponent extends BaseComponent implements OnI
this.refresh(); this.refresh();
} }
getDefaultCriteria(dmpId: String): DatasetCriteria { getDefaultCriteria(): ExploreDatasetCriteriaModel {
const defaultCriteria = new DatasetCriteria(); const defaultCriteria = new ExploreDatasetCriteriaModel();
if (dmpId != null) { // if (dmpId != null) {
defaultCriteria.dmpIds.push(dmpId); // defaultCriteria.dmpIds.push(dmpId);
} // }
return defaultCriteria; return defaultCriteria;
} }
} }