feat: add center view (notes tab) (#787)

Fixes: #785
This commit is contained in:
Muskan Khedia
2020-05-20 17:50:06 +05:30
committed by GitHub
parent a5711131c7
commit 67b766e61f
9 changed files with 253 additions and 3 deletions
@@ -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);
});
}
});
}
}