From f3d961bc16bb43356d398ac360059690e4c6dd45 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 4 May 2024 14:11:37 +0200 Subject: [PATCH 1/6] Feature/move holdings table to holdings tab of home page (#3368) * Move holdings table to holdings tab of home page * Deprecate api/v1/portfolio/positions endpoint * Update changelog --- CHANGELOG.md | 1 + .../src/app/portfolio/portfolio.controller.ts | 3 + .../home-holdings/home-holdings.component.ts | 98 +++++----- .../home-holdings/home-holdings.html | 55 +++--- .../home-holdings/home-holdings.module.ts | 8 +- .../interfaces/interfaces.ts | 0 .../position-detail-dialog.component.scss | 0 .../position-detail-dialog.component.ts | 0 .../position-detail-dialog.html | 0 .../position-detail-dialog.module.ts | 0 .../position/position.component.html | 72 -------- .../position/position.component.scss | 13 -- .../components/position/position.component.ts | 40 ---- .../components/position/position.module.ts | 29 --- .../positions/positions.component.html | 35 ---- .../positions/positions.component.scss | 17 -- .../positions/positions.component.ts | 70 ------- .../components/positions/positions.module.ts | 21 --- .../src/app/components/rules/rules.module.ts | 2 - .../pages/home/home-page-routing.module.ts | 5 + .../activities/activities-page.component.ts | 4 +- .../allocations/allocations-page.component.ts | 6 +- .../analysis/analysis-page.component.ts | 6 +- .../holdings/holdings-page-routing.module.ts | 21 --- .../holdings/holdings-page.component.ts | 171 ------------------ .../portfolio/holdings/holdings-page.html | 38 ---- .../holdings/holdings-page.module.ts | 22 --- .../portfolio/holdings/holdings-page.scss | 3 - .../portfolio-page-routing.module.ts | 7 - .../portfolio/portfolio-page.component.ts | 5 - apps/client/src/app/services/data.service.ts | 3 + .../holdings-table.component.ts | 2 +- 32 files changed, 108 insertions(+), 649 deletions(-) rename apps/client/src/app/components/{position => }/position-detail-dialog/interfaces/interfaces.ts (100%) rename apps/client/src/app/components/{position => }/position-detail-dialog/position-detail-dialog.component.scss (100%) rename apps/client/src/app/components/{position => }/position-detail-dialog/position-detail-dialog.component.ts (100%) rename apps/client/src/app/components/{position => }/position-detail-dialog/position-detail-dialog.html (100%) rename apps/client/src/app/components/{position => }/position-detail-dialog/position-detail-dialog.module.ts (100%) delete mode 100644 apps/client/src/app/components/position/position.component.html delete mode 100644 apps/client/src/app/components/position/position.component.scss delete mode 100644 apps/client/src/app/components/position/position.component.ts delete mode 100644 apps/client/src/app/components/position/position.module.ts delete mode 100644 apps/client/src/app/components/positions/positions.component.html delete mode 100644 apps/client/src/app/components/positions/positions.component.scss delete mode 100644 apps/client/src/app/components/positions/positions.component.ts delete mode 100644 apps/client/src/app/components/positions/positions.module.ts delete mode 100644 apps/client/src/app/pages/portfolio/holdings/holdings-page-routing.module.ts delete mode 100644 apps/client/src/app/pages/portfolio/holdings/holdings-page.component.ts delete mode 100644 apps/client/src/app/pages/portfolio/holdings/holdings-page.html delete mode 100644 apps/client/src/app/pages/portfolio/holdings/holdings-page.module.ts delete mode 100644 apps/client/src/app/pages/portfolio/holdings/holdings-page.scss diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ba54382c..a744b8e3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Moved the holdings table to the holdings tab of the home page - Improved the performance labels (with and without currency effects) in the position detail dialog ## 2.78.0 - 2024-05-02 diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index 0828fb3e4..7aa8e9159 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -490,6 +490,9 @@ export class PortfolioController { return performanceInformation; } + /** + * @deprecated + */ @Get('positions') @UseGuards(AuthGuard('jwt'), HasPermissionGuard) @UseInterceptors(RedactValuesInResponseInterceptor) 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 9dbf9d9bf..1a556e6f4 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 @@ -1,11 +1,11 @@ -import { PositionDetailDialog } from '@ghostfolio/client/components/position/position-detail-dialog/position-detail-dialog.component'; -import { ToggleComponent } from '@ghostfolio/client/components/toggle/toggle.component'; +import { PositionDetailDialogParams } from '@ghostfolio/client/components/position-detail-dialog/interfaces/interfaces'; +import { PositionDetailDialog } from '@ghostfolio/client/components/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'; -import { Position, User } from '@ghostfolio/common/interfaces'; +import { PortfolioPosition, User } from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; -import { DateRange } from '@ghostfolio/common/types'; +import { HoldingType, ToggleOption } from '@ghostfolio/common/types'; import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; @@ -15,19 +15,21 @@ import { DeviceDetectorService } from 'ngx-device-detector'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; -import { PositionDetailDialogParams } from '../position/position-detail-dialog/interfaces/interfaces'; - @Component({ selector: 'gf-home-holdings', styleUrls: ['./home-holdings.scss'], templateUrl: './home-holdings.html' }) export class HomeHoldingsComponent implements OnDestroy, OnInit { - public dateRangeOptions = ToggleComponent.DEFAULT_DATE_RANGE_OPTIONS; public deviceType: string; public hasImpersonationId: boolean; public hasPermissionToCreateOrder: boolean; - public positions: Position[]; + public holdings: PortfolioPosition[]; + public holdingType: HoldingType = 'ACTIVE'; + public holdingTypeOptions: ToggleOption[] = [ + { label: $localize`Active`, value: 'ACTIVE' }, + { label: $localize`Closed`, value: 'CLOSED' } + ]; public user: User; private unsubscribeSubject = new Subject(); @@ -56,6 +58,17 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { }); } }); + } + + public ngOnInit() { + this.deviceType = this.deviceService.getDeviceInfo().deviceType; + + this.impersonationStorageService + .onChangeHasImpersonation() + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe((impersonationId) => { + this.hasImpersonationId = !!impersonationId; + }); this.userService.stateChanged .pipe(takeUntil(this.unsubscribeSubject)) @@ -68,37 +81,32 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { permissions.createOrder ); - this.update(); + this.holdings = undefined; + + this.fetchHoldings() + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(({ holdings }) => { + this.holdings = holdings; + + this.changeDetectorRef.markForCheck(); + }); + + this.changeDetectorRef.markForCheck(); } }); } - public ngOnInit() { - this.deviceType = this.deviceService.getDeviceInfo().deviceType; + public onChangeHoldingType(aHoldingType: HoldingType) { + this.holdingType = aHoldingType; - this.impersonationStorageService - .onChangeHasImpersonation() - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe((impersonationId) => { - this.hasImpersonationId = !!impersonationId; - }); - } + this.holdings = undefined; - public onChangeDateRange(dateRange: DateRange) { - this.dataService - .putUserSetting({ dateRange }) + this.fetchHoldings() .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(() => { - this.userService.remove(); - - this.userService - .get() - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe((user) => { - this.user = user; + .subscribe(({ holdings }) => { + this.holdings = holdings; - this.changeDetectorRef.markForCheck(); - }); + this.changeDetectorRef.markForCheck(); }); } @@ -107,6 +115,19 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { this.unsubscribeSubject.complete(); } + private fetchHoldings() { + const filters = this.userService.getFilters(); + + if (this.holdingType === 'CLOSED') { + filters.push({ id: 'CLOSED', type: 'HOLDING_TYPE' }); + } + + return this.dataService.fetchPortfolioHoldings({ + filters, + range: this.user?.settings?.dateRange + }); + } + private openPositionDialog({ dataSource, symbol @@ -147,19 +168,4 @@ export class HomeHoldingsComponent implements OnDestroy, OnInit { }); }); } - - private update() { - this.positions = undefined; - - this.dataService - .fetchPositions({ range: this.user?.settings?.dateRange }) - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(({ positions }) => { - this.positions = positions; - - this.changeDetectorRef.markForCheck(); - }); - - this.changeDetectorRef.markForCheck(); - } } diff --git a/apps/client/src/app/components/home-holdings/home-holdings.html b/apps/client/src/app/components/home-holdings/home-holdings.html index 72328eac2..a2bd43636 100644 --- a/apps/client/src/app/components/home-holdings/home-holdings.html +++ b/apps/client/src/app/components/home-holdings/home-holdings.html @@ -1,27 +1,38 @@ -
+
-
- - - - - -
- Manage Activities +
+

Holdings

+
+
+
+
+
+
+ + @if (hasPermissionToCreateOrder && holdings?.length > 0) { + + }
diff --git a/apps/client/src/app/components/home-holdings/home-holdings.module.ts b/apps/client/src/app/components/home-holdings/home-holdings.module.ts index b6fa70e8f..f10adeab2 100644 --- a/apps/client/src/app/components/home-holdings/home-holdings.module.ts +++ b/apps/client/src/app/components/home-holdings/home-holdings.module.ts @@ -1,11 +1,9 @@ -import { GfPositionDetailDialogModule } from '@ghostfolio/client/components/position/position-detail-dialog/position-detail-dialog.module'; -import { GfPositionsModule } from '@ghostfolio/client/components/positions/positions.module'; import { GfToggleModule } from '@ghostfolio/client/components/toggle/toggle.module'; +import { GfHoldingsTableComponent } from '@ghostfolio/ui/holdings-table'; import { CommonModule } from '@angular/common'; import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; -import { MatCardModule } from '@angular/material/card'; import { RouterModule } from '@angular/router'; import { HomeHoldingsComponent } from './home-holdings.component'; @@ -14,11 +12,9 @@ import { HomeHoldingsComponent } from './home-holdings.component'; declarations: [HomeHoldingsComponent], imports: [ CommonModule, - GfPositionDetailDialogModule, - GfPositionsModule, + GfHoldingsTableComponent, GfToggleModule, MatButtonModule, - MatCardModule, RouterModule ], schemas: [CUSTOM_ELEMENTS_SCHEMA] diff --git a/apps/client/src/app/components/position/position-detail-dialog/interfaces/interfaces.ts b/apps/client/src/app/components/position-detail-dialog/interfaces/interfaces.ts similarity index 100% rename from apps/client/src/app/components/position/position-detail-dialog/interfaces/interfaces.ts rename to apps/client/src/app/components/position-detail-dialog/interfaces/interfaces.ts diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.scss b/apps/client/src/app/components/position-detail-dialog/position-detail-dialog.component.scss similarity index 100% rename from apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.scss rename to apps/client/src/app/components/position-detail-dialog/position-detail-dialog.component.scss diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts b/apps/client/src/app/components/position-detail-dialog/position-detail-dialog.component.ts similarity index 100% rename from apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts rename to apps/client/src/app/components/position-detail-dialog/position-detail-dialog.component.ts diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html b/apps/client/src/app/components/position-detail-dialog/position-detail-dialog.html similarity index 100% rename from apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.html rename to apps/client/src/app/components/position-detail-dialog/position-detail-dialog.html diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.module.ts b/apps/client/src/app/components/position-detail-dialog/position-detail-dialog.module.ts similarity index 100% rename from apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.module.ts rename to apps/client/src/app/components/position-detail-dialog/position-detail-dialog.module.ts diff --git a/apps/client/src/app/components/position/position.component.html b/apps/client/src/app/components/position/position.component.html deleted file mode 100644 index 4a5ed6f9a..000000000 --- a/apps/client/src/app/components/position/position.component.html +++ /dev/null @@ -1,72 +0,0 @@ - diff --git a/apps/client/src/app/components/position/position.component.scss b/apps/client/src/app/components/position/position.component.scss deleted file mode 100644 index 7044d7795..000000000 --- a/apps/client/src/app/components/position/position.component.scss +++ /dev/null @@ -1,13 +0,0 @@ -:host { - display: block; - - .container { - gf-trend-indicator { - padding-top: 0.15rem; - } - - .chevron { - opacity: 0.33; - } - } -} diff --git a/apps/client/src/app/components/position/position.component.ts b/apps/client/src/app/components/position/position.component.ts deleted file mode 100644 index 3a5fbae81..000000000 --- a/apps/client/src/app/components/position/position.component.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { UNKNOWN_KEY } from '@ghostfolio/common/config'; -import { getLocale } from '@ghostfolio/common/helper'; -import { Position } from '@ghostfolio/common/interfaces'; - -import { - ChangeDetectionStrategy, - Component, - Input, - OnDestroy, - OnInit -} from '@angular/core'; -import { Subject } from 'rxjs'; - -@Component({ - selector: 'gf-position', - changeDetection: ChangeDetectionStrategy.OnPush, - templateUrl: './position.component.html', - styleUrls: ['./position.component.scss'] -}) -export class PositionComponent implements OnDestroy, OnInit { - @Input() baseCurrency: string; - @Input() deviceType: string; - @Input() isLoading: boolean; - @Input() locale = getLocale(); - @Input() position: Position; - @Input() range: string; - - public unknownKey = UNKNOWN_KEY; - - private unsubscribeSubject = new Subject(); - - public constructor() {} - - public ngOnInit() {} - - public ngOnDestroy() { - this.unsubscribeSubject.next(); - this.unsubscribeSubject.complete(); - } -} diff --git a/apps/client/src/app/components/position/position.module.ts b/apps/client/src/app/components/position/position.module.ts deleted file mode 100644 index 6483e274a..000000000 --- a/apps/client/src/app/components/position/position.module.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { GfSymbolModule } from '@ghostfolio/client/pipes/symbol/symbol.module'; -import { GfTrendIndicatorComponent } from '@ghostfolio/ui/trend-indicator'; -import { GfValueComponent } from '@ghostfolio/ui/value'; - -import { CommonModule } from '@angular/common'; -import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; -import { MatDialogModule } from '@angular/material/dialog'; -import { RouterModule } from '@angular/router'; -import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; - -import { GfPositionDetailDialogModule } from './position-detail-dialog/position-detail-dialog.module'; -import { PositionComponent } from './position.component'; - -@NgModule({ - declarations: [PositionComponent], - exports: [PositionComponent], - imports: [ - CommonModule, - GfPositionDetailDialogModule, - GfSymbolModule, - GfTrendIndicatorComponent, - GfValueComponent, - MatDialogModule, - NgxSkeletonLoaderModule, - RouterModule - ], - schemas: [CUSTOM_ELEMENTS_SCHEMA] -}) -export class GfPositionModule {} diff --git a/apps/client/src/app/components/positions/positions.component.html b/apps/client/src/app/components/positions/positions.component.html deleted file mode 100644 index 606c59211..000000000 --- a/apps/client/src/app/components/positions/positions.component.html +++ /dev/null @@ -1,35 +0,0 @@ -
-
-
- - - - - - - - -
- -
-
-
-
-
diff --git a/apps/client/src/app/components/positions/positions.component.scss b/apps/client/src/app/components/positions/positions.component.scss deleted file mode 100644 index d3e8995a1..000000000 --- a/apps/client/src/app/components/positions/positions.component.scss +++ /dev/null @@ -1,17 +0,0 @@ -:host { - display: block; - - gf-position { - &:nth-child(even) { - background-color: rgba(0, 0, 0, var(--gf-theme-alpha-hover)); - } - } -} - -:host-context(.is-dark-theme) { - gf-position { - &:nth-child(even) { - background-color: rgba(255, 255, 255, var(--gf-theme-alpha-hover)); - } - } -} diff --git a/apps/client/src/app/components/positions/positions.component.ts b/apps/client/src/app/components/positions/positions.component.ts deleted file mode 100644 index ab9812462..000000000 --- a/apps/client/src/app/components/positions/positions.component.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { getLocale } from '@ghostfolio/common/helper'; -import { Position } from '@ghostfolio/common/interfaces'; - -import { - ChangeDetectionStrategy, - Component, - Input, - OnChanges, - OnInit -} from '@angular/core'; - -@Component({ - selector: 'gf-positions', - changeDetection: ChangeDetectionStrategy.OnPush, - templateUrl: './positions.component.html', - styleUrls: ['./positions.component.scss'] -}) -export class PositionsComponent implements OnChanges, OnInit { - @Input() baseCurrency: string; - @Input() deviceType: string; - @Input() hasPermissionToCreateOrder: boolean; - @Input() locale = getLocale(); - @Input() positions: Position[]; - @Input() range: string; - - public hasPositions: boolean; - public positionsRest: Position[] = []; - public positionsWithPriority: Position[] = []; - - public constructor() {} - - public ngOnInit() {} - - public ngOnChanges() { - if (this.positions) { - this.hasPositions = this.positions.length > 0; - - if (!this.hasPositions) { - return; - } - - this.positionsRest = []; - this.positionsWithPriority = []; - - for (const portfolioPosition of this.positions) { - if (portfolioPosition.marketState === 'open' || this.range !== '1d') { - // Only show positions where the market is open in today's view - this.positionsWithPriority.push(portfolioPosition); - } else { - this.positionsRest.push(portfolioPosition); - } - } - - this.positionsRest.sort((a, b) => - (a.name || a.symbol)?.toLowerCase() > - (b.name || b.symbol)?.toLowerCase() - ? 1 - : -1 - ); - this.positionsWithPriority.sort((a, b) => - (a.name || a.symbol)?.toLowerCase() > - (b.name || b.symbol)?.toLowerCase() - ? 1 - : -1 - ); - } else { - this.hasPositions = false; - } - } -} diff --git a/apps/client/src/app/components/positions/positions.module.ts b/apps/client/src/app/components/positions/positions.module.ts deleted file mode 100644 index 34bd38b2d..000000000 --- a/apps/client/src/app/components/positions/positions.module.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { GfNoTransactionsInfoComponent } from '@ghostfolio/ui/no-transactions-info'; - -import { CommonModule } from '@angular/common'; -import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; -import { MatButtonModule } from '@angular/material/button'; - -import { GfPositionModule } from '../position/position.module'; -import { PositionsComponent } from './positions.component'; - -@NgModule({ - declarations: [PositionsComponent], - exports: [PositionsComponent], - imports: [ - CommonModule, - GfNoTransactionsInfoComponent, - GfPositionModule, - MatButtonModule - ], - schemas: [CUSTOM_ELEMENTS_SCHEMA] -}) -export class GfPositionsModule {} diff --git a/apps/client/src/app/components/rules/rules.module.ts b/apps/client/src/app/components/rules/rules.module.ts index 3b82c6ab1..26ed1d83e 100644 --- a/apps/client/src/app/components/rules/rules.module.ts +++ b/apps/client/src/app/components/rules/rules.module.ts @@ -6,7 +6,6 @@ import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; import { MatButtonModule } from '@angular/material/button'; import { MatCardModule } from '@angular/material/card'; -import { GfPositionModule } from '../position/position.module'; import { RulesComponent } from './rules.component'; @NgModule({ @@ -15,7 +14,6 @@ import { RulesComponent } from './rules.component'; imports: [ CommonModule, GfNoTransactionsInfoComponent, - GfPositionModule, GfRuleModule, MatButtonModule, MatCardModule diff --git a/apps/client/src/app/pages/home/home-page-routing.module.ts b/apps/client/src/app/pages/home/home-page-routing.module.ts index bccfc2f57..f50b55192 100644 --- a/apps/client/src/app/pages/home/home-page-routing.module.ts +++ b/apps/client/src/app/pages/home/home-page-routing.module.ts @@ -22,6 +22,11 @@ const routes: Routes = [ component: HomeHoldingsComponent, title: $localize`Holdings` }, + { + path: 'holdings', + component: HomeHoldingsComponent, + title: $localize`Holdings` + }, { path: 'summary', component: HomeSummaryComponent, diff --git a/apps/client/src/app/pages/portfolio/activities/activities-page.component.ts b/apps/client/src/app/pages/portfolio/activities/activities-page.component.ts index f6f0feded..6e66bb666 100644 --- a/apps/client/src/app/pages/portfolio/activities/activities-page.component.ts +++ b/apps/client/src/app/pages/portfolio/activities/activities-page.component.ts @@ -1,8 +1,8 @@ import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto'; import { Activity } from '@ghostfolio/api/app/order/interfaces/activities.interface'; import { UpdateOrderDto } from '@ghostfolio/api/app/order/update-order.dto'; -import { PositionDetailDialogParams } from '@ghostfolio/client/components/position/position-detail-dialog/interfaces/interfaces'; -import { PositionDetailDialog } from '@ghostfolio/client/components/position/position-detail-dialog/position-detail-dialog.component'; +import { PositionDetailDialogParams } from '@ghostfolio/client/components/position-detail-dialog/interfaces/interfaces'; +import { PositionDetailDialog } from '@ghostfolio/client/components/position-detail-dialog/position-detail-dialog.component'; import { DataService } from '@ghostfolio/client/services/data.service'; import { IcsService } from '@ghostfolio/client/services/ics/ics.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; 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 6d3aed4d3..0172c8094 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,7 +1,7 @@ import { AccountDetailDialog } from '@ghostfolio/client/components/account-detail-dialog/account-detail-dialog.component'; import { AccountDetailDialogParams } from '@ghostfolio/client/components/account-detail-dialog/interfaces/interfaces'; -import { PositionDetailDialogParams } from '@ghostfolio/client/components/position/position-detail-dialog/interfaces/interfaces'; -import { PositionDetailDialog } from '@ghostfolio/client/components/position/position-detail-dialog/position-detail-dialog.component'; +import { PositionDetailDialogParams } from '@ghostfolio/client/components/position-detail-dialog/interfaces/interfaces'; +import { PositionDetailDialog } from '@ghostfolio/client/components/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'; @@ -103,7 +103,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { private router: Router, private userService: UserService ) { - route.queryParams + this.route.queryParams .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((params) => { if (params['accountId'] && params['accountDetailDialog']) { diff --git a/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts b/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts index 184297b26..4acf6dbb9 100644 --- a/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts +++ b/apps/client/src/app/pages/portfolio/analysis/analysis-page.component.ts @@ -1,5 +1,5 @@ -import { PositionDetailDialogParams } from '@ghostfolio/client/components/position/position-detail-dialog/interfaces/interfaces'; -import { PositionDetailDialog } from '@ghostfolio/client/components/position/position-detail-dialog/position-detail-dialog.component'; +import { PositionDetailDialogParams } from '@ghostfolio/client/components/position-detail-dialog/interfaces/interfaces'; +import { PositionDetailDialog } from '@ghostfolio/client/components/position-detail-dialog/position-detail-dialog.component'; import { ToggleComponent } from '@ghostfolio/client/components/toggle/toggle.component'; import { DataService } from '@ghostfolio/client/services/data.service'; import { ImpersonationStorageService } from '@ghostfolio/client/services/impersonation-storage.service'; @@ -80,7 +80,7 @@ export class AnalysisPageComponent implements OnDestroy, OnInit { const { benchmarks } = this.dataService.fetchInfo(); this.benchmarks = benchmarks; - route.queryParams + this.route.queryParams .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((params) => { if ( diff --git a/apps/client/src/app/pages/portfolio/holdings/holdings-page-routing.module.ts b/apps/client/src/app/pages/portfolio/holdings/holdings-page-routing.module.ts deleted file mode 100644 index 94b49a9d0..000000000 --- a/apps/client/src/app/pages/portfolio/holdings/holdings-page-routing.module.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { AuthGuard } from '@ghostfolio/client/core/auth.guard'; - -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; - -import { HoldingsPageComponent } from './holdings-page.component'; - -const routes: Routes = [ - { - canActivate: [AuthGuard], - component: HoldingsPageComponent, - path: '', - title: $localize`Holdings` - } -]; - -@NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule] -}) -export class HoldingsPageRoutingModule {} diff --git a/apps/client/src/app/pages/portfolio/holdings/holdings-page.component.ts b/apps/client/src/app/pages/portfolio/holdings/holdings-page.component.ts deleted file mode 100644 index 107e8f307..000000000 --- a/apps/client/src/app/pages/portfolio/holdings/holdings-page.component.ts +++ /dev/null @@ -1,171 +0,0 @@ -import { PositionDetailDialogParams } from '@ghostfolio/client/components/position/position-detail-dialog/interfaces/interfaces'; -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'; -import { PortfolioPosition, User } from '@ghostfolio/common/interfaces'; -import { hasPermission, permissions } from '@ghostfolio/common/permissions'; -import { HoldingType, ToggleOption } from '@ghostfolio/common/types'; - -import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; -import { MatDialog } from '@angular/material/dialog'; -import { ActivatedRoute, Router } from '@angular/router'; -import { DataSource } from '@prisma/client'; -import { DeviceDetectorService } from 'ngx-device-detector'; -import { Subject } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; - -@Component({ - selector: 'gf-holdings-page', - styleUrls: ['./holdings-page.scss'], - templateUrl: './holdings-page.html' -}) -export class HoldingsPageComponent implements OnDestroy, OnInit { - public deviceType: string; - public hasImpersonationId: boolean; - public hasPermissionToCreateOrder: boolean; - public holdings: PortfolioPosition[]; - public holdingType: HoldingType = 'ACTIVE'; - public holdingTypeOptions: ToggleOption[] = [ - { label: $localize`Active`, value: 'ACTIVE' }, - { label: $localize`Closed`, value: 'CLOSED' } - ]; - public user: User; - - private unsubscribeSubject = new Subject(); - - public constructor( - private changeDetectorRef: ChangeDetectorRef, - private dataService: DataService, - private deviceService: DeviceDetectorService, - private dialog: MatDialog, - private impersonationStorageService: ImpersonationStorageService, - private route: ActivatedRoute, - private router: Router, - private userService: UserService - ) { - route.queryParams - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe((params) => { - if ( - params['dataSource'] && - params['positionDetailDialog'] && - params['symbol'] - ) { - this.openPositionDialog({ - dataSource: params['dataSource'], - symbol: params['symbol'] - }); - } - }); - } - - public ngOnInit() { - this.deviceType = this.deviceService.getDeviceInfo().deviceType; - - this.impersonationStorageService - .onChangeHasImpersonation() - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe((impersonationId) => { - this.hasImpersonationId = !!impersonationId; - }); - - this.userService.stateChanged - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe((state) => { - if (state?.user) { - this.user = state.user; - - this.hasPermissionToCreateOrder = hasPermission( - this.user.permissions, - permissions.createOrder - ); - - this.holdings = undefined; - - this.fetchHoldings() - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(({ holdings }) => { - this.holdings = holdings; - - this.changeDetectorRef.markForCheck(); - }); - - this.changeDetectorRef.markForCheck(); - } - }); - } - - public onChangeHoldingType(aHoldingType: HoldingType) { - this.holdingType = aHoldingType; - - this.holdings = undefined; - - this.fetchHoldings() - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(({ holdings }) => { - this.holdings = holdings; - - this.changeDetectorRef.markForCheck(); - }); - } - - public ngOnDestroy() { - this.unsubscribeSubject.next(); - this.unsubscribeSubject.complete(); - } - - private fetchHoldings() { - const filters = this.userService.getFilters(); - - if (this.holdingType === 'CLOSED') { - filters.push({ id: 'CLOSED', type: 'HOLDING_TYPE' }); - } - - return this.dataService.fetchPortfolioHoldings({ - filters, - range: this.user?.settings?.dateRange - }); - } - - private openPositionDialog({ - dataSource, - symbol - }: { - dataSource: DataSource; - symbol: string; - }) { - this.userService - .get() - .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe((user) => { - this.user = user; - - const dialogRef = this.dialog.open(PositionDetailDialog, { - autoFocus: false, - data: { - dataSource, - symbol, - baseCurrency: this.user?.settings?.baseCurrency, - colorScheme: this.user?.settings?.colorScheme, - deviceType: this.deviceType, - hasImpersonationId: this.hasImpersonationId, - hasPermissionToReportDataGlitch: hasPermission( - this.user?.permissions, - permissions.reportDataGlitch - ), - 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/holdings/holdings-page.html b/apps/client/src/app/pages/portfolio/holdings/holdings-page.html deleted file mode 100644 index a2bd43636..000000000 --- a/apps/client/src/app/pages/portfolio/holdings/holdings-page.html +++ /dev/null @@ -1,38 +0,0 @@ -
-
-
-

Holdings

-
-
-
-
-
- -
- - @if (hasPermissionToCreateOrder && holdings?.length > 0) { - - } -
-
-
diff --git a/apps/client/src/app/pages/portfolio/holdings/holdings-page.module.ts b/apps/client/src/app/pages/portfolio/holdings/holdings-page.module.ts deleted file mode 100644 index a5040f373..000000000 --- a/apps/client/src/app/pages/portfolio/holdings/holdings-page.module.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { GfToggleModule } from '@ghostfolio/client/components/toggle/toggle.module'; -import { GfHoldingsTableComponent } from '@ghostfolio/ui/holdings-table'; - -import { CommonModule } from '@angular/common'; -import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; -import { MatButtonModule } from '@angular/material/button'; - -import { HoldingsPageRoutingModule } from './holdings-page-routing.module'; -import { HoldingsPageComponent } from './holdings-page.component'; - -@NgModule({ - declarations: [HoldingsPageComponent], - imports: [ - CommonModule, - GfHoldingsTableComponent, - GfToggleModule, - HoldingsPageRoutingModule, - MatButtonModule - ], - schemas: [CUSTOM_ELEMENTS_SCHEMA] -}) -export class HoldingsPageModule {} diff --git a/apps/client/src/app/pages/portfolio/holdings/holdings-page.scss b/apps/client/src/app/pages/portfolio/holdings/holdings-page.scss deleted file mode 100644 index 5d4e87f30..000000000 --- a/apps/client/src/app/pages/portfolio/holdings/holdings-page.scss +++ /dev/null @@ -1,3 +0,0 @@ -:host { - display: block; -} diff --git a/apps/client/src/app/pages/portfolio/portfolio-page-routing.module.ts b/apps/client/src/app/pages/portfolio/portfolio-page-routing.module.ts index d4f93b567..6146c573c 100644 --- a/apps/client/src/app/pages/portfolio/portfolio-page-routing.module.ts +++ b/apps/client/src/app/pages/portfolio/portfolio-page-routing.module.ts @@ -16,13 +16,6 @@ const routes: Routes = [ (m) => m.AnalysisPageModule ) }, - { - path: 'holdings', - loadChildren: () => - import('./holdings/holdings-page.module').then( - (m) => m.HoldingsPageModule - ) - }, { path: 'activities', loadChildren: () => diff --git a/apps/client/src/app/pages/portfolio/portfolio-page.component.ts b/apps/client/src/app/pages/portfolio/portfolio-page.component.ts index bbd70c1c9..0c980e25b 100644 --- a/apps/client/src/app/pages/portfolio/portfolio-page.component.ts +++ b/apps/client/src/app/pages/portfolio/portfolio-page.component.ts @@ -34,11 +34,6 @@ export class PortfolioPageComponent implements OnDestroy, OnInit { label: $localize`Analysis`, path: ['/portfolio'] }, - { - iconName: 'wallet-outline', - label: $localize`Holdings`, - path: ['/portfolio', 'holdings'] - }, { iconName: 'swap-vertical-outline', label: $localize`Activities`, diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.ts index 16d104834..d5c1bec00 100644 --- a/apps/client/src/app/services/data.service.ts +++ b/apps/client/src/app/services/data.service.ts @@ -376,6 +376,9 @@ export class DataService { }); } + /** + * @deprecated + */ public fetchPositions({ filters, range diff --git a/libs/ui/src/lib/holdings-table/holdings-table.component.ts b/libs/ui/src/lib/holdings-table/holdings-table.component.ts index 93ac5b6fe..f25239277 100644 --- a/libs/ui/src/lib/holdings-table/holdings-table.component.ts +++ b/libs/ui/src/lib/holdings-table/holdings-table.component.ts @@ -1,5 +1,5 @@ import { GfAssetProfileIconComponent } from '@ghostfolio/client/components/asset-profile-icon/asset-profile-icon.component'; -import { GfPositionDetailDialogModule } from '@ghostfolio/client/components/position/position-detail-dialog/position-detail-dialog.module'; +import { GfPositionDetailDialogModule } from '@ghostfolio/client/components/position-detail-dialog/position-detail-dialog.module'; import { GfSymbolModule } from '@ghostfolio/client/pipes/symbol/symbol.module'; import { getLocale } from '@ghostfolio/common/helper'; import { PortfolioPosition, UniqueAsset } from '@ghostfolio/common/interfaces'; From c1ad483f3329c663ed561b43abd18be618bb9a5c Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 4 May 2024 15:50:47 +0200 Subject: [PATCH 2/6] Improve alignment (#3370) --- libs/ui/src/lib/value/value.component.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/ui/src/lib/value/value.component.html b/libs/ui/src/lib/value/value.component.html index 3ebda6e52..d1e498bcc 100644 --- a/libs/ui/src/lib/value/value.component.html +++ b/libs/ui/src/lib/value/value.component.html @@ -1,7 +1,7 @@
-
+
Date: Sat, 4 May 2024 15:51:09 +0200 Subject: [PATCH 3/6] Bugfix/fix locale in markets overview (#3369) * Fix locale if no user is logged in * Update changelog --- CHANGELOG.md | 5 +++++ apps/client/src/app/components/home-market/home-market.html | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a744b8e3d..699722298 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moved the holdings table to the holdings tab of the home page - Improved the performance labels (with and without currency effects) in the position detail dialog +### Fixed + +- Fixed an issue with the benchmarks in the markets overview +- Fixed an issue with the _Fear & Greed Index_ (market mood) in the markets overview + ## 2.78.0 - 2024-05-02 ### Added diff --git a/apps/client/src/app/components/home-market/home-market.html b/apps/client/src/app/components/home-market/home-market.html index 333c612f7..0e9d51336 100644 --- a/apps/client/src/app/components/home-market/home-market.html +++ b/apps/client/src/app/components/home-market/home-market.html @@ -11,7 +11,7 @@ [colorScheme]="user?.settings?.colorScheme" [historicalDataItems]="historicalDataItems" [isAnimated]="true" - [locale]="user?.settings?.locale" + [locale]="user?.settings?.locale || undefined" [showXAxis]="true" [showYAxis]="true" [yMax]="100" @@ -30,7 +30,7 @@
Date: Sat, 4 May 2024 15:53:02 +0200 Subject: [PATCH 4/6] Feature/optimize get porfolio details endpoint (#3366) * Eliminate getPerformance() from getSummary() function * Disable cache for getDetails() * Add hint to portfolio summary * Update changelog --- CHANGELOG.md | 1 + .../src/app/portfolio/portfolio.controller.ts | 30 ++--- .../app/portfolio/portfolio.service.spec.ts | 10 +- .../src/app/portfolio/portfolio.service.ts | 105 +++++++++++------- .../portfolio-performance.component.html | 6 +- .../portfolio-performance.component.ts | 9 +- .../portfolio-summary.component.html | 28 +++-- .../portfolio-summary.component.ts | 4 + .../portfolio-summary.module.ts | 3 +- .../portfolio/analysis/analysis-page.html | 20 ++-- .../portfolio-performance.interface.ts | 20 ++-- libs/ui/src/lib/i18n.ts | 1 + 12 files changed, 137 insertions(+), 100 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 699722298..a9e8fd811 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moved the holdings table to the holdings tab of the home page - Improved the performance labels (with and without currency effects) in the position detail dialog +- Optimized the calculations of the of the portfolio details endpoint ### Fixed diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index 7aa8e9159..4a07cd65b 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -165,21 +165,21 @@ export class PortfolioController { portfolioSummary = nullifyValuesInObject(summary, [ 'cash', 'committedFunds', - 'currentGrossPerformance', - 'currentGrossPerformanceWithCurrencyEffect', - 'currentNetPerformance', - 'currentNetPerformanceWithCurrencyEffect', 'currentNetWorth', - 'currentValue', + 'currentValueInBaseCurrency', 'dividendInBaseCurrency', 'emergencyFund', 'excludedAccountsAndActivities', 'fees', 'filteredValueInBaseCurrency', 'fireWealth', + 'grossPerformance', + 'grossPerformanceWithCurrencyEffect', 'interest', 'items', 'liabilities', + 'netPerformance', + 'netPerformanceWithCurrencyEffect', 'totalBuy', 'totalInvestment', 'totalSell', @@ -449,10 +449,14 @@ export class PortfolioController { .div(performanceInformation.performance.totalInvestment) .toNumber(), valueInPercentage: - performanceInformation.performance.currentValue === 0 + performanceInformation.performance.currentValueInBaseCurrency === + 0 ? 0 : new Big(value) - .div(performanceInformation.performance.currentValue) + .div( + performanceInformation.performance + .currentValueInBaseCurrency + ) .toNumber() }; } @@ -461,12 +465,12 @@ export class PortfolioController { performanceInformation.performance = nullifyValuesInObject( performanceInformation.performance, [ - 'currentGrossPerformance', - 'currentGrossPerformanceWithCurrencyEffect', - 'currentNetPerformance', - 'currentNetPerformanceWithCurrencyEffect', 'currentNetWorth', - 'currentValue', + 'currentValueInBaseCurrency', + 'grossPerformance', + 'grossPerformanceWithCurrencyEffect', + 'netPerformance', + 'netPerformanceWithCurrencyEffect', 'totalInvestment' ] ); @@ -483,7 +487,7 @@ export class PortfolioController { ); performanceInformation.performance = nullifyValuesInObject( performanceInformation.performance, - ['currentNetPerformance', 'currentNetPerformancePercent'] + ['netPerformance'] ); } diff --git a/apps/api/src/app/portfolio/portfolio.service.spec.ts b/apps/api/src/app/portfolio/portfolio.service.spec.ts index 7654b7df3..92970f547 100644 --- a/apps/api/src/app/portfolio/portfolio.service.spec.ts +++ b/apps/api/src/app/portfolio/portfolio.service.spec.ts @@ -27,7 +27,7 @@ describe('PortfolioService', () => { portfolioService .getAnnualizedPerformancePercent({ daysInMarket: NaN, // differenceInDays of date-fns returns NaN for the same day - netPerformancePercent: new Big(0) + netPerformancePercentage: new Big(0) }) .toNumber() ).toEqual(0); @@ -36,7 +36,7 @@ describe('PortfolioService', () => { portfolioService .getAnnualizedPerformancePercent({ daysInMarket: 0, - netPerformancePercent: new Big(0) + netPerformancePercentage: new Big(0) }) .toNumber() ).toEqual(0); @@ -48,7 +48,7 @@ describe('PortfolioService', () => { portfolioService .getAnnualizedPerformancePercent({ daysInMarket: 65, // < 1 year - netPerformancePercent: new Big(0.1025) + netPerformancePercentage: new Big(0.1025) }) .toNumber() ).toBeCloseTo(0.729705); @@ -57,7 +57,7 @@ describe('PortfolioService', () => { portfolioService .getAnnualizedPerformancePercent({ daysInMarket: 365, // 1 year - netPerformancePercent: new Big(0.05) + netPerformancePercentage: new Big(0.05) }) .toNumber() ).toBeCloseTo(0.05); @@ -69,7 +69,7 @@ describe('PortfolioService', () => { portfolioService .getAnnualizedPerformancePercent({ daysInMarket: 575, // > 1 year - netPerformancePercent: new Big(0.2374) + netPerformancePercentage: new Big(0.2374) }) .toNumber() ).toBeCloseTo(0.145); diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 4be9d4e00..a98887ca9 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -208,16 +208,16 @@ export class PortfolioService { public getAnnualizedPerformancePercent({ daysInMarket, - netPerformancePercent + netPerformancePercentage }: { daysInMarket: number; - netPerformancePercent: Big; + netPerformancePercentage: Big; }): Big { if (isNumber(daysInMarket) && daysInMarket > 0) { const exponent = new Big(365).div(daysInMarket).toNumber(); return new Big( - Math.pow(netPerformancePercent.plus(1).toNumber(), exponent) + Math.pow(netPerformancePercentage.plus(1).toNumber(), exponent) ).minus(1); } @@ -360,7 +360,7 @@ export class PortfolioService { userId, calculationType: PerformanceCalculationType.TWR, currency: userCurrency, - hasFilters: filters?.length > 0, + hasFilters: true, // disable cache isExperimentalFeatures: this.request.user?.Settings.settings.isExperimentalFeatures }); @@ -704,7 +704,7 @@ export class PortfolioService { const dividendYieldPercent = this.getAnnualizedPerformancePercent({ daysInMarket: differenceInDays(new Date(), parseDate(firstBuyDate)), - netPerformancePercent: timeWeightedInvestment.eq(0) + netPerformancePercentage: timeWeightedInvestment.eq(0) ? new Big(0) : dividendInBaseCurrency.div(timeWeightedInvestment) }); @@ -712,7 +712,9 @@ export class PortfolioService { const dividendYieldPercentWithCurrencyEffect = this.getAnnualizedPerformancePercent({ daysInMarket: differenceInDays(new Date(), parseDate(firstBuyDate)), - netPerformancePercent: timeWeightedInvestmentWithCurrencyEffect.eq(0) + netPerformancePercentage: timeWeightedInvestmentWithCurrencyEffect.eq( + 0 + ) ? new Big(0) : dividendInBaseCurrency.div( timeWeightedInvestmentWithCurrencyEffect @@ -1108,16 +1110,16 @@ export class PortfolioService { firstOrderDate: undefined, hasErrors: false, performance: { - currentGrossPerformance: 0, - currentGrossPerformancePercent: 0, - currentGrossPerformancePercentWithCurrencyEffect: 0, - currentGrossPerformanceWithCurrencyEffect: 0, - currentNetPerformance: 0, - currentNetPerformancePercent: 0, - currentNetPerformancePercentWithCurrencyEffect: 0, - currentNetPerformanceWithCurrencyEffect: 0, currentNetWorth: 0, - currentValue: 0, + currentValueInBaseCurrency: 0, + grossPerformance: 0, + grossPerformancePercentage: 0, + grossPerformancePercentageWithCurrencyEffect: 0, + grossPerformanceWithCurrencyEffect: 0, + netPerformance: 0, + netPerformancePercentage: 0, + netPerformancePercentageWithCurrencyEffect: 0, + netPerformanceWithCurrencyEffect: 0, totalInvestment: 0 } }; @@ -1152,9 +1154,9 @@ export class PortfolioService { let currentNetPerformance = netPerformance; - let currentNetPerformancePercent = netPerformancePercentage; + let currentNetPerformancePercentage = netPerformancePercentage; - let currentNetPerformancePercentWithCurrencyEffect = + let currentNetPerformancePercentageWithCurrencyEffect = netPerformancePercentageWithCurrencyEffect; let currentNetPerformanceWithCurrencyEffect = @@ -1173,11 +1175,11 @@ export class PortfolioService { if (itemOfToday) { currentNetPerformance = new Big(itemOfToday.netPerformance); - currentNetPerformancePercent = new Big( + currentNetPerformancePercentage = new Big( itemOfToday.netPerformanceInPercentage ).div(100); - currentNetPerformancePercentWithCurrencyEffect = new Big( + currentNetPerformancePercentageWithCurrencyEffect = new Big( itemOfToday.netPerformanceInPercentageWithCurrencyEffect ).div(100); @@ -1195,19 +1197,19 @@ export class PortfolioService { firstOrderDate: parseDate(items[0]?.date), performance: { currentNetWorth, - currentGrossPerformance: grossPerformance.toNumber(), - currentGrossPerformancePercent: grossPerformancePercentage.toNumber(), - currentGrossPerformancePercentWithCurrencyEffect: + currentValueInBaseCurrency: currentValueInBaseCurrency.toNumber(), + grossPerformance: grossPerformance.toNumber(), + grossPerformancePercentage: grossPerformancePercentage.toNumber(), + grossPerformancePercentageWithCurrencyEffect: grossPerformancePercentageWithCurrencyEffect.toNumber(), - currentGrossPerformanceWithCurrencyEffect: + grossPerformanceWithCurrencyEffect: grossPerformanceWithCurrencyEffect.toNumber(), - currentNetPerformance: currentNetPerformance.toNumber(), - currentNetPerformancePercent: currentNetPerformancePercent.toNumber(), - currentNetPerformancePercentWithCurrencyEffect: - currentNetPerformancePercentWithCurrencyEffect.toNumber(), - currentNetPerformanceWithCurrencyEffect: + netPerformance: currentNetPerformance.toNumber(), + netPerformancePercentage: currentNetPerformancePercentage.toNumber(), + netPerformancePercentageWithCurrencyEffect: + currentNetPerformancePercentageWithCurrencyEffect.toNumber(), + netPerformanceWithCurrencyEffect: currentNetPerformanceWithCurrencyEffect.toNumber(), - currentValue: currentValueInBaseCurrency.toNumber(), totalInvestment: totalInvestment.toNumber() } }; @@ -1604,11 +1606,6 @@ export class PortfolioService { userId = await this.getUserId(impersonationId, userId); const user = await this.userService.user({ id: userId }); - const { performance } = await this.getPerformance({ - impersonationId, - userId - }); - const { activities } = await this.orderService.getOrders({ userCurrency, userId, @@ -1626,6 +1623,19 @@ export class PortfolioService { } } + const { + currentValueInBaseCurrency, + grossPerformance, + grossPerformancePercentage, + grossPerformancePercentageWithCurrencyEffect, + grossPerformanceWithCurrencyEffect, + netPerformance, + netPerformancePercentage, + netPerformancePercentageWithCurrencyEffect, + netPerformanceWithCurrencyEffect, + totalInvestment + } = await portfolioCalculator.getSnapshot(); + const dividendInBaseCurrency = await portfolioCalculator.getDividendInBaseCurrency(); @@ -1694,7 +1704,7 @@ export class PortfolioService { .toNumber(); const netWorth = new Big(balanceInBaseCurrency) - .plus(performance.currentValue) + .plus(currentValueInBaseCurrency) .plus(valuables) .plus(excludedAccountsAndActivities) .minus(liabilities) @@ -1704,19 +1714,18 @@ export class PortfolioService { const annualizedPerformancePercent = this.getAnnualizedPerformancePercent({ daysInMarket, - netPerformancePercent: new Big(performance.currentNetPerformancePercent) + netPerformancePercentage: new Big(netPerformancePercentage) })?.toNumber(); const annualizedPerformancePercentWithCurrencyEffect = this.getAnnualizedPerformancePercent({ daysInMarket, - netPerformancePercent: new Big( - performance.currentNetPerformancePercentWithCurrencyEffect + netPerformancePercentage: new Big( + netPerformancePercentageWithCurrencyEffect ) })?.toNumber(); return { - ...performance, annualizedPerformancePercent, annualizedPerformancePercentWithCurrencyEffect, cash, @@ -1725,6 +1734,7 @@ export class PortfolioService { totalBuy, totalSell, committedFunds: committedFunds.toNumber(), + currentValueInBaseCurrency: currentValueInBaseCurrency.toNumber(), dividendInBaseCurrency: dividendInBaseCurrency.toNumber(), emergencyFund: { assets: emergencyFundPositionsValueInBaseCurrency, @@ -1738,15 +1748,28 @@ export class PortfolioService { filteredValueInPercentage: netWorth ? filteredValueInBaseCurrency.div(netWorth).toNumber() : undefined, - fireWealth: new Big(performance.currentValue) + fireWealth: new Big(currentValueInBaseCurrency) .minus(emergencyFundPositionsValueInBaseCurrency) .toNumber(), + grossPerformance: grossPerformance.toNumber(), + grossPerformancePercentage: grossPerformancePercentage.toNumber(), + grossPerformancePercentageWithCurrencyEffect: + grossPerformancePercentageWithCurrencyEffect.toNumber(), + grossPerformanceWithCurrencyEffect: + grossPerformanceWithCurrencyEffect.toNumber(), interest: interest.toNumber(), items: valuables.toNumber(), liabilities: liabilities.toNumber(), + netPerformance: netPerformance.toNumber(), + netPerformancePercentage: netPerformancePercentage.toNumber(), + netPerformancePercentageWithCurrencyEffect: + netPerformancePercentageWithCurrencyEffect.toNumber(), + netPerformanceWithCurrencyEffect: + netPerformanceWithCurrencyEffect.toNumber(), ordersCount: activities.filter(({ type }) => { - return type === 'BUY' || type === 'SELL'; + return ['BUY', 'SELL'].includes(type); }).length, + totalInvestment: totalInvestment.toNumber(), totalValueInBaseCurrency: netWorth }; } diff --git a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html index 68d191b5c..3ef55f800 100644 --- a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html +++ b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html @@ -41,9 +41,7 @@ [isCurrency]="true" [locale]="locale" [value]=" - isLoading - ? undefined - : performance?.currentNetPerformanceWithCurrencyEffect + isLoading ? undefined : performance?.netPerformanceWithCurrencyEffect " />
@@ -55,7 +53,7 @@ [value]=" isLoading ? undefined - : performance?.currentNetPerformancePercentWithCurrencyEffect + : performance?.netPerformancePercentageWithCurrencyEffect " />
diff --git a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts index b76ecb004..4d205b761 100644 --- a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts +++ b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts @@ -49,12 +49,12 @@ export class PortfolioPerformanceComponent implements OnChanges, OnInit { this.value.nativeElement.innerHTML = ''; } } else { - if (isNumber(this.performance?.currentValue)) { - new CountUp('value', this.performance?.currentValue, { + if (isNumber(this.performance?.currentValueInBaseCurrency)) { + new CountUp('value', this.performance?.currentValueInBaseCurrency, { decimal: getNumberFormatDecimal(this.locale), decimalPlaces: this.deviceType === 'mobile' && - this.performance?.currentValue >= 100000 + this.performance?.currentValueInBaseCurrency >= 100000 ? 0 : 2, duration: 1, @@ -63,8 +63,7 @@ export class PortfolioPerformanceComponent implements OnChanges, OnInit { } else if (this.showDetails === false) { new CountUp( 'value', - this.performance?.currentNetPerformancePercentWithCurrencyEffect * - 100, + this.performance?.netPerformancePercentageWithCurrencyEffect * 100, { decimal: getNumberFormatDecimal(this.locale), decimalPlaces: 2, diff --git a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html index 347767011..6b80e87b6 100644 --- a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html +++ b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.html @@ -9,9 +9,19 @@ class="flex-nowrap px-3 py-1 row" [hidden]="summary?.ordersCount === null" > -
+
{{ summary?.ordersCount }} - {summary?.ordersCount, plural, =1 {transaction} other {transactions}} + {summary?.ordersCount, plural, + =1 {activity} + other {activities} + } + + +
@@ -65,9 +75,7 @@ [locale]="locale" [unit]="baseCurrency" [value]=" - isLoading - ? undefined - : summary?.currentGrossPerformanceWithCurrencyEffect + isLoading ? undefined : summary?.grossPerformanceWithCurrencyEffect " />
@@ -91,7 +99,7 @@ [value]=" isLoading ? undefined - : summary?.currentGrossPerformancePercentWithCurrencyEffect + : summary?.grossPerformancePercentageWithCurrencyEffect " />
@@ -121,9 +129,7 @@ [locale]="locale" [unit]="baseCurrency" [value]=" - isLoading - ? undefined - : summary?.currentNetPerformanceWithCurrencyEffect + isLoading ? undefined : summary?.netPerformanceWithCurrencyEffect " />
@@ -147,7 +153,7 @@ [value]=" isLoading ? undefined - : summary?.currentNetPerformancePercentWithCurrencyEffect + : summary?.netPerformancePercentageWithCurrencyEffect " />
@@ -164,7 +170,7 @@ [isCurrency]="true" [locale]="locale" [unit]="baseCurrency" - [value]="isLoading ? undefined : summary?.currentValue" + [value]="isLoading ? undefined : summary?.currentValueInBaseCurrency" />
diff --git a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.ts b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.ts index 9ceae5186..020a8fed0 100644 --- a/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.ts +++ b/apps/client/src/app/components/portfolio-summary/portfolio-summary.component.ts @@ -1,5 +1,6 @@ import { getDateFnsLocale, getLocale } from '@ghostfolio/common/helper'; import { PortfolioSummary } from '@ghostfolio/common/interfaces'; +import { translate } from '@ghostfolio/ui/i18n'; import { ChangeDetectionStrategy, @@ -28,6 +29,9 @@ export class PortfolioSummaryComponent implements OnChanges, OnInit { @Output() emergencyFundChanged = new EventEmitter(); + public buyAndSellActivitiesTooltip = translate( + 'BUY_AND_SELL_ACTIVITIES_TOOLTIP' + ); public timeInMarket: string; public constructor() {} diff --git a/apps/client/src/app/components/portfolio-summary/portfolio-summary.module.ts b/apps/client/src/app/components/portfolio-summary/portfolio-summary.module.ts index 603d5271a..b35f1e317 100644 --- a/apps/client/src/app/components/portfolio-summary/portfolio-summary.module.ts +++ b/apps/client/src/app/components/portfolio-summary/portfolio-summary.module.ts @@ -2,13 +2,14 @@ import { GfValueComponent } from '@ghostfolio/ui/value'; import { CommonModule } from '@angular/common'; import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; +import { MatTooltipModule } from '@angular/material/tooltip'; import { PortfolioSummaryComponent } from './portfolio-summary.component'; @NgModule({ declarations: [PortfolioSummaryComponent], exports: [PortfolioSummaryComponent], - imports: [CommonModule, GfValueComponent], + imports: [CommonModule, GfValueComponent, MatTooltipModule], schemas: [CUSTOM_ELEMENTS_SCHEMA] }) export class GfPortfolioSummaryModule {} diff --git a/apps/client/src/app/pages/portfolio/analysis/analysis-page.html b/apps/client/src/app/pages/portfolio/analysis/analysis-page.html index 5f6acdbe2..191dca06f 100644 --- a/apps/client/src/app/pages/portfolio/analysis/analysis-page.html +++ b/apps/client/src/app/pages/portfolio/analysis/analysis-page.html @@ -42,7 +42,7 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformance + : performance?.netPerformance " /> @@ -61,7 +61,7 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformancePercent + : performance?.netPerformancePercentage " /> @@ -86,10 +86,10 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformance === null + : performance?.netPerformance === null ? null - : performance?.currentNetPerformanceWithCurrencyEffect - - performance?.currentNetPerformance + : performance?.netPerformanceWithCurrencyEffect - + performance?.netPerformance " /> @@ -108,10 +108,10 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformancePercent === null + : performance?.netPerformancePercentage === null ? null - : performance?.currentNetPerformancePercentWithCurrencyEffect - - performance?.currentNetPerformancePercent + : performance?.netPerformancePercentageWithCurrencyEffect - + performance?.netPerformancePercentage " /> @@ -131,7 +131,7 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformanceWithCurrencyEffect + : performance?.netPerformanceWithCurrencyEffect " /> @@ -150,7 +150,7 @@ [value]=" isLoadingInvestmentChart ? undefined - : performance?.currentNetPerformancePercentWithCurrencyEffect + : performance?.netPerformancePercentageWithCurrencyEffect " /> diff --git a/libs/common/src/lib/interfaces/portfolio-performance.interface.ts b/libs/common/src/lib/interfaces/portfolio-performance.interface.ts index 1c6f50b30..9d4ac5fab 100644 --- a/libs/common/src/lib/interfaces/portfolio-performance.interface.ts +++ b/libs/common/src/lib/interfaces/portfolio-performance.interface.ts @@ -1,14 +1,14 @@ export interface PortfolioPerformance { annualizedPerformancePercent?: number; - currentGrossPerformance: number; - currentGrossPerformancePercent: number; - currentGrossPerformancePercentWithCurrencyEffect: number; - currentGrossPerformanceWithCurrencyEffect: number; - currentNetPerformance: number; - currentNetPerformancePercent: number; - currentNetPerformancePercentWithCurrencyEffect: number; - currentNetPerformanceWithCurrencyEffect: number; - currentNetWorth: number; - currentValue: number; + currentNetWorth?: number; + currentValueInBaseCurrency: number; + grossPerformance: number; + grossPerformancePercentage: number; + grossPerformancePercentageWithCurrencyEffect: number; + grossPerformanceWithCurrencyEffect: number; + netPerformance: number; + netPerformancePercentage: number; + netPerformancePercentageWithCurrencyEffect: number; + netPerformanceWithCurrencyEffect: number; totalInvestment: number; } diff --git a/libs/ui/src/lib/i18n.ts b/libs/ui/src/lib/i18n.ts index e1266baa3..51b3cab69 100644 --- a/libs/ui/src/lib/i18n.ts +++ b/libs/ui/src/lib/i18n.ts @@ -5,6 +5,7 @@ const locales = { 'Asia-Pacific': $localize`Asia-Pacific`, ASSET_CLASS: $localize`Asset Class`, ASSET_SUB_CLASS: $localize`Asset Sub Class`, + BUY_AND_SELL_ACTIVITIES_TOOLTIP: $localize`Buy and sell`, CORE: $localize`Core`, DATA_IMPORT_AND_EXPORT_TOOLTIP_BASIC: $localize`Switch to Ghostfolio Premium or Ghostfolio Open Source easily`, DATA_IMPORT_AND_EXPORT_TOOLTIP_OSS: $localize`Switch to Ghostfolio Premium easily`, From 30a64e7fc1cd68f28414e65c4208c09edbe85bb8 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 4 May 2024 15:54:29 +0200 Subject: [PATCH 5/6] Release 2.79.0 (#3371) --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9e8fd811..72446d8c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## Unreleased +## 2.79.0 - 2024-05-04 ### Changed diff --git a/package.json b/package.json index e2bb13468..362763b4d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ghostfolio", - "version": "2.78.0", + "version": "2.79.0", "homepage": "https://ghostfol.io", "license": "AGPL-3.0", "repository": "https://github.com/ghostfolio/ghostfolio", From 8438a45bcfb9e6a75ff78903adb43bd8fef6b61e Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 4 May 2024 16:32:32 +0200 Subject: [PATCH 6/6] Update changelog (#3372) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 72446d8c8..5535ba45a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Moved the holdings table to the holdings tab of the home page - Improved the performance labels (with and without currency effects) in the position detail dialog -- Optimized the calculations of the of the portfolio details endpoint +- Optimized the calculations of the portfolio details endpoint ### Fixed