Documents and Notes for Clients, Loans and Clients (#1632)

Co-authored-by: Jose Alberto Hernandez <alberto@MacBook-Pro.local>
This commit is contained in:
José Alberto Hernández
2023-01-05 03:19:41 -06:00
committed by GitHub
co-authored by Jose Alberto Hernandez
parent 28d5d7595f
commit cafe8fa73d
57 changed files with 1119 additions and 468 deletions
@@ -1,11 +1,7 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MatDialog } from '@angular/material/dialog';
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 { LoansService } from '../../loans.service';
@@ -18,84 +14,44 @@ import { AuthenticationService } from '../../../core/authentication/authenticati
})
export class NotesTabComponent implements OnInit {
loanId: string;
entityId: string;
username: string;
loanNotes: any;
noteForm: FormGroup;
@ViewChild('formRef', { static: true }) formRef: any;
entityNotes: any;
constructor(private route: ActivatedRoute,
private formBuilder: FormBuilder,
private loansService: LoansService,
private authenticationService: AuthenticationService,
private dialog: MatDialog) {
private authenticationService: AuthenticationService) {
const savedCredentials = this.authenticationService.getCredentials();
this.username = savedCredentials.username;
this.loanId = this.route.parent.snapshot.params['loanId'];
this.entityId = this.route.parent.snapshot.params['loanId'];
this.route.data.subscribe((data: { loanNotes: any }) => {
this.loanNotes = data.loanNotes;
this.entityNotes = data.loanNotes;
});
}
ngOnInit() {
this.createNoteForm();
}
ngOnInit() { }
createNoteForm() {
this.noteForm = this.formBuilder.group({
'note': ['', Validators.required]
});
}
submit() {
this.loansService.createLoanNote(this.loanId, this.noteForm.value).subscribe((response: any) => {
this.loanNotes.push({
addNote(noteContent: any) {
this.loansService.createLoanNote(this.entityId, noteContent).subscribe((response: any) => {
this.entityNotes.push({
id: response.resourceId,
createdByUsername: this.username,
createdOn: new Date(),
note: this.noteForm.value.note
note: noteContent.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.loansService.editLoanNote(this.loanId, noteId, response.data.value).subscribe(() => {
this.loanNotes[index].note = response.data.value.note;
});
}
editNote(noteId: string, noteContent: any, index: number) {
this.loansService.editLoanNote(this.entityId, noteId, noteContent).subscribe(() => {
this.entityNotes[index].note = noteContent.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.loansService.deleteLoanNote(this.loanId, noteId)
.subscribe(() => {
this.loanNotes.splice(index, 1);
});
}
this.loansService.deleteLoanNote(this.entityId, noteId)
.subscribe(() => {
this.entityNotes.splice(index, 1);
});
}