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
@@ -44,12 +44,18 @@
</mat-card-header>
<mat-card-content>
<nav mat-tab-nav-bar>
<a mat-tab-link [routerLink]="['./general']" routerLinkActive #general="routerLinkActive" [active]="general.isActive">
<a mat-tab-link [routerLink]="['./general']" routerLinkActive #general="routerLinkActive"
[active]="general.isActive">
General
</a>
<a mat-tab-link [routerLink]="['./family-members']" routerLinkActive #familyMembers="routerLinkActive" [active]="familyMembers.isActive">
<a mat-tab-link [routerLink]="['./family-members']" routerLinkActive #familyMembers="routerLinkActive"
[active]="familyMembers.isActive">
Family Members
</a>
<a mat-tab-link [routerLink]="['./identities']" routerLinkActive #identities="routerLinkActive"
[active]="identities.isActive">
Identities
</a>
</nav>
<router-outlet></router-outlet>
</mat-card-content>
@@ -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();
});
}
});
}
}
@@ -0,0 +1,22 @@
<h1 mat-dialog-title>Upload Client Documents</h1>
<div>
<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>
<input type="file" name="file" (change)="onFileSelect($event)" />
<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>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { UploadDocumentDialogComponent } from './upload-document-dialog.component';
describe('UploadDocumentDialogComponent', () => {
let component: UploadDocumentDialogComponent;
let fixture: ComponentFixture<UploadDocumentDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ UploadDocumentDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UploadDocumentDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,41 @@
import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { FormGroup, FormBuilder, Validators, FormControl } from '@angular/forms';
@Component({
selector: 'mifosx-upload-document-dialog',
templateUrl: './upload-document-dialog.component.html',
styleUrls: ['./upload-document-dialog.component.scss']
})
export class UploadDocumentDialogComponent implements OnInit {
/** Upload Document form. */
uploadDocumentForm: FormGroup;
file: any;
uploadDocumentData: any = [];
constructor(public dialogRef: MatDialogRef<UploadDocumentDialogComponent>,
private formBuilder: FormBuilder,
@Inject(MAT_DIALOG_DATA) public data: any) { }
ngOnInit() {
this.createUploadDocumentForm();
}
/**
* Creates the upload Document form.
*/
createUploadDocumentForm() {
this.uploadDocumentForm = this.formBuilder.group({
'fileName': ['', Validators.required],
'file': ['']
});
}
onFileSelect(event: any) {
if (event.target.files.length > 0) {
const file = event.target.files[0];
this.uploadDocumentForm.get('file').setValue(file);
}
}
}