From 245c6c3df3d8b10fd6c3db673cfb4ceb61799fb6 Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Thu, 25 Jun 2020 00:03:12 +0530 Subject: [PATCH] feat: shares account actions (approve-shares) (#908) Fixes: #907 --- src/app/pipes/status-lookup.pipe.ts | 3 +- .../apply-shares/apply-shares.component.ts | 9 +- .../approve-share-dialog.component.html | 8 ++ .../approve-share-dialog.component.scss | 0 .../approve-share-dialog.component.spec.ts | 25 +++++ .../approve-share-dialog.component.ts | 22 +++++ .../approve-shares.component.html | 48 +++++++++ .../approve-shares.component.scss | 12 +++ .../approve-shares.component.spec.ts | 25 +++++ .../approve-shares.component.ts | 97 +++++++++++++++++++ .../redeem-shares/redeem-shares.component.ts | 9 +- .../shares-account-actions.component.html | 5 +- .../shares-account-actions.component.ts | 12 ++- .../shares-account-view.component.ts | 5 +- src/app/shares/shares.module.ts | 11 ++- 15 files changed, 274 insertions(+), 17 deletions(-) create mode 100644 src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.html create mode 100644 src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.scss create mode 100644 src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.spec.ts create mode 100644 src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.ts create mode 100644 src/app/shares/shares-account-actions/approve-shares/approve-shares.component.html create mode 100644 src/app/shares/shares-account-actions/approve-shares/approve-shares.component.scss create mode 100644 src/app/shares/shares-account-actions/approve-shares/approve-shares.component.spec.ts create mode 100644 src/app/shares/shares-account-actions/approve-shares/approve-shares.component.ts diff --git a/src/app/pipes/status-lookup.pipe.ts b/src/app/pipes/status-lookup.pipe.ts index 3d33704d8..877e256f6 100644 --- a/src/app/pipes/status-lookup.pipe.ts +++ b/src/app/pipes/status-lookup.pipe.ts @@ -42,7 +42,8 @@ export class StatusLookupPipe implements PipeTransform { 'groupingStatusType.approved': 'status-approved', 'smsCampaignStatus.active': 'status-active', 'smsCampaignStatus.pending': 'status-pending', - 'smsCampaignStatus.closed': 'status-closed' + 'smsCampaignStatus.closed': 'status-closed', + 'purchasedSharesStatusType.applied': 'status-pending' }; return cssClassNameLookup[status]; } diff --git a/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts index 761cf9ad9..4b4060d7c 100644 --- a/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts +++ b/src/app/shares/shares-account-actions/apply-shares/apply-shares.component.ts @@ -1,5 +1,5 @@ /** Angular Imports */ -import { Component, OnInit } from '@angular/core'; +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'; @@ -17,6 +17,9 @@ import { SharesService } from 'app/shares/shares.service'; }) export class ApplySharesComponent implements OnInit { + /** Shares account data. */ + @Input() sharesAccountData: any; + /** Minimum date allowed. */ minDate = new Date(2000, 0, 1); /** Maximum date allowed. */ @@ -48,9 +51,7 @@ export class ApplySharesComponent implements OnInit { */ ngOnInit() { this.createApplySharesAccountForm(); - this.sharesService.getSharesAccountData(this.accountId, false).subscribe((response: any) => { - this.applySharesForm.get('unitPrice').patchValue(response.currentMarketPrice || ''); - }); + this.applySharesForm.get('unitPrice').patchValue(this.sharesAccountData.currentMarketPrice || ''); } /** diff --git a/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.html b/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.html new file mode 100644 index 000000000..6fac16b9e --- /dev/null +++ b/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.html @@ -0,0 +1,8 @@ +

Approve Share

+
+

Are you sure you want to approve share with id: {{ data.shareId }} ?

+
+ + + + diff --git a/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.scss b/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.spec.ts b/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.spec.ts new file mode 100644 index 000000000..274cb211a --- /dev/null +++ b/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ApproveShareDialogComponent } from './approve-share-dialog.component'; + +describe('ApproveShareDialogComponent', () => { + let component: ApproveShareDialogComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ApproveShareDialogComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ApproveShareDialogComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.ts b/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.ts new file mode 100644 index 000000000..88cc5a2e2 --- /dev/null +++ b/src/app/shares/shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component.ts @@ -0,0 +1,22 @@ +/** Angular Imports */ +import { Component, Inject } from '@angular/core'; +import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material'; + +/** + * Approve share dialog component. + */ +@Component({ + selector: 'mifosx-approve-share-dialog', + templateUrl: './approve-share-dialog.component.html', + styleUrls: ['./approve-share-dialog.component.scss'] +}) +export class ApproveShareDialogComponent { + + /** + * @param {MatDialogRef} dialogRef Component reference to dialog. + * @param {any} data Provides a deleteContext. + */ + constructor(public dialogRef: MatDialogRef, + @Inject(MAT_DIALOG_DATA) public data: any) { } + +} diff --git a/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.html b/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.html new file mode 100644 index 000000000..cc0e4ae20 --- /dev/null +++ b/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.html @@ -0,0 +1,48 @@ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Transaction Date {{ share.purchasedDate | date }} Total Shares {{ share.numberOfShares }} Purchased/Redeemed Price {{ share.purchasedPrice }} Status + + Confirm Approve + +
+ + + +
+ +
diff --git a/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.scss b/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.scss new file mode 100644 index 000000000..573287fc3 --- /dev/null +++ b/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.scss @@ -0,0 +1,12 @@ +table { + width: 100%; + i:hover { + cursor: pointer; + } + .share-action-button{ + min-width: 26px; + padding: 0 6px; + margin: 4px; + line-height: 25px; + } +} diff --git a/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.spec.ts b/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.spec.ts new file mode 100644 index 000000000..960ba8b4a --- /dev/null +++ b/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ApproveSharesComponent } from './approve-shares.component'; + +describe('ApproveSharesComponent', () => { + let component: ApproveSharesComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ApproveSharesComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ApproveSharesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.ts b/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.ts new file mode 100644 index 000000000..536b1b821 --- /dev/null +++ b/src/app/shares/shares-account-actions/approve-shares/approve-shares.component.ts @@ -0,0 +1,97 @@ +/** Angular Imports */ +import { Component, OnInit, ViewChild, Input } from '@angular/core'; +import { MatTableDataSource, MatPaginator, MatSort } from '@angular/material'; +import { ActivatedRoute } from '@angular/router'; +import { MatDialog, MatTable } from '@angular/material'; + +/** Custom Dialogs */ +import { ApproveShareDialogComponent } from './approve-share-dialog/approve-share-dialog.component'; + +/** Custom Serices */ +import { SharesService } from 'app/shares/shares.service'; + +/** + * Approve shares component. + */ +@Component({ + selector: 'mifosx-approve-shares', + templateUrl: './approve-shares.component.html', + styleUrls: ['./approve-shares.component.scss'] +}) +export class ApproveSharesComponent implements OnInit { + + /** Shares account data. */ + @Input() sharesAccountData: any; + + /** Shares account Id */ + accountId: any; + /** Shares account data. */ + sharesData: any[]; + /** Columns to be displayed in shares table. */ + displayedColumns: string[] = ['transactionDate', 'totalShares', 'redeemedPrice', 'status', 'approve']; + /** Data source for shares table. */ + dataSource: MatTableDataSource; + + /** Paginator for shares table. */ + @ViewChild(MatPaginator) paginator: MatPaginator; + /** Sorter for shares table. */ + @ViewChild(MatSort) sort: MatSort; + /** Shares table reference */ + @ViewChild('sharesTable') sharesTableRef: MatTable; + + /** + * @param {SharesService} sharesService Shares Service + */ + constructor(private sharesService: SharesService, + private route: ActivatedRoute, + public dialog: MatDialog) { + this.accountId = this.route.parent.snapshot.params['shareAccountId']; + } + + /** + * Sets the shares table. + */ + ngOnInit() { + this.sharesData = this.sharesAccountData.purchasedShares + .filter((share: any) => share.status.value === 'Pending Approval'); + this.setShares(); + } + + /** + * Initializes the data source, paginator and sorter for shares table. + */ + setShares() { + this.dataSource = new MatTableDataSource(this.sharesData); + this.dataSource.paginator = this.paginator; + this.dataSource.sort = this.sort; + } + + /** + * Approves a share + * @param {any} id Share Id + */ + approve(id: any) { + const approveSharesDialogRef = this.dialog.open(ApproveShareDialogComponent, { + data: { shareId: id } + }); + approveSharesDialogRef.afterClosed().subscribe((response: any) => { + if (response.approve) { + const locale = 'en'; + const dateFormat = 'dd MMMM yyyy'; + const data = { + requestedShares: [{id}], + dateFormat, + locale + }; + this.sharesService.executeSharesAccountCommand(this.accountId, 'approveadditionalshares', data).subscribe(() => { + const share = this.sharesData.find(element => element.id === id); + const index = this.sharesData.indexOf(share); + this.sharesData.splice(index, 1); + this.dataSource.data = this.sharesData; + this.sharesTableRef.renderRows(); + }); + } + }); + } + +} diff --git a/src/app/shares/shares-account-actions/redeem-shares/redeem-shares.component.ts b/src/app/shares/shares-account-actions/redeem-shares/redeem-shares.component.ts index 77d1bbefb..b03c1b920 100644 --- a/src/app/shares/shares-account-actions/redeem-shares/redeem-shares.component.ts +++ b/src/app/shares/shares-account-actions/redeem-shares/redeem-shares.component.ts @@ -1,5 +1,5 @@ /** Angular Imports */ -import { Component, OnInit } from '@angular/core'; +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'; @@ -17,6 +17,9 @@ import { SharesService } from 'app/shares/shares.service'; }) export class RedeemSharesComponent implements OnInit { + /** Shares account data. */ + @Input() sharesAccountData: any; + /** Minimum date allowed. */ minDate = new Date(2000, 0, 1); /** Maximum date allowed. */ @@ -48,9 +51,7 @@ export class RedeemSharesComponent implements OnInit { */ ngOnInit() { this.createRedeemSharesAccountForm(); - this.sharesService.getSharesAccountData(this.accountId, false).subscribe((response: any) => { - this.redeemSharesForm.get('unitPrice').patchValue(response.currentMarketPrice || ''); - }); + this.redeemSharesForm.get('unitPrice').patchValue(this.sharesAccountData.currentMarketPrice || ''); } /** diff --git a/src/app/shares/shares-account-actions/shares-account-actions.component.html b/src/app/shares/shares-account-actions/shares-account-actions.component.html index 01b31ba19..6ea0ee447 100644 --- a/src/app/shares/shares-account-actions/shares-account-actions.component.html +++ b/src/app/shares/shares-account-actions/shares-account-actions.component.html @@ -3,5 +3,6 @@ - - \ No newline at end of file + + + \ No newline at end of file diff --git a/src/app/shares/shares-account-actions/shares-account-actions.component.ts b/src/app/shares/shares-account-actions/shares-account-actions.component.ts index 70bbbdf05..a7166808a 100644 --- a/src/app/shares/shares-account-actions/shares-account-actions.component.ts +++ b/src/app/shares/shares-account-actions/shares-account-actions.component.ts @@ -2,6 +2,9 @@ import { Component } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; +/** Custom Services */ +import { SharesService } from '../shares.service'; + /** * Shares Account Actions Component */ @@ -36,9 +39,14 @@ export class SharesAccountActionsComponent { /** * @param {ActivatedRoute} route Activated Route */ - constructor(private route: ActivatedRoute) { + constructor(private route: ActivatedRoute, + private sharesService: SharesService) { const name = this.route.snapshot.params['name']; - this.actions[name] = true; + const accountId = this.route.parent.snapshot.params['shareAccountId']; + this.sharesService.getSharesAccountData(accountId, false).subscribe((response: any) => { + this.sharesAccountData = response; + this.actions[name] = true; + }); } } diff --git a/src/app/shares/shares-account-view/shares-account-view.component.ts b/src/app/shares/shares-account-view/shares-account-view.component.ts index 52a1b83a3..c104dac19 100644 --- a/src/app/shares/shares-account-view/shares-account-view.component.ts +++ b/src/app/shares/shares-account-view/shares-account-view.component.ts @@ -89,6 +89,7 @@ export class SharesAccountViewComponent implements OnInit { case 'Undo Approval': case 'Apply Additional Shares': case 'Redeem Shares': + case 'Approve Additional Shares': this.router.navigate([`actions/${name}`], { relativeTo: this.route }); break; case 'Modify Application': @@ -104,10 +105,10 @@ export class SharesAccountViewComponent implements OnInit { * Deletes Shares Account. */ private deleteSharesAccount() { - const deleteCurrencyDialogRef = this.dialog.open(DeleteDialogComponent, { + const deleteSharesAccountDialogRef = this.dialog.open(DeleteDialogComponent, { data: { deleteContext: `shares account with id: ${this.sharesAccountData.id}` } }); - deleteCurrencyDialogRef.afterClosed().subscribe((response: any) => { + deleteSharesAccountDialogRef.afterClosed().subscribe((response: any) => { if (response.delete) { this.sharesService.deleteSharesAccount(this.sharesAccountData.id).subscribe(() => { this.router.navigate(['../../'], { relativeTo: this.route }); diff --git a/src/app/shares/shares.module.ts b/src/app/shares/shares.module.ts index 7240b3286..9538648eb 100644 --- a/src/app/shares/shares.module.ts +++ b/src/app/shares/shares.module.ts @@ -25,6 +25,8 @@ import { ActivateSharesAccountComponent } from './shares-account-actions/activat 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'; import { RedeemSharesComponent } from './shares-account-actions/redeem-shares/redeem-shares.component'; +import { ApproveSharesComponent } from './shares-account-actions/approve-shares/approve-shares.component'; +import { ApproveShareDialogComponent } from './shares-account-actions/approve-shares/approve-share-dialog/approve-share-dialog.component'; /** * Shares Module @@ -56,8 +58,13 @@ import { RedeemSharesComponent } from './shares-account-actions/redeem-shares/re ActivateSharesAccountComponent, UndoApprovalSharesAccountComponent, ApplySharesComponent, - RedeemSharesComponent + RedeemSharesComponent, + ApproveSharesComponent, + ApproveShareDialogComponent ], - providers: [DatePipe] + providers: [DatePipe], + entryComponents: [ + ApproveShareDialogComponent + ] }) export class SharesModule { }