Chore: Upgrade to Angular v14
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { Component, Inject, OnInit } from '@angular/core';
|
||||
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } 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';
|
||||
@ -18,14 +18,14 @@ import { MathService } from '../shared/math.service';
|
||||
})
|
||||
export class ReceiptDialogComponent implements OnInit {
|
||||
accounts: Observable<Account[]>;
|
||||
form: FormGroup;
|
||||
form: UntypedFormGroup;
|
||||
account: Account = new Account();
|
||||
accBal: AccountBalance | null = null;
|
||||
|
||||
constructor(
|
||||
public dialogRef: MatDialogRef<ReceiptDialogComponent>,
|
||||
@Inject(MAT_DIALOG_DATA) public data: { journal: Journal; date: string },
|
||||
private fb: FormBuilder,
|
||||
private fb: UntypedFormBuilder,
|
||||
private math: MathService,
|
||||
private accountSer: AccountService,
|
||||
) {
|
||||
@ -35,7 +35,7 @@ export class ReceiptDialogComponent implements OnInit {
|
||||
});
|
||||
this.accBal = null;
|
||||
// Setup Account Autocomplete
|
||||
this.accounts = (this.form.get('account') as FormControl).valueChanges.pipe(
|
||||
this.accounts = (this.form.get('account') as UntypedFormControl).valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, OnDestroy, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup } from '@angular/forms';
|
||||
import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
@ -37,7 +37,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
@ViewChild('dateElement', { static: true }) dateElement?: ElementRef;
|
||||
public journalObservable = new BehaviorSubject<Journal[]>([]);
|
||||
dataSource: ReceiptDataSource = new ReceiptDataSource(this.journalObservable);
|
||||
form: FormGroup;
|
||||
form: UntypedFormGroup;
|
||||
receiptAccounts: Account[] = [];
|
||||
receiptJournal: Journal = new Journal();
|
||||
voucher: Voucher = new Voucher();
|
||||
@ -51,7 +51,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private fb: UntypedFormBuilder,
|
||||
private dialog: MatDialog,
|
||||
private hotkeys: HotkeysService,
|
||||
private toaster: ToasterService,
|
||||
@ -74,7 +74,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.accBal = null;
|
||||
// Listen to Account Autocomplete Change
|
||||
this.accounts = (
|
||||
(this.form.get('addRow') as FormControl).get('account') as FormControl
|
||||
(this.form.get('addRow') as UntypedFormControl).get('account') as UntypedFormControl
|
||||
).valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
@ -83,7 +83,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
);
|
||||
// Listen to Receipt Account Change
|
||||
(this.form.get('receiptAccount') as FormControl).valueChanges.subscribe((x) =>
|
||||
(this.form.get('receiptAccount') as UntypedFormControl).valueChanges.subscribe((x) =>
|
||||
this.router.navigate([], {
|
||||
relativeTo: this.route,
|
||||
queryParams: { a: x },
|
||||
@ -173,7 +173,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
addRow() {
|
||||
const amount = this.math.parseAmount((this.form.get('addRow') as FormControl).value.amount, 2);
|
||||
const amount = this.math.parseAmount((this.form.get('addRow') as UntypedFormControl).value.amount, 2);
|
||||
const debit = -1;
|
||||
if (this.account === null || amount <= 0) {
|
||||
return;
|
||||
@ -202,7 +202,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
resetAddRow() {
|
||||
(this.form.get('addRow') as FormControl).reset({
|
||||
(this.form.get('addRow') as UntypedFormControl).reset({
|
||||
account: null,
|
||||
amount: null,
|
||||
});
|
||||
@ -222,7 +222,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
Math.abs(journals.map((x) => x.amount).reduce((p, c) => p + c, 0)),
|
||||
2,
|
||||
);
|
||||
(this.form.get('receiptAmount') as FormControl).setValue(this.receiptJournal.amount);
|
||||
(this.form.get('receiptAmount') as UntypedFormControl).setValue(this.receiptJournal.amount);
|
||||
}
|
||||
|
||||
editRow(row: Journal) {
|
||||
@ -230,7 +230,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
width: '750px',
|
||||
data: {
|
||||
journal: { ...row },
|
||||
date: moment((this.form.get('date') as FormControl).value).format('DD-MMM-YYYY'),
|
||||
date: moment((this.form.get('date') as UntypedFormControl).value).format('DD-MMM-YYYY'),
|
||||
},
|
||||
});
|
||||
|
||||
@ -337,7 +337,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
accountSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
const account = event.option.value;
|
||||
this.account = account;
|
||||
const date = moment((this.form.get('date') as FormControl).value).format('DD-MMM-YYYY');
|
||||
const date = moment((this.form.get('date') as UntypedFormControl).value).format('DD-MMM-YYYY');
|
||||
this.accountSer.balance(account.id as string, date).subscribe((v) => {
|
||||
this.accBal = v;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user