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,84 +1,45 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MatTable } from '@angular/material/table';
import { MatDialog } from '@angular/material/dialog';
/** Custom Services */
import { ClientsService } from '../../clients.service';
/** Custom Components */
import { UploadDocumentDialogComponent } from '../custom-dialogs/upload-document-dialog/upload-document-dialog.component';
import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component';
@Component({
selector: 'mifosx-documents-tab',
templateUrl: './documents-tab.component.html',
styleUrls: ['./documents-tab.component.scss']
})
export class DocumentsTabComponent implements OnInit {
@ViewChild('documentsTable', { static: true }) documentsTable: MatTable<Element>;
documentsColumns: string[] = ['name', 'description', 'fileName', 'actions'];
clientDocuments: any;
clientId: string;
entityDocuments: any;
entityId: string;
entityType: string = 'clients';
constructor(private route: ActivatedRoute,
private clientService: ClientsService,
private clientsService: ClientsService,
public dialog: MatDialog) {
this.route.data.subscribe((data: { clientDocuments: any }) => {
this.clientDocuments = data.clientDocuments;
this.entityDocuments = data.clientDocuments;
});
this.clientId = this.route.parent.snapshot.paramMap.get('clientId');
this.entityId = this.route.parent.snapshot.paramMap.get('clientId');
}
ngOnInit() {
}
download(parentEntityId: string, documentId: string) {
this.clientService.downloadClientDocument(parentEntityId, documentId).subscribe(res => {
downloadDocument(documentId: string) {
this.clientsService.downloadClientDocument(this.entityId, documentId).subscribe(res => {
const url = window.URL.createObjectURL(res);
window.open(url);
});
}
deleteDocument(parentEntityId: string, documentId: string, index: number) {
const deleteDocumentDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `document id:${documentId}` }
});
deleteDocumentDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.clientService.deleteClientDocument(parentEntityId, documentId).subscribe(res => {
this.clientDocuments.splice(index, 1);
this.documentsTable.renderRows();
});
}
});
deleteDocument(documentId: string) {
this.clientsService.deleteClientDocument(this.entityId, documentId).subscribe(res => {});
}
uploadDocument() {
const uploadDocumentDialogRef = this.dialog.open(UploadDocumentDialogComponent, {
data: { documentIdentifier: false, entityType: 'Client' }
});
uploadDocumentDialogRef.afterClosed().subscribe((dialogResponse: any) => {
if (dialogResponse) {
const formData: FormData = new FormData;
formData.append('name', dialogResponse.fileName);
formData.append('file', dialogResponse.file);
formData.append('description', dialogResponse.description);
this.clientService.uploadClientDocument(this.clientId, formData).subscribe((res: any) => {
this.clientDocuments.push({
id: res.resourceId,
parentEntityType: 'clients',
parentEntityId: this.clientId,
name: dialogResponse.fileName,
description: dialogResponse.description,
fileName: dialogResponse.file.name
});
this.documentsTable.renderRows();
});
}
});
uploadDocument(formData: FormData): any {
return this.clientsService.uploadClientDocument(this.entityId, formData);
}
}