Skip to content

Commit 8fce37c

Browse files
WEB-954: Migrate Subscription management : loans
1 parent 7db3ece commit 8fce37c

41 files changed

Lines changed: 418 additions & 267 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app/loans/create-loans-account/create-loans-account.component.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import {
1212
AfterViewInit,
1313
ChangeDetectorRef,
1414
Component,
15+
DestroyRef,
1516
QueryList,
1617
ViewChild,
1718
ViewChildren,
1819
inject
1920
} from '@angular/core';
21+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2022
import { ActivatedRoute } from '@angular/router';
2123

2224
/** Custom Services */
@@ -62,6 +64,7 @@ import { Dates } from 'app/core/utils/dates';
6264
changeDetection: ChangeDetectionStrategy.OnPush
6365
})
6466
export class CreateLoansAccountComponent extends LoanProductBaseComponent implements AfterViewInit {
67+
private readonly destroyRef = inject(DestroyRef);
6568
private route = inject(ActivatedRoute);
6669
private loansService = inject(LoansService);
6770
private settingsService = inject(SettingsService);
@@ -110,12 +113,12 @@ export class CreateLoansAccountComponent extends LoanProductBaseComponent implem
110113
constructor() {
111114
super();
112115
this.loanProductsBasicDetails = [];
113-
this.route.data.subscribe(
114-
(data: { loansAccountTemplate: any; loanProductsBasicDetails: LoanProductBasicDetails[] }) => {
116+
this.route.data
117+
.pipe(takeUntilDestroyed(this.destroyRef))
118+
.subscribe((data: { loansAccountTemplate: any; loanProductsBasicDetails: LoanProductBasicDetails[] }) => {
115119
this.loanProductsBasicDetails = data.loanProductsBasicDetails;
116120
this.loansAccountTemplate = data.loansAccountTemplate;
117-
}
118-
);
121+
});
119122
}
120123

121124
ngAfterViewInit() {

src/app/loans/custom-dialog/loans-account-add-collateral-dialog/loans-account-add-collateral-dialog.component.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
88

9-
import { ChangeDetectionStrategy, Component, OnInit, inject } from '@angular/core';
9+
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, inject } from '@angular/core';
10+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1011
import {
1112
MatDialogRef,
1213
MAT_DIALOG_DATA,
@@ -15,7 +16,7 @@ import {
1516
MatDialogActions,
1617
MatDialogClose
1718
} from '@angular/material/dialog';
18-
import { UntypedFormGroup, UntypedFormBuilder, Validators, ReactiveFormsModule } from '@angular/forms';
19+
import { UntypedFormGroup, UntypedFormBuilder, Validators } from '@angular/forms';
1920
import { CdkScrollable } from '@angular/cdk/scrolling';
2021
import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
2122

@@ -34,6 +35,7 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
3435
changeDetection: ChangeDetectionStrategy.OnPush
3536
})
3637
export class LoansAccountAddCollateralDialogComponent implements OnInit {
38+
private readonly destroyRef = inject(DestroyRef);
3739
dialogRef = inject<MatDialogRef<LoansAccountAddCollateralDialogComponent>>(MatDialogRef);
3840
data = inject(MAT_DIALOG_DATA);
3941
private formBuilder = inject(UntypedFormBuilder);
@@ -81,16 +83,28 @@ export class LoansAccountAddCollateralDialogComponent implements OnInit {
8183
* Subscribe to Form controls value changes
8284
*/
8385
buildDependencies() {
84-
this.addCollateralForm.controls.collateral.valueChanges.subscribe((collateral: any) => {
85-
this.collateralData = collateral;
86-
this.maxQuantity = collateral.quantity;
87-
});
86+
this.addCollateralForm.controls.collateral.valueChanges
87+
.pipe(takeUntilDestroyed(this.destroyRef))
88+
.subscribe((collateral: any) => {
89+
this.collateralData = collateral;
90+
this.maxQuantity = collateral.quantity;
91+
});
8892

89-
this.addCollateralForm.controls.quantity.valueChanges.subscribe((quantity: any) => {
90-
this.addCollateralForm.patchValue({
91-
totalValue: this.collateralData.basePrice * quantity,
92-
totalCollateralValue: (this.collateralData.basePrice * this.collateralData.pctToBase * quantity) / 100
93+
this.addCollateralForm.controls.quantity.valueChanges
94+
.pipe(takeUntilDestroyed(this.destroyRef))
95+
.subscribe((quantity: any) => {
96+
if (!this.collateralData || quantity === null || quantity === '') {
97+
this.addCollateralForm.patchValue({ totalValue: '', totalCollateralValue: '' }, { emitEvent: false });
98+
return;
99+
}
100+
101+
const basePrice = Number(this.collateralData.basePrice) || 0;
102+
const pctToBase = Number(this.collateralData.pctToBase) || 0;
103+
const qty = Number(quantity) || 0;
104+
this.addCollateralForm.patchValue({
105+
totalValue: basePrice * qty,
106+
totalCollateralValue: (basePrice * pctToBase * qty) / 100
107+
});
93108
});
94-
});
95109
}
96110
}

src/app/loans/edit-loans-account/edit-loans-account.component.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
88

9-
import { ChangeDetectionStrategy, Component, ViewChild, inject } from '@angular/core';
9+
import { ChangeDetectionStrategy, Component, DestroyRef, ViewChild, inject } from '@angular/core';
10+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1011
import { ActivatedRoute } from '@angular/router';
1112
import { LoansService } from '../loans.service';
1213
import { LoansAccountDetailsStepComponent } from '../loans-account-stepper/loans-account-details-step/loans-account-details-step.component';
@@ -47,6 +48,7 @@ import { LoanProductBaseComponent } from 'app/products/loan-products/common/loan
4748
changeDetection: ChangeDetectionStrategy.OnPush
4849
})
4950
export class EditLoansAccountComponent extends LoanProductBaseComponent {
51+
private readonly destroyRef = inject(DestroyRef);
5052
private route = inject(ActivatedRoute);
5153
private dateUtils = inject(Dates);
5254
private loansService = inject(LoansService);
@@ -79,8 +81,9 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
7981
this.loanProductService.initialize(LoanProductBaseComponent.resolveProductTypeDefault(this.route, 'loan'));
8082

8183
this.loanId = this.route.snapshot.params['loanId'];
82-
this.route.data.subscribe(
83-
(data: { loansAccountAndTemplate: any; loanProductsBasicDetails: LoanProductBasicDetails[] }) => {
84+
this.route.data
85+
.pipe(takeUntilDestroyed(this.destroyRef))
86+
.subscribe((data: { loansAccountAndTemplate: any; loanProductsBasicDetails: LoanProductBasicDetails[] }) => {
8487
this.loansAccountAndTemplate = data.loansAccountAndTemplate;
8588
if (this.loanProductService.isLoanProduct) {
8689
this.loansAccountProductTemplate = data.loansAccountAndTemplate;
@@ -92,8 +95,7 @@ export class EditLoansAccountComponent extends LoanProductBaseComponent {
9295
);
9396
}
9497
this.loanProductsBasicDetails = data.loanProductsBasicDetails;
95-
}
96-
);
98+
});
9799
}
98100

99101
/**

src/app/loans/glim-account/create-glim-account/create-glim-account.component.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@
77
*/
88

99
/** Angular Imports */
10-
import { ChangeDetectionStrategy, Component, QueryList, ViewChild, ViewChildren, inject } from '@angular/core';
10+
import {
11+
ChangeDetectionStrategy,
12+
Component,
13+
DestroyRef,
14+
QueryList,
15+
ViewChild,
16+
ViewChildren,
17+
inject
18+
} from '@angular/core';
19+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1120
import { I18nService } from 'app/core/i18n/i18n.service';
1221
import { ActivatedRoute, Router } from '@angular/router';
1322

@@ -51,6 +60,7 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
5160
changeDetection: ChangeDetectionStrategy.OnPush
5261
})
5362
export class CreateGlimAccountComponent {
63+
private readonly destroyRef = inject(DestroyRef);
5464
private route = inject(ActivatedRoute);
5565
private router = inject(Router);
5666
private loansService = inject(LoansService);
@@ -97,10 +107,12 @@ export class CreateGlimAccountComponent {
97107
* @param {ClientsService} clientService Client Service
98108
*/
99109
constructor() {
100-
this.route.data.subscribe((data: { loansAccountTemplate: any; groupsData: any }) => {
101-
this.loansAccountTemplate = data.loansAccountTemplate;
102-
this.dataSource = data.groupsData.activeClientMembers;
103-
});
110+
this.route.data
111+
.pipe(takeUntilDestroyed(this.destroyRef))
112+
.subscribe((data: { loansAccountTemplate: any; groupsData: any }) => {
113+
this.loansAccountTemplate = data.loansAccountTemplate;
114+
this.dataSource = data.groupsData.activeClientMembers;
115+
});
104116
}
105117

106118
/**

src/app/loans/glim-account/glim-account.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
77
*/
88

9-
import { ChangeDetectionStrategy, Component, OnInit, ViewChild, inject } from '@angular/core';
9+
import { ChangeDetectionStrategy, Component, DestroyRef, OnInit, ViewChild, inject } from '@angular/core';
10+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1011
import { MatDialog } from '@angular/material/dialog';
1112
import { MatPaginator } from '@angular/material/paginator';
1213
import {
@@ -53,6 +54,7 @@ import { STANDALONE_SHARED_IMPORTS } from 'app/standalone-shared.module';
5354
changeDetection: ChangeDetectionStrategy.OnPush
5455
})
5556
export class GlimAccountComponent implements OnInit {
57+
private readonly destroyRef = inject(DestroyRef);
5658
private route = inject(ActivatedRoute);
5759
dialog = inject(MatDialog);
5860

@@ -81,7 +83,7 @@ export class GlimAccountComponent implements OnInit {
8183
* @param {MatDialog} dialog Dialog reference.
8284
*/
8385
constructor() {
84-
this.route.data.subscribe((data: { glimData: any }) => {
86+
this.route.data.pipe(takeUntilDestroyed(this.destroyRef)).subscribe((data: { glimData: any }) => {
8587
this.glimOverviewData = data.glimData;
8688
});
8789
}

src/app/loans/loans-account-stepper/loans-account-details-step/loans-account-details-step.component.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ import {
1111
ChangeDetectionStrategy,
1212
ChangeDetectorRef,
1313
Component,
14+
DestroyRef,
1415
OnInit,
1516
Input,
1617
Output,
1718
EventEmitter,
18-
OnDestroy,
1919
inject
2020
} from '@angular/core';
21+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2122
import { UntypedFormGroup, UntypedFormBuilder, Validators, UntypedFormControl } from '@angular/forms';
2223
import { ActivatedRoute } from '@angular/router';
2324
import { SettingsService } from 'app/settings/settings.service';
@@ -26,8 +27,7 @@ import { TranslateService } from '@ngx-translate/core';
2627
/** Custom Services */
2728
import { LoansService } from '../../loans.service';
2829
import { Commons } from 'app/core/utils/commons';
29-
import { takeUntil } from 'rxjs/operators';
30-
import { ReplaySubject, Subject } from 'rxjs';
30+
import { ReplaySubject } from 'rxjs';
3131
import { MatTooltip } from '@angular/material/tooltip';
3232
import { NgxMatSelectSearchModule } from 'ngx-mat-select-search';
3333
import { AsyncPipe } from '@angular/common';
@@ -62,7 +62,8 @@ import { LoanProductBaseComponent } from 'app/products/loan-products/common/loan
6262
],
6363
changeDetection: ChangeDetectionStrategy.OnPush
6464
})
65-
export class LoansAccountDetailsStepComponent extends LoanProductBaseComponent implements OnInit, OnDestroy {
65+
export class LoansAccountDetailsStepComponent extends LoanProductBaseComponent implements OnInit {
66+
private readonly destroyRef = inject(DestroyRef);
6667
private formBuilder = inject(UntypedFormBuilder);
6768
private loansService = inject(LoansService);
6869
private route = inject(ActivatedRoute);
@@ -106,8 +107,6 @@ export class LoansAccountDetailsStepComponent extends LoanProductBaseComponent i
106107
protected productData: ReplaySubject<string[]> = new ReplaySubject<string[]>(1);
107108
/** control for the filter select */
108109
protected filterFormCtrl: UntypedFormControl = new UntypedFormControl('');
109-
/** Subject that emits when the component has been destroyed. */
110-
protected _onDestroy = new Subject<void>();
111110

112111
productSelected: LoanProductBasicDetails | null = null;
113112

@@ -167,17 +166,12 @@ export class LoansAccountDetailsStepComponent extends LoanProductBaseComponent i
167166
this.getProductTemplate(false);
168167
}
169168
}
170-
this.filterFormCtrl.valueChanges.pipe(takeUntil(this._onDestroy)).subscribe(() => {
169+
this.filterFormCtrl.valueChanges.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
171170
this.searchItem();
172171
});
173172
this.productData.next(this.productList.slice());
174173
}
175174

176-
ngOnDestroy(): void {
177-
this._onDestroy.next();
178-
this._onDestroy.complete();
179-
}
180-
181175
searchItem(): void {
182176
if (this.productList) {
183177
const search: string = this.filterFormCtrl.value.toLowerCase();

0 commit comments

Comments
 (0)