From e82dcc8ace0656702e26dea7116b04d354c3c72d Mon Sep 17 00:00:00 2001 From: Arshad Jamal Date: Tue, 30 Jan 2024 00:07:09 +0530 Subject: [PATCH] Feature/fix export in lazy-loaded activities table (#2939) * Fix export in lazy-loaded activities table * Update changelog --------- Co-authored-by: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> --- CHANGELOG.md | 6 ++++++ apps/api/src/app/export/export.controller.ts | 14 +++++++++++++- apps/api/src/app/export/export.module.ts | 2 ++ apps/api/src/app/export/export.service.ts | 5 ++++- .../account-detail-dialog.component.ts | 2 +- .../position-detail-dialog.component.ts | 2 +- .../activities/activities-page.component.ts | 10 ++++++++-- .../portfolio/activities/activities-page.html | 2 +- apps/client/src/app/services/data.service.ts | 10 ++++++++-- .../activities-table-lazy.component.ts | 2 +- 10 files changed, 45 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8532f7fd0..f0831e1bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ 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 + +### Fixed + +- Fixed the export in the lazy-loaded activities table on the portfolio activities page (experimental) + ## 2.46.0 - 2024-01-28 ### Added diff --git a/apps/api/src/app/export/export.controller.ts b/apps/api/src/app/export/export.controller.ts index 88ba79989..baa0179bb 100644 --- a/apps/api/src/app/export/export.controller.ts +++ b/apps/api/src/app/export/export.controller.ts @@ -1,4 +1,5 @@ import { HasPermissionGuard } from '@ghostfolio/api/guards/has-permission.guard'; +import { ApiService } from '@ghostfolio/api/services/api/api.service'; import { Export } from '@ghostfolio/common/interfaces'; import type { RequestWithUser } from '@ghostfolio/common/types'; import { Controller, Get, Inject, Query, UseGuards } from '@nestjs/common'; @@ -10,6 +11,7 @@ import { ExportService } from './export.service'; @Controller('export') export class ExportController { public constructor( + private readonly apiService: ApiService, private readonly exportService: ExportService, @Inject(REQUEST) private readonly request: RequestWithUser ) {} @@ -17,10 +19,20 @@ export class ExportController { @Get() @UseGuards(AuthGuard('jwt'), HasPermissionGuard) public async export( - @Query('activityIds') activityIds?: string[] + @Query('accounts') filterByAccounts?: string, + @Query('activityIds') activityIds?: string[], + @Query('assetClasses') filterByAssetClasses?: string, + @Query('tags') filterByTags?: string ): Promise { + const filters = this.apiService.buildFiltersFromQueryParams({ + filterByAccounts, + filterByAssetClasses, + filterByTags + }); + return this.exportService.export({ activityIds, + filters, userCurrency: this.request.user.Settings.settings.baseCurrency, userId: this.request.user.id }); diff --git a/apps/api/src/app/export/export.module.ts b/apps/api/src/app/export/export.module.ts index ca4588925..847695d17 100644 --- a/apps/api/src/app/export/export.module.ts +++ b/apps/api/src/app/export/export.module.ts @@ -1,6 +1,7 @@ import { AccountModule } from '@ghostfolio/api/app/account/account.module'; import { OrderModule } from '@ghostfolio/api/app/order/order.module'; import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; +import { ApiModule } from '@ghostfolio/api/services/api/api.module'; import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module'; import { DataGatheringModule } from '@ghostfolio/api/services/data-gathering/data-gathering.module'; import { DataProviderModule } from '@ghostfolio/api/services/data-provider/data-provider.module'; @@ -12,6 +13,7 @@ import { ExportService } from './export.service'; @Module({ imports: [ AccountModule, + ApiModule, ConfigurationModule, DataGatheringModule, DataProviderModule, diff --git a/apps/api/src/app/export/export.service.ts b/apps/api/src/app/export/export.service.ts index 031111d7f..64cd13929 100644 --- a/apps/api/src/app/export/export.service.ts +++ b/apps/api/src/app/export/export.service.ts @@ -1,7 +1,7 @@ import { AccountService } from '@ghostfolio/api/app/account/account.service'; import { OrderService } from '@ghostfolio/api/app/order/order.service'; import { environment } from '@ghostfolio/api/environments/environment'; -import { Export } from '@ghostfolio/common/interfaces'; +import { Filter, Export } from '@ghostfolio/common/interfaces'; import { Injectable } from '@nestjs/common'; @Injectable() @@ -13,10 +13,12 @@ export class ExportService { public async export({ activityIds, + filters, userCurrency, userId }: { activityIds?: string[]; + filters?: Filter[]; userCurrency: string; userId: string; }): Promise { @@ -42,6 +44,7 @@ export class ExportService { ); let { activities } = await this.orderService.getOrders({ + filters, userCurrency, userId, includeDrafts: true, diff --git a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts index 90736d7cf..d5dfc7680 100644 --- a/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts +++ b/apps/client/src/app/components/account-detail-dialog/account-detail-dialog.component.ts @@ -178,7 +178,7 @@ export class AccountDetailDialog implements OnDestroy, OnInit { } this.dataService - .fetchExport(activityIds) + .fetchExport({ activityIds }) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((data) => { downloadAsFile({ diff --git a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts index 053d1d305..55dcadec3 100644 --- a/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts +++ b/apps/client/src/app/components/position/position-detail-dialog/position-detail-dialog.component.ts @@ -281,7 +281,7 @@ export class PositionDetailDialog implements OnDestroy, OnInit { } this.dataService - .fetchExport(activityIds) + .fetchExport({ activityIds }) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((data) => { downloadAsFile({ 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 b125dd784..01f939905 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 @@ -199,8 +199,14 @@ export class ActivitiesPageComponent implements OnDestroy, OnInit { } public onExport(activityIds?: string[]) { + let fetchExportParams: any = { activityIds }; + + if (!activityIds) { + fetchExportParams = { filters: this.userService.getFilters() }; + } + this.dataService - .fetchExport(activityIds) + .fetchExport(fetchExportParams) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((data) => { for (const activity of data.activities) { @@ -220,7 +226,7 @@ export class ActivitiesPageComponent implements OnDestroy, OnInit { public onExportDrafts(activityIds?: string[]) { this.dataService - .fetchExport(activityIds) + .fetchExport({ activityIds }) .pipe(takeUntil(this.unsubscribeSubject)) .subscribe((data) => { downloadAsFile({ diff --git a/apps/client/src/app/pages/portfolio/activities/activities-page.html b/apps/client/src/app/pages/portfolio/activities/activities-page.html index 534a8089e..3322ff184 100644 --- a/apps/client/src/app/pages/portfolio/activities/activities-page.html +++ b/apps/client/src/app/pages/portfolio/activities/activities-page.html @@ -20,7 +20,7 @@ (activityToClone)="onCloneActivity($event)" (activityToUpdate)="onUpdateActivity($event)" (deleteAllActivities)="onDeleteAllActivities()" - (export)="onExport($event)" + (export)="onExport()" (exportDrafts)="onExportDrafts($event)" (import)="onImport()" (importDividends)="onImportDividends()" diff --git a/apps/client/src/app/services/data.service.ts b/apps/client/src/app/services/data.service.ts index e6c99dd7f..0dfbcb716 100644 --- a/apps/client/src/app/services/data.service.ts +++ b/apps/client/src/app/services/data.service.ts @@ -279,8 +279,14 @@ export class DataService { return this.http.get('/api/v1/benchmark'); } - public fetchExport(activityIds?: string[]) { - let params = new HttpParams(); + public fetchExport({ + activityIds, + filters + }: { + activityIds?: string[]; + filters?: Filter[]; + } = {}) { + let params = this.buildFiltersAsQueryParams({ filters }); if (activityIds) { params = params.append('activityIds', activityIds.join(',')); diff --git a/libs/ui/src/lib/activities-table-lazy/activities-table-lazy.component.ts b/libs/ui/src/lib/activities-table-lazy/activities-table-lazy.component.ts index 0ceb69bef..a58651a41 100644 --- a/libs/ui/src/lib/activities-table-lazy/activities-table-lazy.component.ts +++ b/libs/ui/src/lib/activities-table-lazy/activities-table-lazy.component.ts @@ -55,7 +55,7 @@ export class ActivitiesTableLazyComponent @Output() activityToClone = new EventEmitter(); @Output() activityToUpdate = new EventEmitter(); @Output() deleteAllActivities = new EventEmitter(); - @Output() export = new EventEmitter(); + @Output() export = new EventEmitter(); @Output() exportDrafts = new EventEmitter(); @Output() import = new EventEmitter(); @Output() importDividends = new EventEmitter();