2019-09-23 10:17:03 +02:00
|
|
|
|
|
|
|
import {of as observableOf, Observable } from 'rxjs';
|
2019-01-18 18:03:45 +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-06-07 13:03:10 +02:00
|
|
|
import { Router, ActivatedRoute, Params } from '@angular/router';
|
2019-05-08 11:55:49 +02:00
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
import { BaseComponent } from '../../../core/common/base/base.component';
|
|
|
|
import { DataTableRequest } from '../../../core/model/data-table/data-table-request';
|
2019-08-01 09:54:40 +02:00
|
|
|
import { GrantListingModel } from '../../../core/model/grant/grant-listing';
|
|
|
|
import { GrantCriteria } from '../../../core/query/grant/grant-criteria';
|
|
|
|
import { GrantService } from '../../../core/services/grant/grant.service';
|
2019-01-18 18:03:45 +01:00
|
|
|
import { BreadcrumbItem } from '../../misc/breadcrumb/definition/breadcrumb-item';
|
|
|
|
import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCrumbComponent';
|
2019-08-01 09:54:40 +02:00
|
|
|
import { GrantCriteriaComponent } from './criteria/grant-criteria.component';
|
2019-06-07 13:03:10 +02:00
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
2017-12-14 14:10:56 +01:00
|
|
|
|
|
|
|
@Component({
|
2019-08-01 09:54:40 +02:00
|
|
|
selector: 'app-grant-listing-component',
|
|
|
|
templateUrl: 'grant-listing.component.html',
|
|
|
|
styleUrls: ['./grant-listing.component.scss']
|
2017-12-14 14:10:56 +01:00
|
|
|
})
|
2019-08-01 09:54:40 +02:00
|
|
|
export class GrantListingComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
|
2017-12-14 14:10:56 +01:00
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
@ViewChild(MatPaginator, { static: true }) _paginator: MatPaginator;
|
|
|
|
@ViewChild(MatSort, { static: false }) sort: MatSort;
|
|
|
|
@ViewChild(GrantCriteriaComponent, { static: true }) criteria: GrantCriteriaComponent;
|
2017-12-14 14:10:56 +01:00
|
|
|
|
2019-06-07 13:03:10 +02:00
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
2019-05-08 11:55:49 +02:00
|
|
|
totalCount: number;
|
2019-08-01 09:54:40 +02:00
|
|
|
listingItems: GrantListingModel[] = [];
|
2017-12-14 14:10:56 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
constructor(
|
2019-08-01 09:54:40 +02:00
|
|
|
private grantService: GrantService,
|
2019-05-08 11:55:49 +02:00
|
|
|
private router: Router,
|
2019-06-07 13:03:10 +02:00
|
|
|
private route: ActivatedRoute,
|
2019-09-06 12:00:01 +02:00
|
|
|
public language: TranslateService
|
2018-10-05 17:00:54 +02:00
|
|
|
) {
|
2019-05-08 11:55:49 +02:00
|
|
|
super();
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2017-12-14 14:10:56 +01:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
ngOnInit() {
|
2018-06-27 12:29:21 +02:00
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
this.criteria.setCriteria(this.getDefaultCriteria());
|
|
|
|
this.refresh();
|
2019-05-17 15:29:00 +02:00
|
|
|
this.criteria.setRefreshCallback((resetPages) => this.refresh(resetPages));
|
2019-06-07 13:03:10 +02:00
|
|
|
|
2019-09-23 10:17:03 +02:00
|
|
|
this.breadCrumbs = observableOf([{
|
2019-06-07 13:03:10 +02:00
|
|
|
parentComponentName: null,
|
2019-08-01 09:54:40 +02:00
|
|
|
label: this.language.instant('NAV-BAR.GRANTS').toUpperCase(),
|
|
|
|
url: '/grants'
|
2019-06-07 13:03:10 +02:00
|
|
|
}]);
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2017-12-14 14:10:56 +01:00
|
|
|
|
2019-05-17 15:29:00 +02:00
|
|
|
refresh(resetPages = false) {
|
|
|
|
if (this._paginator.pageSize === undefined) this._paginator.pageSize = 10;
|
|
|
|
if (resetPages) this._paginator.pageIndex = 0;
|
2019-05-08 11:55:49 +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]; }
|
2019-08-01 09:54:40 +02:00
|
|
|
const request = new DataTableRequest<GrantCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
|
2019-05-08 11:55:49 +02:00
|
|
|
request.criteria = this.criteria.criteria;
|
2019-08-01 09:54:40 +02:00
|
|
|
this.grantService.getPaged(request, "listing").pipe(takeUntil(this._destroyed)).subscribe(result => {
|
2019-05-08 11:55:49 +02:00
|
|
|
if (!result) { return []; }
|
|
|
|
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
|
|
|
|
this.listingItems = result.data;
|
|
|
|
});
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2017-12-14 14:10:56 +01:00
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
rowClicked(grant: GrantListingModel) {
|
|
|
|
this.router.navigate(['/grants/edit/' + grant.id]);
|
2018-10-05 17:00:54 +02:00
|
|
|
}
|
2017-12-14 14:10:56 +01:00
|
|
|
|
2019-08-01 09:54:40 +02:00
|
|
|
getDefaultCriteria(): GrantCriteria {
|
|
|
|
const defaultCriteria = new GrantCriteria();
|
2018-10-05 17:00:54 +02:00
|
|
|
return defaultCriteria;
|
|
|
|
}
|
2019-05-17 15:29:00 +02:00
|
|
|
|
|
|
|
pageThisEvent(event) {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2017-12-14 14:10:56 +01:00
|
|
|
}
|
|
|
|
|
2018-10-05 17:00:54 +02:00
|
|
|
|