diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d62dc94c..92a277712 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 + +- Added support to create custom tags in the create or update activity dialog (experimental) + ### Changed - Improved the language localization for German (`de`) diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts index d866275c0..cdaea83dc 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts @@ -452,10 +452,9 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit { if (state?.user) { this.user = state.user; - this.hasPermissionToCreateOwnTag = hasPermission( - this.user.permissions, - permissions.createOwnTag - ); + this.hasPermissionToCreateOwnTag = + hasPermission(this.user.permissions, permissions.createOwnTag) && + this.user?.settings?.isExperimentalFeatures; this.tagsAvailable = this.user?.tags?.map((tag) => { diff --git a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html index 55ebbcd78..0f6c46a80 100644 --- a/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html +++ b/apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html @@ -388,9 +388,7 @@ , 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 = + this.data.user?.settings?.isExperimentalFeatures && + hasPermission(this.data.user?.permissions, permissions.createOwnTag); this.locale = this.data.user?.settings?.locale; this.mode = this.data.activity?.id ? 'update' : 'create'; @@ -219,6 +226,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..985394a40 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 @@ -313,8 +313,9 @@ -
+