107 lines
3.3 KiB
TypeScript
107 lines
3.3 KiB
TypeScript
|
import { BaseComponent } from "../../core/common/base/base.component";
|
||
|
import { Component, OnInit, ViewChild } from "@angular/core";
|
||
|
import { Router, ActivatedRoute } from "@angular/router";
|
||
|
import { MatPaginator, MatSort, MatSnackBar, PageEvent } from "@angular/material";
|
||
|
import { DataSource } from "@angular/cdk/collections";
|
||
|
import { DmpListingModel } from "../../core/model/dmp/dmp-listing";
|
||
|
import { TranslateService } from "@ngx-translate/core";
|
||
|
import { Observable } from "rxjs";
|
||
|
import { DmpService } from "../../core/services/dmp/dmp.service";
|
||
|
import { ExploreDmpCriteriaModel } from "../../core/query/explore-dmp/explore-dmp-criteria";
|
||
|
import { DataTableRequest } from "../../core/model/data-table/data-table-request";
|
||
|
import { DmpCriteria } from "../../core/query/dmp/dmp-criteria";
|
||
|
|
||
|
@Component({
|
||
|
selector: 'app-explore-dmp-listing-component',
|
||
|
templateUrl: 'explore-dmp-listing.component.html',
|
||
|
styleUrls: ['./explore-dmp-listing.component.scss'],
|
||
|
})
|
||
|
export class ExploreDmpListingComponent extends BaseComponent implements OnInit {
|
||
|
|
||
|
@ViewChild(MatPaginator) _paginator: MatPaginator;
|
||
|
@ViewChild(MatSort) sort: MatSort;
|
||
|
criteria: ExploreDmpCriteriaModel = new ExploreDmpCriteriaModel();
|
||
|
|
||
|
dataSource: DmpDataSource | null;
|
||
|
displayedColumns: String[] = ['name', 'project', 'organisations', 'created'];
|
||
|
pageEvent: PageEvent;
|
||
|
titlePrefix: String;
|
||
|
dmpId: string;
|
||
|
|
||
|
constructor(
|
||
|
public dmpService: DmpService,
|
||
|
private router: Router,
|
||
|
private languageService: TranslateService,
|
||
|
public snackBar: MatSnackBar,
|
||
|
public route: ActivatedRoute
|
||
|
) {
|
||
|
super();
|
||
|
}
|
||
|
|
||
|
ngOnInit() {
|
||
|
this.refresh();
|
||
|
}
|
||
|
|
||
|
rowClick(rowId: String) {
|
||
|
this.router.navigate(['/plans/publicEdit/' + rowId]);
|
||
|
}
|
||
|
|
||
|
refresh() {
|
||
|
this.dataSource = new DmpDataSource(this.dmpService, this._paginator, this.sort, this.languageService, this.snackBar, this.criteria);
|
||
|
}
|
||
|
|
||
|
getDefaultCriteria(dmpId: String): DmpCriteria {
|
||
|
const defaultCriteria = new DmpCriteria();
|
||
|
return defaultCriteria;
|
||
|
}
|
||
|
|
||
|
onCriteriaChange(event: ExploreDmpCriteriaModel) {
|
||
|
//console.log(event)
|
||
|
this.criteria = event;
|
||
|
this.refresh();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export class DmpDataSource extends DataSource<DmpListingModel> {
|
||
|
|
||
|
totalCount = 0;
|
||
|
|
||
|
constructor(
|
||
|
private _service: DmpService,
|
||
|
private _paginator: MatPaginator,
|
||
|
private _sort: MatSort,
|
||
|
private _languageService: TranslateService,
|
||
|
private _snackBar: MatSnackBar,
|
||
|
private _criteria: ExploreDmpCriteriaModel,
|
||
|
) {
|
||
|
super();
|
||
|
}
|
||
|
|
||
|
connect(): Observable<DmpListingModel[]> {
|
||
|
const displayDataChanges = [
|
||
|
this._paginator.page
|
||
|
];
|
||
|
|
||
|
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<ExploreDmpCriteriaModel>(startIndex, this._paginator.pageSize, { fields: fields });
|
||
|
request.criteria = this._criteria;
|
||
|
//if (this.dmpId) request.criteria.allVersions = true;
|
||
|
return this._service.getPublicPaged(request);
|
||
|
})
|
||
|
.map(result => {
|
||
|
if (!result) { return []; }
|
||
|
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
|
||
|
return result.data;
|
||
|
});
|
||
|
}
|
||
|
|
||
|
disconnect(): void {
|
||
|
// No-op
|
||
|
}
|
||
|
}
|