From a1cd561453216bebf78cd02005db26a203fdf17f Mon Sep 17 00:00:00 2001 From: Karan Takalkar Date: Thu, 13 Aug 2020 09:56:25 +0530 Subject: [PATCH] refactor: shares module (#1200) See: #1196 --- src/app/clients/clients-routing.module.ts | 2 +- .../clients-view/clients-view.component.html | 2 +- .../general-tab/general-tab.component.html | 8 ++-- .../notifications-page.component.ts | 2 +- .../notifications-tray.component.ts | 2 +- .../search-page/search-page.component.ts | 2 +- .../share-account-actions.resolver.ts | 41 +++++++++++++++++++ .../edit-shares-account.component.ts | 2 +- .../apply-shares/apply-shares.component.ts | 5 ++- .../approve-shares.component.ts | 5 ++- .../redeem-shares/redeem-shares.component.ts | 5 ++- .../reject-shares/reject-shares.component.ts | 5 ++- .../shares-account-actions.component.html | 8 ++-- .../shares-account-actions.component.ts | 9 +--- .../shares-account-view.component.html | 2 +- .../shares-account-view.component.ts | 5 ++- src/app/shares/shares-routing.module.ts | 17 ++++++-- src/app/shares/shares.service.ts | 10 ++++- 18 files changed, 99 insertions(+), 33 deletions(-) create mode 100644 src/app/shares/common-resolvers/share-account-actions.resolver.ts diff --git a/src/app/clients/clients-routing.module.ts b/src/app/clients/clients-routing.module.ts index 3ec27b3da..3bb1f4b56 100644 --- a/src/app/clients/clients-routing.module.ts +++ b/src/app/clients/clients-routing.module.ts @@ -246,7 +246,7 @@ const routes: Routes = [ loadChildren: '../deposits/recurring-deposits/recurring-deposits.module#RecurringDepositsModule' }, { - path: 'sharesaccounts', + path: 'shares-accounts', loadChildren: '../shares/shares.module#SharesModule' }, { diff --git a/src/app/clients/clients-view/clients-view.component.html b/src/app/clients/clients-view/clients-view.component.html index a98963d9c..8cafb9e73 100644 --- a/src/app/clients/clients-view/clients-view.component.html +++ b/src/app/clients/clients-view/clients-view.component.html @@ -64,7 +64,7 @@ - + diff --git a/src/app/clients/clients-view/general-tab/general-tab.component.html b/src/app/clients/clients-view/general-tab/general-tab.component.html index 342a1fa83..6d62481e7 100644 --- a/src/app/clients/clients-view/general-tab/general-tab.component.html +++ b/src/app/clients/clients-view/general-tab/general-tab.component.html @@ -544,15 +544,15 @@ Actions @@ -561,7 +561,7 @@ + [routerLink]="['../', 'shares-accounts', row.id, 'transactions']"> diff --git a/src/app/notifications/notifications-page/notifications-page.component.ts b/src/app/notifications/notifications-page/notifications-page.component.ts index c432152c9..ef2857c2b 100644 --- a/src/app/notifications/notifications-page/notifications-page.component.ts +++ b/src/app/notifications/notifications-page/notifications-page.component.ts @@ -29,7 +29,7 @@ export class NotificationsPageComponent implements OnInit { 'group' : '/groups/', 'loan' : '/loans/', 'center' : '/centers/', - 'shareAccount' : '/sharesaccounts/', + 'shareAccount' : '/shares-accounts/', 'fixedDeposit' : '/fixed-deposits-accounts/', 'recurringDepositAccount': '/recurringdeposits/', 'savingsAccount' : '/savingsaccounts/', diff --git a/src/app/notifications/notifications-tray/notifications-tray.component.ts b/src/app/notifications/notifications-tray/notifications-tray.component.ts index b953cfce0..41a93e33a 100644 --- a/src/app/notifications/notifications-tray/notifications-tray.component.ts +++ b/src/app/notifications/notifications-tray/notifications-tray.component.ts @@ -36,7 +36,7 @@ export class NotificationsTrayComponent implements OnInit, OnDestroy { 'group' : '/groups/', 'loan' : '/loans/', 'center' : '/centers/', - 'shareAccount' : '/sharesaccounts/', + 'shareAccount' : '/shares-accounts/', 'fixedDeposit' : '/fixed-deposits-accounts/', 'recurringDepositAccount': '/recurringdeposits/', 'savingsAccount' : '/savingsaccounts/', diff --git a/src/app/search/search-page/search-page.component.ts b/src/app/search/search-page/search-page.component.ts index f4b4d2b66..42f1afb41 100644 --- a/src/app/search/search-page/search-page.component.ts +++ b/src/app/search/search-page/search-page.component.ts @@ -48,7 +48,7 @@ export class SearchPageComponent { this.router.navigate(['groups', entity.entityId]); break; case 'SHARE': - this.router.navigate(['clients', entity.parentId, 'sharesaccounts', entity.entityId]); + this.router.navigate(['clients', entity.parentId, 'shares-accounts', entity.entityId]); break; case 'SAVING': this.router.navigate(['clients', entity.parentId, 'savingsaccounts', entity.entityId]); diff --git a/src/app/shares/common-resolvers/share-account-actions.resolver.ts b/src/app/shares/common-resolvers/share-account-actions.resolver.ts new file mode 100644 index 000000000..93372b0c6 --- /dev/null +++ b/src/app/shares/common-resolvers/share-account-actions.resolver.ts @@ -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 { + + /** + * @param {sharesService} SharesService Shares service. + */ + constructor(private sharesService: SharesService) { } + + /** + * Returns the Shares account actions data. + * @param {ActivatedRouteSnapshot} route Route Snapshot + * @returns {Observable} + */ + resolve(route: ActivatedRouteSnapshot): Observable { + 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; + } + } + +} diff --git a/src/app/shares/edit-shares-account/edit-shares-account.component.ts b/src/app/shares/edit-shares-account/edit-shares-account.component.ts index db291da99..e5965bd41 100644 --- a/src/app/shares/edit-shares-account/edit-shares-account.component.ts +++ b/src/app/shares/edit-shares-account/edit-shares-account.component.ts @@ -98,7 +98,7 @@ export class EditSharesAccountComponent { } /** - * Creates a new share account. + * Updates a share account. */ submit() { // TODO: Update once language and date settings are setup 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 4b4060d7c..7683081ef 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 @@ -18,7 +18,7 @@ import { SharesService } from 'app/shares/shares.service'; export class ApplySharesComponent implements OnInit { /** Shares account data. */ - @Input() sharesAccountData: any; + sharesAccountData: any; /** Minimum date allowed. */ minDate = new Date(2000, 0, 1); @@ -42,6 +42,9 @@ export class ApplySharesComponent implements OnInit { private route: ActivatedRoute, private router: Router) { this.accountId = this.route.parent.snapshot.params['shareAccountId']; + this.route.data.subscribe((data: { shareAccountActionData: any }) => { + this.sharesAccountData = data.shareAccountActionData; + }); } /** 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 index 536b1b821..5604efed5 100644 --- 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 @@ -21,7 +21,7 @@ import { SharesService } from 'app/shares/shares.service'; export class ApproveSharesComponent implements OnInit { /** Shares account data. */ - @Input() sharesAccountData: any; + sharesAccountData: any; /** Shares account Id */ accountId: any; @@ -46,6 +46,9 @@ export class ApproveSharesComponent implements OnInit { private route: ActivatedRoute, public dialog: MatDialog) { this.accountId = this.route.parent.snapshot.params['shareAccountId']; + this.route.data.subscribe((data: { shareAccountActionData: any }) => { + this.sharesAccountData = data.shareAccountActionData; + }); } /** 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 b03c1b920..16f370bee 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 @@ -18,7 +18,7 @@ import { SharesService } from 'app/shares/shares.service'; export class RedeemSharesComponent implements OnInit { /** Shares account data. */ - @Input() sharesAccountData: any; + sharesAccountData: any; /** Minimum date allowed. */ minDate = new Date(2000, 0, 1); @@ -42,6 +42,9 @@ export class RedeemSharesComponent implements OnInit { private route: ActivatedRoute, private router: Router) { this.accountId = this.route.parent.snapshot.params['shareAccountId']; + this.route.data.subscribe((data: { shareAccountActionData: any }) => { + this.sharesAccountData = data.shareAccountActionData; + }); } /** diff --git a/src/app/shares/shares-account-actions/reject-shares/reject-shares.component.ts b/src/app/shares/shares-account-actions/reject-shares/reject-shares.component.ts index c50c79896..24547dbda 100644 --- a/src/app/shares/shares-account-actions/reject-shares/reject-shares.component.ts +++ b/src/app/shares/shares-account-actions/reject-shares/reject-shares.component.ts @@ -21,7 +21,7 @@ import { SharesService } from 'app/shares/shares.service'; export class RejectSharesComponent implements OnInit { /** Shares account data. */ - @Input() sharesAccountData: any; + sharesAccountData: any; /** Shares account Id */ accountId: any; @@ -48,6 +48,9 @@ export class RejectSharesComponent implements OnInit { private route: ActivatedRoute, public dialog: MatDialog) { this.accountId = this.route.parent.snapshot.params['shareAccountId']; + this.route.data.subscribe((data: { shareAccountActionData: any }) => { + this.sharesAccountData = data.shareAccountActionData; + }); } /** 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 0c7c1a4f0..d4ad09118 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,7 +3,7 @@ - - - - \ 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 0c1d440a0..3a9f05bcb 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 @@ -43,14 +43,9 @@ export class SharesAccountActionsComponent { /** * @param {ActivatedRoute} route Activated Route */ - constructor(private route: ActivatedRoute, - private sharesService: SharesService) { + constructor(private route: ActivatedRoute) { const name = this.route.snapshot.params['name']; - const accountId = this.route.parent.snapshot.params['shareAccountId']; - this.sharesService.getSharesAccountData(accountId, false).subscribe((response: any) => { - this.sharesAccountData = response; - this.actions[name] = true; - }); + this.actions[name] = true; } } diff --git a/src/app/shares/shares-account-view/shares-account-view.component.html b/src/app/shares/shares-account-view/shares-account-view.component.html index f57be6c05..b8fed945e 100644 --- a/src/app/shares/shares-account-view/shares-account-view.component.html +++ b/src/app/shares/shares-account-view/shares-account-view.component.html @@ -38,7 +38,7 @@ {{button.name}} - + 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 4423e6928..1b6ba1333 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 @@ -30,6 +30,9 @@ export class SharesAccountViewComponent implements OnInit { /** * Fetches shares account data from `resolve` * @param {ActivatedRoute} route Activated Route + * @param {Router} router Router + * @param {SharesService} sharesService Shares Service + * @param {MatDialog} dialog Mat Dialog */ constructor(private route: ActivatedRoute, private router: Router, @@ -94,7 +97,7 @@ export class SharesAccountViewComponent implements OnInit { this.router.navigate([`actions/${name}`], { relativeTo: this.route }); break; case 'Modify Application': - this.router.navigate(['edit-shares-account'], { relativeTo: this.route }); + this.router.navigate(['edit'], { relativeTo: this.route }); break; case 'Delete': this.deleteSharesAccount(); diff --git a/src/app/shares/shares-routing.module.ts b/src/app/shares/shares-routing.module.ts index bec5f131c..45c16231b 100644 --- a/src/app/shares/shares-routing.module.ts +++ b/src/app/shares/shares-routing.module.ts @@ -16,16 +16,18 @@ import { SharesAccountActionsComponent } from './shares-account-actions/shares-a /** Custom Resolvers */ 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 { SharesAccountAndTemplateResolver } from './common-resolvers/share-account-and-template.resolver'; +/** Shares Routes */ const routes: Routes = [ { path: '', data: { title: extract('Shares'), breadcrumb: 'Shares', routeParamBreadcrumb: false }, children: [ { - path: 'create-shares-account', + path: 'create', data: { title: extract('Create Shares Account'), breadcrumb: 'Create Shares Account' }, component: CreateSharesAccountComponent, resolve: { @@ -61,7 +63,7 @@ const routes: Routes = [ ] }, { - path: 'edit-shares-account', + path: 'edit', data: { title: extract('Edit Shares Account'), breadcrumb: 'Edit', routeParamBreadcrumb: false }, component: EditSharesAccountComponent, resolve: { @@ -71,7 +73,10 @@ const routes: Routes = [ { path: 'actions/: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({ imports: [RouterModule.forChild(routes)], exports: [RouterModule], providers: [ SharesAccountViewResolver, SharesAccountTemplateResolver, - SharesAccountAndTemplateResolver + SharesAccountAndTemplateResolver, + ShareAccountActionsResolver ] }) export class SharesRoutingModule { } diff --git a/src/app/shares/shares.service.ts b/src/app/shares/shares.service.ts index ddd13e6af..be480d43a 100644 --- a/src/app/shares/shares.service.ts +++ b/src/app/shares/shares.service.ts @@ -13,10 +13,14 @@ import { Observable } from 'rxjs'; }) export class SharesService { + /** + * @param {HttpClient} http Http Client + */ 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} Shares data. */ getSharesAccountData(accountId: string, template: boolean): Observable { @@ -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} Shares account template. */ getSharesAccountTemplate(clientId: string, productId?: string): Observable { @@ -43,6 +48,7 @@ export class SharesService { } /** + * @param {string} accountId: Shares account Id. * @param {any} sharesAccount Shares Account * @returns {Observable} */