feat: add loan button (undo-approval) (#860)

Fixes: #858
This commit is contained in:
Benura Abeywardena
2020-06-11 01:18:12 +05:30
committed by GitHub
parent 8503dc6d97
commit fb52d3cf21
8 changed files with 113 additions and 2 deletions
@@ -1,5 +1,6 @@
<div class="container">
<mat-card>
<mifosx-loans-account-close *ngIf="actions.close"></mifosx-loans-account-close>
<mifosx-undo-approval *ngIf="actions.undo_approval"></mifosx-undo-approval>
</mat-card>
</div>
@@ -1,6 +1,10 @@
import { Component, OnInit } from '@angular/core';
/** Angular Imports. */
import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
/**
* Loan Account Actions component.
*/
@Component({
selector: 'mifosx-loan-account-actions',
templateUrl: './loan-account-actions.component.html',
@@ -9,11 +13,18 @@ import { ActivatedRoute, Router } from '@angular/router';
export class LoanAccountActionsComponent {
/** flag object to store possible actions and render appropriate UI to the user */
actions: { close: boolean } = { close: false };
actions: { close: boolean, undo_approval: boolean } = { close: false, undo_approval: false };
/**
* @param router Router.
* @param route Activated Route.
*/
constructor(private router: Router,
private route: ActivatedRoute) {
this.route.params.subscribe(params => {
if (params['action'].indexOf('-') > 0) {
this.actions[params['action'].replace('-', '_')] = true;
}
this.actions[params['action']] = true;
});
}
@@ -0,0 +1,17 @@
<div class="container">
<mat-card-content>
<mat-form-field fxLayoutAlign="center">
<mat-label>Note</mat-label>
<textarea matInput [formControl]="note"></textarea>
</mat-form-field>
<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" (click)="submit()" *mifosxHasPermission="'APPROVALUNDO_LOAN'">Submit</button>
</mat-card-actions>
</mat-card-content>
</div>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { UndoApprovalComponent } from './undo-approval.component';
describe('UndoApprovalComponent', () => {
let component: UndoApprovalComponent;
let fixture: ComponentFixture<UndoApprovalComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ UndoApprovalComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UndoApprovalComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,45 @@
/** Angular Imports. */
import { Component, OnInit } from '@angular/core';
import { FormControl, FormBuilder } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services. */
import { LoansService } from 'app/loans/loans.service';
/**
* Undo Loan component.
*/
@Component({
selector: 'mifosx-undo-approval',
templateUrl: './undo-approval.component.html',
styleUrls: ['./undo-approval.component.scss']
})
export class UndoApprovalComponent implements OnInit {
/** Form Controller. */
note: FormControl;
/**
* @param loanService Loan Service.
* @param route Activated Route.
* @param router Router.
*/
constructor(private loanService: LoansService,
private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router) { }
ngOnInit() {
this.note = this.formBuilder.control('');
}
/**
* Submits undo approval form.
*/
submit() {
const loanId = this.route.parent.snapshot.params['loanId'];
this.loanService.undoLoanApproval(loanId, {'note': this.note.value}).subscribe((response: any) => {
this.router.navigate(['../general'], {relativeTo: this.route});
});
}
}