refactor: shares module (#1200)

See: #1196
This commit is contained in:
Karan Takalkar
2020-08-13 09:56:25 +05:30
committed by GitHub
parent 6f3b6c40e7
commit a1cd561453
18 changed files with 99 additions and 33 deletions
+1 -1
View File
@@ -246,7 +246,7 @@ const routes: Routes = [
loadChildren: '../deposits/recurring-deposits/recurring-deposits.module#RecurringDepositsModule' loadChildren: '../deposits/recurring-deposits/recurring-deposits.module#RecurringDepositsModule'
}, },
{ {
path: 'sharesaccounts', path: 'shares-accounts',
loadChildren: '../shares/shares.module#SharesModule' loadChildren: '../shares/shares.module#SharesModule'
}, },
{ {
@@ -64,7 +64,7 @@
<mat-menu #Applications="matMenu"> <mat-menu #Applications="matMenu">
<button mat-menu-item [routerLink]="['loans', 'create-loans-account']">New Loan Account</button> <button mat-menu-item [routerLink]="['loans', 'create-loans-account']">New Loan Account</button>
<button mat-menu-item [routerLink]="['savingsaccounts', 'create-savings-account']">New Savings Account</button> <button mat-menu-item [routerLink]="['savingsaccounts', 'create-savings-account']">New Savings Account</button>
<button mat-menu-item [routerLink]="['sharesaccounts', 'create-shares-account']">New Share Account</button> <button mat-menu-item *mifosxHasPermission="'CREATE_SHAREACCOUNT'" [routerLink]="['shares-accounts', 'create']">New Share Account</button>
<button mat-menu-item [routerLink]="['recurringdeposits', 'create-recurring-deposits-account']">New Recurring Deposit Account</button> <button mat-menu-item [routerLink]="['recurringdeposits', 'create-recurring-deposits-account']">New Recurring Deposit Account</button>
<button mat-menu-item [routerLink]="['fixed-deposits-accounts', 'create-fixed-deposit-account']">New Fixed Deposits Account</button> <button mat-menu-item [routerLink]="['fixed-deposits-accounts', 'create-fixed-deposit-account']">New Fixed Deposits Account</button>
</mat-menu> </mat-menu>
@@ -544,15 +544,15 @@
<th mat-header-cell *matHeaderCellDef> Actions </th> <th mat-header-cell *matHeaderCellDef> Actions </th>
<td mat-cell *matCellDef="let element"> <td mat-cell *matCellDef="let element">
<button *ngIf="element.status.submittedAndPendingApproval" class="account-action-button" mat-raised-button <button *ngIf="element.status.submittedAndPendingApproval" class="account-action-button" mat-raised-button
color="primary" (click)="routeEdit($event)" [routerLink]="['../','sharesaccounts', element.id, 'actions', 'Approve']"> color="primary" (click)="routeEdit($event)" [routerLink]="['../','shares-accounts', element.id, 'actions', 'Approve']">
<i class="fa fa-check"></i> <i class="fa fa-check"></i>
</button> </button>
<button *ngIf="!element.status.submittedAndPendingApproval && !element.status.active" <button *ngIf="!element.status.submittedAndPendingApproval && !element.status.active"
class="account-action-button" mat-raised-button color="primary" (click)="routeEdit($event)" [routerLink]="['../','sharesaccounts', element.id, 'actions', 'Undo Approval']"> class="account-action-button" mat-raised-button color="primary" (click)="routeEdit($event)" [routerLink]="['../','shares-accounts', element.id, 'actions', 'Undo Approval']">
<i class="fa fa-undo"></i> <i class="fa fa-undo"></i>
</button> </button>
<button *ngIf="!element.status.submittedAndPendingApproval && !element.status.active" <button *ngIf="!element.status.submittedAndPendingApproval && !element.status.active"
class="account-action-button" mat-raised-button color="primary" (click)="routeEdit($event)" [routerLink]="['../','sharesaccounts', element.id, 'actions', 'Activate']"> class="account-action-button" mat-raised-button color="primary" (click)="routeEdit($event)" [routerLink]="['../','shares-accounts', element.id, 'actions', 'Activate']">
<i class="fa fa-check-circle"></i> <i class="fa fa-check-circle"></i>
</button> </button>
</td> </td>
@@ -561,7 +561,7 @@
<tr mat-header-row *matHeaderRowDef="openSharesColumns"></tr> <tr mat-header-row *matHeaderRowDef="openSharesColumns"></tr>
<tr mat-row *matRowDef="let row; columns: openSharesColumns;" <tr mat-row *matRowDef="let row; columns: openSharesColumns;"
[routerLink]="['../', 'sharesaccounts', row.id, 'transactions']"></tr> [routerLink]="['../', 'shares-accounts', row.id, 'transactions']"></tr>
</table> </table>
<!-- Closed Share Accounts --> <!-- Closed Share Accounts -->
<table *ngIf="showClosedShareAccounts" mat-table [dataSource]="shareAccounts|accountsFilter:'share':'closed'"> <table *ngIf="showClosedShareAccounts" mat-table [dataSource]="shareAccounts|accountsFilter:'share':'closed'">
@@ -29,7 +29,7 @@ export class NotificationsPageComponent implements OnInit {
'group' : '/groups/', 'group' : '/groups/',
'loan' : '/loans/', 'loan' : '/loans/',
'center' : '/centers/', 'center' : '/centers/',
'shareAccount' : '/sharesaccounts/', 'shareAccount' : '/shares-accounts/',
'fixedDeposit' : '/fixed-deposits-accounts/', 'fixedDeposit' : '/fixed-deposits-accounts/',
'recurringDepositAccount': '/recurringdeposits/', 'recurringDepositAccount': '/recurringdeposits/',
'savingsAccount' : '/savingsaccounts/', 'savingsAccount' : '/savingsaccounts/',
@@ -36,7 +36,7 @@ export class NotificationsTrayComponent implements OnInit, OnDestroy {
'group' : '/groups/', 'group' : '/groups/',
'loan' : '/loans/', 'loan' : '/loans/',
'center' : '/centers/', 'center' : '/centers/',
'shareAccount' : '/sharesaccounts/', 'shareAccount' : '/shares-accounts/',
'fixedDeposit' : '/fixed-deposits-accounts/', 'fixedDeposit' : '/fixed-deposits-accounts/',
'recurringDepositAccount': '/recurringdeposits/', 'recurringDepositAccount': '/recurringdeposits/',
'savingsAccount' : '/savingsaccounts/', 'savingsAccount' : '/savingsaccounts/',
@@ -48,7 +48,7 @@ export class SearchPageComponent {
this.router.navigate(['groups', entity.entityId]); this.router.navigate(['groups', entity.entityId]);
break; break;
case 'SHARE': case 'SHARE':
this.router.navigate(['clients', entity.parentId, 'sharesaccounts', entity.entityId]); this.router.navigate(['clients', entity.parentId, 'shares-accounts', entity.entityId]);
break; break;
case 'SAVING': case 'SAVING':
this.router.navigate(['clients', entity.parentId, 'savingsaccounts', entity.entityId]); this.router.navigate(['clients', entity.parentId, 'savingsaccounts', entity.entityId]);
@@ -0,0 +1,41 @@
/** Angular Imports */
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
/** rxjs Imports */
import { Observable } from 'rxjs';
/** Custom Services */
import { SharesService } from '../shares.service';
/**
* Shares Account Actions data resolver.
*/
@Injectable()
export class ShareAccountActionsResolver implements Resolve<Object> {
/**
* @param {sharesService} SharesService Shares service.
*/
constructor(private sharesService: SharesService) { }
/**
* Returns the Shares account actions data.
* @param {ActivatedRouteSnapshot} route Route Snapshot
* @returns {Observable<any>}
*/
resolve(route: ActivatedRouteSnapshot): Observable<any> {
const actionName = route.paramMap.get('name');
const shareAccountId = route.paramMap.get('shareAccountId') || route.parent.parent.paramMap.get('shareAccountId');
switch (actionName) {
case 'Apply Additional Shares':
case 'Redeem Shares':
case 'Approve Additional Shares':
case 'Reject Additional Shares':
return this.sharesService.getSharesAccountData(shareAccountId, true);
default:
return undefined;
}
}
}
@@ -98,7 +98,7 @@ export class EditSharesAccountComponent {
} }
/** /**
* Creates a new share account. * Updates a share account.
*/ */
submit() { submit() {
// TODO: Update once language and date settings are setup // TODO: Update once language and date settings are setup
@@ -18,7 +18,7 @@ import { SharesService } from 'app/shares/shares.service';
export class ApplySharesComponent implements OnInit { export class ApplySharesComponent implements OnInit {
/** Shares account data. */ /** Shares account data. */
@Input() sharesAccountData: any; sharesAccountData: any;
/** Minimum date allowed. */ /** Minimum date allowed. */
minDate = new Date(2000, 0, 1); minDate = new Date(2000, 0, 1);
@@ -42,6 +42,9 @@ export class ApplySharesComponent implements OnInit {
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router) {
this.accountId = this.route.parent.snapshot.params['shareAccountId']; this.accountId = this.route.parent.snapshot.params['shareAccountId'];
this.route.data.subscribe((data: { shareAccountActionData: any }) => {
this.sharesAccountData = data.shareAccountActionData;
});
} }
/** /**
@@ -21,7 +21,7 @@ import { SharesService } from 'app/shares/shares.service';
export class ApproveSharesComponent implements OnInit { export class ApproveSharesComponent implements OnInit {
/** Shares account data. */ /** Shares account data. */
@Input() sharesAccountData: any; sharesAccountData: any;
/** Shares account Id */ /** Shares account Id */
accountId: any; accountId: any;
@@ -46,6 +46,9 @@ export class ApproveSharesComponent implements OnInit {
private route: ActivatedRoute, private route: ActivatedRoute,
public dialog: MatDialog) { public dialog: MatDialog) {
this.accountId = this.route.parent.snapshot.params['shareAccountId']; this.accountId = this.route.parent.snapshot.params['shareAccountId'];
this.route.data.subscribe((data: { shareAccountActionData: any }) => {
this.sharesAccountData = data.shareAccountActionData;
});
} }
/** /**
@@ -18,7 +18,7 @@ import { SharesService } from 'app/shares/shares.service';
export class RedeemSharesComponent implements OnInit { export class RedeemSharesComponent implements OnInit {
/** Shares account data. */ /** Shares account data. */
@Input() sharesAccountData: any; sharesAccountData: any;
/** Minimum date allowed. */ /** Minimum date allowed. */
minDate = new Date(2000, 0, 1); minDate = new Date(2000, 0, 1);
@@ -42,6 +42,9 @@ export class RedeemSharesComponent implements OnInit {
private route: ActivatedRoute, private route: ActivatedRoute,
private router: Router) { private router: Router) {
this.accountId = this.route.parent.snapshot.params['shareAccountId']; this.accountId = this.route.parent.snapshot.params['shareAccountId'];
this.route.data.subscribe((data: { shareAccountActionData: any }) => {
this.sharesAccountData = data.shareAccountActionData;
});
} }
/** /**
@@ -21,7 +21,7 @@ import { SharesService } from 'app/shares/shares.service';
export class RejectSharesComponent implements OnInit { export class RejectSharesComponent implements OnInit {
/** Shares account data. */ /** Shares account data. */
@Input() sharesAccountData: any; sharesAccountData: any;
/** Shares account Id */ /** Shares account Id */
accountId: any; accountId: any;
@@ -48,6 +48,9 @@ export class RejectSharesComponent implements OnInit {
private route: ActivatedRoute, private route: ActivatedRoute,
public dialog: MatDialog) { public dialog: MatDialog) {
this.accountId = this.route.parent.snapshot.params['shareAccountId']; this.accountId = this.route.parent.snapshot.params['shareAccountId'];
this.route.data.subscribe((data: { shareAccountActionData: any }) => {
this.sharesAccountData = data.shareAccountActionData;
});
} }
/** /**
@@ -3,7 +3,7 @@
<mifosx-close-shares-account *ngIf="actions['Close']"></mifosx-close-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-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 [sharesAccountData]="sharesAccountData" *ngIf="actions['Apply Additional Shares']"></mifosx-apply-shares> <mifosx-apply-shares *ngIf="actions['Apply Additional Shares']"></mifosx-apply-shares>
<mifosx-redeem-shares [sharesAccountData]="sharesAccountData" *ngIf="actions['Redeem Shares']"></mifosx-redeem-shares> <mifosx-redeem-shares *ngIf="actions['Redeem Shares']"></mifosx-redeem-shares>
<mifosx-approve-shares [sharesAccountData]="sharesAccountData" *ngIf="actions['Approve Additional Shares']"></mifosx-approve-shares> <mifosx-approve-shares *ngIf="actions['Approve Additional Shares']"></mifosx-approve-shares>
<mifosx-reject-shares [sharesAccountData]="sharesAccountData" *ngIf="actions['Reject Additional Shares']"></mifosx-reject-shares> <mifosx-reject-shares *ngIf="actions['Reject Additional Shares']"></mifosx-reject-shares>
@@ -43,14 +43,9 @@ export class SharesAccountActionsComponent {
/** /**
* @param {ActivatedRoute} route Activated Route * @param {ActivatedRoute} route Activated Route
*/ */
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute) {
private sharesService: SharesService) {
const name = this.route.snapshot.params['name']; const name = this.route.snapshot.params['name'];
const accountId = this.route.parent.snapshot.params['shareAccountId']; this.actions[name] = true;
this.sharesService.getSharesAccountData(accountId, false).subscribe((response: any) => {
this.sharesAccountData = response;
this.actions[name] = true;
});
} }
} }
@@ -38,7 +38,7 @@
<i class="{{button.icon}}"></i> {{button.name}}</button> <i class="{{button.icon}}"></i> {{button.name}}</button>
</ng-container> </ng-container>
<ng-container *ngIf="buttonConfig.options"> <ng-container *ngIf="buttonConfig.options.length">
<button mat-raised-button [matMenuTriggerFor]="More">More</button> <button mat-raised-button [matMenuTriggerFor]="More">More</button>
<mat-menu #More="matMenu"> <mat-menu #More="matMenu">
<span *ngFor="let option of buttonConfig.options"> <span *ngFor="let option of buttonConfig.options">
@@ -30,6 +30,9 @@ export class SharesAccountViewComponent implements OnInit {
/** /**
* Fetches shares account data from `resolve` * Fetches shares account data from `resolve`
* @param {ActivatedRoute} route Activated Route * @param {ActivatedRoute} route Activated Route
* @param {Router} router Router
* @param {SharesService} sharesService Shares Service
* @param {MatDialog} dialog Mat Dialog
*/ */
constructor(private route: ActivatedRoute, constructor(private route: ActivatedRoute,
private router: Router, private router: Router,
@@ -94,7 +97,7 @@ export class SharesAccountViewComponent implements OnInit {
this.router.navigate([`actions/${name}`], { relativeTo: this.route }); this.router.navigate([`actions/${name}`], { relativeTo: this.route });
break; break;
case 'Modify Application': case 'Modify Application':
this.router.navigate(['edit-shares-account'], { relativeTo: this.route }); this.router.navigate(['edit'], { relativeTo: this.route });
break; break;
case 'Delete': case 'Delete':
this.deleteSharesAccount(); this.deleteSharesAccount();
+13 -4
View File
@@ -16,16 +16,18 @@ import { SharesAccountActionsComponent } from './shares-account-actions/shares-a
/** Custom Resolvers */ /** Custom Resolvers */
import { SharesAccountViewResolver } from './common-resolvers/share-account-view.resolver'; import { SharesAccountViewResolver } from './common-resolvers/share-account-view.resolver';
import { ShareAccountActionsResolver } from './common-resolvers/share-account-actions.resolver';
import { SharesAccountTemplateResolver } from './common-resolvers/shares-account-template.resolver'; import { SharesAccountTemplateResolver } from './common-resolvers/shares-account-template.resolver';
import { SharesAccountAndTemplateResolver } from './common-resolvers/share-account-and-template.resolver'; import { SharesAccountAndTemplateResolver } from './common-resolvers/share-account-and-template.resolver';
/** Shares Routes */
const routes: Routes = [ const routes: Routes = [
{ {
path: '', path: '',
data: { title: extract('Shares'), breadcrumb: 'Shares', routeParamBreadcrumb: false }, data: { title: extract('Shares'), breadcrumb: 'Shares', routeParamBreadcrumb: false },
children: [ children: [
{ {
path: 'create-shares-account', path: 'create',
data: { title: extract('Create Shares Account'), breadcrumb: 'Create Shares Account' }, data: { title: extract('Create Shares Account'), breadcrumb: 'Create Shares Account' },
component: CreateSharesAccountComponent, component: CreateSharesAccountComponent,
resolve: { resolve: {
@@ -61,7 +63,7 @@ const routes: Routes = [
] ]
}, },
{ {
path: 'edit-shares-account', path: 'edit',
data: { title: extract('Edit Shares Account'), breadcrumb: 'Edit', routeParamBreadcrumb: false }, data: { title: extract('Edit Shares Account'), breadcrumb: 'Edit', routeParamBreadcrumb: false },
component: EditSharesAccountComponent, component: EditSharesAccountComponent,
resolve: { resolve: {
@@ -71,7 +73,10 @@ const routes: Routes = [
{ {
path: 'actions/:name', path: 'actions/:name',
data: { title: extract('Shares Account Actions'), breadcrumb: 'Actions', routeParamBreadcrumb: 'name' }, data: { title: extract('Shares Account Actions'), breadcrumb: 'Actions', routeParamBreadcrumb: 'name' },
component: SharesAccountActionsComponent component: SharesAccountActionsComponent,
resolve: {
shareAccountActionData: ShareAccountActionsResolver
}
} }
] ]
}, },
@@ -79,13 +84,17 @@ const routes: Routes = [
} }
]; ];
/**
* Shares Routinf Module
*/
@NgModule({ @NgModule({
imports: [RouterModule.forChild(routes)], imports: [RouterModule.forChild(routes)],
exports: [RouterModule], exports: [RouterModule],
providers: [ providers: [
SharesAccountViewResolver, SharesAccountViewResolver,
SharesAccountTemplateResolver, SharesAccountTemplateResolver,
SharesAccountAndTemplateResolver SharesAccountAndTemplateResolver,
ShareAccountActionsResolver
] ]
}) })
export class SharesRoutingModule { } export class SharesRoutingModule { }
+8 -2
View File
@@ -13,10 +13,14 @@ import { Observable } from 'rxjs';
}) })
export class SharesService { export class SharesService {
/**
* @param {HttpClient} http Http Client
*/
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
/** /**
* @param accountId Shares Account Id of account to get data for. * @param {string} accountId Shares Account Id of account to get data for.
* @param {boolean} template Shares account template required?.
* @returns {Observable<any>} Shares data. * @returns {Observable<any>} Shares data.
*/ */
getSharesAccountData(accountId: string, template: boolean): Observable<any> { getSharesAccountData(accountId: string, template: boolean): Observable<any> {
@@ -25,7 +29,8 @@ export class SharesService {
} }
/** /**
* @param clientId Client Id assosciated with shares account. * @param {string} clientId Client Id assosciated with shares account.
* @param {string} productId Product Id
* @returns {Observable<any>} Shares account template. * @returns {Observable<any>} Shares account template.
*/ */
getSharesAccountTemplate(clientId: string, productId?: string): Observable<any> { getSharesAccountTemplate(clientId: string, productId?: string): Observable<any> {
@@ -43,6 +48,7 @@ export class SharesService {
} }
/** /**
* @param {string} accountId: Shares account Id.
* @param {any} sharesAccount Shares Account * @param {any} sharesAccount Shares Account
* @returns {Observable<any>} * @returns {Observable<any>}
*/ */