Browse Source

Feature/support creating custom tags in create or update activity dialog (#4801)

* Support creating custom tags in create or update activity dialog

* Update changelog
pull/4807/head
Thomas Kaul 1 month ago
committed by GitHub
parent
commit
7342e7e5ec
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      CHANGELOG.md
  2. 7
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts
  3. 4
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html
  4. 37
      apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts
  5. 3
      apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html

4
CHANGELOG.md

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased ## Unreleased
### Added
- Added support to create custom tags in the create or update activity dialog (experimental)
### Changed ### Changed
- Improved the language localization for German (`de`) - Improved the language localization for German (`de`)

7
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) { if (state?.user) {
this.user = state.user; this.user = state.user;
this.hasPermissionToCreateOwnTag = hasPermission( this.hasPermissionToCreateOwnTag =
this.user.permissions, hasPermission(this.user.permissions, permissions.createOwnTag) &&
permissions.createOwnTag this.user?.settings?.isExperimentalFeatures;
);
this.tagsAvailable = this.tagsAvailable =
this.user?.tags?.map((tag) => { this.user?.tags?.map((tag) => {

4
apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.html

@ -388,9 +388,7 @@
</mat-tab-group> </mat-tab-group>
<gf-tags-selector <gf-tags-selector
[hasPermissionToCreateTag]=" [hasPermissionToCreateTag]="hasPermissionToCreateOwnTag"
hasPermissionToCreateOwnTag && user?.settings?.isExperimentalFeatures
"
[readonly]="!data.hasPermissionToUpdateOrder" [readonly]="!data.hasPermissionToUpdateOrder"
[tags]="activityForm.get('tags')?.value" [tags]="activityForm.get('tags')?.value"
[tagsAvailable]="tagsAvailable" [tagsAvailable]="tagsAvailable"

37
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 { CreateOrderDto } from '@ghostfolio/api/app/order/create-order.dto';
import { UpdateOrderDto } from '@ghostfolio/api/app/order/update-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 { getDateFormatString } from '@ghostfolio/common/helper';
import { hasPermission, permissions } from '@ghostfolio/common/permissions';
import { translate } from '@ghostfolio/ui/i18n'; import { translate } from '@ghostfolio/ui/i18n';
import { import {
@ -42,6 +44,7 @@ export class CreateOrUpdateActivityDialog implements OnDestroy {
public currencyOfAssetProfile: string; public currencyOfAssetProfile: string;
public currentMarketPrice = null; public currentMarketPrice = null;
public defaultDateFormat: string; public defaultDateFormat: string;
public hasPermissionToCreateOwnTag: boolean;
public isLoading = false; public isLoading = false;
public isToday = isToday; public isToday = isToday;
public mode: 'create' | 'update'; public mode: 'create' | 'update';
@ -60,11 +63,15 @@ export class CreateOrUpdateActivityDialog implements OnDestroy {
private dateAdapter: DateAdapter<any>, private dateAdapter: DateAdapter<any>,
public dialogRef: MatDialogRef<CreateOrUpdateActivityDialog>, public dialogRef: MatDialogRef<CreateOrUpdateActivityDialog>,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
@Inject(MAT_DATE_LOCALE) private locale: string @Inject(MAT_DATE_LOCALE) private locale: string,
private userService: UserService
) {} ) {}
public ngOnInit() { public ngOnInit() {
this.currencyOfAssetProfile = this.data.activity?.SymbolProfile?.currency; 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.locale = this.data.user?.settings?.locale;
this.mode = this.data.activity?.id ? 'update' : 'create'; this.mode = this.data.activity?.id ? 'update' : 'create';
@ -219,6 +226,34 @@ export class CreateOrUpdateActivityDialog implements OnDestroy {
this.changeDetectorRef.markForCheck(); 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 this.activityForm
.get('type') .get('type')
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) .valueChanges.pipe(takeUntil(this.unsubscribeSubject))

3
apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.html

@ -313,8 +313,9 @@
</mat-select> </mat-select>
</mat-form-field> </mat-form-field>
</div> </div>
<div class="mb-3" [ngClass]="{ 'd-none': tagsAvailable?.length < 1 }"> <div class="mb-3">
<gf-tags-selector <gf-tags-selector
[hasPermissionToCreateTag]="hasPermissionToCreateOwnTag"
[tags]="activityForm.get('tags')?.value" [tags]="activityForm.get('tags')?.value"
[tagsAvailable]="tagsAvailable" [tagsAvailable]="tagsAvailable"
(tagsChanged)="onTagsChanged($event)" (tagsChanged)="onTagsChanged($event)"

Loading…
Cancel
Save