feat: client notes page
- add notes-tab.component - add edit-note-dialog.coponent fixes: #111
This commit is contained in:
committed by
Abhay Chawla
parent
d84dbf50ed
commit
0cd987cabf
@@ -15,6 +15,7 @@ import { FamilyMembersTabComponent } from './clients-view/family-members-tab/fam
|
|||||||
import { AddFamilyMemberComponent } from './clients-view/family-members-tab/add-family-member/add-family-member.component';
|
import { AddFamilyMemberComponent } from './clients-view/family-members-tab/add-family-member/add-family-member.component';
|
||||||
import { EditFamilyMemberComponent } from './clients-view/family-members-tab/edit-family-member/edit-family-member.component';
|
import { EditFamilyMemberComponent } from './clients-view/family-members-tab/edit-family-member/edit-family-member.component';
|
||||||
import { IdentitiesTabComponent } from './clients-view/identities-tab/identities-tab.component';
|
import { IdentitiesTabComponent } from './clients-view/identities-tab/identities-tab.component';
|
||||||
|
import { NotesTabComponent } from './clients-view/notes-tab/notes-tab.component';
|
||||||
|
|
||||||
/** Custom Resolvers */
|
/** Custom Resolvers */
|
||||||
import { ClientsResolver } from './common-resolvers/clients.resolver';
|
import { ClientsResolver } from './common-resolvers/clients.resolver';
|
||||||
@@ -26,6 +27,7 @@ import { ClientFamilyMembersResolver } from './common-resolvers/client-family-me
|
|||||||
import { ClientFamilyMemberResolver } from './common-resolvers/client-family-member.resolver';
|
import { ClientFamilyMemberResolver } from './common-resolvers/client-family-member.resolver';
|
||||||
import { ClientTemplateResolver } from './common-resolvers/client-template.resolver';
|
import { ClientTemplateResolver } from './common-resolvers/client-template.resolver';
|
||||||
import { ClientIdentitiesResolver } from './common-resolvers/client-identities.resolver';
|
import { ClientIdentitiesResolver } from './common-resolvers/client-identities.resolver';
|
||||||
|
import { ClientNotesResolver } from './common-resolvers/client-notes.resolver';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
Route.withShell([{
|
Route.withShell([{
|
||||||
@@ -92,6 +94,13 @@ const routes: Routes = [
|
|||||||
resolve: {
|
resolve: {
|
||||||
clientIdentities: ClientIdentitiesResolver
|
clientIdentities: ClientIdentitiesResolver
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'notes',
|
||||||
|
component: NotesTabComponent,
|
||||||
|
resolve: {
|
||||||
|
clientNotes: ClientNotesResolver
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -112,7 +121,8 @@ const routes: Routes = [
|
|||||||
ClientFamilyMembersResolver,
|
ClientFamilyMembersResolver,
|
||||||
ClientFamilyMemberResolver,
|
ClientFamilyMemberResolver,
|
||||||
ClientTemplateResolver,
|
ClientTemplateResolver,
|
||||||
ClientIdentitiesResolver
|
ClientIdentitiesResolver,
|
||||||
|
ClientNotesResolver
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class ClientsRoutingModule { }
|
export class ClientsRoutingModule { }
|
||||||
|
|||||||
@@ -56,6 +56,10 @@
|
|||||||
[active]="identities.isActive">
|
[active]="identities.isActive">
|
||||||
Identities
|
Identities
|
||||||
</a>
|
</a>
|
||||||
|
<a mat-tab-link [routerLink]="['./notes']" routerLinkActive #notes="routerLinkActive"
|
||||||
|
[active]="notes.isActive">
|
||||||
|
Notes
|
||||||
|
</a>
|
||||||
</nav>
|
</nav>
|
||||||
<router-outlet></router-outlet>
|
<router-outlet></router-outlet>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<h1 mat-dialog-title>Edit Note</h1>
|
||||||
|
<div>
|
||||||
|
<form #formRef="ngForm" [formGroup]="noteForm">
|
||||||
|
<mat-form-field>
|
||||||
|
<textarea formControlName="note" matInput placeholder="Write a note ...."></textarea>
|
||||||
|
</mat-form-field>
|
||||||
|
<mat-dialog-actions align="end">
|
||||||
|
<button mat-raised-button mat-dialog-close>Cancel</button>
|
||||||
|
<button mat-raised-button color="primary" [disabled]="noteForm.pristine"
|
||||||
|
[mat-dialog-close]="{ editForm: noteForm }">Confirm</button>
|
||||||
|
</mat-dialog-actions>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { EditNotesDialogComponent } from './edit-notes-dialog.component';
|
||||||
|
|
||||||
|
describe('EditNotesDialogComponent', () => {
|
||||||
|
let component: EditNotesDialogComponent;
|
||||||
|
let fixture: ComponentFixture<EditNotesDialogComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ EditNotesDialogComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(EditNotesDialogComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
/** Angular Imports */
|
||||||
|
import { Component, OnInit, Inject } from '@angular/core';
|
||||||
|
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
|
||||||
|
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'mifosx-edit-notes-dialog',
|
||||||
|
templateUrl: './edit-notes-dialog.component.html',
|
||||||
|
styleUrls: ['./edit-notes-dialog.component.scss']
|
||||||
|
})
|
||||||
|
export class EditNotesDialogComponent implements OnInit {
|
||||||
|
noteForm: FormGroup;
|
||||||
|
|
||||||
|
constructor(public dialogRef: MatDialogRef<EditNotesDialogComponent>,
|
||||||
|
private formBuilder: FormBuilder,
|
||||||
|
@Inject(MAT_DIALOG_DATA) public data: any) { }
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.createNoteForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
createNoteForm() {
|
||||||
|
this.noteForm = this.formBuilder.group({
|
||||||
|
'note': [this.data.noteContent, Validators.required]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<div class="tab-container mat-typography">
|
||||||
|
|
||||||
|
<h3>Notes</h3>
|
||||||
|
<div>
|
||||||
|
<form #formRef="ngForm" [formGroup]="noteForm" fxLayout="row" fxLayoutAlign="start baseline" fxLayoutGap="20px"
|
||||||
|
(ngSubmit)="submit()">
|
||||||
|
<mat-form-field fxFlex="calc(90%-20px)">
|
||||||
|
<textarea formControlName="note" matInput placeholder="Write a note ...."></textarea>
|
||||||
|
</mat-form-field>
|
||||||
|
<button mat-raised-button fxFlex color="primary" [disabled]="!noteForm.valid">
|
||||||
|
<fa-icon icon="plus"></fa-icon> Add
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<mat-list>
|
||||||
|
<mat-list-item *ngFor="let clientNote of clientNotes; let i=index;">
|
||||||
|
<fa-icon icon="sticky-note" matListIcon></fa-icon>
|
||||||
|
<h3 matLine>{{clientNote.note}} </h3>
|
||||||
|
<p matLine>
|
||||||
|
<span>Created by: {{clientNote.createdByUsername}}</span><br />
|
||||||
|
<span>Date: {{clientNote.createdOn | date}}</span>
|
||||||
|
</p>
|
||||||
|
<div fxLayout="row" fxLayoutAlign="flex-start">
|
||||||
|
<button mat-button color="primary" (click)="editNote(clientNote.id,clientNote.note,i)">
|
||||||
|
<fa-icon icon="edit"></fa-icon>
|
||||||
|
</button>
|
||||||
|
<button mat-button color="warn" (click)="deleteNote(clientNote.id,i)">
|
||||||
|
<fa-icon icon="trash"></fa-icon>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</mat-list-item>
|
||||||
|
</mat-list>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
.tab-container {
|
||||||
|
padding: 1%;
|
||||||
|
margin: 1%;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { NotesTabComponent } from './notes-tab.component';
|
||||||
|
|
||||||
|
describe('NotesTabComponent', () => {
|
||||||
|
let component: NotesTabComponent;
|
||||||
|
let fixture: ComponentFixture<NotesTabComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [ NotesTabComponent ]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(NotesTabComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { MatDialog } from '@angular/material';
|
||||||
|
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
|
||||||
|
|
||||||
|
/** Custom Components */
|
||||||
|
import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component';
|
||||||
|
|
||||||
|
/** Custom Services */
|
||||||
|
import { ClientsService } from '../../clients.service';
|
||||||
|
import { EditNotesDialogComponent } from '../edit-notes-dialog/edit-notes-dialog.component';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'mifosx-notes-tab',
|
||||||
|
templateUrl: './notes-tab.component.html',
|
||||||
|
styleUrls: ['./notes-tab.component.scss']
|
||||||
|
})
|
||||||
|
export class NotesTabComponent implements OnInit {
|
||||||
|
clientId: string;
|
||||||
|
username: string;
|
||||||
|
clientNotes: any;
|
||||||
|
noteForm: FormGroup;
|
||||||
|
@ViewChild('formRef') formRef: any;
|
||||||
|
|
||||||
|
|
||||||
|
constructor(private route: ActivatedRoute,
|
||||||
|
private formBuilder: FormBuilder,
|
||||||
|
private clientsService: ClientsService,
|
||||||
|
public dialog: MatDialog) {
|
||||||
|
|
||||||
|
this.username = JSON.parse(sessionStorage.getItem('mifosXCredentials')).username;
|
||||||
|
this.clientId = this.route.parent.snapshot.params['clientId'];
|
||||||
|
this.route.data.subscribe((data: { clientNotes: any }) => {
|
||||||
|
this.clientNotes = data.clientNotes;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.createNoteForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
createNoteForm() {
|
||||||
|
this.noteForm = this.formBuilder.group({
|
||||||
|
'note': ['', Validators.required]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
submit() {
|
||||||
|
this.clientsService.createClientNote(this.clientId, this.noteForm.value).subscribe((response: any) => {
|
||||||
|
this.clientNotes.push({
|
||||||
|
id: response.resourceId,
|
||||||
|
createdByUsername: this.username,
|
||||||
|
createdOn: new Date(),
|
||||||
|
note: this.noteForm.value.note
|
||||||
|
});
|
||||||
|
this.formRef.resetForm();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
editNote(noteId: string, noteContent: string, index: number) {
|
||||||
|
const editNoteDialogRef = this.dialog.open(EditNotesDialogComponent, {
|
||||||
|
data: { noteContent: noteContent }
|
||||||
|
});
|
||||||
|
editNoteDialogRef.afterClosed().subscribe((response: { editForm: any }) => {
|
||||||
|
if (response.editForm) {
|
||||||
|
this.clientsService.editClientNote(this.clientId, noteId, response.editForm.value).subscribe(() => {
|
||||||
|
this.clientNotes[index].note = response.editForm.value.note;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
deleteNote(noteId: string, index: number) {
|
||||||
|
const deleteNoteDialogRef = this.dialog.open(DeleteDialogComponent, {
|
||||||
|
data: { deleteContext: `Note id:${noteId}` }
|
||||||
|
});
|
||||||
|
deleteNoteDialogRef.afterClosed().subscribe((response: any) => {
|
||||||
|
if (response.delete) {
|
||||||
|
this.clientsService.deleteClientNote(this.clientId, noteId)
|
||||||
|
.subscribe(() => {
|
||||||
|
this.clientNotes.splice(index, 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,17 +5,19 @@ import { DatePipe } from '@angular/common';
|
|||||||
/** Custom Modules */
|
/** Custom Modules */
|
||||||
import { ClientsRoutingModule } from './clients-routing.module';
|
import { ClientsRoutingModule } from './clients-routing.module';
|
||||||
import { SharedModule } from 'app/shared/shared.module';
|
import { SharedModule } from 'app/shared/shared.module';
|
||||||
|
import {PipesModule} from '../pipes/pipes.module';
|
||||||
|
|
||||||
/** Custom Components */
|
/** Custom Components */
|
||||||
import { ClientsComponent } from './clients.component';
|
import { ClientsComponent } from './clients.component';
|
||||||
import { ClientsViewComponent } from './clients-view/clients-view.component';
|
import { ClientsViewComponent } from './clients-view/clients-view.component';
|
||||||
import { GeneralTabComponent } from './clients-view/general-tab/general-tab.component';
|
import { GeneralTabComponent } from './clients-view/general-tab/general-tab.component';
|
||||||
import {PipesModule} from '../pipes/pipes.module';
|
|
||||||
import { FamilyMembersTabComponent } from './clients-view/family-members-tab/family-members-tab.component';
|
import { FamilyMembersTabComponent } from './clients-view/family-members-tab/family-members-tab.component';
|
||||||
import { AddFamilyMemberComponent } from './clients-view/family-members-tab/add-family-member/add-family-member.component';
|
import { AddFamilyMemberComponent } from './clients-view/family-members-tab/add-family-member/add-family-member.component';
|
||||||
import { EditFamilyMemberComponent } from './clients-view/family-members-tab/edit-family-member/edit-family-member.component';
|
import { EditFamilyMemberComponent } from './clients-view/family-members-tab/edit-family-member/edit-family-member.component';
|
||||||
import { IdentitiesTabComponent } from './clients-view/identities-tab/identities-tab.component';
|
import { IdentitiesTabComponent } from './clients-view/identities-tab/identities-tab.component';
|
||||||
import { UploadDocumentDialogComponent } from './clients-view/upload-document-dialog/upload-document-dialog.component';
|
import { UploadDocumentDialogComponent } from './clients-view/upload-document-dialog/upload-document-dialog.component';
|
||||||
|
import { NotesTabComponent } from './clients-view/notes-tab/notes-tab.component';
|
||||||
|
import { EditNotesDialogComponent } from './clients-view/edit-notes-dialog/edit-notes-dialog.component';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,10 +39,13 @@ import { UploadDocumentDialogComponent } from './clients-view/upload-document-di
|
|||||||
AddFamilyMemberComponent,
|
AddFamilyMemberComponent,
|
||||||
EditFamilyMemberComponent,
|
EditFamilyMemberComponent,
|
||||||
IdentitiesTabComponent,
|
IdentitiesTabComponent,
|
||||||
UploadDocumentDialogComponent
|
UploadDocumentDialogComponent,
|
||||||
|
NotesTabComponent,
|
||||||
|
EditNotesDialogComponent
|
||||||
],
|
],
|
||||||
entryComponents: [
|
entryComponents: [
|
||||||
UploadDocumentDialogComponent
|
UploadDocumentDialogComponent,
|
||||||
|
EditNotesDialogComponent
|
||||||
],
|
],
|
||||||
providers: [DatePipe]
|
providers: [DatePipe]
|
||||||
|
|
||||||
|
|||||||
@@ -87,4 +87,20 @@ export class ClientsService {
|
|||||||
uploadClientIdentifierDocument(identifierId: string, documentData: any) {
|
uploadClientIdentifierDocument(identifierId: string, documentData: any) {
|
||||||
return this.http.post(`/client_identifiers/${identifierId}/documents`, documentData);
|
return this.http.post(`/client_identifiers/${identifierId}/documents`, documentData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getClientNotes(clientId: string) {
|
||||||
|
return this.http.get(`/clients/${clientId}/notes`);
|
||||||
|
}
|
||||||
|
|
||||||
|
createClientNote(clientId: string, noteData: any) {
|
||||||
|
return this.http.post(`/clients/${clientId}/notes`, noteData);
|
||||||
|
}
|
||||||
|
|
||||||
|
editClientNote(clientId: string, noteId: string, noteData: any) {
|
||||||
|
return this.http.put(`/clients/${clientId}/notes/${noteId}`, noteData);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteClientNote(clientId: string, noteId: string) {
|
||||||
|
return this.http.delete(`/clients/${clientId}/notes/${noteId}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/** 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';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client Notes resolver.
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class ClientNotesResolver implements Resolve<Object> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ClientsService} ClientsService Clients service.
|
||||||
|
*/
|
||||||
|
constructor(private clientsService: ClientsService) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the Client's Notes.
|
||||||
|
* @returns {Observable<any>}
|
||||||
|
*/
|
||||||
|
resolve(route: ActivatedRouteSnapshot): Observable<any> {
|
||||||
|
const clientId = route.parent.paramMap.get('clientId');
|
||||||
|
return this.clientsService.getClientNotes(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -69,7 +69,8 @@ import {
|
|||||||
faDownload,
|
faDownload,
|
||||||
faCloudDownloadAlt,
|
faCloudDownloadAlt,
|
||||||
faCloudUploadAlt,
|
faCloudUploadAlt,
|
||||||
faTimes
|
faTimes,
|
||||||
|
faStickyNote
|
||||||
} from '@fortawesome/free-solid-svg-icons';
|
} from '@fortawesome/free-solid-svg-icons';
|
||||||
|
|
||||||
/** Add icons to the library for convenient access in other components. */
|
/** Add icons to the library for convenient access in other components. */
|
||||||
@@ -138,7 +139,8 @@ library.add(
|
|||||||
faDownload,
|
faDownload,
|
||||||
faCloudDownloadAlt,
|
faCloudDownloadAlt,
|
||||||
faCloudUploadAlt,
|
faCloudUploadAlt,
|
||||||
faTimes
|
faTimes,
|
||||||
|
faStickyNote
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user