Fix to upload documents (#1621)

Co-authored-by: Jose Alberto Hernandez <alberto@MacBook-Pro.local>
This commit is contained in:
José Alberto Hernández
2023-01-03 20:47:10 -06:00
committed by GitHub
co-authored by Jose Alberto Hernandez
parent 9d19d1b061
commit 28d5d7595f
14 changed files with 227 additions and 284 deletions
@@ -1,26 +1,27 @@
<h1 mat-dialog-title>Upload Client Documents</h1>
<h1 mat-dialog-title>Upload {{ entityType }} Documents</h1>
<div>
<form [formGroup]="uploadDocumentForm" fxLayout="column">
<form [formGroup]="uploadDocumentForm" fxLayout="column">
<mat-form-field fxFlex>
<mat-label>File Name</mat-label>
<input formControlName="fileName" required matInput />
<mat-error *ngIf="uploadDocumentForm.controls.fileName.hasError('required')">
File Name is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex>
<mat-label>File Name</mat-label>
<input formControlName="fileName" required matInput />
<mat-error *ngIf="uploadDocumentForm.controls.fileName.hasError('required')">
File Name is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field fxFlex *ngIf="!documentIdentifier">
<mat-label>Description</mat-label>
<input formControlName="description" matInput />
</mat-form-field>
<mat-form-field fxFlex *ngIf="!documentIdentifier">
<mat-label>Description</mat-label>
<input formControlName="description" matInput />
</mat-form-field>
<mifosx-file-upload flex="60%" (change)="onFileSelect($event)"></mifosx-file-upload>
<mifosx-file-upload flex="60%" (change)="onFileSelect($event)"></mifosx-file-upload>
<mat-dialog-actions align="end">
<button mat-raised-button mat-dialog-close>Cancel</button>
<button mat-raised-button color="primary" [disabled]="!uploadDocumentForm.valid" [mat-dialog-close]="uploadDocumentForm.value">Confirm</button>
</mat-dialog-actions>
<mat-dialog-actions align="end">
<button mat-raised-button mat-dialog-close>Cancel</button>
<button mat-raised-button color="primary" [disabled]="!uploadDocumentForm.valid"
[mat-dialog-close]="uploadDocumentForm.value">Confirm</button>
</mat-dialog-actions>
</form>
</div>
</form>
</div>
@@ -15,6 +15,8 @@ export class UploadDocumentDialogComponent implements OnInit {
uploadDocumentData: any = [];
/** Triggers description field */
documentIdentifier = false;
/** Entity Type */
entityType: string;
/**
* @param {MatDialogRef} dialogRef Dialog reference element
@@ -25,6 +27,7 @@ export class UploadDocumentDialogComponent implements OnInit {
private formBuilder: FormBuilder,
@Inject(MAT_DIALOG_DATA) public data: any) {
this.documentIdentifier = data.documentIdentifier;
this.entityType = data.entityType;
}
ngOnInit() {
@@ -1,47 +1,47 @@
<div class="tab-container mat-typography">
<!-- Documents Table -->
<!-- Documents Table -->
<h3>Documents</h3>
<h3>Documents</h3>
<button mat-raised-button class="f-right" color="primary" (click)="uploadDocument()" *mifosxHasPermission="'CREATE_DOCUMENT'">
<fa-icon icon="plus"></fa-icon>
&nbsp;&nbsp; Add
<button mat-raised-button class="f-right" color="primary" (click)="uploadDocument()"
*mifosxHasPermission="'CREATE_DOCUMENT'">
<fa-icon icon="plus" class="m-r-10"></fa-icon>Add
</button>
<table mat-table #documentsTable [dataSource]="clientDocuments">
<table mat-table #documentsTable [dataSource]="clientDocuments" matSort>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let document">
{{document.name}} </td>
</ng-container>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef> Name </th>
<td mat-cell *matCellDef="let document"> {{document.name}} </td>
</ng-container>
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef> Description </th>
<td mat-cell *matCellDef="let document"> {{document.description}} </td>
</ng-container>
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef> Description </th>
<td mat-cell *matCellDef="let document"> {{document.description}} </td>
</ng-container>
<ng-container matColumnDef="fileName">
<th mat-header-cell *matHeaderCellDef> File Name </th>
<td mat-cell *matCellDef="let document"> {{document.fileName}}
</td>
</ng-container>
<ng-container matColumnDef="fileName">
<th mat-header-cell *matHeaderCellDef> File Name </th>
<td mat-cell *matCellDef="let document"> {{document.fileName}} </td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let document; let i = index">
<button class="document-action-button" mat-raised-button color="primary" (click)="download(document.parentEntityId,document.id)">
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let document; let i = index">
<button class="document-action-button" mat-raised-button color="primary"
(click)="download(document.parentEntityId,document.id)">
<fa-icon icon="cloud-download-alt"></fa-icon>
</button>
<button class="document-action-button" mat-raised-button color="warn" (click)="deleteDocument(document.parentEntityId,document.id,i)">
<button class="document-action-button" mat-raised-button color="warn"
(click)="deleteDocument(document.parentEntityId,document.id,i)">
<fa-icon icon="times"></fa-icon>
</button>
</td>
</ng-container>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="documentsColumns"></tr>
<tr mat-row *matRowDef="let row; columns: documentsColumns;"></tr>
</table>
<tr mat-header-row *matHeaderRowDef="documentsColumns"></tr>
<tr mat-row *matRowDef="let row; columns: documentsColumns;"></tr>
</table>
</div>
</div>
@@ -28,8 +28,6 @@ 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');
}
@@ -60,10 +58,9 @@ export class DocumentsTabComponent implements OnInit {
uploadDocument() {
const uploadDocumentDialogRef = this.dialog.open(UploadDocumentDialogComponent, {
data: { documentIdentifier: false }
data: { documentIdentifier: false, entityType: 'Client' }
});
uploadDocumentDialogRef.afterClosed().subscribe((dialogResponse: any) => {
console.log(dialogResponse);
if (dialogResponse) {
const formData: FormData = new FormData;
formData.append('name', dialogResponse.fileName);
@@ -79,7 +76,6 @@ export class DocumentsTabComponent implements OnInit {
fileName: dialogResponse.file.name
});
this.documentsTable.renderRows();
console.log('document Uploaded');
});
}
});