Clients search enhancement (#1605)

Co-authored-by: Jose Alberto Hernandez <alberto@MacBook-Pro.local>
This commit is contained in:
José Alberto Hernández
2022-12-26 14:25:49 -06:00
committed by GitHub
co-authored by Jose Alberto Hernandez
parent 475059a974
commit d0dc2aabb2
29 changed files with 514 additions and 234 deletions
+22 -50
View File
@@ -1,72 +1,34 @@
/** Angular Imports. */
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatCheckbox } from '@angular/material/checkbox';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { ClientsDataSource } from './clients.datasource';
/** rxjs Imports */
import { merge } from 'rxjs';
import { tap } from 'rxjs/operators';
import { MatTableDataSource } from '@angular/material/table';
/** Custom Services */
import { ClientsService } from './clients.service';
import { SearchService } from 'app/search/search.service';
@Component({
selector: 'mifosx-clients',
templateUrl: './clients.component.html',
styleUrls: ['./clients.component.scss'],
})
export class ClientsComponent implements OnInit, AfterViewInit {
export class ClientsComponent implements OnInit {
@ViewChild('showClosedAccounts', { static: true }) showClosedAccounts: MatCheckbox;
displayedColumns = ['name', 'clientNo', 'externalId', 'status', 'office', 'staff'];
dataSource: MatTableDataSource<any>;
displayedColumns = ['name', 'clientno', 'externalid', 'status', 'mobileNo', 'gender', 'office', 'staff'];
dataSource: ClientsDataSource;
/** Get the required filter value. */
searchValue = '';
existsClientsToFilter = false;
notExistsClientsToFilter = false;
moreClientsToFilter = false;
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
@ViewChild(MatSort, { static: true }) sort: MatSort;
constructor(private clientsService: ClientsService) {
}
constructor(private searchService: SearchService) { }
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;
}
if (this.searchValue !== '') {
this.applyFilter(this.searchValue);
} else {
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);
}
/**
@@ -74,8 +36,18 @@ export class ClientsComponent implements OnInit, AfterViewInit {
* @param {string} filterValue Value to filter data.
*/
applyFilter(filterValue: string = '') {
this.searchValue = filterValue;
this.dataSource.filterClients(filterValue.trim().toLowerCase(), this.sort.active, this.sort.direction, this.paginator.pageIndex, this.paginator.pageSize, this.showClosedAccounts.checked);
this.dataSource.filter = filterValue.trim().toLowerCase();
}
/**
* Searches server for query and resource.
*/
search(value: string) {
this.searchService.getSearchResults(value, 'clients').subscribe((data: any) => {
this.dataSource = new MatTableDataSource(data);
this.existsClientsToFilter = (data.length > 0);
this.notExistsClientsToFilter = !this.existsClientsToFilter;
this.moreClientsToFilter = (data.length > 50);
});
}
}