feat: shares account actions (approve) (#890)

Fixes: #889
This commit is contained in:
Karan Takalkar
2020-06-23 15:30:03 +05:30
committed by GitHub
parent 02e2155f15
commit 5701bd1ed0
14 changed files with 298 additions and 72 deletions
@@ -302,7 +302,7 @@
<th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let element">
<button *ngIf="element.status.submittedAndPendingApproval" class="account-action-button" mat-raised-button
color="primary">
color="primary" [routerLink]="['../','sharesaccounts', element.id, 'actions', 'Approve']">
<i class="fa fa-check"></i>
</button>
<button *ngIf="!element.status.submittedAndPendingApproval && !element.status.active"
@@ -0,0 +1,39 @@
<div class="container">
<mat-card>
<form [formGroup]="approveSharesAccountForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Approved On Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="approvedDatePicker" required formControlName="approvedDate">
<mat-datepicker-toggle matSuffix [for]="approvedDatePicker"></mat-datepicker-toggle>
<mat-datepicker #approvedDatePicker></mat-datepicker>
<mat-error *ngIf="approveSharesAccountForm.controls.approvedDate.hasError('required')">
Approved On Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Note</mat-label>
<textarea matInput formControlName="note"></textarea>
</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="accent" [disabled]="!approveSharesAccountForm.valid">Confirm</button>
</mat-card-actions>
</form>
</mat-card>
</div>
@@ -0,0 +1,3 @@
.container {
max-width: 37rem;
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ApproveSharesAccountComponent } from './approve-shares-account.component';
describe('ApproveSharesAccountComponent', () => {
let component: ApproveSharesAccountComponent;
let fixture: ComponentFixture<ApproveSharesAccountComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ApproveSharesAccountComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ApproveSharesAccountComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,76 @@
/** Angular Imports */
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { DatePipe } from '@angular/common';
import { ActivatedRoute, Router } from '@angular/router';
/** Custom Services */
import { SharesService } from 'app/shares/shares.service';
/**
* Approve Shares Account Component
*/
@Component({
selector: 'mifosx-approve-shares-account',
templateUrl: './approve-shares-account.component.html',
styleUrls: ['./approve-shares-account.component.scss']
})
export class ApproveSharesAccountComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Approve Share Account form. */
approveSharesAccountForm: FormGroup;
/** Shares Account Id */
accountId: any;
constructor(private formBuilder: FormBuilder,
private sharesService: SharesService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.accountId = this.route.parent.parent.snapshot.params['shareAccountId'];
}
/**
* Creates the approve shares form.
*/
ngOnInit() {
this.createApproveSharesAccountForm();
}
/**
* Creates the approve shares account form.
*/
createApproveSharesAccountForm() {
this.approveSharesAccountForm = this.formBuilder.group({
'approvedDate': ['', Validators.required],
'note': ['']
});
}
/**
* Submits the form and approves the share account,
* if successful redirects to the share account.
*/
submit() {
// TODO: Update once language and date settings are setup
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const prevApprovedDate: Date = this.approveSharesAccountForm.value.approvedDate;
this.approveSharesAccountForm.patchValue({
approvedDate: this.datePipe.transform(prevApprovedDate, dateFormat),
});
const data = {
...this.approveSharesAccountForm.value,
dateFormat,
locale
};
this.sharesService.executeSharesAccountCommand(this.accountId, 'approve', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -0,0 +1 @@
<mifosx-approve-shares-account *ngIf="actions.Approve"></mifosx-approve-shares-account>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { SharesAccountActionsComponent } from './shares-account-actions.component';
describe('SharesAccountActionsComponent', () => {
let component: SharesAccountActionsComponent;
let fixture: ComponentFixture<SharesAccountActionsComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ SharesAccountActionsComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(SharesAccountActionsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,23 @@
/** Angular Imports */
import { Component } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
/**
* Shares Account Actions Component
*/
@Component({
selector: 'mifosx-shares-account-actions',
templateUrl: './shares-account-actions.component.html',
styleUrls: ['./shares-account-actions.component.scss']
})
export class SharesAccountActionsComponent {
/** Flag object to store possible actions and render appropriate UI to the user */
actions: { Approve: boolean } = { Approve: false };
constructor(private route: ActivatedRoute) {
const name = this.route.snapshot.params['name'];
this.actions[name] = true;
}
}
@@ -67,11 +67,18 @@ export class SharesAccountViewComponent implements OnInit {
}
}
/**
* Performs button action
* @param {string} name Action name
*/
doAction(name: string) {
switch (name) {
case 'Modify Application':
this.router.navigate(['edit-shares-account'], { relativeTo: this.route });
break;
this.router.navigate(['edit-shares-account'], { relativeTo: this.route });
break;
case 'Approve':
this.router.navigate(['actions/Approve'], { relativeTo: this.route });
break;
}
}
@@ -28,57 +28,57 @@ export class SharesButtonsConfiguration {
setButtons(status: string) {
switch (status) {
case 'Active':
this.buttonsArray = [
{
name: 'Apply Additional Shares',
icon: 'fa fa-arrow-right',
taskPermissionName: 'APPLYADDITIONAL_SHAREACCOUNT'
},
{
name: 'Approve Additional Shares',
icon: 'fa fa-arrow-right',
taskPermissionName: 'APPROVEADDITIONAL_SHAREACCOUNT'
},
{
name: 'Reject Additional Shares',
icon: 'fa fa-arrow-right',
taskPermissionName: 'REJECTADDITIONAL_SHAREACCOUNT'
},
{
name: 'Redeem Shares',
icon: 'fa fa-arrow-left',
taskPermissionName: 'WITHDRAW_SAVINGSACCOUNT'
}
];
break;
this.buttonsArray = [
{
name: 'Apply Additional Shares',
icon: 'fa fa-arrow-right',
taskPermissionName: 'APPLYADDITIONAL_SHAREACCOUNT'
},
{
name: 'Approve Additional Shares',
icon: 'fa fa-arrow-right',
taskPermissionName: 'APPROVEADDITIONAL_SHAREACCOUNT'
},
{
name: 'Reject Additional Shares',
icon: 'fa fa-arrow-right',
taskPermissionName: 'REJECTADDITIONAL_SHAREACCOUNT'
},
{
name: 'Redeem Shares',
icon: 'fa fa-arrow-left',
taskPermissionName: 'WITHDRAW_SAVINGSACCOUNT'
}
];
break;
case 'Submitted and pending approval':
this.buttonsArray = [
{
name: 'Modify Application',
icon: 'fa fa-pencil ',
taskPermissionName: 'UPDATE_SHAREACCOUNT'
},
{
name: 'Approve',
icon: 'fa fa-check',
taskPermissionName: 'APPROVE_SHAREACCOUNT'
}
];
break;
this.buttonsArray = [
{
name: 'Modify Application',
icon: 'fa fa-pencil ',
taskPermissionName: 'UPDATE_SHAREACCOUNT'
},
{
name: 'Approve',
icon: 'fa fa-check',
taskPermissionName: 'APPROVE_SHAREACCOUNT'
}
];
break;
case 'Approved':
this.buttonsArray = [
{
name: 'Undo Approval',
icon: 'fa fa-undo',
taskPermissionName: 'APPROVALUNDO_SHAREACCOUNT'
},
{
name: 'Activate',
icon: 'fa fa-check',
taskPermissionName: 'ACTIVATE_SHAREACCOUNT'
}
];
break;
this.buttonsArray = [
{
name: 'Undo Approval',
icon: 'fa fa-undo',
taskPermissionName: 'APPROVALUNDO_SHAREACCOUNT'
},
{
name: 'Activate',
icon: 'fa fa-check',
taskPermissionName: 'ACTIVATE_SHAREACCOUNT'
}
];
break;
default:
this.buttonsArray = [];
}
@@ -86,26 +86,26 @@ export class SharesButtonsConfiguration {
setOptions(status: string) {
switch (status) {
case 'Active':
this.optionArray = [
{
name: 'Close',
taskPermissionName: 'CLOSE_SHAREACCOUNT'
}
];
break;
case 'Active':
this.optionArray = [
{
name: 'Close',
taskPermissionName: 'CLOSE_SHAREACCOUNT'
}
];
break;
case 'Submitted and pending approval':
this.optionArray = [
{
name: 'Reject',
taskPermissionName: 'REJECT_SHAREACCOUNT'
},
{
name: 'Delete',
taskPermissionName: 'DELETE_SHAREACCOUNT'
}
];
break;
this.optionArray = [
{
name: 'Reject',
taskPermissionName: 'REJECT_SHAREACCOUNT'
},
{
name: 'Delete',
taskPermissionName: 'DELETE_SHAREACCOUNT'
}
];
break;
case 'Approved':
default:
this.optionArray = [];
+12
View File
@@ -12,6 +12,7 @@ import { ChargesTabComponent } from './shares-account-view/charges-tab/charges-t
import { DividendsTabComponent } from './shares-account-view/dividends-tab/dividends-tab.component';
import { CreateSharesAccountComponent } from './create-shares-account/create-shares-account.component';
import { EditSharesAccountComponent } from './edit-shares-account/edit-shares-account.component';
import { SharesAccountActionsComponent } from './shares-account-actions/shares-account-actions.component';
/** Custom Resolvers */
import { SharesAccountViewResolver } from './common-resolvers/share-account-view.resolver';
@@ -66,6 +67,17 @@ const routes: Routes = [
resolve: {
sharesAccountAndTemplate: SharesAccountAndTemplateResolver
}
},
{
path: 'actions',
data: { title: extract('Shares Account Actions'), breadcrumb: 'Actions', routeParamBreadcrumb: false },
children: [
{
path: ':name',
data: { routeParamBreadcrumb: 'name' },
component: SharesAccountActionsComponent
}
]
}
]
},
+5 -1
View File
@@ -17,6 +17,8 @@ import { SharesAccountTermsStepComponent } from './shares-account-stepper/shares
import { SharesAccountChargesStepComponent } from './shares-account-stepper/shares-account-charges-step/shares-account-charges-step.component';
import { SharesAccountPreviewStepComponent } from './shares-account-stepper/shares-account-preview-step/shares-account-preview-step.component';
import { EditSharesAccountComponent } from './edit-shares-account/edit-shares-account.component';
import { SharesAccountActionsComponent } from './shares-account-actions/shares-account-actions.component';
import { ApproveSharesAccountComponent } from './shares-account-actions/approve-shares-account/approve-shares-account.component';
/**
* Shares Module
@@ -40,7 +42,9 @@ import { EditSharesAccountComponent } from './edit-shares-account/edit-shares-ac
SharesAccountTermsStepComponent,
SharesAccountChargesStepComponent,
SharesAccountPreviewStepComponent,
EditSharesAccountComponent
EditSharesAccountComponent,
SharesAccountActionsComponent,
ApproveSharesAccountComponent
],
providers: [DatePipe]
})
+11
View File
@@ -50,4 +50,15 @@ export class SharesService {
return this.http.put(`/accounts/share/${accountId}`, sharesAccount);
}
/**
* @param {string} accountId Shares Account Id
* @param {string} command Command
* @param {any} data Data
* @returns {Observable<any>} Shares data.
*/
executeSharesAccountCommand(accountId: string, command: string, data: any): Observable<any> {
const httpParams = new HttpParams().set('command', command);
return this.http.post(`/accounts/share/${accountId}`, data, { params: httpParams });
}
}