feat: shares account actions (apply-shares) (#902)

Fixes: #901
This commit is contained in:
Karan Takalkar
2020-06-24 02:38:13 +05:30
committed by GitHub
parent 96144d4447
commit 4b36a60517
15 changed files with 231 additions and 33 deletions
@@ -26,12 +26,19 @@ export class ActivateSharesAccountComponent implements OnInit {
/** Shares Account Id */
accountId: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {SharesService} sharesService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
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'];
this.accountId = this.route.parent.snapshot.params['shareAccountId'];
}
/**
@@ -0,0 +1,47 @@
<div class="container">
<mat-card>
<form [formGroup]="applySharesForm" (ngSubmit)="submit()">
<mat-card-content>
<div fxLayout="column">
<mat-form-field>
<mat-label>Request Date</mat-label>
<input matInput [min]="minDate" [max]="maxDate" [matDatepicker]="requestedDatePicker" required formControlName="requestedDate">
<mat-datepicker-toggle matSuffix [for]="requestedDatePicker"></mat-datepicker-toggle>
<mat-datepicker #requestedDatePicker></mat-datepicker>
<mat-error *ngIf="applySharesForm.controls.requestedDate.hasError('required')">
Request Date is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Total No. of Shares</mat-label>
<input matInput required formControlName="requestedShares">
<mat-error *ngIf="applySharesForm.controls.requestedShares.hasError('required')">
Requested Shares is <strong>required</strong>
</mat-error>
</mat-form-field>
<mat-form-field>
<mat-label>Today's Price</mat-label>
<input matInput required formControlName="unitPrice">
</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]="!applySharesForm.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 { ApplySharesComponent } from './apply-shares.component';
describe('ApplySharesComponent', () => {
let component: ApplySharesComponent;
let fixture: ComponentFixture<ApplySharesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ApplySharesComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ApplySharesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,93 @@
/** Angular Imports */
import { Component, OnInit, Input } 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';
/**
* App;y Shares Component
*/
@Component({
selector: 'mifosx-apply-shares',
templateUrl: './apply-shares.component.html',
styleUrls: ['./apply-shares.component.scss']
})
export class ApplySharesComponent implements OnInit {
/** Minimum date allowed. */
minDate = new Date(2000, 0, 1);
/** Maximum date allowed. */
maxDate = new Date();
/** Apply Share Account form. */
applySharesForm: FormGroup;
/** Shares Account Id */
accountId: any;
/** Unit Price */
unitPrice: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {SharesService} sharesService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private formBuilder: FormBuilder,
private sharesService: SharesService,
private datePipe: DatePipe,
private route: ActivatedRoute,
private router: Router) {
this.accountId = this.route.parent.snapshot.params['shareAccountId'];
}
/**
* Creates the apply shares form.
* Fetching data from service as action buttons malfunction
* in clients view upon using a common resolver.
*/
ngOnInit() {
this.createApplySharesAccountForm();
this.sharesService.getSharesAccountData(this.accountId, false).subscribe((response: any) => {
this.applySharesForm.get('unitPrice').patchValue(response.currentMarketPrice || '');
});
}
/**
* Creates the apply shares form.
*/
createApplySharesAccountForm() {
this.applySharesForm = this.formBuilder.group({
'requestedDate': ['', Validators.required],
'requestedShares': ['', Validators.required],
'unitPrice': [{value: '', disabled: true}]
});
}
/**
* Submits the form and applies additional shares to 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 prevRequestedDate: Date = this.applySharesForm.value.requestedDate;
this.applySharesForm.patchValue({
requestedDate: this.datePipe.transform(prevRequestedDate, dateFormat),
});
const data = {
...this.applySharesForm.value,
unitPrice: this.unitPrice,
dateFormat,
locale
};
this.sharesService.executeSharesAccountCommand(this.accountId, 'applyadditionalshares', data).subscribe(() => {
this.router.navigate(['../../'], { relativeTo: this.route });
});
}
}
@@ -26,12 +26,19 @@ export class ApproveSharesAccountComponent implements OnInit {
/** Shares Account Id */
accountId: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {SharesService} sharesService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
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'];
this.accountId = this.route.parent.snapshot.params['shareAccountId'];
}
/**
@@ -26,12 +26,19 @@ export class CloseSharesAccountComponent implements OnInit {
/** Shares Account Id */
accountId: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {SharesService} sharesService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
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'];
this.accountId = this.route.parent.snapshot.params['shareAccountId'];
}
/**
@@ -26,12 +26,19 @@ export class RejectSharesAccountComponent implements OnInit {
/** Shares Account Id */
accountId: any;
/**
* @param {FormBuilder} formBuilder Form Builder
* @param {SharesService} sharesService Shares Service
* @param {DatePipe} datePipe Date Pipe
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
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'];
this.accountId = this.route.parent.snapshot.params['shareAccountId'];
}
/**
@@ -2,4 +2,5 @@
<mifosx-reject-shares-account *ngIf="actions['Reject']"></mifosx-reject-shares-account>
<mifosx-close-shares-account *ngIf="actions['Close']"></mifosx-close-shares-account>
<mifosx-activate-shares-account *ngIf="actions['Activate']"></mifosx-activate-shares-account>
<mifosx-undo-approval-shares-account *ngIf="actions['Undo Approval']"></mifosx-undo-approval-shares-account>
<mifosx-undo-approval-shares-account *ngIf="actions['Undo Approval']"></mifosx-undo-approval-shares-account>
<mifosx-apply-shares *ngIf="actions['Apply Additional Shares']"></mifosx-apply-shares>
@@ -12,6 +12,8 @@ import { ActivatedRoute } from '@angular/router';
})
export class SharesAccountActionsComponent {
/** Shares Account Data */
sharesAccountData: any;
/** Flag object to store possible actions and render appropriate UI to the user */
actions: {
'Approve': boolean
@@ -19,14 +21,19 @@ export class SharesAccountActionsComponent {
'Close': boolean
'Activate': boolean
'Undo Approval': boolean
'Apply Additional Shares': boolean
} = {
'Approve': false,
'Reject': false,
'Close': false,
'Activate': false,
'Undo Approval': false
'Undo Approval': false,
'Apply Additional Shares': false
};
/**
* @param {ActivatedRoute} route Activated Route
*/
constructor(private route: ActivatedRoute) {
const name = this.route.snapshot.params['name'];
this.actions[name] = true;
@@ -9,7 +9,7 @@
<div>
<p class="mat-typography confirm-text">
Are you sure you want to undo aprroval of shares account with ID: {{accountId}} ?
Are you sure you want to undo approval of shares account with ID: {{accountId}} ?
</p>
</div>
@@ -18,10 +18,15 @@ export class UndoApprovalSharesAccountComponent {
/** Shares Account Id */
accountId: any;
/**
* @param {SharesService} sharesService Shares Service
* @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
*/
constructor(private sharesService: SharesService,
private route: ActivatedRoute,
private router: Router) {
this.accountId = this.route.parent.parent.snapshot.params['shareAccountId'];
this.accountId = this.route.parent.snapshot.params['shareAccountId'];
}
/**
@@ -82,24 +82,17 @@ export class SharesAccountViewComponent implements OnInit {
*/
doAction(name: string) {
switch (name) {
case 'Approve':
case 'Reject':
case 'Close':
case 'Activate':
case 'Undo Approval':
case 'Apply Additional Shares':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Modify Application':
this.router.navigate(['edit-shares-account'], { relativeTo: this.route });
break;
case 'Approve':
this.router.navigate(['actions/Approve'], { relativeTo: this.route });
break;
case 'Reject':
this.router.navigate(['actions/Reject'], { relativeTo: this.route });
break;
case 'Close':
this.router.navigate(['actions/Close'], { relativeTo: this.route });
break;
case 'Activate':
this.router.navigate(['actions/Activate'], { relativeTo: this.route });
break;
case 'Undo Approval':
this.router.navigate(['actions/Undo Approval'], { relativeTo: this.route });
break;
case 'Delete':
this.deleteSharesAccount();
break;
+3 -9
View File
@@ -69,15 +69,9 @@ const routes: Routes = [
}
},
{
path: 'actions',
data: { title: extract('Shares Account Actions'), breadcrumb: 'Actions', routeParamBreadcrumb: false },
children: [
{
path: ':name',
data: { routeParamBreadcrumb: 'name' },
component: SharesAccountActionsComponent
}
]
path: 'actions/:name',
data: { title: extract('Shares Account Actions'), breadcrumb: 'Actions', routeParamBreadcrumb: 'name' },
component: SharesAccountActionsComponent
}
]
},
+3 -1
View File
@@ -23,6 +23,7 @@ import { RejectSharesAccountComponent } from './shares-account-actions/reject-sh
import { CloseSharesAccountComponent } from './shares-account-actions/close-shares-account/close-shares-account.component';
import { ActivateSharesAccountComponent } from './shares-account-actions/activate-shares-account/activate-shares-account.component';
import { UndoApprovalSharesAccountComponent } from './shares-account-actions/undo-approval-shares-account/undo-approval-shares-account.component';
import { ApplySharesComponent } from './shares-account-actions/apply-shares/apply-shares.component';
/**
* Shares Module
@@ -52,7 +53,8 @@ import { UndoApprovalSharesAccountComponent } from './shares-account-actions/und
RejectSharesAccountComponent,
CloseSharesAccountComponent,
ActivateSharesAccountComponent,
UndoApprovalSharesAccountComponent
UndoApprovalSharesAccountComponent,
ApplySharesComponent
],
providers: [DatePipe]
})