You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.1 KiB
TypeScript
86 lines
3.1 KiB
TypeScript
|
|
import {of as observableOf, Observable } from 'rxjs';
|
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
|
import { MatPaginator } from '@angular/material/paginator';
|
|
import { MatSort } from '@angular/material/sort';
|
|
import { Router, ActivatedRoute, Params } 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 { GrantListingModel } from '../../../core/model/grant/grant-listing';
|
|
import { GrantCriteria } from '../../../core/query/grant/grant-criteria';
|
|
import { GrantService } from '../../../core/services/grant/grant.service';
|
|
import { BreadcrumbItem } from '../../misc/breadcrumb/definition/breadcrumb-item';
|
|
import { IBreadCrumbComponent } from '../../misc/breadcrumb/definition/IBreadCrumbComponent';
|
|
import { GrantCriteriaComponent } from './criteria/grant-criteria.component';
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
@Component({
|
|
selector: 'app-grant-listing-component',
|
|
templateUrl: 'grant-listing.component.html',
|
|
styleUrls: ['./grant-listing.component.scss']
|
|
})
|
|
export class GrantListingComponent extends BaseComponent implements OnInit, IBreadCrumbComponent {
|
|
|
|
@ViewChild(MatPaginator, { static: true }) _paginator: MatPaginator;
|
|
@ViewChild(MatSort, { static: false }) sort: MatSort;
|
|
@ViewChild(GrantCriteriaComponent, { static: true }) criteria: GrantCriteriaComponent;
|
|
|
|
breadCrumbs: Observable<BreadcrumbItem[]>;
|
|
totalCount: number;
|
|
listingItems: GrantListingModel[] = [];
|
|
|
|
constructor(
|
|
private grantService: GrantService,
|
|
private router: Router,
|
|
private route: ActivatedRoute,
|
|
public language: TranslateService
|
|
) {
|
|
super();
|
|
}
|
|
|
|
ngOnInit() {
|
|
|
|
this.criteria.setCriteria(this.getDefaultCriteria());
|
|
this.refresh();
|
|
this.criteria.setRefreshCallback((resetPages) => this.refresh(resetPages));
|
|
|
|
this.breadCrumbs = observableOf([{
|
|
parentComponentName: null,
|
|
label: this.language.instant('NAV-BAR.GRANTS').toUpperCase(),
|
|
url: '/grants'
|
|
}]);
|
|
|
|
}
|
|
|
|
refresh(resetPages = false) {
|
|
if (this._paginator.pageSize === undefined) this._paginator.pageSize = 10;
|
|
if (resetPages) this._paginator.pageIndex = 0;
|
|
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<GrantCriteria>(startIndex, this._paginator.pageSize, { fields: fields });
|
|
request.criteria = this.criteria.criteria;
|
|
this.grantService.getPaged(request, "listing").pipe(takeUntil(this._destroyed)).subscribe(result => {
|
|
if (!result) { return []; }
|
|
if (this._paginator.pageIndex === 0) { this.totalCount = result.totalCount; }
|
|
this.listingItems = result.data;
|
|
});
|
|
}
|
|
|
|
rowClicked(grant: GrantListingModel) {
|
|
this.router.navigate(['/grants/edit/' + grant.id]);
|
|
}
|
|
|
|
getDefaultCriteria(): GrantCriteria {
|
|
const defaultCriteria = new GrantCriteria();
|
|
return defaultCriteria;
|
|
}
|
|
|
|
pageThisEvent(event) {
|
|
this.refresh();
|
|
}
|
|
}
|
|
|
|
|