|
@ -16,10 +16,10 @@ import { |
|
|
} from '@angular/material/autocomplete'; |
|
|
} from '@angular/material/autocomplete'; |
|
|
import { MatFormFieldControl } from '@angular/material/form-field'; |
|
|
import { MatFormFieldControl } from '@angular/material/form-field'; |
|
|
import { MatInput } from '@angular/material/input'; |
|
|
import { MatInput } from '@angular/material/input'; |
|
|
|
|
|
import { Currency } from '@ghostfolio/common/interfaces/currency.interface'; |
|
|
|
|
|
import { AbstractMatFormField } from '@ghostfolio/ui/shared/abstract-mat-form-field'; |
|
|
import { Subject } from 'rxjs'; |
|
|
import { Subject } from 'rxjs'; |
|
|
import { map, startWith, takeUntil } from 'rxjs/operators'; |
|
|
import { map, startWith, takeUntil } from 'rxjs/operators'; |
|
|
import { Currency } from '@ghostfolio/common/interfaces/currency.interface'; |
|
|
|
|
|
import { AbstractMatFormField } from '../symbol-autocomplete/abstract-mat-form-field'; |
|
|
|
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
changeDetection: ChangeDetectionStrategy.OnPush, |
|
|
changeDetection: ChangeDetectionStrategy.OnPush, |
|
@ -27,15 +27,15 @@ import { AbstractMatFormField } from '../symbol-autocomplete/abstract-mat-form-f |
|
|
'[attr.aria-describedBy]': 'describedBy', |
|
|
'[attr.aria-describedBy]': 'describedBy', |
|
|
'[id]': 'id' |
|
|
'[id]': 'id' |
|
|
}, |
|
|
}, |
|
|
selector: 'gf-currency-autocomplete', |
|
|
|
|
|
styleUrls: ['./currency-selector.component.scss'], |
|
|
|
|
|
templateUrl: 'currency-selector.component.html', |
|
|
|
|
|
providers: [ |
|
|
providers: [ |
|
|
{ |
|
|
{ |
|
|
provide: MatFormFieldControl, |
|
|
provide: MatFormFieldControl, |
|
|
useExisting: CurrencySelectorComponent |
|
|
useExisting: CurrencySelectorComponent |
|
|
} |
|
|
} |
|
|
] |
|
|
], |
|
|
|
|
|
selector: 'gf-currency-autocomplete', |
|
|
|
|
|
styleUrls: ['./currency-selector.component.scss'], |
|
|
|
|
|
templateUrl: 'currency-selector.component.html' |
|
|
}) |
|
|
}) |
|
|
export class CurrencySelectorComponent |
|
|
export class CurrencySelectorComponent |
|
|
extends AbstractMatFormField<Currency> |
|
|
extends AbstractMatFormField<Currency> |
|
@ -81,10 +81,12 @@ export class CurrencySelectorComponent |
|
|
.pipe( |
|
|
.pipe( |
|
|
takeUntil(this.unsubscribeSubject), |
|
|
takeUntil(this.unsubscribeSubject), |
|
|
startWith(''), |
|
|
startWith(''), |
|
|
map((value) => (value ? this.filter(value) : this.currencies.slice())) |
|
|
map((value) => { |
|
|
|
|
|
return value ? this.filter(value) : this.currencies.slice(); |
|
|
|
|
|
}) |
|
|
) |
|
|
) |
|
|
.subscribe((val) => { |
|
|
.subscribe((values) => { |
|
|
this.filteredCurrencies = val; |
|
|
this.filteredCurrencies = values; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -96,17 +98,6 @@ export class CurrencySelectorComponent |
|
|
return this.input?.empty; |
|
|
return this.input?.empty; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private filter(value: Currency | string) { |
|
|
|
|
|
const filterValue = |
|
|
|
|
|
typeof value === 'string' |
|
|
|
|
|
? value?.toLowerCase() |
|
|
|
|
|
: value?.value.toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
return this.currencies.filter((currency) => |
|
|
|
|
|
currency.value.toLowerCase().startsWith(filterValue) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public focus() { |
|
|
public focus() { |
|
|
this.input.focus(); |
|
|
this.input.focus(); |
|
|
} |
|
|
} |
|
@ -138,6 +129,17 @@ export class CurrencySelectorComponent |
|
|
this.unsubscribeSubject.complete(); |
|
|
this.unsubscribeSubject.complete(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private filter(value: Currency | string) { |
|
|
|
|
|
const filterValue = |
|
|
|
|
|
typeof value === 'string' |
|
|
|
|
|
? value?.toLowerCase() |
|
|
|
|
|
: value?.value.toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
return this.currencies.filter((currency) => { |
|
|
|
|
|
return currency.value.toLowerCase().startsWith(filterValue); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private validateRequired() { |
|
|
private validateRequired() { |
|
|
const requiredCheck = super.required |
|
|
const requiredCheck = super.required |
|
|
? !super.value.label || !super.value.value |
|
|
? !super.value.label || !super.value.value |
|
|