From 11f277b6bc9ae40f9b79772815189282be832643 Mon Sep 17 00:00:00 2001 From: Anwesh Nayak Date: Tue, 24 Jul 2018 20:33:26 +0530 Subject: [PATCH] feat(client): edit address form (#146) * feat(client): edit address form --- src/app/clients/clients-routing.module.ts | 6 + src/app/clients/clients.module.ts | 4 +- src/app/clients/clients.service.ts | 42 +++++++ .../create-address.component.html | 2 - .../edit-address/edit-address.component.html | 64 +++++++++++ .../edit-address/edit-address.component.scss | 13 +++ .../edit-address.component.spec.ts | 28 +++++ .../edit-address/edit-address.component.ts | 108 ++++++++++++++++++ .../view-client-component-dialog.html | 8 ++ .../view-client/view-client.component.html | 6 +- .../view-client/view-client.component.ts | 58 +++++++++- 11 files changed, 329 insertions(+), 10 deletions(-) create mode 100644 src/app/clients/edit-address/edit-address.component.html create mode 100644 src/app/clients/edit-address/edit-address.component.scss create mode 100644 src/app/clients/edit-address/edit-address.component.spec.ts create mode 100644 src/app/clients/edit-address/edit-address.component.ts create mode 100644 src/app/clients/view-client/view-client-component-dialog.html diff --git a/src/app/clients/clients-routing.module.ts b/src/app/clients/clients-routing.module.ts index 0126969a5..83df39606 100644 --- a/src/app/clients/clients-routing.module.ts +++ b/src/app/clients/clients-routing.module.ts @@ -9,6 +9,7 @@ import { ViewLoanComponent } from './view-loan/view-loan.component'; import { CreateAddressComponent } from './create-address/create-address.component'; import { CreateIdentityComponent } from './create-identity/create-identity.component'; import { UploadDocumentComponent } from './upload-document/upload-document.component'; +import { EditAddressComponent } from './edit-address/edit-address.component'; const routes: Routes = [ Route.withShell([ @@ -37,6 +38,11 @@ const routes: Routes = [ component: CreateAddressComponent, data: { title: extract('Create Address') } }, + { + path: 'clients/editaddress/:id/:addressTypeId/:addressId', + component: EditAddressComponent, + data: { title: extract('Edit Address') } + }, { path: 'clients/addclientidentifier/:id', component: CreateIdentityComponent, diff --git a/src/app/clients/clients.module.ts b/src/app/clients/clients.module.ts index be1ec0dea..94f14d867 100644 --- a/src/app/clients/clients.module.ts +++ b/src/app/clients/clients.module.ts @@ -19,6 +19,7 @@ import { CreateIdentityComponent } from './create-identity/create-identity.compo import { ClientsService } from './clients.service'; import { UploadDocumentComponent } from './upload-document/upload-document.component'; +import { EditAddressComponent } from './edit-address/edit-address.component'; @NgModule({ imports: [ @@ -40,7 +41,8 @@ import { UploadDocumentComponent } from './upload-document/upload-document.compo ViewLoanComponent, CreateAddressComponent, CreateIdentityComponent, - UploadDocumentComponent + UploadDocumentComponent, + EditAddressComponent ], providers: [ ClientsService, diff --git a/src/app/clients/clients.service.ts b/src/app/clients/clients.service.ts index dba31ca41..de5e5ef38 100644 --- a/src/app/clients/clients.service.ts +++ b/src/app/clients/clients.service.ts @@ -183,6 +183,28 @@ export class ClientsService { ); } + putClientAddress(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.put('https://demo.openmf.org/fineract-provider/api/v1/client/' + clientId + + '/addresses?' + 'tenantIdentifier=default', body, + options) + .pipe( + map( + (response: Response) => { // tslint:disable-line + response.json(); + } + ) + ); + } + getClientIdentifierTemplate(clientId: number) { const headers = new Headers(); // tslint:disable-line this.createAuthorizationHeader(headers); @@ -301,5 +323,25 @@ export class ClientsService { ) ); } + + downloadClientDocuments(clientId: number, documentId: number) { + const headers = new Headers(); // tslint:disable-line + this.createAuthorizationHeader(headers); + return this.http.get('https://demo.openmf.org/fineract-provider/api/v1/clients/' + clientId + + '/documents/' + documentId + '/attachment/?tenantIdentifier=default', { + headers: headers + }) + .pipe( + map( + (response: Response) => { // tslint:disable-line + return response.json(); + } + ) + ); + } + + + + } diff --git a/src/app/clients/create-address/create-address.component.html b/src/app/clients/create-address/create-address.component.html index f6e871dd6..d587c67dc 100644 --- a/src/app/clients/create-address/create-address.component.html +++ b/src/app/clients/create-address/create-address.component.html @@ -3,8 +3,6 @@ -
diff --git a/src/app/clients/edit-address/edit-address.component.html b/src/app/clients/edit-address/edit-address.component.html new file mode 100644 index 000000000..e91808eed --- /dev/null +++ b/src/app/clients/edit-address/edit-address.component.html @@ -0,0 +1,64 @@ +
+ + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + +
+ + {{item?.name}} +
+
+
+ + +
+ + {{item?.name}} +
+
+
+ + + + + + +
+ +
+
+ + +
+ + +
+
+
diff --git a/src/app/clients/edit-address/edit-address.component.scss b/src/app/clients/edit-address/edit-address.component.scss new file mode 100644 index 000000000..15edfa57c --- /dev/null +++ b/src/app/clients/edit-address/edit-address.component.scss @@ -0,0 +1,13 @@ +.example-card { + width: 500px; + } + + .example-form { + min-width: 150px; + max-width: 500px; + width: 100%; + } + + .example-full-width { + width: 100%; + } \ No newline at end of file diff --git a/src/app/clients/edit-address/edit-address.component.spec.ts b/src/app/clients/edit-address/edit-address.component.spec.ts new file mode 100644 index 000000000..7e9277a5a --- /dev/null +++ b/src/app/clients/edit-address/edit-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 { EditAddressComponent } from './edit-address.component'; + +describe('EditAddressComponent', () => { + let component: EditAddressComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ EditAddressComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(EditAddressComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/clients/edit-address/edit-address.component.ts b/src/app/clients/edit-address/edit-address.component.ts new file mode 100644 index 000000000..159cd10dc --- /dev/null +++ b/src/app/clients/edit-address/edit-address.component.ts @@ -0,0 +1,108 @@ +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 { FormControl } from '@angular/forms'; +import { ClientsService } from 'app/clients/clients.service'; + +@Component({ + selector: 'mifosx-app-edit-address', + templateUrl: './edit-address.component.html', + styleUrls: ['./edit-address.component.scss'] +}) +export class EditAddressComponent implements OnInit { + + id: number = undefined; + paramsSubscription: Subscription; + clientAddress: any = undefined; + clientAddressK: any = undefined; + value: any = undefined; + mymodel: any = undefined; + addressTypeId: number = undefined; + addressId: number = undefined; + addressStateId: any = undefined; + addressCountryId: any = undefined; + random: any = undefined; + + address: any = undefined; + + form: 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']; + this.addressTypeId = +params['addressTypeId']; + this.addressId = +params['addressId']; + + console.log(this.addressId); + console.log(this.addressTypeId); + } + ); + this.getClientAddressTemplate(); + this.getClientAddress(this.id, this.addressId); + } + + getClientAddressTemplate() { + this.clientService.getClientAddressTemplate() + .subscribe( + (res => { + this.clientAddress = res; + // console.log(res); + }) + ); + } + + getClientAddress(id: any, addressId: any) { + this.clientService.getClientAddress(id) + .subscribe( + (res => { + this.form = {}; + this.clientAddressK = res; + this.clientAddressK.forEach((item: any) => { + if (item.addressId === addressId) { + this.form.street = item.street; + this.form.addressLine1 = item.addressLine1; + this.form.addressLine2 = item.addressLine2; + this.form.addressLine3 = item.addressLine3; + this.form.city = item.city; + this.form.stateProvinceId = item.stateProvinceId; + this.form.countryId = item.countryId; + this.form.postalCode = item.postalCode; + } + }); + }) + ); + } + + onSubmit() { + this.address = {}; + this.address.addressId = this.addressId; + this.address.street = this.form.street; + this.address.addressLine1 = this.form.addressLine1; + this.address.addressLine2 = this.form.addressLine2; + this.address.addressLine3 = this.form.addressLine3; + this.address.city = this.form.city; + this.address.stateProvinceId = this.form.stateProvinceId; + this.address.countryId = this.form.countryId; + this.address.postalCode = this.form.postalCode; + this.address.locale = 'en'; + + console.log(this.address); + + this.clientService.putClientAddress(this.id, this.address, this.addressTypeId) + .subscribe( + (res => { + return true; + }) + ); + } +} + diff --git a/src/app/clients/view-client/view-client-component-dialog.html b/src/app/clients/view-client/view-client-component-dialog.html new file mode 100644 index 000000000..9feb3e42c --- /dev/null +++ b/src/app/clients/view-client/view-client-component-dialog.html @@ -0,0 +1,8 @@ +

Install Angular

+ + Photo of a Shiba Inu + + + + + diff --git a/src/app/clients/view-client/view-client.component.html b/src/app/clients/view-client/view-client.component.html index f46814ea0..dfe1d3803 100644 --- a/src/app/clients/view-client/view-client.component.html +++ b/src/app/clients/view-client/view-client.component.html @@ -264,7 +264,7 @@
- + @@ -373,7 +373,9 @@ Actions - + + + diff --git a/src/app/clients/view-client/view-client.component.ts b/src/app/clients/view-client/view-client.component.ts index 0e62cf5b0..fe5578810 100644 --- a/src/app/clients/view-client/view-client.component.ts +++ b/src/app/clients/view-client/view-client.component.ts @@ -3,7 +3,7 @@ import { Component, OnInit, OnDestroy, ViewEncapsulation, ViewChild } from '@ang import { ActivatedRoute, Params } from '@angular/router'; import { Subscription } from 'rxjs'; import { DataSource } from '@angular/cdk/collections'; -import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material'; +import { MatPaginator, MatSort, MatTableDataSource, MatDialog, MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; import { NgForm } from '@angular/forms'; import { Router } from '@angular/router'; @Component({ @@ -26,6 +26,7 @@ export class ViewClientComponent implements OnInit, OnDestroy { allNotes: any = undefined; clientIdentifiers: any = undefined; clientDocuments: any = undefined; + docId: any = undefined; private LOAN_DATA: any = undefined; private SAVINGS_DATA: any = undefined; private SHARES_DATA: any = undefined; @@ -45,7 +46,8 @@ export class ViewClientComponent implements OnInit, OnDestroy { @ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; - constructor(private route: ActivatedRoute, private clientService: ClientsService, private router: Router) {} + constructor(private route: ActivatedRoute, private clientService: ClientsService, + private router: Router, public dialog: MatDialog) {} ngOnInit() { this.paramsSubscription = this.route.params @@ -62,7 +64,6 @@ export class ViewClientComponent implements OnInit, OnDestroy { this.getClientNotes(this.id); this.getClientIdentifier(this.id); this.getClientDocuments(this.id); - // this.deleteClientDocuments(this.id, this.docId); } getClientId(id: any) { @@ -141,10 +142,8 @@ export class ViewClientComponent implements OnInit, OnDestroy { this.clientIdentifiers = res; this.clientIdentifiers.forEach(function (item: any) { item.status = item.status.split('.')[1]; - console.log(item.status); }); - // this.clientIdentifiers.status = this.clientIdentifiers.status.split('.')[1]; this.dataSourceIdentifiers = new MatTableDataSource(this.clientIdentifiers); this.dataSourceIdentifiers.paginator = this.paginator; this.dataSourceIdentifiers.sort = this.sort; @@ -157,6 +156,7 @@ export class ViewClientComponent implements OnInit, OnDestroy { .subscribe( (res => { this.clientDocuments = res; + this.docId = res.id; this.dataSourceDocuments = new MatTableDataSource(res); this.dataSourceDocuments.paginator = this.paginator; this.dataSourceDocuments.sort = this.sort; @@ -202,6 +202,16 @@ export class ViewClientComponent implements OnInit, OnDestroy { ); } +/* openDialog() { + const dialogRef = this.dialog.open(ViewClientDialogComponent, { + height: '350px' + }); + + dialogRef.afterClosed().subscribe(result => { + console.log(`Dialog result: ${result}`); + }); + } + */ ngOnDestroy() { this.paramsSubscription.unsubscribe(); } @@ -209,3 +219,41 @@ export class ViewClientComponent implements OnInit, OnDestroy { } +/* +@Component({ + selector: 'mifosx-view-client-component-dialog', + templateUrl: 'view-client-component-dialog.html', +}) +export class ViewClientDialogComponent implements OnInit, OnDestroy { + + paramsSubscription: Subscription; + id: any = undefined; + clientDocuments: any = undefined; + constructor(private route: ActivatedRoute, private clientService: ClientsService, + private router: Router, public dialog: MatDialog) {} + + ngOnInit() { + this.paramsSubscription = this.route.params + .subscribe( + (params: Params) => { + this.id = params['id']; + } + ); + this.getClientDocuments(this.id); + } + + getClientDocuments(id: any) { + this.clientService.getClientDocuments(id) + .subscribe( + (res => { + this.clientDocuments = res; + }) + ); + } + + ngOnDestroy() { + this.paramsSubscription.unsubscribe(); + } + +} + */