feat: client notes page

- add notes-tab.component
- add edit-note-dialog.coponent

fixes: #111
This commit is contained in:
Jivjyot Singh
2019-12-01 23:20:51 +03:00
committed by Abhay Chawla
parent d84dbf50ed
commit 0cd987cabf
14 changed files with 295 additions and 6 deletions
@@ -56,6 +56,10 @@
[active]="identities.isActive">
Identities
</a>
<a mat-tab-link [routerLink]="['./notes']" routerLinkActive #notes="routerLinkActive"
[active]="notes.isActive">
Notes
</a>
</nav>
<router-outlet></router-outlet>
</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>&nbsp;&nbsp; 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);
});
}
});
}
}