From 5d4eadeceb8c9178273cebbaf7ce785434d9418f Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Thu, 19 Jan 2023 20:29:36 +0100 Subject: [PATCH] Rename allocationCurrent, remove allocationInvestment --- .../src/app/portfolio/portfolio.controller.ts | 2 +- .../src/app/portfolio/portfolio.service.ts | 13 +--- .../allocations/allocations-page.component.ts | 74 +++++-------------- .../allocations/allocations-page.html | 48 ------------ .../allocations/allocations-page.module.ts | 2 - .../app/pages/public/public-page.component.ts | 2 +- .../portfolio-position.interface.ts | 3 +- .../portfolio-public-details.interface.ts | 2 +- .../holdings-table.component.html | 6 +- .../holdings-table.component.ts | 2 +- 10 files changed, 28 insertions(+), 126 deletions(-) diff --git a/apps/api/src/app/portfolio/portfolio.controller.ts b/apps/api/src/app/portfolio/portfolio.controller.ts index 3a1fa9898..7879fa4a5 100644 --- a/apps/api/src/app/portfolio/portfolio.controller.ts +++ b/apps/api/src/app/portfolio/portfolio.controller.ts @@ -441,7 +441,7 @@ export class PortfolioController { for (const [symbol, portfolioPosition] of Object.entries(holdings)) { portfolioPublicDetails.holdings[symbol] = { - allocationCurrent: portfolioPosition.value / totalValue, + allocationInPercentage: portfolioPosition.value / totalValue, countries: hasDetails ? portfolioPosition.countries : [], currency: hasDetails ? portfolioPosition.currency : undefined, dataSource: portfolioPosition.dataSource, diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index 210b5b838..ea5e1fdb6 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -537,12 +537,9 @@ export class PortfolioService { holdings[item.symbol] = { markets, - allocationCurrent: filteredValueInBaseCurrency.eq(0) + allocationInPercentage: filteredValueInBaseCurrency.eq(0) ? 0 : value.div(filteredValueInBaseCurrency).toNumber(), - allocationInvestment: item.investment - .div(totalInvestmentInBaseCurrency) - .toNumber(), assetClass: symbolProfile.assetClass, assetSubClass: symbolProfile.assetSubClass, countries: symbolProfile.countries, @@ -1258,12 +1255,9 @@ export class PortfolioService { for (const symbol of Object.keys(cashPositions)) { // Calculate allocations for each currency - cashPositions[symbol].allocationCurrent = value.gt(0) + cashPositions[symbol].allocationInPercentage = value.gt(0) ? new Big(cashPositions[symbol].value).div(value).toNumber() : 0; - cashPositions[symbol].allocationInvestment = investment.gt(0) - ? new Big(cashPositions[symbol].investment).div(investment).toNumber() - : 0; } return cashPositions; @@ -1430,8 +1424,7 @@ export class PortfolioService { }): PortfolioPosition { return { currency, - allocationCurrent: 0, - allocationInvestment: 0, + allocationInPercentage: 0, assetClass: AssetClass.CASH, assetSubClass: AssetClass.CASH, countries: [], 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 6a5a57c82..910629a3e 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 @@ -18,7 +18,7 @@ import { User } from '@ghostfolio/common/interfaces'; import { hasPermission, permissions } from '@ghostfolio/common/permissions'; -import { Market, ToggleOption } from '@ghostfolio/common/types'; +import { Market } from '@ghostfolio/common/types'; import { translate } from '@ghostfolio/ui/i18n'; import { Account, AssetClass, DataSource } from '@prisma/client'; import { DeviceDetectorService } from 'ngx-device-detector'; @@ -53,11 +53,6 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { public markets: { [key in Market]: { name: string; value: number }; }; - public period = 'current'; - public periodOptions: ToggleOption[] = [ - { label: $localize`Initial`, value: 'original' }, - { label: $localize`Current`, value: 'current' } - ]; public placeholder = ''; public portfolioDetails: PortfolioDetails; public positions: { @@ -146,7 +141,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { .subscribe((portfolioDetails) => { this.portfolioDetails = portfolioDetails; - this.initializeAnalysisData(this.period); + this.initializeAnalysisData(); this.isLoading = false; @@ -248,7 +243,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { }; } - public initializeAnalysisData(aPeriod: string) { + public initializeAnalysisData() { this.initialize(); for (const [id, { current, name, original }] of Object.entries( @@ -257,7 +252,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { this.accounts[id] = { id, name, - value: aPeriod === 'original' ? original : current + value: current }; } @@ -266,18 +261,10 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { )) { let value = 0; - if (aPeriod === 'original') { - if (this.hasImpersonationId) { - value = position.allocationInvestment; - } else { - value = position.investment; - } + if (this.hasImpersonationId) { + value = position.allocationInPercentage; } else { - if (this.hasImpersonationId) { - value = position.allocationCurrent; - } else { - value = position.value; - } + value = position.value; } this.positions[symbol] = { @@ -294,14 +281,11 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { if (position.countries.length > 0) { this.markets.developedMarkets.value += - position.markets.developedMarkets * - (aPeriod === 'original' ? position.investment : position.value); + position.markets.developedMarkets * position.value; this.markets.emergingMarkets.value += - position.markets.emergingMarkets * - (aPeriod === 'original' ? position.investment : position.value); + position.markets.emergingMarkets * position.value; this.markets.otherMarkets.value += - position.markets.otherMarkets * - (aPeriod === 'original' ? position.investment : position.value); + position.markets.otherMarkets * position.value; for (const country of position.countries) { const { code, continent, name, weight } = country; @@ -311,11 +295,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { } else { this.continents[continent] = { name: continent, - value: - weight * - (aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value) + value: weight * this.portfolioDetails.holdings[symbol].value }; } @@ -324,24 +304,16 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { } else { this.countries[code] = { name, - value: - weight * - (aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value) + value: weight * this.portfolioDetails.holdings[symbol].value }; } } } else { this.continents[UNKNOWN_KEY].value += - aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value; + this.portfolioDetails.holdings[symbol].value; this.countries[UNKNOWN_KEY].value += - aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value; + this.portfolioDetails.holdings[symbol].value; } if (position.sectors.length > 0) { @@ -353,19 +325,13 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { } else { this.sectors[name] = { name, - value: - weight * - (aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value) + value: weight * this.portfolioDetails.holdings[symbol].value }; } } } else { this.sectors[UNKNOWN_KEY].value += - aPeriod === 'original' - ? this.portfolioDetails.holdings[symbol].investment - : this.portfolioDetails.holdings[symbol].value; + this.portfolioDetails.holdings[symbol].value; } } @@ -373,7 +339,7 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { dataSource: position.dataSource, name: position.name, symbol: prettifySymbol(symbol), - value: aPeriod === 'original' ? position.investment : position.value + value: position.value }; } @@ -398,12 +364,6 @@ export class AllocationsPageComponent implements OnDestroy, OnInit { } } - public onChangePeriod(aValue: string) { - this.period = aValue; - - this.initializeAnalysisData(this.period); - } - public onSymbolChartClicked({ dataSource, symbol }: UniqueAsset) { if (dataSource && symbol) { this.router.navigate([], { diff --git a/apps/client/src/app/pages/portfolio/allocations/allocations-page.html b/apps/client/src/app/pages/portfolio/allocations/allocations-page.html index 78d86d182..5ee7deb33 100644 --- a/apps/client/src/app/pages/portfolio/allocations/allocations-page.html +++ b/apps/client/src/app/pages/portfolio/allocations/allocations-page.html @@ -39,12 +39,6 @@ By Account - - - By Holding - - - - - @@ -85,7 +85,7 @@ - + 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 6ff3c1c7f..a4aee7710 100644 --- a/libs/ui/src/lib/holdings-table/holdings-table.component.ts +++ b/libs/ui/src/lib/holdings-table/holdings-table.component.ts @@ -58,7 +58,7 @@ export class HoldingsTableComponent implements OnChanges, OnDestroy, OnInit { this.displayedColumns.push('value'); } - this.displayedColumns.push('allocationCurrent'); + this.displayedColumns.push('allocationInPercentage'); this.displayedColumns.push('performance'); this.isLoading = true;