Browse Source

Feature/align holdings and regions of public page with allocations page (#3815)

* Align holdings and regions of public page with allocations page

* Update changelog
pull/3813/head^2
Thomas Kaul 4 months ago
committed by GitHub
parent
commit
4a97e2bb54
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 2
      apps/api/src/app/endpoints/public/public.controller.ts
  3. 123
      apps/client/src/app/pages/public/public-page.component.ts
  4. 1
      libs/common/src/lib/interfaces/responses/public-portfolio-response.interface.ts

1
CHANGELOG.md

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Improved the usability of various action menus by introducing horizontal lines to separate the delete action - Improved the usability of various action menus by introducing horizontal lines to separate the delete action
- Aligned the holdings and regions of the public page with the allocations page
- Considered the user’s language in the link of the access table to share the portfolio - Considered the user’s language in the link of the access table to share the portfolio
- Improved the language localization for German (`de`) - Improved the language localization for German (`de`)

2
apps/api/src/app/endpoints/public/public.controller.ts

@ -63,7 +63,6 @@ export class PublicController {
{ performance: performanceYtd } { performance: performanceYtd }
] = await Promise.all([ ] = await Promise.all([
this.portfolioService.getDetails({ this.portfolioService.getDetails({
filters: [{ id: 'EQUITY', type: 'ASSET_CLASS' }],
impersonationId: access.userId, impersonationId: access.userId,
userId: user.id, userId: user.id,
withMarkets: true withMarkets: true
@ -114,6 +113,7 @@ export class PublicController {
publicPortfolioResponse.holdings[symbol] = { publicPortfolioResponse.holdings[symbol] = {
allocationInPercentage: allocationInPercentage:
portfolioPosition.valueInBaseCurrency / totalValue, portfolioPosition.valueInBaseCurrency / totalValue,
assetClass: hasDetails ? portfolioPosition.assetClass : undefined,
countries: hasDetails ? portfolioPosition.countries : [], countries: hasDetails ? portfolioPosition.countries : [],
currency: hasDetails ? portfolioPosition.currency : undefined, currency: hasDetails ? portfolioPosition.currency : undefined,
dataSource: portfolioPosition.dataSource, dataSource: portfolioPosition.dataSource,

123
apps/client/src/app/pages/public/public-page.component.ts

@ -9,6 +9,7 @@ import { Market } from '@ghostfolio/common/types';
import { ChangeDetectorRef, Component, OnInit } from '@angular/core'; import { ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute, Router } from '@angular/router';
import { AssetClass } from '@prisma/client';
import { StatusCodes } from 'http-status-codes'; import { StatusCodes } from 'http-status-codes';
import { isNumber } from 'lodash'; import { isNumber } from 'lodash';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
@ -145,69 +146,77 @@ export class PublicPageComponent implements OnInit {
value: position.allocationInPercentage value: position.allocationInPercentage
}; };
if (position.countries.length > 0) { if (position.assetClass !== AssetClass.LIQUIDITY) {
this.markets.developedMarkets.value += // Prepare analysis data by continents, countries, holdings and sectors except for liquidity
position.markets.developedMarkets * position.valueInBaseCurrency;
this.markets.emergingMarkets.value += if (position.countries.length > 0) {
position.markets.emergingMarkets * position.valueInBaseCurrency; this.markets.developedMarkets.value +=
this.markets.otherMarkets.value += position.markets.developedMarkets * position.valueInBaseCurrency;
position.markets.otherMarkets * position.valueInBaseCurrency; this.markets.emergingMarkets.value +=
position.markets.emergingMarkets * position.valueInBaseCurrency;
for (const country of position.countries) { this.markets.otherMarkets.value +=
const { code, continent, name, weight } = country; position.markets.otherMarkets * position.valueInBaseCurrency;
if (this.continents[continent]?.value) { for (const country of position.countries) {
this.continents[continent].value += const { code, continent, name, weight } = country;
weight * position.valueInBaseCurrency;
} else { if (this.continents[continent]?.value) {
this.continents[continent] = { this.continents[continent].value +=
name: continent, weight * position.valueInBaseCurrency;
value: } else {
weight * this.continents[continent] = {
this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency name: continent,
}; value:
weight *
this.publicPortfolioDetails.holdings[symbol]
.valueInBaseCurrency
};
}
if (this.countries[code]?.value) {
this.countries[code].value +=
weight * position.valueInBaseCurrency;
} else {
this.countries[code] = {
name,
value:
weight *
this.publicPortfolioDetails.holdings[symbol]
.valueInBaseCurrency
};
}
} }
} else {
this.continents[UNKNOWN_KEY].value +=
this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency;
if (this.countries[code]?.value) { this.countries[UNKNOWN_KEY].value +=
this.countries[code].value += weight * position.valueInBaseCurrency; this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency;
} else {
this.countries[code] = {
name,
value:
weight *
this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency
};
}
}
} else {
this.continents[UNKNOWN_KEY].value +=
this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency;
this.countries[UNKNOWN_KEY].value +=
this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency;
this.markets[UNKNOWN_KEY].value += this.markets[UNKNOWN_KEY].value +=
this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency; this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency;
} }
if (position.sectors.length > 0) { if (position.sectors.length > 0) {
for (const sector of position.sectors) { for (const sector of position.sectors) {
const { name, weight } = sector; const { name, weight } = sector;
if (this.sectors[name]?.value) { if (this.sectors[name]?.value) {
this.sectors[name].value += weight * position.valueInBaseCurrency; this.sectors[name].value += weight * position.valueInBaseCurrency;
} else { } else {
this.sectors[name] = { this.sectors[name] = {
name, name,
value: value:
weight * weight *
this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency this.publicPortfolioDetails.holdings[symbol]
}; .valueInBaseCurrency
};
}
} }
} else {
this.sectors[UNKNOWN_KEY].value +=
this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency;
} }
} else {
this.sectors[UNKNOWN_KEY].value +=
this.publicPortfolioDetails.holdings[symbol].valueInBaseCurrency;
} }
this.symbols[prettifySymbol(symbol)] = { this.symbols[prettifySymbol(symbol)] = {

1
libs/common/src/lib/interfaces/responses/public-portfolio-response.interface.ts

@ -7,6 +7,7 @@ export interface PublicPortfolioResponse extends PublicPortfolioResponseV1 {
[symbol: string]: Pick< [symbol: string]: Pick<
PortfolioPosition, PortfolioPosition,
| 'allocationInPercentage' | 'allocationInPercentage'
| 'assetClass'
| 'countries' | 'countries'
| 'currency' | 'currency'
| 'dataSource' | 'dataSource'

Loading…
Cancel
Save