From 5249257dd8dda8b5fba34af800d8f9ebf5d5428d Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 6 May 2023 20:24:16 +0200 Subject: [PATCH] Feature/improve platform managment in admin control (#1939) * Refactoring, fix tab style, add account count * Update changelog --- CHANGELOG.md | 1 + apps/api/src/app/info/info.module.ts | 2 + apps/api/src/app/info/info.service.ts | 11 +++-- .../src/app/platform/platform.controller.ts | 4 +- apps/api/src/app/platform/platform.service.ts | 46 +++++++++++++++++-- .../admin-platform.component.html} | 14 ++++++ .../admin-platform.component.scss} | 0 .../admin-platform.module.ts} | 0 ...te-or-update-account-platform.component.ts | 0 .../create-or-update-platform-dialog.html | 0 ...create-or-update-platform-dialog.module.ts | 0 .../create-or-update-platform-dialog.scss | 0 .../interfaces/interfaces.ts | 0 .../platform.component.ts | 9 ++-- .../pages/admin/admin-page-routing.module.ts | 2 +- .../src/app/pages/admin/admin-page.html | 1 + .../src/app/pages/admin/admin-page.module.ts | 2 +- 17 files changed, 77 insertions(+), 15 deletions(-) rename apps/client/src/app/components/{platform/platform.component.html => admin-platform/admin-platform.component.html} (87%) rename apps/client/src/app/components/{platform/platform.component.scss => admin-platform/admin-platform.component.scss} (100%) rename apps/client/src/app/components/{platform/platform.module.ts => admin-platform/admin-platform.module.ts} (100%) rename apps/client/src/app/components/{platform => admin-platform}/create-or-update-platform-dialog/create-or-update-account-platform.component.ts (100%) rename apps/client/src/app/components/{platform => admin-platform}/create-or-update-platform-dialog/create-or-update-platform-dialog.html (100%) rename apps/client/src/app/components/{platform => admin-platform}/create-or-update-platform-dialog/create-or-update-platform-dialog.module.ts (100%) rename apps/client/src/app/components/{platform => admin-platform}/create-or-update-platform-dialog/create-or-update-platform-dialog.scss (100%) rename apps/client/src/app/components/{platform => admin-platform}/create-or-update-platform-dialog/interfaces/interfaces.ts (100%) rename apps/client/src/app/components/{platform => admin-platform}/platform.component.ts (96%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bc12a7fb..51413fc2b 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 +- Improved the management of platforms in the admin control panel - Improved the language localization for German (`de`) ## 1.266.0 - 2023-05-06 diff --git a/apps/api/src/app/info/info.module.ts b/apps/api/src/app/info/info.module.ts index aa2637393..75d681b56 100644 --- a/apps/api/src/app/info/info.module.ts +++ b/apps/api/src/app/info/info.module.ts @@ -1,4 +1,5 @@ import { BenchmarkModule } from '@ghostfolio/api/app/benchmark/benchmark.module'; +import { PlatformModule } from '@ghostfolio/api/app/platform/platform.module'; import { RedisCacheModule } from '@ghostfolio/api/app/redis-cache/redis-cache.module'; import { ConfigurationModule } from '@ghostfolio/api/services/configuration/configuration.module'; import { DataGatheringModule } from '@ghostfolio/api/services/data-gathering/data-gathering.module'; @@ -26,6 +27,7 @@ import { InfoService } from './info.service'; secret: process.env.JWT_SECRET_KEY, signOptions: { expiresIn: '30 days' } }), + PlatformModule, PrismaModule, PropertyModule, RedisCacheModule, diff --git a/apps/api/src/app/info/info.service.ts b/apps/api/src/app/info/info.service.ts index f2cf36ae0..f825418eb 100644 --- a/apps/api/src/app/info/info.service.ts +++ b/apps/api/src/app/info/info.service.ts @@ -1,4 +1,5 @@ import { BenchmarkService } from '@ghostfolio/api/app/benchmark/benchmark.service'; +import { PlatformService } from '@ghostfolio/api/app/platform/platform.service'; import { RedisCacheService } from '@ghostfolio/api/app/redis-cache/redis-cache.service'; import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; @@ -38,6 +39,7 @@ export class InfoService { private readonly configurationService: ConfigurationService, private readonly exchangeRateDataService: ExchangeRateDataService, private readonly jwtService: JwtService, + private readonly platformService: PlatformService, private readonly prismaService: PrismaService, private readonly propertyService: PropertyService, private readonly redisCacheService: RedisCacheService, @@ -47,9 +49,12 @@ export class InfoService { public async get(): Promise { const info: Partial = {}; let isReadOnlyMode: boolean; - const platforms = await this.prismaService.platform.findMany({ - orderBy: { name: 'asc' }, - select: { id: true, name: true } + const platforms = ( + await this.platformService.getPlatforms({ + orderBy: { name: 'asc' } + }) + ).map(({ id, name }) => { + return { id, name }; }); let systemMessage: string; diff --git a/apps/api/src/app/platform/platform.controller.ts b/apps/api/src/app/platform/platform.controller.ts index 85d92da68..8c4d62bd6 100644 --- a/apps/api/src/app/platform/platform.controller.ts +++ b/apps/api/src/app/platform/platform.controller.ts @@ -30,8 +30,8 @@ export class PlatformController { @Get() @UseGuards(AuthGuard('jwt')) - public async getPlatforms(): Promise { - return this.platformService.getPlatforms(); + public async getPlatforms() { + return this.platformService.getPlatformsWithAccountCount(); } @Post() diff --git a/apps/api/src/app/platform/platform.service.ts b/apps/api/src/app/platform/platform.service.ts index 9832252a4..12d107604 100644 --- a/apps/api/src/app/platform/platform.service.ts +++ b/apps/api/src/app/platform/platform.service.ts @@ -6,10 +6,6 @@ import { Platform, Prisma } from '@prisma/client'; export class PlatformService { public constructor(private readonly prismaService: PrismaService) {} - public async getPlatforms(): Promise { - return this.prismaService.platform.findMany(); - } - public async getPlatform( platformWhereUniqueInput: Prisma.PlatformWhereUniqueInput ): Promise { @@ -18,6 +14,48 @@ export class PlatformService { }); } + public async getPlatforms({ + cursor, + orderBy, + skip, + take, + where + }: { + cursor?: Prisma.PlatformWhereUniqueInput; + orderBy?: Prisma.PlatformOrderByWithRelationInput; + skip?: number; + take?: number; + where?: Prisma.PlatformWhereInput; + } = {}) { + return this.prismaService.platform.findMany({ + cursor, + orderBy, + skip, + take, + where + }); + } + + public async getPlatformsWithAccountCount() { + const platformsWithAccountCount = + await this.prismaService.platform.findMany({ + include: { + _count: { + select: { Account: true } + } + } + }); + + return platformsWithAccountCount.map(({ _count, id, name, url }) => { + return { + id, + name, + url, + accountCount: _count.Account + }; + }); + } + public async createPlatform(data: Prisma.PlatformCreateInput) { return this.prismaService.platform.create({ data diff --git a/apps/client/src/app/components/platform/platform.component.html b/apps/client/src/app/components/admin-platform/admin-platform.component.html similarity index 87% rename from apps/client/src/app/components/platform/platform.component.html rename to apps/client/src/app/components/admin-platform/admin-platform.component.html index b4560e0c4..ce83ddfdc 100644 --- a/apps/client/src/app/components/platform/platform.component.html +++ b/apps/client/src/app/components/admin-platform/admin-platform.component.html @@ -43,6 +43,20 @@ + + + Accounts + + + {{ element.accountCount }} + + + = new MatTableDataSource(); public deviceType: string; - public displayedColumns = ['name', 'url', 'actions']; + public displayedColumns = ['name', 'url', 'accounts', 'actions']; public hasPermissionToCreatePlatform: boolean; public hasPermissionToDeletePlatform: boolean; public platforms: PlatformModel[]; diff --git a/apps/client/src/app/pages/admin/admin-page-routing.module.ts b/apps/client/src/app/pages/admin/admin-page-routing.module.ts index 28cd84617..6cdc44856 100644 --- a/apps/client/src/app/pages/admin/admin-page-routing.module.ts +++ b/apps/client/src/app/pages/admin/admin-page-routing.module.ts @@ -3,8 +3,8 @@ import { RouterModule, Routes } from '@angular/router'; import { AdminJobsComponent } from '@ghostfolio/client/components/admin-jobs/admin-jobs.component'; import { AdminMarketDataComponent } from '@ghostfolio/client/components/admin-market-data/admin-market-data.component'; import { AdminOverviewComponent } from '@ghostfolio/client/components/admin-overview/admin-overview.component'; +import { AdminPlatformComponent } from '@ghostfolio/client/components/admin-platform/platform.component'; import { AdminUsersComponent } from '@ghostfolio/client/components/admin-users/admin-users.component'; -import { AdminPlatformComponent } from '@ghostfolio/client/components/platform/platform.component'; import { AuthGuard } from '@ghostfolio/client/core/auth.guard'; import { AdminPageComponent } from './admin-page.component'; diff --git a/apps/client/src/app/pages/admin/admin-page.html b/apps/client/src/app/pages/admin/admin-page.html index ed3c46bd5..8de616498 100644 --- a/apps/client/src/app/pages/admin/admin-page.html +++ b/apps/client/src/app/pages/admin/admin-page.html @@ -6,6 +6,7 @@