|
@ -19,10 +19,10 @@ import { FormBuilder, FormControl } from '@angular/forms'; |
|
|
import { MatMenuTrigger } from '@angular/material/menu'; |
|
|
import { MatMenuTrigger } from '@angular/material/menu'; |
|
|
import { AdminService } from '@ghostfolio/client/services/admin.service'; |
|
|
import { AdminService } from '@ghostfolio/client/services/admin.service'; |
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
import { DataService } from '@ghostfolio/client/services/data.service'; |
|
|
import { User } from '@ghostfolio/common/interfaces'; |
|
|
import { Filter, User } from '@ghostfolio/common/interfaces'; |
|
|
import { DateRange } from '@ghostfolio/common/types'; |
|
|
import { DateRange } from '@ghostfolio/common/types'; |
|
|
import { translate } from '@ghostfolio/ui/i18n'; |
|
|
import { translate } from '@ghostfolio/ui/i18n'; |
|
|
import { Tag } from '@prisma/client'; |
|
|
import { Account, Tag } from '@prisma/client'; |
|
|
import { EMPTY, Observable, Subject, lastValueFrom } from 'rxjs'; |
|
|
import { EMPTY, Observable, Subject, lastValueFrom } from 'rxjs'; |
|
|
import { |
|
|
import { |
|
|
catchError, |
|
|
catchError, |
|
@ -81,7 +81,7 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
@Output() closed = new EventEmitter<void>(); |
|
|
@Output() closed = new EventEmitter<void>(); |
|
|
@Output() dateRangeChanged = new EventEmitter<DateRange>(); |
|
|
@Output() dateRangeChanged = new EventEmitter<DateRange>(); |
|
|
@Output() selectedTagChanged = new EventEmitter<Tag>(); |
|
|
@Output() filtersChanged = new EventEmitter<Filter[]>(); |
|
|
|
|
|
|
|
|
@ViewChild('menuTrigger') menuTriggerElement: MatMenuTrigger; |
|
|
@ViewChild('menuTrigger') menuTriggerElement: MatMenuTrigger; |
|
|
@ViewChild('search', { static: true }) searchElement: ElementRef; |
|
|
@ViewChild('search', { static: true }) searchElement: ElementRef; |
|
@ -91,6 +91,7 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
public static readonly SEARCH_RESULTS_DEFAULT_LIMIT = 5; |
|
|
public static readonly SEARCH_RESULTS_DEFAULT_LIMIT = 5; |
|
|
|
|
|
|
|
|
|
|
|
public accounts: Account[] = []; |
|
|
public dateRangeFormControl = new FormControl<string>(undefined); |
|
|
public dateRangeFormControl = new FormControl<string>(undefined); |
|
|
public readonly dateRangeOptions = [ |
|
|
public readonly dateRangeOptions = [ |
|
|
{ label: $localize`Today`, value: '1d' }, |
|
|
{ label: $localize`Today`, value: '1d' }, |
|
@ -111,6 +112,7 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { |
|
|
{ label: $localize`Max`, value: 'max' } |
|
|
{ label: $localize`Max`, value: 'max' } |
|
|
]; |
|
|
]; |
|
|
public filterForm = this.formBuilder.group({ |
|
|
public filterForm = this.formBuilder.group({ |
|
|
|
|
|
account: new FormControl<string>(undefined), |
|
|
tag: new FormControl<string>(undefined) |
|
|
tag: new FormControl<string>(undefined) |
|
|
}); |
|
|
}); |
|
|
public isLoading = false; |
|
|
public isLoading = false; |
|
@ -136,6 +138,7 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { |
|
|
public ngOnInit() { |
|
|
public ngOnInit() { |
|
|
const { tags } = this.dataService.fetchInfo(); |
|
|
const { tags } = this.dataService.fetchInfo(); |
|
|
|
|
|
|
|
|
|
|
|
this.accounts = this.user?.accounts; |
|
|
this.tags = tags.map(({ id, name }) => { |
|
|
this.tags = tags.map(({ id, name }) => { |
|
|
return { |
|
|
return { |
|
|
id, |
|
|
id, |
|
@ -143,15 +146,19 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { |
|
|
}; |
|
|
}; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
this.filterForm |
|
|
this.filterForm.valueChanges |
|
|
.get('tag') |
|
|
.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.valueChanges.pipe(takeUntil(this.unsubscribeSubject)) |
|
|
.subscribe(({ account, tag }) => { |
|
|
.subscribe((tagId) => { |
|
|
this.filtersChanged.emit([ |
|
|
const tag = this.tags.find(({ id }) => { |
|
|
{ |
|
|
return id === tagId; |
|
|
id: account, |
|
|
}); |
|
|
type: 'ACCOUNT' |
|
|
|
|
|
}, |
|
|
this.selectedTagChanged.emit(tag); |
|
|
{ |
|
|
|
|
|
id: tag, |
|
|
|
|
|
type: 'TAG' |
|
|
|
|
|
} |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
this.onCloseAssistant(); |
|
|
this.onCloseAssistant(); |
|
|
}); |
|
|
}); |
|
@ -200,6 +207,7 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
this.filterForm.setValue( |
|
|
this.filterForm.setValue( |
|
|
{ |
|
|
{ |
|
|
|
|
|
account: this.user?.settings?.['filters.accounts']?.[0] ?? null, |
|
|
tag: this.user?.settings?.['filters.tags']?.[0] ?? null |
|
|
tag: this.user?.settings?.['filters.tags']?.[0] ?? null |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|