feat(notes): Notes feature added with GET/POST (#112)

* feat(notes): Notes feature added with GET/POST
This commit is contained in:
Anwesh Nayak
2018-07-08 09:31:22 +05:30
committed by GitHub
parent c48daa2703
commit 21072b245e
3 changed files with 97 additions and 4 deletions
+35
View File
@@ -106,4 +106,39 @@ export class ClientsService {
) )
); );
} }
getClientNote (clientId: 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
+ '/notes' + '?tenantIdentifier=default&pretty=true',
{headers: headers})
.pipe(
map(
(response: Response) => { // tslint:disable-line
response = response.json();
return response;
}
)
);
}
postClientNote (clientId: number, notes: any) {
const headers = new Headers(); // tslint:disable-line
this.createAuthorizationHeader(headers);
const body = JSON.stringify(notes);
return this.http.post
('https://demo.openmf.org/fineract-provider/api/v1/clients/' + clientId
+ '/notes' + '?tenantIdentifier=default&pretty=true', notes ,
{headers: headers})
.pipe(
map(
(response: Response) => { // tslint:disable-line
response.json();
}
)
);
}
} }
@@ -266,7 +266,29 @@
</div> </div>
</div> </div>
</mat-tab> </mat-tab>
<mat-tab label="First"> Content 1 </mat-tab> <mat-tab label="Notes">
<div fxLayout="row" fxLayoutGap="20px" class="m-t-30" fxLayoutAlign="center center">
<div fxFlex="70%">
<form (ngSubmit)="onSubmit()" #f="ngForm">
<mat-form-field>
<input matInput name="clientnotes" placeholder="Textarea" ngModel>
</mat-form-field>
<mat-card-actions>
<button mat-raised-button>Create</button>
</mat-card-actions>
</form>
<div *ngFor="let item of allNotes">
<mat-card class="m-t-30">
{{item.note}}
</mat-card>
</div>
</div>
</div>
</mat-tab>
<mat-tab label="Second"> Content 2 </mat-tab> <mat-tab label="Second"> Content 2 </mat-tab>
<mat-tab label="Third"> Content 3 </mat-tab> <mat-tab label="Third"> Content 3 </mat-tab>
@@ -275,3 +297,4 @@
</div> </div>
<p>User with ID {{ id }} loaded.</p> <p>User with ID {{ id }} loaded.</p>
@@ -1,9 +1,10 @@
import { ClientsService } from 'app/clients/clients.service'; import { ClientsService } from 'app/clients/clients.service';
import { Component, OnInit, OnDestroy, ViewEncapsulation } from '@angular/core'; import { Component, OnInit, OnDestroy, ViewEncapsulation, ViewChild } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router'; import { ActivatedRoute, Params } from '@angular/router';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { DataSource } from '@angular/cdk/collections'; import { DataSource } from '@angular/cdk/collections';
import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material'; import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
import { NgForm } from '@angular/forms';
@Component({ @Component({
selector: 'mifosx-view-client', selector: 'mifosx-view-client',
@@ -12,7 +13,8 @@ import { MatPaginator, MatSort, MatTableDataSource } from '@angular/material';
encapsulation: ViewEncapsulation.None encapsulation: ViewEncapsulation.None
}) })
export class ViewClientComponent implements OnInit, OnDestroy { export class ViewClientComponent implements OnInit, OnDestroy {
public id: number = undefined; notes: any = undefined;
id: number = undefined;
loanAccounts: any = undefined; loanAccounts: any = undefined;
savingsAccounts: any = undefined; savingsAccounts: any = undefined;
shareAccounts: any = undefined; shareAccounts: any = undefined;
@@ -21,6 +23,7 @@ export class ViewClientComponent implements OnInit, OnDestroy {
paramsSubscription: Subscription; paramsSubscription: Subscription;
post: any = []; post: any = [];
clientAddress: any = undefined; clientAddress: any = undefined;
allNotes: any = undefined;
private LOAN_DATA: any = undefined; private LOAN_DATA: any = undefined;
private SAVINGS_DATA: any = undefined; private SAVINGS_DATA: any = undefined;
private SHARES_DATA: any = undefined; private SHARES_DATA: any = undefined;
@@ -32,6 +35,7 @@ export class ViewClientComponent implements OnInit, OnDestroy {
dataSourceSavings = new MatTableDataSource(); dataSourceSavings = new MatTableDataSource();
dataSourceShares = new MatTableDataSource(); dataSourceShares = new MatTableDataSource();
@ViewChild('f') noteForm: NgForm;
constructor(private route: ActivatedRoute, private clientService: ClientsService) {} constructor(private route: ActivatedRoute, private clientService: ClientsService) {}
@@ -47,6 +51,7 @@ export class ViewClientComponent implements OnInit, OnDestroy {
this.getClientAccounts(this.id); this.getClientAccounts(this.id);
this.getClientCharges(this.id); this.getClientCharges(this.id);
this.getClientAddress(this.id); this.getClientAddress(this.id);
this.getClientNotes(this.id);
} }
getClientId(id: any) { getClientId(id: any) {
@@ -94,7 +99,7 @@ export class ViewClientComponent implements OnInit, OnDestroy {
} }
getClientAddress(id: any) { getClientAddress(id: any) {
this.clientService.getClientAddress(this.id) this.clientService.getClientAddress(id)
.subscribe( .subscribe(
(res => { (res => {
this.clientAddress = res; this.clientAddress = res;
@@ -103,8 +108,38 @@ export class ViewClientComponent implements OnInit, OnDestroy {
); );
} }
getClientNotes(id: any) {
this.clientService.getClientNote(id)
.subscribe(
(res => {
this.allNotes = res;
console.log(res);
})
);
}
onSubmit() {
// this.submitted = true;
this.notes = {};
// const d = new Date();
this.notes.note = this.noteForm.value.clientnotes;
// this.notes.createdOn = d;
console.log(this.notes);
this.clientService.postClientNote(this.id, this.notes)
.subscribe(
(res => {
this.getClientNotes(this.id);
return true;
})
);
this.noteForm.reset();
}
ngOnDestroy() { ngOnDestroy() {
this.paramsSubscription.unsubscribe(); this.paramsSubscription.unsubscribe();
} }
} }