feat: standing instructions history (#1177)

Fixes: #1176
This commit is contained in:
Karan Takalkar
2020-08-05 17:04:59 +05:30
committed by GitHub
parent eefb325bdd
commit 8a783a3394
10 changed files with 362 additions and 6 deletions
@@ -0,0 +1,141 @@
<div class="container input">
<mat-card *ngIf="!isCollapsed">
<form [formGroup]="instructionForm" (ngSubmit)="search()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Client Name</mat-label>
<input matInput formControlName="clientName">
</mat-form-field>
<mat-form-field>
<mat-label>Client Id</mat-label>
<input matInput formControlName="clientId">
</mat-form-field>
<mat-form-field>
<mat-label>Transfer Type</mat-label>
<mat-select formControlName="transferType">
<mat-option *ngFor="let transferType of standingInstructionsTemplate.transferTypeOptions" [value]="transferType.id">
{{ transferType.value }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field>
<mat-label>Account Type</mat-label>
<mat-select formControlName="fromAccountType">
<mat-option *ngFor="let accountType of standingInstructionsTemplate.fromAccountTypeOptions" [value]="accountType.id">
{{ accountType.value }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field *ngIf="instructionForm.contains('fromAccountId')">
<mat-label>From Account ID</mat-label>
<input matInput formControlName="fromAccountId">
</mat-form-field>
<mat-form-field>
<mat-label>From Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" formControlName="fromDate" [matDatepicker]="fromDatePicker">
<mat-datepicker-toggle matSuffix [for]="fromDatePicker"></mat-datepicker-toggle>
<mat-datepicker #fromDatePicker></mat-datepicker>
</mat-form-field>
<mat-form-field>
<mat-label>To Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" formControlName="toDate" [matDatepicker]="toDatePicker">
<mat-datepicker-toggle matSuffix [for]="toDatePicker"></mat-datepicker-toggle>
<mat-datepicker #toDatePicker></mat-datepicker>
</mat-form-field>
</div>
</mat-card-content>
<mat-card-actions fxLayout="row" fxLayout.xs="column" fxLayoutAlign="center" fxLayoutGap="5px">
<button type="button" mat-raised-button [routerLink]="['../']">Cancel</button>
<button mat-raised-button color="primary">
<fa-icon icon="search"></fa-icon>
&nbsp; Search Instructions
</button>
</mat-card-actions>
</form>
</mat-card>
</div>
<div class="container output" *ngIf="isCollapsed">
<mat-card>
<div class="m-b-20">
<button mat-raised-button color="primary" (click)="isCollapsed = false">
Parameters
</button>
</div>
<table class="mat-elevation-z1" mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="fromClient">
<th mat-header-cell *matHeaderCellDef mat-sort-header> From Client </th>
<td mat-cell *matCellDef="let instruction"> {{ instruction.fromClient.displayName }}({{ instruction.fromClient.id }}) </td>
</ng-container>
<ng-container matColumnDef="fromAccount">
<th mat-header-cell *matHeaderCellDef mat-sort-header> From Account </th>
<td mat-cell *matCellDef="let instruction"> {{ instruction.fromAccount.productName }}({{ instruction.fromAccount.id }}) </td>
</ng-container>
<ng-container matColumnDef="toClient">
<th mat-header-cell *matHeaderCellDef mat-sort-header> To Client </th>
<td mat-cell *matCellDef="let instruction"> {{ instruction.toClient.displayName }}({{ instruction.toClient.id }}) </td>
</ng-container>
<ng-container matColumnDef="toAccount">
<th mat-header-cell *matHeaderCellDef mat-sort-header> To Account </th>
<td mat-cell *matCellDef="let instruction"> {{ instruction.toAccount.productName }}({{ instruction.toAccount.id }}) </td>
</ng-container>
<ng-container matColumnDef="executionTime">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Execution Time </th>
<td mat-cell *matCellDef="let instruction"> {{ instruction.executionTime }} </td>
</ng-container>
<ng-container matColumnDef="amount">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Amount </th>
<td mat-cell *matCellDef="let instruction"> {{ instruction.amount | number }} </td>
</ng-container>
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Status </th>
<td mat-cell *matCellDef="let instruction"> {{ instruction.status }} </td>
</ng-container>
<ng-container matColumnDef="errorLog">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Error Log </th>
<td mat-cell *matCellDef="let instruction">
<button *ngIf="instruction.status === 'failed'" class="error-log" mat-raised-button color="warn" [matTooltip]="instruction.errorLog">
<i class="fa fa-exclamation"></i>
</button>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table>
<mat-paginator [pageSizeOptions]="[10, 25, 50, 100]" showFirstLastButtons></mat-paginator>
</mat-card>
</div>
@@ -0,0 +1,12 @@
.input {
max-width: 37rem;
}
.output {
.error-log{
min-width: 26px;
padding: 0 6px;
margin: 4px;
line-height: 25px;
}
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { StandingInstructionsHistoryComponent } from './standing-instructions-history.component';
describe('StandingInstructionsHistoryComponent', () => {
let component: StandingInstructionsHistoryComponent;
let fixture: ComponentFixture<StandingInstructionsHistoryComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ StandingInstructionsHistoryComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(StandingInstructionsHistoryComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,115 @@
/** Angular Imports */
import { Component, OnInit, ViewChild } from '@angular/core';
import { MatTableDataSource, MatPaginator, MatSort, MatTable } from '@angular/material';
import { FormGroup, FormBuilder, FormControl } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { DatePipe } from '@angular/common';
/** Custom Services */
import { OrganizationService } from '../organization.service';
/**
* View Standing Instructions History Component.
*/
@Component({
selector: 'mifosx-standing-instructions-history',
templateUrl: './standing-instructions-history.component.html',
styleUrls: ['./standing-instructions-history.component.scss']
})
export class StandingInstructionsHistoryComponent implements OnInit {
/** Minimum Date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum Date allowed. */
maxDate = new Date();
/** Instruction form. */
instructionForm: FormGroup;
/** Standing Instructions Template */
standingInstructionsTemplate: any;
/** Toggles b/w form and table */
isCollapsed = false;
/** Columns to be displayed in instructions table. */
displayedColumns: string[] = ['fromClient', 'fromAccount', 'toClient', 'toAccount', 'executionTime', 'amount', 'status', 'errorLog'];
/** Data source for instructions table. */
dataSource: MatTableDataSource<any>;
/** Paginator for instructions table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for instructions table. */
@ViewChild(MatSort) sort: MatSort;
/**
* Retrieves the instructions template from `resolve`.
* @param {FormBuilder} formBuilder Form Builder.
* @param {OrganizationService} organizationService Organization Service.
* @param {ActivatedRoute} route Activated Route.
* @param {Router} router Router for navigation.
* @param {DatePipe} datePipe Date Pipe to format date.
*/
constructor(private formBuilder: FormBuilder,
private organizationService: OrganizationService,
private router: Router,
private route: ActivatedRoute,
private datePipe: DatePipe) {
this.route.data.subscribe((data: { standingInstructionsTemplate: any }) => {
this.standingInstructionsTemplate = data.standingInstructionsTemplate;
});
}
ngOnInit() {
this.createInstructionForm();
this.buildDependencies();
}
/**
* Creates the Instruction Form
*/
createInstructionForm() {
this.instructionForm = this.formBuilder.group({
'clientName': [''],
'clientId': [''],
'transferType': [''],
'fromAccountType': [''],
'fromDate': [''],
'toDate': ['']
});
}
/**
* Sets conditional child controls.
*/
buildDependencies() {
this.instructionForm.get('fromAccountType').valueChanges.subscribe(() => {
this.instructionForm.addControl('fromAccountId', new FormControl(''));
});
}
/**
* Initializes the data source, paginator and sorter for instructions table.
* @param {any} data
*/
setInstructions(data: any) {
this.dataSource = new MatTableDataSource(data);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
/**
* Searches standing instructions.
*/
search() {
this.isCollapsed = true;
// TODO: Update once language and date settings are setup
const dateFormat = 'dd MMMM yyyy';
const instruction = this.instructionForm.value;
instruction.locale = 'en';
instruction.dateFormat = dateFormat;
instruction.fromDate = this.datePipe.transform(instruction.fromDate, dateFormat);
instruction.toDate = this.datePipe.transform(instruction.toDate, dateFormat);
this.organizationService.getStandingInstructions(instruction).subscribe((response: any) => {
this.setInstructions(response.pageItems);
});
}
}
@@ -0,0 +1,30 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { OrganizationService } from '../organization.service';
/**
* Standing Instructions Template resolver.
*/
@Injectable()
export class StandingInstructionsTemplateResolver implements Resolve<Object> {
/**
* @param {OrganizationService} organizationService Organization service.
*/
constructor(private organizationService: OrganizationService) {}
/**
* Returns the Standing Instruction template.
* @returns {Observable<any>}
*/
resolve(): Observable<any> {
return this.organizationService.getStandingInstructionTemplate();
}
}