From 63925a37c32ebb273520a5600f17b3648ac276f6 Mon Sep 17 00:00:00 2001 From: Anwesh Nayak Date: Wed, 11 Jul 2018 06:01:03 +0530 Subject: [PATCH] feat(client): POST client address && fix(client): fixed sorting and pagination in view clients (#115) * feat(client): POST client address && fix(client): fixed sorting and pagination in view clients --- src/app/clients/clients-routing.module.ts | 6 ++ src/app/clients/clients.component.html | 16 ++-- src/app/clients/clients.component.scss | 9 +++ src/app/clients/clients.component.ts | 35 +++++---- src/app/clients/clients.module.ts | 8 +- src/app/clients/clients.service.ts | 43 ++++++++++- .../create-address.component.html | 73 ++++++++++++++++++ .../create-address.component.scss | 17 ++++ .../create-address.component.spec.ts | 28 +++++++ .../create-address.component.ts | 77 +++++++++++++++++++ .../view-client/view-client.component.html | 57 +++++++------- .../view-client/view-client.component.ts | 19 +++-- 12 files changed, 330 insertions(+), 58 deletions(-) create mode 100644 src/app/clients/create-address/create-address.component.html create mode 100644 src/app/clients/create-address/create-address.component.scss create mode 100644 src/app/clients/create-address/create-address.component.spec.ts create mode 100644 src/app/clients/create-address/create-address.component.ts diff --git a/src/app/clients/clients-routing.module.ts b/src/app/clients/clients-routing.module.ts index 48cf5af27..862228c0e 100644 --- a/src/app/clients/clients-routing.module.ts +++ b/src/app/clients/clients-routing.module.ts @@ -6,6 +6,7 @@ import { ClientsComponent } from './clients.component'; import { CreateClientComponent} from './create-client/create-client.component'; import { ViewClientComponent } from './view-client/view-client.component'; import { ViewLoanComponent } from './view-loan/view-loan.component'; +import { CreateAddressComponent } from './create-address/create-address.component'; const routes: Routes = [ Route.withShell([ @@ -28,6 +29,11 @@ const routes: Routes = [ path: 'clients/viewloan', component: ViewLoanComponent, data: { title: extract('View Loan') } + }, + { + path: 'clients/address/:id', + component: CreateAddressComponent, + data: { title: extract('Create Address') } } ]) ]; diff --git a/src/app/clients/clients.component.html b/src/app/clients/clients.component.html index bb506cc94..9b27137ac 100644 --- a/src/app/clients/clients.component.html +++ b/src/app/clients/clients.component.html @@ -1,4 +1,4 @@ -
+
@@ -9,19 +9,19 @@ - Name + Name {{row.displayName}} - Account # + Account # {{row.accountNo}} - ExternalID + ExternalID {{row.externalId}} @@ -29,20 +29,20 @@ - Status + Status {{row.active}} - OfficeName + OfficeName {{row.officeName}} - StaffName + StaffName {{row.staffName}} @@ -52,7 +52,7 @@ - +
diff --git a/src/app/clients/clients.component.scss b/src/app/clients/clients.component.scss index a0fe1a069..f633a10bd 100644 --- a/src/app/clients/clients.component.scss +++ b/src/app/clients/clients.component.scss @@ -15,3 +15,12 @@ td, th { .filter{ width: 50%; } + +.inactive { + color: grey; +} + +.active { + color: green; +} + diff --git a/src/app/clients/clients.component.ts b/src/app/clients/clients.component.ts index ab4e9c354..d8b3dcc0c 100644 --- a/src/app/clients/clients.component.ts +++ b/src/app/clients/clients.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit, ViewChild} from '@angular/core'; +import {Component, OnInit, ViewChild, ViewEncapsulation} from '@angular/core'; import {MatPaginator, MatSort, MatTableDataSource} from '@angular/material'; import { Response} from '@angular/http'; import {ClientsService} from './clients.service'; @@ -7,7 +7,9 @@ import { Observable } from 'rxjs'; @Component({ selector: 'mifosx-clients', templateUrl: './clients.component.html', - styleUrls: ['./clients.component.scss'] + styleUrls: ['./clients.component.scss'], + encapsulation: ViewEncapsulation.None + }) export class ClientsComponent implements OnInit { post: any = []; @@ -18,21 +20,24 @@ export class ClientsComponent implements OnInit { @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; - constructor(private clientService: ClientsService) { - // GET from clients API - this.clientService.getClients() - .subscribe( - (res => { - // console.log(res); - this.ELEMENT_DATA = res; - this.dataSource = new MatTableDataSource(this.ELEMENT_DATA); - }) - ); - } + constructor(private clientService: ClientsService) {} ngOnInit() { - this.dataSource.paginator = this.paginator; - this.dataSource.sort = this.sort; + this.getClients(); + } + + // GET from clients API + getClients() { + this.clientService.getClients() + .subscribe( + (res => { + console.log(res); + this.dataSource = new MatTableDataSource(res); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + this.dataSource.sortingDataAccessor = (data, header) => data[header]; + }) + ); } applyFilter(filterValue: string) { diff --git a/src/app/clients/clients.module.ts b/src/app/clients/clients.module.ts index 4a28c9db1..37ecacbb0 100644 --- a/src/app/clients/clients.module.ts +++ b/src/app/clients/clients.module.ts @@ -14,6 +14,7 @@ import { ClientsComponent } from './clients.component'; import { CreateClientComponent} from './create-client/create-client.component'; import { ViewClientComponent } from './view-client/view-client.component'; import { ViewLoanComponent } from './view-loan/view-loan.component'; +import { CreateAddressComponent } from './create-address/create-address.component'; import { ClientsService } from './clients.service'; @@ -28,14 +29,15 @@ import { ClientsService } from './clients.service'; BrowserModule, // tslint:disable HttpModule, MatTableModule, - ArchwizardModule + ArchwizardModule, ], declarations: [ ClientsComponent, CreateClientComponent, ViewClientComponent, - ViewLoanComponent - ], + ViewLoanComponent, + CreateAddressComponent +], providers: [ ClientsService, HttpModule // tslint:disable diff --git a/src/app/clients/clients.service.ts b/src/app/clients/clients.service.ts index 747460c49..137233259 100644 --- a/src/app/clients/clients.service.ts +++ b/src/app/clients/clients.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core'; -import { Http, Headers, Response } from '@angular/http'; +import { Http, Headers, Response, RequestOptions, URLSearchParams } from '@angular/http'; /* import { HttpHeaders, HttpClient } from '@angular/common/http'; */ import { Observable } from 'rxjs'; @@ -141,4 +141,45 @@ export class ClientsService { ) ); } + + getClientAddressTemplate() { + const headers = new Headers(); // tslint:disable-line + this.createAuthorizationHeader(headers); + return this.http.get + ('https://demo.openmf.org/fineract-provider/api/v1/client/' + + 'addresses/template?tenantIdentifier=default', + {headers: headers}) + .pipe( + map( + (response: Response) => { // tslint:disable-line + response = response.json(); + return response; + + } + ) + ); + } + + postClientAddress (clientId: number, body: any, type: any) { + const headers = new Headers(); // tslint:disable-line + const params = new URLSearchParams(); // tslint:disable-line + params.set('type', type); + this.createAuthorizationHeader(headers); + body = JSON.stringify(body); + const options = new RequestOptions({ // tslint:disable-line + headers: headers, + params: params, + }); + return this.http.post + ('https://demo.openmf.org/fineract-provider/api/v1/client/' + clientId + + '/addresses?' + '&tenantIdentifier=default&pretty=true', body , + options) + .pipe( + map( + (response: Response) => { // tslint:disable-line + response.json(); + } + ) + ); + } } diff --git a/src/app/clients/create-address/create-address.component.html b/src/app/clients/create-address/create-address.component.html new file mode 100644 index 000000000..f6e871dd6 --- /dev/null +++ b/src/app/clients/create-address/create-address.component.html @@ -0,0 +1,73 @@ +
+ + + + + +
+ + + + +
+ + +
+ + {{item?.name}} +
+
+
+ + + + + + + + + + + + + + + + + + + + +
+ + {{item?.name}} +
+
+
+ + +
+ + {{item?.name}} +
+
+
+ + + + + + +
+ +
+
+ + +
+ + +
+
+
diff --git a/src/app/clients/create-address/create-address.component.scss b/src/app/clients/create-address/create-address.component.scss new file mode 100644 index 000000000..4ad60da3c --- /dev/null +++ b/src/app/clients/create-address/create-address.component.scss @@ -0,0 +1,17 @@ + + + .example-form { + min-width: 150px; + max-width: 500px; + width: 100%; + } + + .example-full-width { + width: 100%; + padding:5px 3px; + } + + .mat-raised-button{ + margin-left:10px; + margin-top:10px; + } \ No newline at end of file diff --git a/src/app/clients/create-address/create-address.component.spec.ts b/src/app/clients/create-address/create-address.component.spec.ts new file mode 100644 index 000000000..bbfc57503 --- /dev/null +++ b/src/app/clients/create-address/create-address.component.spec.ts @@ -0,0 +1,28 @@ +/* tslint:disable:no-unused-variable */ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { DebugElement } from '@angular/core'; + +import { CreateAddressComponent } from './create-address.component'; + +describe('CreateAddressComponent', () => { + let component: CreateAddressComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ CreateAddressComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(CreateAddressComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/clients/create-address/create-address.component.ts b/src/app/clients/create-address/create-address.component.ts new file mode 100644 index 000000000..80267b638 --- /dev/null +++ b/src/app/clients/create-address/create-address.component.ts @@ -0,0 +1,77 @@ +import { Component, OnInit, ViewEncapsulation, ViewChild } from '@angular/core'; +import { ActivatedRoute, Params } from '@angular/router'; +import { Subscription } from 'rxjs'; +import { NgForm } from '@angular/forms'; +import { Router } from '@angular/router'; + +import { ClientsService } from 'app/clients/clients.service'; + +@Component({ + selector: 'mifosx-app-create-address', + templateUrl: './create-address.component.html', + styleUrls: ['./create-address.component.scss'], + encapsulation: ViewEncapsulation.None + +}) +export class CreateAddressComponent implements OnInit { + id: number = undefined; + paramsSubscription: Subscription; + clientAddress: any = undefined; + value: any = undefined; + mymodel: any = undefined; + addressTypeId: any = undefined; + addressStateId: any = undefined; + addressCountryId: any = undefined; + + address: any = undefined; + + constructor(private route: ActivatedRoute, private clientService: ClientsService) {} + + @ViewChild('f') addressForm: NgForm; + + + ngOnInit() { + this.paramsSubscription = this.route.params + .subscribe( + (params: Params) => { + this.id = params['id']; + } + ); + console.log(this.id); + this.getClientAddressTemplate(); + } + + getClientAddressTemplate() { + this.clientService.getClientAddressTemplate() + .subscribe( + (res => { + this.clientAddress = res; + console.log(res); + }) + ); + } + + onSubmit() { + this.address = {}; + console.log(this.addressTypeId); + this.address.street = this.addressForm.value.street; + this.address.addressLine1 = this.addressForm.value.addressLine1; + this.address.addressLine2 = this.addressForm.value.addressLine2; + this.address.addressLine3 = this.addressForm.value.addressLine3; + this.address.city = this.addressForm.value.city; + this.address.stateProvinceId = this.addressStateId; + this.address.countryId = this.addressCountryId; + this.address.postalCode = this.addressForm.value.postalCode; + + + this.clientService.postClientAddress(this.id, this.address, this.addressTypeId) + .subscribe( + (res => { + return true; + }) + ); + this.addressForm.reset(); + } +} + + diff --git a/src/app/clients/view-client/view-client.component.html b/src/app/clients/view-client/view-client.component.html index 8603fc2d8..155caad38 100644 --- a/src/app/clients/view-client/view-client.component.html +++ b/src/app/clients/view-client/view-client.component.html @@ -69,25 +69,26 @@ Loan Account Overview + - + - + - + @@ -95,20 +96,20 @@ - + - + - + @@ -122,27 +123,25 @@
- -

Savings Account Overview

-
+ Savings Account Overview
-
Account #ng Account #ng {{row.accountNo}} Loan Account Loan Account {{row.productName}} Original Loan Original Loan {{row.originalLoan}} Loan Balance Loan Balance {{row.loanBalance}} Amount Paid Amount Paid {{row.amountPaid}} Type Type {{row.loanType.value}}
+
- + - + - + @@ -150,7 +149,7 @@ - + @@ -160,6 +159,7 @@
Account # Account # {{row.accountNo}} Saving Account Saving Account {{row.productName}} Last Active Last Active {{row.lastActiveTransactionDate}} Balance Balance {{row.accountBalance}}
+
@@ -167,27 +167,25 @@
- -

Shares Account Overview

-
+ Shares Account Overview
- + - + - + @@ -195,7 +193,7 @@ - + @@ -205,15 +203,18 @@
Account # Account # {{row.accountNo}} Share Account# Share Account# {{row.productName}} Approved Shares Approved Shares {{row.totalApprovedShares}} Pending for Approval Shares Pending for Approval Shares {{row.totalPendingForApprovalShares}}
+
- +
+ +
- +
{{item?.addressType}} @@ -243,9 +244,13 @@ {{item?.city}} - State / Province /th> + State / Province {{item?.stateName}} + + Country + {{item?.countryName}} + Postal Code {{item?.postalCode}} @@ -274,9 +279,9 @@ - +
- +
diff --git a/src/app/clients/view-client/view-client.component.ts b/src/app/clients/view-client/view-client.component.ts index 4471b9009..8206d1e98 100644 --- a/src/app/clients/view-client/view-client.component.ts +++ b/src/app/clients/view-client/view-client.component.ts @@ -5,7 +5,7 @@ import { Subscription } from 'rxjs'; import { DataSource } from '@angular/cdk/collections'; import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material'; import { NgForm } from '@angular/forms'; - +import { Router } from '@angular/router'; @Component({ selector: 'mifosx-view-client', templateUrl: './view-client.component.html', @@ -31,13 +31,15 @@ export class ViewClientComponent implements OnInit, OnDestroy { displayedSavingsColumns = ['account', 'savingsAccount', 'lastActive', 'balance']; displayedSharesColumns = ['account', 'shareAccount', 'approvedShares', 'pending']; - dataSourceLoan = new MatTableDataSource(); - dataSourceSavings = new MatTableDataSource(); - dataSourceShares = new MatTableDataSource(); + dataSourceLoan = new MatTableDataSource([]); + dataSourceSavings = new MatTableDataSource([]); + dataSourceShares = new MatTableDataSource([]); @ViewChild('f') noteForm: NgForm; + @ViewChild(MatPaginator) paginator: MatPaginator; + @ViewChild(MatSort) sort: MatSort; - constructor(private route: ActivatedRoute, private clientService: ClientsService) {} + constructor(private route: ActivatedRoute, private clientService: ClientsService, private router: Router) {} ngOnInit() { this.paramsSubscription = this.route.params @@ -85,6 +87,13 @@ export class ViewClientComponent implements OnInit, OnDestroy { this.dataSourceLoan = new MatTableDataSource(this.LOAN_DATA); this.dataSourceSavings = new MatTableDataSource(this.SAVINGS_DATA); this.dataSourceShares = new MatTableDataSource(this.SHARES_DATA); + this.dataSourceLoan.paginator = this.paginator; + this.dataSourceSavings.paginator = this.paginator; + this.dataSourceShares.paginator = this.paginator; + this.dataSourceLoan.sort = this.sort; + this.dataSourceSavings.sort = this.sort; + this.dataSourceShares.sort = this.sort; + }) ); }