Chore: Upgrade to Angular v14
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, 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';
|
||||
@@ -30,7 +30,7 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('ingredientElement', { static: true }) ingredientElement?: ElementRef;
|
||||
public itemsObservable = new BehaviorSubject<RecipeItem[]>([]);
|
||||
dataSource: RecipeDetailDatasource = new RecipeDetailDatasource(this.itemsObservable);
|
||||
form: FormGroup;
|
||||
form: UntypedFormGroup;
|
||||
product: ProductSku | null;
|
||||
products: Observable<ProductSku[]>;
|
||||
ingredient: ProductSku | null;
|
||||
@@ -42,7 +42,7 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private fb: UntypedFormBuilder,
|
||||
private dialog: MatDialog,
|
||||
private toaster: ToasterService,
|
||||
private math: MathService,
|
||||
@@ -66,7 +66,7 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
||||
}),
|
||||
});
|
||||
// Setup Product Autocomplete
|
||||
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),
|
||||
@@ -75,7 +75,7 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
||||
);
|
||||
// Setup Product Autocomplete
|
||||
this.ingredients = (
|
||||
(this.form.get('addRow') as FormControl).get('ingredient') as FormControl
|
||||
(this.form.get('addRow') as UntypedFormControl).get('ingredient') as UntypedFormControl
|
||||
).valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
@@ -133,8 +133,8 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
||||
productSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
const product: ProductSku = event.option.value;
|
||||
this.item.sku = product;
|
||||
(this.form.get('product') as FormControl).setValue(product);
|
||||
(this.form.get('salePrice') as FormControl).setValue('' + (product.salePrice ?? 0));
|
||||
(this.form.get('product') as UntypedFormControl).setValue(product);
|
||||
(this.form.get('salePrice') as UntypedFormControl).setValue('' + (product.salePrice ?? 0));
|
||||
}
|
||||
|
||||
ingredientSelected(event: MatAutocompleteSelectedEvent): void {
|
||||
@@ -144,14 +144,14 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
||||
this.ser
|
||||
.getIngredientDetails(ingredient.id, item.validFrom, item.validTill)
|
||||
.subscribe((x) =>
|
||||
((this.form.get('addRow') as FormControl).get('rate') as FormControl).setValue(
|
||||
((this.form.get('addRow') as UntypedFormControl).get('rate') as UntypedFormControl).setValue(
|
||||
'' + x.costPrice,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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);
|
||||
const rate = this.math.parseAmount(formValue.rate, 2);
|
||||
if (this.ingredient === null || quantity <= 0 || rate <= 0) {
|
||||
@@ -176,7 +176,7 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
resetAddRow() {
|
||||
(this.form.get('addRow') as FormControl).reset({
|
||||
(this.form.get('addRow') as UntypedFormControl).reset({
|
||||
ingredient: null,
|
||||
quantity: '',
|
||||
rate: '',
|
||||
@@ -195,13 +195,13 @@ export class RecipeDetailComponent implements OnInit, AfterViewInit {
|
||||
this.item.items.map((x) => x.quantity * x.price).reduce((p, c) => p + c, 0),
|
||||
2,
|
||||
);
|
||||
(this.form.get('costPrice') as FormControl).setValue(costPrice);
|
||||
(this.form.get('costPrice') as UntypedFormControl).setValue(costPrice);
|
||||
const salePrice = this.math.parseAmount(this.form.value.salePrice, 2);
|
||||
if (salePrice < 0) {
|
||||
return;
|
||||
}
|
||||
const costPercentage = round((100 * costPrice) / salePrice, 2);
|
||||
(this.form.get('costPercentage') as FormControl).setValue(costPercentage);
|
||||
(this.form.get('costPercentage') as UntypedFormControl).setValue(costPercentage);
|
||||
}
|
||||
|
||||
deleteRow(row: RecipeItem) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
@@ -19,7 +19,7 @@ import { RecipeListDatasource } from './recipe-list-datasource';
|
||||
export class RecipeListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator, { static: true }) paginator?: MatPaginator;
|
||||
@ViewChild(MatSort, { static: true }) sort?: MatSort;
|
||||
form: FormGroup;
|
||||
form: UntypedFormGroup;
|
||||
productGroups: ProductGroup[] = [];
|
||||
validFromFilter: BehaviorSubject<Date | null> = new BehaviorSubject<Date | null>(null);
|
||||
validTillFilter: BehaviorSubject<Date | null> = new BehaviorSubject<Date | null>(null);
|
||||
@@ -36,7 +36,7 @@ export class RecipeListComponent implements OnInit {
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'validity', 'salePrice', 'costPrice', 'costPercentage'];
|
||||
|
||||
constructor(private route: ActivatedRoute, private fb: FormBuilder) {
|
||||
constructor(private route: ActivatedRoute, private fb: UntypedFormBuilder) {
|
||||
this.form = this.fb.group({
|
||||
validFrom: '',
|
||||
validTill: '',
|
||||
|
||||
Reference in New Issue
Block a user