@@ -0,0 +1,32 @@
|
||||
<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" *mifosxHasPermission="'CREATE_GROUPNOTE'">
|
||||
<fa-icon icon="plus"></fa-icon> Add
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
<mat-list>
|
||||
<mat-list-item *ngFor="let centerNote of centerNotes; let i=index;">
|
||||
<fa-icon icon="sticky-note" matListIcon></fa-icon>
|
||||
<h3 matLine>{{centerNote.note}} </h3>
|
||||
<p matLine>
|
||||
<span>Created by: {{centerNote.createdByUsername}}</span><br />
|
||||
<span>Date: {{centerNote.createdOn | date}}</span>
|
||||
</p>
|
||||
<div fxLayout="row" fxLayoutAlign="flex-start">
|
||||
<button mat-button color="primary" (click)="editNote(centerNote.id,centerNote.note,i)">
|
||||
<fa-icon icon="edit"></fa-icon>
|
||||
</button>
|
||||
<button mat-button color="warn" (click)="deleteNote(centerNote.id,i)">
|
||||
<fa-icon icon="trash"></fa-icon>
|
||||
</button>
|
||||
</div>
|
||||
</mat-list-item>
|
||||
</mat-list>
|
||||
</div>
|
||||
@@ -0,0 +1,4 @@
|
||||
.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,100 @@
|
||||
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';
|
||||
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
|
||||
|
||||
/** Custom Services */
|
||||
import { CentersService } from '../../centers.service';
|
||||
import { AuthenticationService } from '../../../core/authentication/authentication.service';
|
||||
|
||||
@Component({
|
||||
selector: 'mifosx-notes-tab',
|
||||
templateUrl: './notes-tab.component.html',
|
||||
styleUrls: ['./notes-tab.component.scss']
|
||||
})
|
||||
export class NotesTabComponent implements OnInit {
|
||||
centerId: string;
|
||||
username: string;
|
||||
centerNotes: any;
|
||||
noteForm: FormGroup;
|
||||
@ViewChild('formRef') formRef: any;
|
||||
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
private formBuilder: FormBuilder,
|
||||
private centersService: CentersService,
|
||||
private authenticationService: AuthenticationService,
|
||||
private dialog: MatDialog) {
|
||||
const savedCredentials = this.authenticationService.getCredentials();
|
||||
this.username = savedCredentials.username;
|
||||
this.centerId = this.route.parent.snapshot.params['centerId'];
|
||||
this.route.data.subscribe((data: { centerNotes: any }) => {
|
||||
this.centerNotes = data.centerNotes;
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.createNoteForm();
|
||||
}
|
||||
|
||||
createNoteForm() {
|
||||
this.noteForm = this.formBuilder.group({
|
||||
'note': ['', Validators.required]
|
||||
});
|
||||
}
|
||||
|
||||
submit() {
|
||||
this.centersService.createCenterNote(this.centerId, this.noteForm.value).subscribe((response: any) => {
|
||||
this.centerNotes.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(FormDialogComponent, {
|
||||
data: { formfields: [{
|
||||
controlName: 'note',
|
||||
required: true,
|
||||
value: noteContent,
|
||||
controlType: 'input',
|
||||
label: 'Note'
|
||||
}],
|
||||
layout: {
|
||||
columns: 1,
|
||||
addButtonText: 'Confirm'
|
||||
},
|
||||
title: 'Edit Note'
|
||||
}
|
||||
});
|
||||
editNoteDialogRef.afterClosed().subscribe((response: any) => {
|
||||
if (response.data) {
|
||||
this.centersService.editCenterNote(this.centerId, noteId, response.data.value).subscribe(() => {
|
||||
this.centerNotes[index].note = response.data.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.centersService.deleteCenterNote(this.centerId, noteId)
|
||||
.subscribe(() => {
|
||||
this.centerNotes.splice(index, 1);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user