feat: shares account actions (reject-shares) (#910)

Fixes: #909
This commit is contained in:
Karan Takalkar
2020-06-25 03:53:41 +05:30
committed by GitHub
parent 245c6c3df3
commit 018bbabac1
13 changed files with 255 additions and 5 deletions
@@ -0,0 +1,8 @@
<h1 mat-dialog-title>Reject Share</h1>
<div mat-dialog-content>
<p>Are you sure you want to reject share with id: {{ data.shareId }} ?</p>
</div>
<mat-dialog-actions align="end">
<button mat-raised-button mat-dialog-close>Cancel</button>
<button mat-raised-button color="warn" [mat-dialog-close]="{ reject: true }">Confirm</button>
</mat-dialog-actions>
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RejectShareDialogComponent } from './reject-share-dialog.component';
describe('RejectSharesDialogComponent', () => {
let component: RejectShareDialogComponent;
let fixture: ComponentFixture<RejectShareDialogComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ RejectShareDialogComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(RejectShareDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,22 @@
/** Angular Imports */
import { Component, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
/**
* Reject share dialog component.
*/
@Component({
selector: 'mifosx-reject-share-dialog',
templateUrl: './reject-share-dialog.component.html',
styleUrls: ['./reject-share-dialog.component.scss']
})
export class RejectShareDialogComponent {
/**
* @param {MatDialogRef} dialogRef Component reference to dialog.
* @param {any} data Provides a deleteContext.
*/
constructor(public dialogRef: MatDialogRef<RejectShareDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) { }
}
@@ -0,0 +1,48 @@
<div class="container">
<div class="mat-elevation-z8">
<table #sharesTable mat-table [dataSource]="dataSource" matSort>
<ng-container matColumnDef="transactionDate">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Transaction Date </th>
<td mat-cell *matCellDef="let share"> {{ share.purchasedDate | date }}</td>
</ng-container>
<ng-container matColumnDef="totalShares">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Total Shares </th>
<td mat-cell *matCellDef="let share"> {{ share.numberOfShares }} </td>
</ng-container>
<ng-container matColumnDef="redeemedPrice">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Purchased/Redeemed Price </th>
<td mat-cell *matCellDef="let share"> {{ share.purchasedPrice }} </td>
</ng-container>
<ng-container matColumnDef="status">
<th mat-header-cell *matHeaderCellDef> Status </th>
<td mat-cell *matCellDef="let share">
<i class="fa fa-stop" [ngClass]="share.status.code|statusLookup" [matTooltip]="share.status.value"></i>
</td>
</ng-container>
<ng-container matColumnDef="reject">
<th mat-header-cell *matHeaderCellDef mat-sort-header> Confirm Reject </th>
<td mat-cell *matCellDef="let share">
<button class="share-action-button" mat-raised-button color="warn" matTooltip="Reject Share"
(click)="reject(share.id)">
<i class="fa fa-times"></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>
</div>
</div>
@@ -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;
}
}
@@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { RejectSharesComponent } from './reject-shares.component';
describe('RejectSharesComponent', () => {
let component: RejectSharesComponent;
let fixture: ComponentFixture<RejectSharesComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ RejectSharesComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(RejectSharesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@@ -0,0 +1,99 @@
/** 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 { RejectShareDialogComponent } from './reject-share-dialog/reject-share-dialog.component';
/** Custom Serices */
import { SharesService } from 'app/shares/shares.service';
/**
* Reject shares component.
*/
@Component({
selector: 'mifosx-reject-shares',
templateUrl: './reject-shares.component.html',
styleUrls: ['./reject-shares.component.scss']
})
export class RejectSharesComponent 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', 'reject'];
/** Data source for shares table. */
dataSource: MatTableDataSource<any>;
/** Paginator for shares table. */
@ViewChild(MatPaginator) paginator: MatPaginator;
/** Sorter for shares table. */
@ViewChild(MatSort) sort: MatSort;
/** Shares table reference */
@ViewChild('sharesTable') sharesTableRef: MatTable<Element>;
/**
* @param {SharesService} sharesService Shares Service
* @param {ActivatedRoute} route Activated Route
* @param {MatDialog} dialog Mat Dialog
*/
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;
}
/**
* Rejects a share
* @param {any} id Share Id
*/
reject(id: any) {
const rejectSharesDialogRef = this.dialog.open(RejectShareDialogComponent, {
data: { shareId: id }
});
rejectSharesDialogRef.afterClosed().subscribe((response: any) => {
if (response.reject) {
const locale = 'en';
const dateFormat = 'dd MMMM yyyy';
const data = {
requestedShares: [{id}],
dateFormat,
locale
};
this.sharesService.executeSharesAccountCommand(this.accountId, 'rejectadditionalshares', 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();
});
}
});
}
}
@@ -5,4 +5,5 @@
<mifosx-undo-approval-shares-account *ngIf="actions['Undo Approval']"></mifosx-undo-approval-shares-account>
<mifosx-apply-shares [sharesAccountData]="sharesAccountData" *ngIf="actions['Apply Additional Shares']"></mifosx-apply-shares>
<mifosx-redeem-shares [sharesAccountData]="sharesAccountData" *ngIf="actions['Redeem Shares']"></mifosx-redeem-shares>
<mifosx-approve-shares [sharesAccountData]="sharesAccountData" *ngIf="actions['Approve Additional Shares']"></mifosx-approve-shares>
<mifosx-approve-shares [sharesAccountData]="sharesAccountData" *ngIf="actions['Approve Additional Shares']"></mifosx-approve-shares>
<mifosx-reject-shares [sharesAccountData]="sharesAccountData" *ngIf="actions['Reject Additional Shares']"></mifosx-reject-shares>
@@ -26,6 +26,8 @@ export class SharesAccountActionsComponent {
'Undo Approval': boolean
'Apply Additional Shares': boolean
'Redeem Shares': boolean
'Approve Additional Shares': boolean
'Reject Additional Shares': boolean
} = {
'Approve': false,
'Reject': false,
@@ -33,7 +35,9 @@ export class SharesAccountActionsComponent {
'Activate': false,
'Undo Approval': false,
'Apply Additional Shares': false,
'Redeem Shares': false
'Redeem Shares': false,
'Approve Additional Shares': false,
'Reject Additional Shares': false
};
/**
@@ -90,6 +90,7 @@ export class SharesAccountViewComponent implements OnInit {
case 'Apply Additional Shares':
case 'Redeem Shares':
case 'Approve Additional Shares':
case 'Reject Additional Shares':
this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break;
case 'Modify Application':
@@ -41,7 +41,7 @@ export class SharesButtonsConfiguration {
},
{
name: 'Reject Additional Shares',
icon: 'fa fa-arrow-right',
icon: 'fa fa-arrow-left',
taskPermissionName: 'REJECTADDITIONAL_SHAREACCOUNT'
},
{
+7 -2
View File
@@ -27,6 +27,8 @@ import { ApplySharesComponent } from './shares-account-actions/apply-shares/appl
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';
import { RejectSharesComponent } from './shares-account-actions/reject-shares/reject-shares.component';
import { RejectShareDialogComponent } from './shares-account-actions/reject-shares/reject-share-dialog/reject-share-dialog.component';
/**
* Shares Module
@@ -60,11 +62,14 @@ import { ApproveShareDialogComponent } from './shares-account-actions/approve-sh
ApplySharesComponent,
RedeemSharesComponent,
ApproveSharesComponent,
ApproveShareDialogComponent
ApproveShareDialogComponent,
RejectSharesComponent,
RejectShareDialogComponent
],
providers: [DatePipe],
entryComponents: [
ApproveShareDialogComponent
ApproveShareDialogComponent,
RejectShareDialogComponent
]
})
export class SharesModule { }