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
@@ -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);
});
}
});
}
}