From 98c4caf8ed935239daeeadfb4c9f151d49cf3d5e Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 31 May 2025 20:27:39 +0200 Subject: [PATCH] Support creating custom tags in holding detail dialog --- ...ate-or-update-activity-dialog.component.ts | 38 ++++++++++++++++++- .../create-or-update-activity-dialog.html | 4 ++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts index 5f651195a..291254445 100644 --- a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts +++ b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts @@ -1,6 +1,8 @@ import { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto'; import { UpdateOrderDto } from '@ghostfolio/api/app/order/update-order.dto'; +import { UserService } from '@ghostfolio/client/services/user/user.service'; import { getDateFormatString } from '@ghostfolio/common/helper'; +import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { translate } from '@ghostfolio/ui/i18n'; import { @@ -42,6 +44,7 @@ export class CreateOrUpdateActivityDialog implements OnDestroy { public currencyOfAssetProfile: string; public currentMarketPrice = null; public defaultDateFormat: string; + public hasPermissionToCreateOwnTag: boolean; public isLoading = false; public isToday = isToday; public mode: 'create' | 'update'; @@ -60,11 +63,16 @@ export class CreateOrUpdateActivityDialog implements OnDestroy { private dateAdapter: DateAdapter, public dialogRef: MatDialogRef, private formBuilder: FormBuilder, - @Inject(MAT_DATE_LOCALE) private locale: string + @Inject(MAT_DATE_LOCALE) private locale: string, + private userService: UserService ) {} public ngOnInit() { this.currencyOfAssetProfile = this.data.activity?.SymbolProfile?.currency; + this.hasPermissionToCreateOwnTag = hasPermission( + this.data.user?.permissions, + permissions.createOwnTag + ); this.locale = this.data.user?.settings?.locale; this.mode = this.data.activity?.id ? 'update' : 'create'; @@ -219,6 +227,34 @@ export class CreateOrUpdateActivityDialog implements OnDestroy { this.changeDetectorRef.markForCheck(); }); + this.activityForm.get('tags').valueChanges.subscribe((tags: Tag[]) => { + const newTag = tags.find(({ id }) => { + return id === undefined; + }); + + if (newTag && this.hasPermissionToCreateOwnTag) { + this.dataService + .postTag({ ...newTag, userId: this.data.user.id }) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe((tag) => { + this.activityForm.get('tags').setValue( + tags.map((currentTag) => { + if (currentTag.id === undefined) { + return tag; + } + + return currentTag; + }) + ); + + this.userService + .get(true) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(); + }); + } + }); + this.activityForm .get('type') .valueChanges.pipe(takeUntil(this.unsubscribeSubject)) diff --git a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html index 08e1b5162..06ad791f3 100644 --- a/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html +++ b/apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html @@ -315,6 +315,10 @@