From 19ab6a66de1687848d0a5448fa35971a35994c84 Mon Sep 17 00:00:00 2001 From: Thomas <4159106+dtslvr@users.noreply.github.com> Date: Sun, 2 Jan 2022 10:49:44 +0100 Subject: [PATCH] Add Top 3 / Bottom 3 --- .../analysis/analysis-page.component.ts | 25 +++++- .../portfolio/analysis/analysis-page.html | 80 ++++++++++++++++++- .../analysis/analysis-page.module.ts | 6 +- 3 files changed, 108 insertions(+), 3 deletions(-) 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 1c9b872fe..9cf798a18 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 @@ -2,9 +2,10 @@ import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; 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 { User } from '@ghostfolio/common/interfaces'; +import { Position, User } from '@ghostfolio/common/interfaces'; import { InvestmentItem } from '@ghostfolio/common/interfaces/investment-item.interface'; import { differenceInDays } from 'date-fns'; +import { sortBy } from 'lodash'; import { DeviceDetectorService } from 'ngx-device-detector'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -16,10 +17,12 @@ import { takeUntil } from 'rxjs/operators'; templateUrl: './analysis-page.html' }) export class AnalysisPageComponent implements OnDestroy, OnInit { + public bottom3: Position[]; public daysInMarket: number; public deviceType: string; public hasImpersonationId: boolean; public investments: InvestmentItem[]; + public top3: Position[]; public user: User; private unsubscribeSubject = new Subject(); @@ -58,6 +61,26 @@ export class AnalysisPageComponent implements OnDestroy, OnInit { this.changeDetectorRef.markForCheck(); }); + this.dataService + .fetchPositions({ range: 'max' }) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(({ positions }) => { + const positionsSorted = sortBy( + positions, + 'netPerformancePercentage' + ).reverse(); + + this.top3 = positionsSorted.slice(0, 3); + + if (positions?.length > 3) { + this.bottom3 = positionsSorted.slice(-3).reverse(); + } else { + this.bottom3 = []; + } + + this.changeDetectorRef.markForCheck(); + }); + this.userService.stateChanged .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((state) => { 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 4d396d6cd..361110d76 100644 --- a/apps/client/src/app/pages/portfolio/analysis/analysis-page.html +++ b/apps/client/src/app/pages/portfolio/analysis/analysis-page.html @@ -5,7 +5,7 @@ TimelineInvestment Timeline @@ -19,4 +19,82 @@ + +
+
+ + + Top 3 + + +
+
+ {{ i + 1 }}. {{ position.name }} +
+
+ +
+
+
+ +
+
+
+
+
+ + + Bottom 3 + + +
+
+ {{ i + 1 }}. {{ position.name }} +
+
+ +
+
+
+ +
+
+
+
+
diff --git a/apps/client/src/app/pages/portfolio/analysis/analysis-page.module.ts b/apps/client/src/app/pages/portfolio/analysis/analysis-page.module.ts index 53e9bb283..ec22a3704 100644 --- a/apps/client/src/app/pages/portfolio/analysis/analysis-page.module.ts +++ b/apps/client/src/app/pages/portfolio/analysis/analysis-page.module.ts @@ -2,6 +2,8 @@ import { CommonModule } from '@angular/common'; import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'; import { MatCardModule } from '@angular/material/card'; import { GfInvestmentChartModule } from '@ghostfolio/client/components/investment-chart/investment-chart.module'; +import { GfValueModule } from '@ghostfolio/ui/value'; +import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { AnalysisPageRoutingModule } from './analysis-page-routing.module'; import { AnalysisPageComponent } from './analysis-page.component'; @@ -13,7 +15,9 @@ import { AnalysisPageComponent } from './analysis-page.component'; AnalysisPageRoutingModule, CommonModule, GfInvestmentChartModule, - MatCardModule + GfValueModule, + MatCardModule, + NgxSkeletonLoaderModule ], providers: [], schemas: [CUSTOM_ELEMENTS_SCHEMA]