Strict done!!
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
@ -17,7 +17,7 @@ import { MathService } from '../shared/math.service';
|
||||
export class ReceiptDialogComponent implements OnInit {
|
||||
accounts: Observable<Account[]>;
|
||||
form: FormGroup;
|
||||
account: Account;
|
||||
account: Account = new Account();
|
||||
accBal: any;
|
||||
|
||||
constructor(
|
||||
@ -32,7 +32,14 @@ export class ReceiptDialogComponent implements OnInit {
|
||||
amount: '',
|
||||
});
|
||||
this.accBal = null;
|
||||
this.setupAccountAutocomplete();
|
||||
// Setup Account Autocomplete
|
||||
this.accounts = (this.form.get('account') as FormControl).valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@ -43,24 +50,14 @@ export class ReceiptDialogComponent implements OnInit {
|
||||
this.account = this.data.journal.account;
|
||||
}
|
||||
|
||||
setupAccountAutocomplete(): void {
|
||||
const control = this.form.get('account');
|
||||
this.accounts = control.valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
);
|
||||
}
|
||||
|
||||
displayFn(account?: Account): string | undefined {
|
||||
return account ? account.name : undefined;
|
||||
displayFn(account?: Account): string {
|
||||
return account ? account.name : '';
|
||||
}
|
||||
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
this.account = event.option.value;
|
||||
this.accountSer.balance(this.account.id, this.data.date).subscribe((v) => {
|
||||
const account = event.option.value;
|
||||
this.account = account;
|
||||
this.accountSer.balance(account.id as string, this.data.date).subscribe((v) => {
|
||||
this.accBal = v;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user