-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add notes-tab.component - add edit-note-dialog.coponent fixes: #111
- Loading branch information
Showing
14 changed files
with
295 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/app/clients/clients-view/edit-notes-dialog/edit-notes-dialog.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Empty file.
25 changes: 25 additions & 0 deletions
25
src/app/clients/clients-view/edit-notes-dialog/edit-notes-dialog.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
src/app/clients/clients-view/edit-notes-dialog/edit-notes-dialog.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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] | ||
}); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/app/clients/clients-view/notes-tab/notes-tab.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
5 changes: 5 additions & 0 deletions
5
src/app/clients/clients-view/notes-tab/notes-tab.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.tab-container { | ||
padding: 1%; | ||
margin: 1%; | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/app/clients/clients-view/notes-tab/notes-tab.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |
89 changes: 89 additions & 0 deletions
89
src/app/clients/clients-view/notes-tab/notes-tab.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters