Files
cbsnexora/src/app/clients/clients.component.ts
T
Jivjyot SinghandAbhay Chawla 504a14b968 refactor(clients): clients list page
- use statuslookup.pipe to set styles to represent status of the client
- add button to import client and create client
- add server side pagination
- toggle show closed clients in table
2019-12-01 23:20:51 +03:00

61 lines
1.9 KiB
TypeScript

import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { MatPaginator, MatSort, MatTableDataSource, MatCheckbox } from '@angular/material';
import { ClientsDataSource } from './clients.datasource';
/** rxjs Imports */
import { merge } from 'rxjs';
import { tap } from 'rxjs/operators';
/** Custom Services */
import { ClientsService } from './clients.service';
@Component({
selector: 'mifosx-clients',
templateUrl: './clients.component.html',
styleUrls: ['./clients.component.scss'],
})
export class ClientsComponent implements OnInit, AfterViewInit {
@ViewChild('showClosedAccounts') showClosedAccounts: MatCheckbox;
displayedColumns = ['name', 'clientno', 'externalid', 'status', 'mobileNo', 'gender', 'office', 'staff'];
dataSource: ClientsDataSource;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
constructor(private clientsService: ClientsService) {
}
ngOnInit() {
this.getClients();
}
ngAfterViewInit() {
this.sort.sortChange.subscribe(() => this.paginator.pageIndex = 0);
merge(this.sort.sortChange, this.paginator.page, this.showClosedAccounts.change)
.pipe(
tap(() => this.loadClientsPage())
)
.subscribe();
}
/**
* Loads a page of journal entries.
*/
loadClientsPage() {
if (!this.sort.direction) {
delete this.sort.active;
}
this.dataSource.getClients(this.sort.active, this.sort.direction, this.paginator.pageIndex, this.paginator.pageSize, !this.showClosedAccounts.checked);
}
/**
* Initializes the data source for clients table and loads the first page.
*/
getClients() {
this.dataSource = new ClientsDataSource(this.clientsService);
this.dataSource.getClients(this.sort.active, this.sort.direction, this.paginator.pageIndex, this.paginator.pageSize, !this.showClosedAccounts.checked);
}
}