From 124bdc028d660216b0b1de2a213ca74d197a492d Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Fri, 31 Dec 2021 09:51:30 +0100 Subject: [PATCH] Bugfix/fix reload of position detail dialog (#603) * Fix reload of position detail dialog * Update changelog --- CHANGELOG.md | 1 + .../home-holdings/home-holdings.component.ts | 43 +++++++++------- .../position-detail-dialog.html | 2 +- .../positions-table.component.ts | 42 +--------------- .../allocations/allocations-page.component.ts | 49 ++++++++++++++++++- .../transactions-page.component.ts | 49 +++++++++++-------- 6 files changed, 104 insertions(+), 82 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 707896b00..0a9f5ebb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed an exception with the market state caused by a failed data provider request +- Fixed the reload of the position detail dialog (with query parameters) ## 1.98.0 - 29.12.2021 diff --git a/apps/client/src/app/components/home-holdings/home-holdings.component.ts b/apps/client/src/app/components/home-holdings/home-holdings.component.ts index 13b6ffe0d..3d26b373e 100644 --- a/apps/client/src/app/components/home-holdings/home-holdings.component.ts +++ b/apps/client/src/app/components/home-holdings/home-holdings.component.ts @@ -48,7 +48,7 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((params) => { if (params['positionDetailDialog'] && params['symbol']) { - this.openDialog(params['symbol']); + this.openPositionDialog({ symbol: params['symbol'] }); } }); @@ -91,24 +91,31 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { this.unsubscribeSubject.complete(); } - private openDialog(aSymbol: string): void { - const dialogRef = this.dialog.open(PositionDetailDialog, { - autoFocus: false, - data: { - baseCurrency: this.user?.settings?.baseCurrency, - deviceType: this.deviceType, - locale: this.user?.settings?.locale, - symbol: aSymbol - }, - height: this.deviceType === 'mobile' ? '97.5vh' : '80vh', - width: this.deviceType === 'mobile' ? '100vw' : '50rem' - }); - - dialogRef - .afterClosed() + private openPositionDialog({ symbol }: { symbol: string }) { + this.userService + .get() .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(() => { - this.router.navigate(['.'], { relativeTo: this.route }); + .subscribe((user) => { + this.user = user; + + const dialogRef = this.dialog.open(PositionDetailDialog, { + autoFocus: false, + data: { + symbol, + baseCurrency: this.user?.settings?.baseCurrency, + deviceType: this.deviceType, + locale: this.user?.settings?.locale + }, + height: this.deviceType === 'mobile' ? '97.5vh' : '80vh', + width: this.deviceType === 'mobile' ? '100vw' : '50rem' + }); + + dialogRef + .afterClosed() + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(() => { + this.router.navigate(['.'], { relativeTo: this.route }); + }); }); } diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html index 00d949263..3bd2b780b 100644 --- a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html +++ b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html @@ -12,7 +12,7 @@
diff --git a/apps/client/src/app/components/positions-table/positions-table.component.ts b/apps/client/src/app/components/positions-table/positions-table.component.ts index da6fe7f54..b06a052be 100644 --- a/apps/client/src/app/components/positions-table/positions-table.component.ts +++ b/apps/client/src/app/components/positions-table/positions-table.component.ts @@ -9,16 +9,13 @@ import { Output, ViewChild } from '@angular/core'; -import { MatDialog } from '@angular/material/dialog'; import { MatPaginator } from '@angular/material/paginator'; import { MatSort } from '@angular/material/sort'; import { MatTableDataSource } from '@angular/material/table'; -import { ActivatedRoute, Router } from '@angular/router'; -import { PositionDetailDialog } from '@ghostfolio/client/components/position/position-detail-dialog/position-detail-dialog.component'; +import { Router } from '@angular/router'; import { PortfolioPosition } from '@ghostfolio/common/interfaces'; import { AssetClass, Order as OrderModel } from '@prisma/client'; import { Subject, Subscription } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; @Component({ selector: 'gf-positions-table', @@ -48,21 +45,7 @@ export class PositionsTableComponent implements OnChanges, OnDestroy, OnInit { private unsubscribeSubject = new Subject(); - public constructor( - private dialog: MatDialog, - private route: ActivatedRoute, - private router: Router - ) { - this.routeQueryParams = route.queryParams - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe((params) => { - if (params['positionDetailDialog'] && params['symbol']) { - this.openPositionDialog({ - symbol: params['symbol'] - }); - } - }); - } + public constructor(private router: Router) {} public ngOnInit() {} @@ -105,27 +88,6 @@ export class PositionsTableComponent implements OnChanges, OnDestroy, OnInit { }); } - public openPositionDialog({ symbol }: { symbol: string }): void { - const dialogRef = this.dialog.open(PositionDetailDialog, { - autoFocus: false, - data: { - symbol, - baseCurrency: this.baseCurrency, - deviceType: this.deviceType, - locale: this.locale - }, - height: this.deviceType === 'mobile' ? '97.5vh' : '80vh', - width: this.deviceType === 'mobile' ? '100vw' : '50rem' - }); - - dialogRef - .afterClosed() - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(() => { - this.router.navigate(['.'], { relativeTo: this.route }); - }); - } - public ngOnDestroy() { this.unsubscribeSubject.next(); this.unsubscribeSubject.complete(); diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts index 482313244..678c87801 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.component.ts @@ -1,4 +1,7 @@ import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; +import { MatDialog } from '@angular/material/dialog'; +import { ActivatedRoute, Router } from '@angular/router'; +import { PositionDetailDialog } from '@ghostfolio/client/components/position/position-detail-dialog/position-detail-dialog.component'; import { DataService } from '@ghostfolio/client/services/data.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; import { UserService } from '@ghostfolio/client/services/user/user.service'; @@ -12,7 +15,7 @@ import { import { ToggleOption } from '@ghostfolio/common/types'; import { AssetClass } from '@prisma/client'; import { DeviceDetectorService } from 'ngx-device-detector'; -import { Subject } from 'rxjs'; +import { Subject, Subscription } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @Component({ @@ -51,6 +54,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { >; }; public positionsArray: PortfolioPosition[]; + public routeQueryParams: Subscription; public sectors: { [name: string]: { name: string; value: number }; }; @@ -69,9 +73,22 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { private changeDetectorRef: ChangeDetectorRef, private dataService: DataService, private deviceService: DeviceDetectorService, + private dialog: MatDialog, private impersonationStorageService: ImpersonationStorageService, + private route: ActivatedRoute, + private router: Router, private userService: UserService - ) {} + ) { + this.routeQueryParams = route.queryParams + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe((params) => { + if (params['positionDetailDialog'] && params['symbol']) { + this.openPositionDialog({ + symbol: params['symbol'] + }); + } + }); + } /** * Initializes the controller @@ -266,4 +283,32 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { this.unsubscribeSubject.next(); this.unsubscribeSubject.complete(); } + + private openPositionDialog({ symbol }: { symbol: string }) { + this.userService + .get() + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe((user) => { + this.user = user; + + const dialogRef = this.dialog.open(PositionDetailDialog, { + autoFocus: false, + data: { + symbol, + baseCurrency: this.user?.settings?.baseCurrency, + deviceType: this.deviceType, + locale: this.user?.settings?.locale + }, + height: this.deviceType === 'mobile' ? '97.5vh' : '80vh', + width: this.deviceType === 'mobile' ? '100vw' : '50rem' + }); + + dialogRef + .afterClosed() + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(() => { + this.router.navigate(['.'], { relativeTo: this.route }); + }); + }); + } } diff --git a/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts b/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts index 59342f335..2b9f85a0d 100644 --- a/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts +++ b/apps/client/src/app/pages/portfolio/transactions/transactions-page.component.ts @@ -255,27 +255,6 @@ export class TransactionsPageComponent implements OnDestroy, OnInit { }); } - public openPositionDialog({ symbol }: { symbol: string }): void { - const dialogRef = this.dialog.open(PositionDetailDialog, { - autoFocus: false, - data: { - symbol, - baseCurrency: this.user?.settings?.baseCurrency, - deviceType: this.deviceType, - locale: this.user?.settings?.locale - }, - height: this.deviceType === 'mobile' ? '97.5vh' : '80vh', - width: this.deviceType === 'mobile' ? '100vw' : '50rem' - }); - - dialogRef - .afterClosed() - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(() => { - this.router.navigate(['.'], { relativeTo: this.route }); - }); - } - public openUpdateTransactionDialog({ accountId, currency, @@ -412,4 +391,32 @@ export class TransactionsPageComponent implements OnDestroy, OnInit { this.router.navigate(['.'], { relativeTo: this.route }); }); } + + private openPositionDialog({ symbol }: { symbol: string }) { + this.userService + .get() + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe((user) => { + this.user = user; + + const dialogRef = this.dialog.open(PositionDetailDialog, { + autoFocus: false, + data: { + symbol, + baseCurrency: this.user?.settings?.baseCurrency, + deviceType: this.deviceType, + locale: this.user?.settings?.locale + }, + height: this.deviceType === 'mobile' ? '97.5vh' : '80vh', + width: this.deviceType === 'mobile' ? '100vw' : '50rem' + }); + + dialogRef + .afterClosed() + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(() => { + this.router.navigate(['.'], { relativeTo: this.route }); + }); + }); + } }