Chore: Upgrade to Angular v14

This commit is contained in:
2022-07-11 20:12:38 +05:30
parent a4c3ae1035
commit b1c003a935
54 changed files with 355 additions and 325 deletions

View File

@ -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 { round } from 'mathjs';
@ -20,13 +20,13 @@ import { MathService } from '../shared/math.service';
})
export class PurchaseDialogComponent implements OnInit {
products: Observable<ProductSku[]>;
form: FormGroup;
form: UntypedFormGroup;
product: ProductSku = new ProductSku();
constructor(
public dialogRef: MatDialogRef<PurchaseDialogComponent>,
@Inject(MAT_DIALOG_DATA) public data: { inventory: Inventory },
private fb: FormBuilder,
private fb: UntypedFormBuilder,
private math: MathService,
private productSer: ProductService,
) {
@ -38,7 +38,7 @@ export class PurchaseDialogComponent implements OnInit {
discount: '',
});
// Listen to Product Autocomplete Change
this.products = (this.form.get('product') as FormControl).valueChanges.pipe(
this.products = (this.form.get('product') as UntypedFormControl).valueChanges.pipe(
startWith(null),
map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150),
@ -64,7 +64,7 @@ export class PurchaseDialogComponent implements OnInit {
productSelected(event: MatAutocompleteSelectedEvent): void {
this.product = event.option.value;
(this.form.get('price') as FormControl).setValue(this.product.costPrice);
(this.form.get('price') as UntypedFormControl).setValue(this.product.costPrice);
}
accept(): void {

View File

@ -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';
@ -42,7 +42,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
@ViewChild('dateElement', { static: true }) dateElement?: ElementRef;
public inventoryObservable = new BehaviorSubject<Inventory[]>([]);
dataSource: PurchaseDataSource = new PurchaseDataSource(this.inventoryObservable);
form: FormGroup;
form: UntypedFormGroup;
voucher: Voucher = new Voucher();
product: ProductSku | null = null;
accBal: AccountBalance | null = null;
@ -55,7 +55,7 @@ export class PurchaseComponent 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,
@ -81,7 +81,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
});
this.accBal = null;
// Listen to Account Autocomplete Change
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),
@ -90,7 +90,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
);
// Listen to Product Autocomplete Change
this.products = (
(this.form.get('addRow') as FormControl).get('product') as FormControl
(this.form.get('addRow') as UntypedFormControl).get('product') as UntypedFormControl
).valueChanges.pipe(
startWith(null),
map((x) => (x !== null && x.length >= 1 ? x : null)),
@ -191,7 +191,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
}
addRow() {
const formValue = (this.form.get('addRow') as FormControl).value;
const formValue = (this.form.get('addRow') as UntypedFormControl).value;
const quantity = this.math.parseAmount(formValue.quantity, 2);
if (this.product === null || quantity <= 0) {
return;
@ -228,7 +228,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
}
resetAddRow() {
(this.form.get('addRow') as FormControl).reset({
(this.form.get('addRow') as UntypedFormControl).reset({
product: null,
quantity: '',
price: '',
@ -236,9 +236,9 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
discount: '',
});
this.product = null;
((this.form.get('addRow') as FormControl).get('price') as FormControl).enable();
((this.form.get('addRow') as FormControl).get('tax') as FormControl).enable();
((this.form.get('addRow') as FormControl).get('discount') as FormControl).enable();
((this.form.get('addRow') as UntypedFormControl).get('price') as UntypedFormControl).enable();
((this.form.get('addRow') as UntypedFormControl).get('tax') as UntypedFormControl).enable();
((this.form.get('addRow') as UntypedFormControl).get('discount') as UntypedFormControl).enable();
setTimeout(() => {
if (this.productElement) {
this.productElement.nativeElement.focus();
@ -248,7 +248,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
updateView() {
this.inventoryObservable.next(this.voucher.inventories);
(this.form.get('amount') as FormControl).setValue(
(this.form.get('amount') as UntypedFormControl).setValue(
round(Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)), 2),
);
}
@ -360,26 +360,26 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
}
accountSelected(event: MatAutocompleteSelectedEvent): void {
(this.form.get('account') as FormControl).setValue(event.option.value);
(this.form.get('account') as UntypedFormControl).setValue(event.option.value);
}
productSelected(event: MatAutocompleteSelectedEvent): void {
const product: ProductSku = event.option.value;
const addRowForm: FormControl = this.form.get('addRow') as FormControl;
const addRowForm: UntypedFormControl = this.form.get('addRow') as UntypedFormControl;
this.product = product;
(addRowForm.get('price') as FormControl).setValue(product.costPrice);
(addRowForm.get('price') as UntypedFormControl).setValue(product.costPrice);
if (product.isRateContracted) {
(addRowForm.get('price') as FormControl).disable();
(addRowForm.get('tax') as FormControl).disable();
(addRowForm.get('discount') as FormControl).disable();
(addRowForm.get('tax') as FormControl).setValue('RC');
(addRowForm.get('discount') as FormControl).setValue('RC');
(addRowForm.get('price') as UntypedFormControl).disable();
(addRowForm.get('tax') as UntypedFormControl).disable();
(addRowForm.get('discount') as UntypedFormControl).disable();
(addRowForm.get('tax') as UntypedFormControl).setValue('RC');
(addRowForm.get('discount') as UntypedFormControl).setValue('RC');
} else {
(addRowForm.get('price') as FormControl).enable();
(addRowForm.get('tax') as FormControl).enable();
(addRowForm.get('discount') as FormControl).enable();
(addRowForm.get('tax') as FormControl).setValue('');
(addRowForm.get('discount') as FormControl).setValue('');
(addRowForm.get('price') as UntypedFormControl).enable();
(addRowForm.get('tax') as UntypedFormControl).enable();
(addRowForm.get('discount') as UntypedFormControl).enable();
(addRowForm.get('tax') as UntypedFormControl).setValue('');
(addRowForm.get('discount') as UntypedFormControl).setValue('');
}
}