committed by
Abhay Chawla
parent
c2bd5d1444
commit
357b3731cc
@@ -5,6 +5,9 @@ import { MatDialog } from '@angular/material';
|
||||
|
||||
/** Custom Services */
|
||||
import { ClientsService } from '../../clients.service';
|
||||
|
||||
/** Custom Components */
|
||||
import { UploadDocumentDialogComponent } from '../upload-document-dialog/upload-document-dialog.component';
|
||||
import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component';
|
||||
|
||||
|
||||
@@ -17,6 +20,7 @@ export class DocumentsTabComponent implements OnInit {
|
||||
@ViewChild('documentsTable') documentsTable: MatTable<Element>;
|
||||
documentsColumns: string[] = ['name', 'description', 'fileName', 'actions'];
|
||||
clientDocuments: any;
|
||||
clientId: string;
|
||||
|
||||
|
||||
constructor(private route: ActivatedRoute,
|
||||
@@ -24,7 +28,10 @@ export class DocumentsTabComponent implements OnInit {
|
||||
public dialog: MatDialog) {
|
||||
this.route.data.subscribe((data: { clientDocuments: any }) => {
|
||||
this.clientDocuments = data.clientDocuments;
|
||||
console.log(this.clientDocuments);
|
||||
|
||||
});
|
||||
this.clientId = this.route.parent.snapshot.paramMap.get('clientId');
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -38,10 +45,10 @@ export class DocumentsTabComponent implements OnInit {
|
||||
}
|
||||
|
||||
deleteDocument(parentEntityId: string, documentId: string, index: number) {
|
||||
const deleteFamilyMemberDialogRef = this.dialog.open(DeleteDialogComponent, {
|
||||
const deleteDocumentDialogRef = this.dialog.open(DeleteDialogComponent, {
|
||||
data: { deleteContext: `document id:${documentId}` }
|
||||
});
|
||||
deleteFamilyMemberDialogRef.afterClosed().subscribe((response: any) => {
|
||||
deleteDocumentDialogRef.afterClosed().subscribe((response: any) => {
|
||||
if (response.delete) {
|
||||
this.clientService.deleteClientDocument(parentEntityId, documentId).subscribe(res => {
|
||||
this.clientDocuments.splice(index, 1);
|
||||
@@ -51,4 +58,31 @@ export class DocumentsTabComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
uploadDocument() {
|
||||
const uploadDocumentDialogRef = this.dialog.open(UploadDocumentDialogComponent, {
|
||||
data: { documentIdentifier: false }
|
||||
});
|
||||
uploadDocumentDialogRef.afterClosed().subscribe((dialogResponse: any) => {
|
||||
console.log(dialogResponse);
|
||||
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();
|
||||
console.log('document Uploaded');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user