|
@ -24,6 +24,7 @@ import { |
|
|
import { FormBuilder, FormControl } from '@angular/forms'; |
|
|
import { FormBuilder, FormControl } from '@angular/forms'; |
|
|
import { MatMenuTrigger } from '@angular/material/menu'; |
|
|
import { MatMenuTrigger } from '@angular/material/menu'; |
|
|
import { Account, AssetClass } from '@prisma/client'; |
|
|
import { Account, AssetClass } from '@prisma/client'; |
|
|
|
|
|
import { filter } from 'lodash'; |
|
|
import { EMPTY, Observable, Subject, lastValueFrom } from 'rxjs'; |
|
|
import { EMPTY, Observable, Subject, lastValueFrom } from 'rxjs'; |
|
|
import { |
|
|
import { |
|
|
catchError, |
|
|
catchError, |
|
@ -117,9 +118,9 @@ 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), |
|
|
account: new FormControl<string[]>(undefined), |
|
|
assetClass: new FormControl<string>(undefined), |
|
|
assetClass: new FormControl<string[]>(undefined), |
|
|
tag: new FormControl<string>(undefined) |
|
|
tag: new FormControl<string[]>(undefined) |
|
|
}); |
|
|
}); |
|
|
public isLoading = false; |
|
|
public isLoading = false; |
|
|
public isOpen = false; |
|
|
public isOpen = false; |
|
@ -203,9 +204,9 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { |
|
|
|
|
|
|
|
|
this.filterForm.setValue( |
|
|
this.filterForm.setValue( |
|
|
{ |
|
|
{ |
|
|
account: this.user?.settings?.['filters.accounts']?.[0] ?? null, |
|
|
account: this.user?.settings?.['filters.accounts'] ?? null, |
|
|
assetClass: this.user?.settings?.['filters.assetClasses']?.[0] ?? null, |
|
|
assetClass: this.user?.settings?.['filters.assetClasses'] ?? null, |
|
|
tag: this.user?.settings?.['filters.tags']?.[0] ?? null |
|
|
tag: this.user?.settings?.['filters.tags'] ?? null |
|
|
}, |
|
|
}, |
|
|
{ |
|
|
{ |
|
|
emitEvent: false |
|
|
emitEvent: false |
|
@ -213,7 +214,7 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public hasFilter(aFormValue: { [key: string]: string }) { |
|
|
public hasFilter(aFormValue: { [key: string]: string[] }) { |
|
|
return Object.values(aFormValue).some((value) => { |
|
|
return Object.values(aFormValue).some((value) => { |
|
|
return !!value; |
|
|
return !!value; |
|
|
}); |
|
|
}); |
|
@ -243,20 +244,28 @@ export class AssistantComponent implements OnChanges, OnDestroy, OnInit { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public onApplyFilters() { |
|
|
public onApplyFilters() { |
|
|
this.filtersChanged.emit([ |
|
|
let accountFilters = |
|
|
{ |
|
|
this.filterForm |
|
|
id: this.filterForm.get('account').value, |
|
|
.get('account') |
|
|
type: 'ACCOUNT' |
|
|
.value?.reduce( |
|
|
}, |
|
|
(arr, val) => [...arr, { id: val, type: 'ACCOUNT' }], |
|
|
{ |
|
|
[] |
|
|
id: this.filterForm.get('assetClass').value, |
|
|
) ?? []; |
|
|
type: 'ASSET_CLASS' |
|
|
let assetClassFilters = |
|
|
}, |
|
|
this.filterForm |
|
|
{ |
|
|
.get('assetClass') |
|
|
id: this.filterForm.get('tag').value, |
|
|
.value?.reduce( |
|
|
type: 'TAG' |
|
|
(arr, val) => [...arr, { id: val, type: 'ASSET_CLASS' }], |
|
|
} |
|
|
[] |
|
|
]); |
|
|
) ?? []; |
|
|
|
|
|
let tagFilters = |
|
|
|
|
|
this.filterForm |
|
|
|
|
|
.get('tag') |
|
|
|
|
|
.value?.reduce((arr, val) => [...arr, { id: val, type: 'TAG' }], []) ?? |
|
|
|
|
|
[]; |
|
|
|
|
|
let filters = [...accountFilters, ...assetClassFilters]; |
|
|
|
|
|
filters = [...filters, ...tagFilters]; |
|
|
|
|
|
this.filtersChanged.emit(filters); |
|
|
|
|
|
|
|
|
this.onCloseAssistant(); |
|
|
this.onCloseAssistant(); |
|
|
} |
|
|
} |
|
|