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
+11 -3
View File
@@ -29,6 +29,9 @@ import { MaterialModule } from './material.module';
import { TranslateModule } from '@ngx-translate/core';
import { ExternalIdentifierComponent } from './external-identifier/external-identifier.component';
import { PipesModule } from 'app/pipes/pipes.module';
import { EntityNotesTabComponent } from './tabs/entity-notes-tab/entity-notes-tab.component';
import { EntityDocumentsTabComponent } from './tabs/entity-documents-tab/entity-documents-tab.component';
import { DirectivesModule } from 'app/directives/directives.module';
/**
* Shared Module
@@ -42,7 +45,8 @@ import { PipesModule } from 'app/pipes/pipes.module';
MaterialModule,
ReactiveFormsModule,
TranslateModule.forRoot(),
PipesModule
PipesModule,
DirectivesModule
],
declarations: [
FormfieldComponent,
@@ -63,7 +67,9 @@ import { PipesModule } from 'app/pipes/pipes.module';
SearchToolComponent,
ServerSelectorComponent,
TenantSelectorComponent,
ExternalIdentifierComponent
ExternalIdentifierComponent,
EntityNotesTabComponent,
EntityDocumentsTabComponent
],
exports: [
FileUploadComponent,
@@ -81,7 +87,9 @@ import { PipesModule } from 'app/pipes/pipes.module';
ReactiveFormsModule,
TranslateModule,
TenantSelectorComponent,
ExternalIdentifierComponent
ExternalIdentifierComponent,
EntityNotesTabComponent,
EntityDocumentsTabComponent
]
})
export class SharedModule { }
@@ -0,0 +1,50 @@
<div class="tab-container mat-typography">
<div fxLayout="row" fxLayoutAlign="start center">
<h3 fxFlex="90%">Documents</h3>
<div fxFlex="10%" *mifosxHasPermission="'CREATE_DOCUMENT'">
<button mat-raised-button class="f-right" color="primary" (click)="uploadDocument()">
<fa-icon icon="plus" class="m-r-10"></fa-icon>Add
</button>
</div>
</div>
<table mat-table #documentsTable [dataSource]="dataSource" matSort>
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Name </th>
<td mat-cell *matCellDef="let document"> {{ document.name }} </td>
</ng-container>
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Description </th>
<td mat-cell *matCellDef="let document"> {{ document.description }} </td>
</ng-container>
<ng-container matColumnDef="filename">
<th mat-header-cell *matHeaderCellDef mat-sort-header> File Name </th>
<td mat-cell *matCellDef="let document"> {{ document.fileName }} </td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Actions </th>
<td mat-cell *matCellDef="let document; let index">
<button class="document-action-button" mat-raised-button color="primary"
(click)="downloadDocument(document.id)">
<fa-icon icon="cloud-download-alt"></fa-icon>
</button>
<button class="document-action-button" mat-raised-button color="warn"
(click)="deleteDocument(document.id, document.name)">
<fa-icon icon="times"></fa-icon>
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator *ngIf="entityDocuments.length > 10" [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
</div>
@@ -0,0 +1,15 @@
table {
width: 100%;
margin-top: 3%;
.document-action-button {
min-width: 26px;
padding: 0 6px;
margin: 4px;
line-height: 25px;
}
}
.tab-container {
padding: 1%;
margin: 1%;
}
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { EntityDocumentsTabComponent } from './entity-documents-tab.component';
describe('EntityDocumentsTabComponent', () => {
let component: EntityDocumentsTabComponent;
let fixture: ComponentFixture<EntityDocumentsTabComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ EntityDocumentsTabComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(EntityDocumentsTabComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,108 @@
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { MatTable, MatTableDataSource } from '@angular/material/table';
import { UploadDocumentDialogComponent } from 'app/clients/clients-view/custom-dialogs/upload-document-dialog/upload-document-dialog.component';
import { ClientsService } from 'app/clients/clients.service';
import { LoansService } from 'app/loans/loans.service';
import { SavingsService } from 'app/savings/savings.service';
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
import { Observable } from 'rxjs';
@Component({
selector: 'mifosx-entity-documents-tab',
templateUrl: './entity-documents-tab.component.html',
styleUrls: ['./entity-documents-tab.component.scss']
})
export class EntityDocumentsTabComponent implements OnInit {
@ViewChild('documentsTable', { static: true }) documentsTable: MatTable<Element>;
@Input() entityId: string;
@Input() entityType: string;
@Input() entityDocuments: any;
@Input() callbackUpload: (documentData: FormData) => Observable<any>;
@Input() callbackDownload: (documentId: string) => void;
@Input() callbackDelete: (documentId: string) => void;
/** Status of the loan account */
status: any;
/** Choice */
choice: boolean;
/** Columns to be displayed in loan documents table. */
displayedColumns: string[] = ['name', 'description', 'filename', 'actions'];
/** Data source for loan documents table. */
dataSource: MatTableDataSource<any>;
/** Paginator for codes table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for codes table. */
@ViewChild(MatSort) sort: MatSort;
/**
*
* @param {MatDialog} dialog Dialog for Inputs.
* @param {SavingsService} savingsService Savings Account services.
* @param {LoansService} loansService Loan Account services.
* @param {ClientsService} clientsService Client services.
*/
constructor(public dialog: MatDialog,
private savingsService: SavingsService,
private loansService: LoansService,
private clientsService: ClientsService) { }
ngOnInit() {
this.dataSource = new MatTableDataSource(this.entityDocuments);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
downloadDocument(documentId: string) {
this.callbackDownload(documentId);
}
uploadDocument() {
const uploadDocumentDialogRef = this.dialog.open(UploadDocumentDialogComponent, {
data: { documentIdentifier: false, entityType: 'Loan' }
});
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.callbackUpload(formData).subscribe((res: any) => {
this.entityDocuments.push({
id: res.resourceId,
parentEntityType: this.entityType,
parentEntityId: this.entityId,
name: dialogResponse.fileName,
description: dialogResponse.description,
fileName: dialogResponse.file.name
});
this.documentsTable.renderRows();
});
}
});
}
deleteDocument(documentId: string, name: number) {
const deleteDocumentDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `Document: ${name}` }
});
deleteDocumentDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.callbackDelete(documentId);
for (let i = 0; i < this.entityDocuments.length; i++) {
if (this.entityDocuments[i].id === documentId) {
this.entityDocuments.splice(i, 1);
}
}
this.documentsTable.renderRows();
}
});
}
}
@@ -0,0 +1,35 @@
<div class="tab-container mat-typography">
<h3>Notes</h3>
<div>
<form #formRef="ngForm" [formGroup]="noteForm" fxLayout="row" fxLayoutAlign="start baseline" fxLayoutGap="20px"
(ngSubmit)="addNote()">
<mat-form-field fxFlex="calc(90%-20px)">
<textarea required formControlName="note" matInput placeholder="Write a note ...." cdkTextareaAutosize cdkAutosizeMinRows="2"></textarea>
</mat-form-field>
<button mat-raised-button fxFlex color="primary" [disabled]="!noteForm.valid">
<fa-icon icon="plus" class="m-r-10"></fa-icon>Add
</button>
</form>
</div>
<mat-list>
<mat-list-item *ngFor="let entityNote of entityNotes; let i=index;">
<fa-icon icon="sticky-note" matListIcon></fa-icon>
<h3 matLine>{{ entityNote.note }} </h3>
<p matLine>
<span>Created by: {{entityNote.createdByUsername}}</span><br />
<span>Date: {{entityNote.createdOn | dateFormat}}</span>
</p>
<div fxLayout="row" fxLayoutAlign="flex-start">
<button mat-button color="primary" (click)="editNote(entityNote.id, entityNote.note, i)">
<fa-icon icon="edit"></fa-icon>
</button>
<button mat-button color="warn" (click)="deleteNote(entityNote.id, i)">
<fa-icon icon="trash"></fa-icon>
</button>
</div>
</mat-list-item>
</mat-list>
</div>
@@ -0,0 +1,4 @@
.tab-container {
padding: 1%;
margin: 1%;
}
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { EntityNotesTabComponent } from './entity-notes-tab.component';
describe('EntityNotesTabComponent', () => {
let component: EntityNotesTabComponent;
let fixture: ComponentFixture<EntityNotesTabComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ EntityNotesTabComponent ]
})
.compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(EntityNotesTabComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,83 @@
import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ClientsService } from 'app/clients/clients.service';
import { LoansService } from 'app/loans/loans.service';
import { SavingsService } from 'app/savings/savings.service';
import { DeleteDialogComponent } from 'app/shared/delete-dialog/delete-dialog.component';
import { FormDialogComponent } from 'app/shared/form-dialog/form-dialog.component';
@Component({
selector: 'mifosx-entity-notes-tab',
templateUrl: './entity-notes-tab.component.html',
styleUrls: ['./entity-notes-tab.component.scss']
})
export class EntityNotesTabComponent implements OnInit {
@ViewChild('formRef', { static: true }) formRef: any;
@Input() entityId: string;
@Input() entityNotes: any;
@Input() callbackAdd: (note: any) => void;
@Input() callbackEdit: (noteId: string, note: string, index: number) => void;
@Input() callbackDelete: (noteId: string, index: number) => void;
noteForm: FormGroup;
constructor(private formBuilder: FormBuilder,
private savingsService: SavingsService,
private loansService: LoansService,
private clientsService: ClientsService,
private dialog: MatDialog) { }
ngOnInit() {
this.createNoteForm();
}
createNoteForm() {
this.noteForm = this.formBuilder.group({
'note': ['', Validators.required]
});
}
addNote() {
this.callbackAdd(this.noteForm.value);
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 && response.data.value.note !== noteContent) {
this.callbackEdit(noteId, response.data.value, index);
}
});
}
deleteNote(noteId: string, index: number) {
const deleteNoteDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `Note: ${this.entityNotes[index].note}` }
});
deleteNoteDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.callbackDelete(noteId, index);
}
});
}
}