feat: clients identities page

- add identities-tab component
- add upload-document-dialog component
- remove content-type header from authentication interceptor

fixes: #261
This commit is contained in:
Jivjyot Singh
2019-12-01 23:20:51 +03:00
committed by Abhay Chawla
parent c33995ba77
commit d84dbf50ed
15 changed files with 376 additions and 7 deletions
@@ -0,0 +1,62 @@
<div class="tab-container mat-typography">
<!-- Identities Table -->
<h3>Identities</h3>
<button mat-raised-button class="f-right" color="primary">
<fa-icon icon="plus"></fa-icon>&nbsp;&nbsp; Add
</button>
<table mat-table #identifiersTable [dataSource]="clientIdentities" class="mat-elevation-z1">
<ng-container matColumnDef="id">
<th mat-header-cell *matHeaderCellDef> Id </th>
<td mat-cell *matCellDef="let identity">
{{identity.id}} </td>
</ng-container>
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef> Description </th>
<td mat-cell *matCellDef="let identity"> {{identity.description}} </td>
</ng-container>
<ng-container matColumnDef="type">
<th mat-header-cell *matHeaderCellDef> type </th>
<td mat-cell *matCellDef="let identity"> {{identity.documentType.name}}
</td>
</ng-container>
<ng-container matColumnDef="documents">
<th mat-header-cell *matHeaderCellDef>Identity Documents </th>
<td mat-cell *matCellDef="let identity">
<div *ngFor="let document of identity.documents">
{{document.name}}
<fa-icon icon="cloud-download-alt" (click)="download(document.parentEntityId,document.id)"></fa-icon>
</div>
</td>
</ng-container>
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef> Status </th>
<td mat-cell *matCellDef="let identity">
{{(identity.status==='clientIdentifierStatusType.active')?'active':'inactive'}} </td>
</ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let identity; let i = index">
<button class="identity-action-button" mat-raised-button color="primary" (click)="uploadDocument(i,identity.id)">
<fa-icon icon="cloud-upload-alt"></fa-icon>
</button>
<button class="identity-action-button" mat-raised-button color="warn" (click)="deleteIdentifier(identity.clientId,identity.id,index)">
<fa-icon icon="times"></fa-icon>
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="identitiesColumns"></tr>
<tr mat-row *matRowDef="let row; columns: identitiesColumns;"></tr>
</table>
</div>
@@ -0,0 +1,18 @@
.tab-container {
padding: 1%;
margin: 1%;
h3{
margin:1% auto;
}
table {
width: 100%;
.identity-action-button{
min-width: 26px;
padding: 0 6px;
margin: 4px;
line-height: 25px;
}
}
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { IdentitiesTabComponent } from './identities-tab.component';
describe('IdentitiesTabComponent', () => {
let component: IdentitiesTabComponent;
let fixture: ComponentFixture<IdentitiesTabComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ IdentitiesTabComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(IdentitiesTabComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,75 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MatTable } from '@angular/material/table';
import { MatDialog } from '@angular/material';
/** Custom Components */
import { UploadDocumentDialogComponent } from '../upload-document-dialog/upload-document-dialog.component';
import { DeleteDialogComponent } from '../../../shared/delete-dialog/delete-dialog.component';
/** Custom Services */
import { ClientsService } from '../../clients.service';
@Component({
selector: 'mifosx-identities-tab',
templateUrl: './identities-tab.component.html',
styleUrls: ['./identities-tab.component.scss']
})
export class IdentitiesTabComponent implements OnInit {
@ViewChild('identifiersTable') identifiersTable: MatTable<Element>;
identitiesColumns: string[] = ['id', 'description', 'type', 'documents', 'status', 'actions'];
clientIdentities: any;
constructor(private route: ActivatedRoute,
public dialog: MatDialog,
private clientService: ClientsService) {
this.route.data.subscribe((data: { clientIdentities: any }) => {
this.clientIdentities = data.clientIdentities;
});
}
ngOnInit() {
}
download(parentEntityId: string, documentId: string) {
this.clientService.downloadClientIdentificationDocument(parentEntityId, documentId).subscribe(res => {
const url = window.URL.createObjectURL(res);
window.open(url);
});
}
deleteIdentifier(clientId: string, identifierId: string, index: number) {
const deleteFamilyMemberDialogRef = this.dialog.open(DeleteDialogComponent, {
data: { deleteContext: `identifier id:${identifierId}` }
});
deleteFamilyMemberDialogRef.afterClosed().subscribe((response: any) => {
if (response.delete) {
this.clientService.deleteClientIdentifier(clientId, identifierId).subscribe(res => {
this.clientIdentities.splice(index, 1);
this.identifiersTable.renderRows();
});
}
});
}
uploadDocument(index: number, identifierId: string) {
const uploadDocumentDialogRef = this.dialog.open(UploadDocumentDialogComponent);
uploadDocumentDialogRef.afterClosed().subscribe((dialogResponse: any) => {
if (dialogResponse) {
const formData: FormData = new FormData;
formData.append('name', dialogResponse.fileName);
formData.append('file', dialogResponse.file);
this.clientService.uploadClientIdentifierDocument(identifierId, formData).subscribe((res: any) => {
this.clientIdentities[index].documents.push({
id: res.resourceId,
parentEntityType: 'client_identifiers',
parentEntityId: identifierId,
name: dialogResponse.fileName,
fileName: dialogResponse.file.fileName
});
this.identifiersTable.renderRows();
});
}
});
}
}