diff --git a/src/app/centers/centers.component.ts b/src/app/centers/centers.component.ts
index 8cd00b953..68cc6720a 100644
--- a/src/app/centers/centers.component.ts
+++ b/src/app/centers/centers.component.ts
@@ -8,7 +8,7 @@ import { Observable } from 'rxjs';
selector: 'mifosx-app-centers',
templateUrl: './centers.component.html',
styleUrls: ['./centers.component.scss'],
- encapsulation: ViewEncapsulation.None
+
})
export class CentersComponent implements OnInit {
private ELEMENT_DATA: any = undefined;
diff --git a/src/app/clients/clients-routing.module.ts b/src/app/clients/clients-routing.module.ts
index eb8c5a89f..652b490a1 100644
--- a/src/app/clients/clients-routing.module.ts
+++ b/src/app/clients/clients-routing.module.ts
@@ -21,7 +21,6 @@ import { DatatableTabComponent } from './clients-view/datatable-tab/datatable-ta
import { AddressTabComponent } from './clients-view/address-tab/address-tab.component';
/** Custom Resolvers */
-import { ClientsResolver } from './common-resolvers/clients.resolver';
import { ClientViewResolver } from './common-resolvers/client-view.resolver';
import { ClientAccountsResolver } from './common-resolvers/client-accounts.resolver';
import { ClientAddressResolver } from './common-resolvers/client-address.resolver';
@@ -47,9 +46,6 @@ const routes: Routes = [
{
path: '',
component: ClientsComponent,
- resolve: {
- clientsData: ClientsResolver
- }
},
{
path: ':clientId',
@@ -152,7 +148,6 @@ const routes: Routes = [
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
providers: [
- ClientsResolver,
ClientViewResolver,
ClientAccountsResolver,
ClientAddressResolver,
diff --git a/src/app/clients/clients.component.html b/src/app/clients/clients.component.html
index b128bcc58..bb9e86621 100644
--- a/src/app/clients/clients.component.html
+++ b/src/app/clients/clients.component.html
@@ -1,10 +1,22 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+ Show Closed Accounts
+
+
+
+
+
+
+
+
@@ -25,16 +37,14 @@
| {{row.externalId}} |
-
-
- Status |
-
- |
@@ -42,11 +52,11 @@
Mobile Number |
{{ client.mobileNo }} |
-
+
- Gender |
- {{ client.gender.name }} |
+ Gender |
+ {{ client.gender.name }} |
@@ -64,11 +74,11 @@
-
-
+
-
+
\ No newline at end of file
diff --git a/src/app/clients/clients.component.scss b/src/app/clients/clients.component.scss
index 18b291765..5c31bdbf3 100644
--- a/src/app/clients/clients.component.scss
+++ b/src/app/clients/clients.component.scss
@@ -1,26 +1,11 @@
- table {
- width: 100%;
+.container {
+ .action-button{
+ margin-left: auto;
+ }
+ .search-button{
+ min-width: 30px;
+ margin: 4px;
+
+ }
}
-
-.mat-form-field {
- font-size: 14px;
- width: 100%;
-}
-
-td, th {
- width: 15%;
-}
-
-.filter{
- width: 50%;
-}
-
-.inactive {
- color: red;
-}
-
-.active {
- color: green;
-}
-
diff --git a/src/app/clients/clients.component.ts b/src/app/clients/clients.component.ts
index a4e087f97..fa45c061e 100644
--- a/src/app/clients/clients.component.ts
+++ b/src/app/clients/clients.component.ts
@@ -1,48 +1,60 @@
-import { Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
-import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
-import { ActivatedRoute } from '@angular/router';
+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'],
- encapsulation: ViewEncapsulation.None
-
})
-export class ClientsComponent implements OnInit {
- post: any = [];
+export class ClientsComponent implements OnInit, AfterViewInit {
+ @ViewChild('showClosedAccounts') showClosedAccounts: MatCheckbox;
+
displayedColumns = ['name', 'clientno', 'externalid', 'status', 'mobileNo', 'gender', 'office', 'staff'];
- dataSource = new MatTableDataSource();
+ dataSource: ClientsDataSource;
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
- constructor(private route: ActivatedRoute) {
- this.route.data.subscribe((clientsData: { clientsData: any }) => {
- const res = clientsData.clientsData.pageItems;
- res.active = !!res.active;
- this.dataSource = new MatTableDataSource(res);
- this.dataSource.paginator = this.paginator;
- this.dataSource.sortingDataAccessor = (data: any, property: any) => {
- switch (property) {
- case 'gender': return data.gender.name;
- default: return data[property];
- }
- };
- this.dataSource.sort = this.sort;
- });
+ 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();
+ }
- ngOnInit() { }
-
- applyFilter(filterValue: string) {
- filterValue = filterValue.trim(); // Remove whitespace
- filterValue = filterValue.toLowerCase(); // Datasource defaults to lowercase matches
- this.dataSource.filter = filterValue;
- if (this.dataSource.paginator) {
- this.dataSource.paginator.firstPage();
+ /**
+ * 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);
+ }
}
diff --git a/src/app/clients/clients.datasource.ts b/src/app/clients/clients.datasource.ts
new file mode 100644
index 000000000..fe8ecaff8
--- /dev/null
+++ b/src/app/clients/clients.datasource.ts
@@ -0,0 +1,60 @@
+/** Angular Imports */
+import { CollectionViewer, DataSource } from '@angular/cdk/collections';
+
+/** rxjs Imports */
+import { Observable, BehaviorSubject } from 'rxjs';
+
+/** Custom Services */
+import { ClientsService } from './clients.service';
+
+/**
+ * Clients custom data source to implement server side filtering, pagination and sorting.
+ */
+export class ClientsDataSource implements DataSource
{
+
+ /** clients behavior subject to represent loaded journal clients page. */
+ private clientsSubject = new BehaviorSubject([]);
+ /** Records subject to represent total number of filtered clients records. */
+ private recordsSubject = new BehaviorSubject(0);
+ /** Records observable which can be subscribed to get the value of total number of filtered clients records. */
+ public records$ = this.recordsSubject.asObservable();
+
+ /**
+ * @param {ClientsService} clientsService Clients Service
+ */
+ constructor(private clientsService: ClientsService) { }
+
+ /**
+ * Gets clients on the basis of provided parameters and emits the value.
+ * @param {any} filterBy Properties by which clients should be filtered.
+ * @param {string} orderBy Property by which clients should be sorted.
+ * @param {string} sortOrder Sort order: ascending or descending.
+ * @param {number} pageIndex Page number.
+ * @param {number} limit Number of clients within the page.
+ */
+ getClients(orderBy: string = '', sortOrder: string = '', pageIndex: number = 0, limit: number = 10, clientActive: boolean = true) {
+ this.clientsSubject.next([]);
+ this.clientsService.getClients(orderBy, sortOrder, pageIndex * limit, limit)
+ .subscribe((clients: any) => {
+ clients.pageItems = (clientActive) ? (clients.pageItems.filter((client: any) => client.active)) : clients.pageItems;
+ this.recordsSubject.next(clients.totalFilteredRecords);
+ this.clientsSubject.next(clients.pageItems);
+ });
+ }
+
+ /**
+ * @param {CollectionViewer} collectionViewer
+ */
+ connect(collectionViewer: CollectionViewer): Observable {
+ return this.clientsSubject.asObservable();
+ }
+
+ /**
+ * @param {CollectionViewer} collectionViewer
+ */
+ disconnect(collectionViewer: CollectionViewer): void {
+ this.clientsSubject.complete();
+ this.recordsSubject.complete();
+ }
+
+}
diff --git a/src/app/clients/clients.module.ts b/src/app/clients/clients.module.ts
index dd54f570a..8ca8095fd 100644
--- a/src/app/clients/clients.module.ts
+++ b/src/app/clients/clients.module.ts
@@ -5,7 +5,7 @@ import { DatePipe } from '@angular/common';
/** Custom Modules */
import { ClientsRoutingModule } from './clients-routing.module';
import { SharedModule } from 'app/shared/shared.module';
-import {PipesModule} from '../pipes/pipes.module';
+import { PipesModule } from '../pipes/pipes.module';
/** Custom Components */
import { ClientsComponent } from './clients.component';
diff --git a/src/app/clients/clients.service.ts b/src/app/clients/clients.service.ts
index a2baa259a..f7c0b7303 100644
--- a/src/app/clients/clients.service.ts
+++ b/src/app/clients/clients.service.ts
@@ -16,8 +16,13 @@ export class ClientsService {
*/
constructor(private http: HttpClient) { }
- getClients(): Observable {
- const httpParams = new HttpParams().set('orderBy', 'id');
+ getClients(orderBy: string, sortOrder: string, offset: number, limit: number): Observable {
+ const httpParams = new HttpParams()
+ .set('offset', offset.toString())
+ .set('limit', limit.toString())
+ .set('sortOrder', sortOrder)
+ .set('orderBy', orderBy);
+
return this.http.get('/clients', { params: httpParams });
}
diff --git a/src/app/clients/common-resolvers/clients.resolver.ts b/src/app/clients/common-resolvers/clients.resolver.ts
deleted file mode 100644
index a672e861f..000000000
--- a/src/app/clients/common-resolvers/clients.resolver.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-/** Angular Imports */
-import { Injectable } from '@angular/core';
-import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
-
-/** rxjs Imports */
-import { Observable } from 'rxjs';
-
-/** Custom Services */
-import { ClientsService } from '../clients.service';
-
-/**
- * Clients data resolver.
- */
-@Injectable()
-export class ClientsResolver implements Resolve