Browse Source

Refactoring

pull/3859/head
Thomas Kaul 11 months ago
parent
commit
270b94dd15
  1. 17
      apps/api/src/services/tag/tag.service.ts
  2. 36
      apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts
  3. 14
      apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts
  4. 37
      libs/ui/src/lib/assistant/assistant.component.ts

17
apps/api/src/services/tag/tag.service.ts

@ -6,22 +6,8 @@ import { Injectable } from '@nestjs/common';
export class TagService { export class TagService {
public constructor(private readonly prismaService: PrismaService) {} public constructor(private readonly prismaService: PrismaService) {}
public async getPublic() {
return this.prismaService.tag.findMany({
orderBy: {
name: 'asc'
},
where: {
userId: null
}
});
}
public async getTagsForUser(userId: string) { public async getTagsForUser(userId: string) {
const tags = await this.prismaService.tag.findMany({ const tags = await this.prismaService.tag.findMany({
orderBy: {
name: 'asc'
},
include: { include: {
_count: { _count: {
select: { select: {
@ -33,6 +19,9 @@ export class TagService {
} }
} }
}, },
orderBy: {
name: 'asc'
},
where: { where: {
OR: [ OR: [
{ {

36
apps/client/src/app/components/holding-detail-dialog/holding-detail-dialog.component.ts

@ -147,16 +147,6 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
) {} ) {}
public ngOnInit() { public ngOnInit() {
this.userService.stateChanged
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((state) => {
if (state?.user) {
this.user = state.user;
this.changeDetectorRef.markForCheck();
}
});
this.activityForm = this.formBuilder.group({ this.activityForm = this.formBuilder.group({
tags: <string[]>[] tags: <string[]>[]
}); });
@ -166,14 +156,6 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
{ id: this.data.symbol, type: 'SYMBOL' } { id: this.data.symbol, type: 'SYMBOL' }
]; ];
const { tags } = this.user;
this.tagsAvailable = tags.map((tag) => {
return {
...tag,
name: translate(tag.name)
};
});
this.activityForm this.activityForm
.get('tags') .get('tags')
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) .valueChanges.pipe(takeUntil(this.unsubscribeSubject))
@ -436,6 +418,24 @@ export class GfHoldingDetailDialogComponent implements OnDestroy, OnInit {
this.changeDetectorRef.markForCheck(); this.changeDetectorRef.markForCheck();
} }
); );
this.userService.stateChanged
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((state) => {
if (state?.user) {
this.user = state.user;
this.tagsAvailable =
this.user?.tags?.map((tag) => {
return {
...tag,
name: translate(tag.name)
};
}) ?? [];
this.changeDetectorRef.markForCheck();
}
});
} }
public onAddTag(event: MatAutocompleteSelectedEvent) { public onAddTag(event: MatAutocompleteSelectedEvent) {

14
apps/client/src/app/pages/portfolio/activities/create-or-update-activity-dialog/create-or-update-activity-dialog.component.ts

@ -82,13 +82,13 @@ export class CreateOrUpdateActivityDialog implements OnDestroy {
this.defaultDateFormat = getDateFormatString(this.locale); this.defaultDateFormat = getDateFormatString(this.locale);
this.platforms = platforms; this.platforms = platforms;
const tags = this.data.user?.tags; this.tagsAvailable =
this.tagsAvailable = tags.map((tag) => { this.data.user?.tags?.map((tag) => {
return { return {
...tag, ...tag,
name: translate(tag.name) name: translate(tag.name)
}; };
}); }) ?? [];
Object.keys(Type).forEach((type) => { Object.keys(Type).forEach((type) => {
this.typesTranslationMap[Type[type]] = translate(Type[type]); this.typesTranslationMap[Type[type]] = translate(Type[type]);

37
libs/ui/src/lib/assistant/assistant.component.ts

@ -156,7 +156,6 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
) {} ) {}
public ngOnInit() { public ngOnInit() {
this.accounts = this.user?.accounts;
this.assetClasses = Object.keys(AssetClass).map((assetClass) => { this.assetClasses = Object.keys(AssetClass).map((assetClass) => {
return { return {
id: assetClass, id: assetClass,
@ -164,13 +163,6 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
type: 'ASSET_CLASS' type: 'ASSET_CLASS'
}; };
}); });
this.tags = this.user?.tags
.filter(({ isUsed }) => isUsed)
.map(({ id, name }) => ({
id,
label: translate(name),
type: 'TAG'
}));
this.searchFormControl.valueChanges this.searchFormControl.valueChanges
.pipe( .pipe(
@ -212,6 +204,8 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
} }
public ngOnChanges() { public ngOnChanges() {
this.accounts = this.user?.accounts ?? [];
this.dateRangeOptions = [ this.dateRangeOptions = [
{ label: $localize`Today`, value: '1d' }, { label: $localize`Today`, value: '1d' },
{ {
@ -269,16 +263,6 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
this.filterForm.enable({ emitEvent: false }); this.filterForm.enable({ emitEvent: false });
} }
this.tags = this.user?.tags
.filter(({ isUsed }) => isUsed)
.map(({ id, name }) => {
return {
id,
label: translate(name),
type: 'TAG'
};
});
this.filterForm.setValue( this.filterForm.setValue(
{ {
account: this.user?.settings?.['filters.accounts']?.[0] ?? null, account: this.user?.settings?.['filters.accounts']?.[0] ?? null,
@ -289,6 +273,23 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
emitEvent: false emitEvent: false
} }
); );
this.tags =
this.user?.tags
?.filter(({ isUsed }) => {
return isUsed;
})
.map(({ id, name }) => {
return {
id,
label: translate(name),
type: 'TAG'
};
}) ?? [];
if (this.tags.length === 0) {
this.filterForm.get('tag').disable({ emitEvent: false });
}
} }
public hasFilter(aFormValue: { [key: string]: string }) { public hasFilter(aFormValue: { [key: string]: string }) {

Loading…
Cancel
Save