From 06ba7a4b1b065b6c936aea9b1c4d7ed72b03df14 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sun, 4 Feb 2024 15:50:58 +0100 Subject: [PATCH] Feature/extend assistant by asset class selector (#2957) * Remove tabs * Add asset class selector * Update changelog --- CHANGELOG.md | 4 + .../src/app/user/update-user-setting.dto.ts | 4 + .../app/components/header/header.component.ts | 2 + .../src/app/services/user/user.service.ts | 7 ++ .../src/lib/assistant/assistant.component.ts | 44 +++++--- libs/ui/src/lib/assistant/assistant.html | 103 ++++++++---------- libs/ui/src/lib/assistant/assistant.module.ts | 2 - 7 files changed, 92 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7ed7ed57..73cc26f15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Added + +- Extended the assistant by an asset class selector (experimental) + ### Changed - Improved the usability of the account selector in the assistant (experimental) diff --git a/apps/api/src/app/user/update-user-setting.dto.ts b/apps/api/src/app/user/update-user-setting.dto.ts index 7d69f202d..1700180dd 100644 --- a/apps/api/src/app/user/update-user-setting.dto.ts +++ b/apps/api/src/app/user/update-user-setting.dto.ts @@ -42,6 +42,10 @@ export class UpdateUserSettingDto { @IsOptional() 'filters.accounts'?: string[]; + @IsArray() + @IsOptional() + 'filters.assetClasses'?: string[]; + @IsArray() @IsOptional() 'filters.tags'?: string[]; diff --git a/apps/client/src/app/components/header/header.component.ts b/apps/client/src/app/components/header/header.component.ts index c706abe0a..412082de8 100644 --- a/apps/client/src/app/components/header/header.component.ts +++ b/apps/client/src/app/components/header/header.component.ts @@ -170,6 +170,8 @@ export class HeaderComponent implements OnChanges { if (filter.type === 'ACCOUNT') { filtersType = 'accounts'; + } else if (filter.type === 'ASSET_CLASS') { + filtersType = 'assetClasses'; } else if (filter.type === 'TAG') { filtersType = 'tags'; } diff --git a/apps/client/src/app/services/user/user.service.ts b/apps/client/src/app/services/user/user.service.ts index 539752f0a..ece6653bd 100644 --- a/apps/client/src/app/services/user/user.service.ts +++ b/apps/client/src/app/services/user/user.service.ts @@ -58,6 +58,13 @@ export class UserService extends ObservableStore { }); } + if (user.settings['filters.assetClasses']) { + filters.push({ + id: user.settings['filters.assetClasses'][0], + type: 'ASSET_CLASS' + }); + } + if (user.settings['filters.tags']) { filters.push({ id: user.settings['filters.tags'][0], diff --git a/libs/ui/src/lib/assistant/assistant.component.ts b/libs/ui/src/lib/assistant/assistant.component.ts index 0996d90e6..cdb1ebe20 100644 --- a/libs/ui/src/lib/assistant/assistant.component.ts +++ b/libs/ui/src/lib/assistant/assistant.component.ts @@ -22,7 +22,7 @@ import { DataService } from '@ghostfolio/client/services/data.service'; import { Filter, User } from '@ghostfolio/common/interfaces'; import { DateRange } from '@ghostfolio/common/types'; import { translate } from '@ghostfolio/ui/i18n'; -import { Account, Tag } from '@prisma/client'; +import { Account, AssetClass, Tag } from '@prisma/client'; import { EMPTY, Observable, Subject, lastValueFrom } from 'rxjs'; import { catchError, @@ -92,6 +92,7 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { public static readonly SEARCH_RESULTS_DEFAULT_LIMIT = 5; public accounts: Account[] = []; + public assetClasses: Filter[] = []; public dateRangeFormControl = new FormControl(undefined); public readonly dateRangeOptions = [ { label: $localize`Today`, value: '1d' }, @@ -116,6 +117,7 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { ]; public filterForm = this.formBuilder.group({ account: new FormControl(undefined), + assetClass: new FormControl(undefined), tag: new FormControl(undefined) }); public isLoading = false; @@ -126,8 +128,9 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { assetProfiles: [], holdings: [] }; - public tags: Tag[] = []; + public tags: Filter[] = []; + private filterTypes: Filter['type'][] = ['ACCOUNT', 'ASSET_CLASS', 'TAG']; private keyManager: FocusKeyManager; private unsubscribeSubject = new Subject(); @@ -140,28 +143,38 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { public ngOnInit() { this.accounts = this.user?.accounts; + this.assetClasses = Object.keys(AssetClass).map((assetClass) => { + return { + id: assetClass, + label: translate(assetClass), + type: 'ASSET_CLASS' + }; + }); this.tags = this.user?.tags.map(({ id, name }) => { return { id, - name: translate(name) + label: translate(name), + type: 'TAG' }; }); this.filterForm.valueChanges .pipe(takeUntil(this.unsubscribeSubject)) - .subscribe(({ account, tag }) => { + .subscribe(({ account, assetClass, tag }) => { this.filtersChanged.emit([ { id: account, type: 'ACCOUNT' }, + { + id: assetClass, + type: 'ASSET_CLASS' + }, { id: tag, type: 'TAG' } ]); - - this.onCloseAssistant(); }); this.searchFormControl.valueChanges @@ -209,6 +222,7 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { this.filterForm.setValue( { account: this.user?.settings?.['filters.accounts']?.[0] ?? null, + assetClass: this.user?.settings?.['filters.assetClasses']?.[0] ?? null, tag: this.user?.settings?.['filters.tags']?.[0] ?? null }, { @@ -257,16 +271,14 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { } public onResetFilters() { - this.filtersChanged.emit([ - { - id: null, - type: 'ACCOUNT' - }, - { - id: null, - type: 'TAG' - } - ]); + this.filtersChanged.emit( + this.filterTypes.map((type) => { + return { + type, + id: null + }; + }) + ); this.onCloseAssistant(); } diff --git a/libs/ui/src/lib/assistant/assistant.html b/libs/ui/src/lib/assistant/assistant.html index ac19c34a8..d78c899f0 100644 --- a/libs/ui/src/lib/assistant/assistant.html +++ b/libs/ui/src/lib/assistant/assistant.html @@ -89,9 +89,9 @@
-
+
Date Range
- - - Accounts -
- - - - @for (account of accounts; track account.id) { - -
- {{ account.name }} -
-
- } -
-
-
-
- - Tags -
- - - - @for (tag of tags; track tag.id) { - {{ tag.name }} - } - - -
-
-
-
+
+ + Accounts + + + @for (account of accounts; track account.id) { + +
+ {{ account.name }} +
+
+ } +
+
+
+
+ + Tags + + + @for (tag of tags; track tag.id) { + {{ tag.label }} + } + + +
+
+ + Asset Classes + + + @for (assetClass of assetClasses; track assetClass.id) { + {{ assetClass.label }} + } + + +
+