Updated to angular 11
Now compiling with strict mode in typescript Need to error checking now
This commit is contained in:
@ -3,4 +3,12 @@ export class UpdateProductPricesItem {
|
||||
name: string;
|
||||
oldPrice: number;
|
||||
newPrice: number;
|
||||
|
||||
public constructor(init?: Partial<UpdateProductPricesItem>) {
|
||||
this.id = '';
|
||||
this.name = '';
|
||||
this.oldPrice = 0;
|
||||
this.newPrice = 0;
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { UpdateProductPricesComponent } from './update-product-prices.component';
|
||||
|
||||
@ -6,11 +6,13 @@ describe('UpdateProductPricesComponent', () => {
|
||||
let component: UpdateProductPricesComponent;
|
||||
let fixture: ComponentFixture<UpdateProductPricesComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [UpdateProductPricesComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [UpdateProductPricesComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(UpdateProductPricesComponent);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { AbstractControl, FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { map } from 'rxjs/operators';
|
||||
@ -18,10 +18,10 @@ import { UpdateProductPricesService } from './update-product-prices.service';
|
||||
styleUrls: ['./update-product-prices.component.css'],
|
||||
})
|
||||
export class UpdateProductPricesComponent implements OnInit {
|
||||
dataSource: UpdateProductPricesDataSource;
|
||||
info: UpdateProductPrices = new UpdateProductPrices();
|
||||
dataSource: UpdateProductPricesDataSource = new UpdateProductPricesDataSource(this.info.items);
|
||||
form: FormGroup;
|
||||
menuCategories: MenuCategory[];
|
||||
info: UpdateProductPrices;
|
||||
menuCategories: MenuCategory[] = [];
|
||||
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'oldPrice', 'newPrice'];
|
||||
@ -34,14 +34,22 @@ export class UpdateProductPricesComponent implements OnInit {
|
||||
private toaster: ToasterService,
|
||||
private ser: UpdateProductPricesService,
|
||||
) {
|
||||
this.createForm();
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
date: '',
|
||||
menuCategory: '',
|
||||
prices: this.fb.array([]),
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.pipe(
|
||||
map((data: { menuCategories: MenuCategory[]; info: UpdateProductPrices }) => {
|
||||
data.menuCategories.unshift(new MenuCategory({ id: null, name: '-- All Categories --' }));
|
||||
map((value) => {
|
||||
const data = value as { menuCategories: MenuCategory[]; info: UpdateProductPrices };
|
||||
data.menuCategories.unshift(
|
||||
new MenuCategory({ id: undefined, name: '-- All Categories --' }),
|
||||
);
|
||||
return data;
|
||||
}),
|
||||
)
|
||||
@ -53,10 +61,12 @@ export class UpdateProductPricesComponent implements OnInit {
|
||||
|
||||
loadData(info: UpdateProductPrices) {
|
||||
this.info = info;
|
||||
this.form.get('date').setValue(moment(this.info.date, 'DD-MMM-YYYY').toDate());
|
||||
this.form
|
||||
.get('menuCategory')
|
||||
.setValue(this.info.menuCategoryId !== undefined ? this.info.menuCategoryId : '');
|
||||
(this.form.get('date') as AbstractControl).setValue(
|
||||
moment(this.info.date, 'DD-MMM-YYYY').toDate(),
|
||||
);
|
||||
(this.form.get('menuCategory') as AbstractControl).setValue(
|
||||
this.info.menuCategoryId !== undefined ? this.info.menuCategoryId : '',
|
||||
);
|
||||
this.form.setControl(
|
||||
'prices',
|
||||
this.fb.array(
|
||||
@ -73,7 +83,7 @@ export class UpdateProductPricesComponent implements OnInit {
|
||||
show() {
|
||||
const info = this.getInfo();
|
||||
const route = ['update-product-prices'];
|
||||
if (info.menuCategoryId !== null) route.push(info.menuCategoryId);
|
||||
if (info.menuCategoryId !== null) route.push(info.menuCategoryId as string);
|
||||
this.router.navigate(route, {
|
||||
queryParams: {
|
||||
date: info.date,
|
||||
@ -81,14 +91,6 @@ export class UpdateProductPricesComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
date: '',
|
||||
menuCategory: '',
|
||||
prices: this.fb.array([]),
|
||||
});
|
||||
}
|
||||
|
||||
getInfo(): UpdateProductPrices {
|
||||
const formModel = this.form.value;
|
||||
const array = this.form.get('prices') as FormArray;
|
||||
|
||||
@ -17,7 +17,7 @@ const serviceName = 'UpdateProductPricesService';
|
||||
export class UpdateProductPricesService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string, date: string): Observable<UpdateProductPrices> {
|
||||
get(id: string | null, date: string | null): Observable<UpdateProductPrices> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
const options = { params: new HttpParams() };
|
||||
if (date !== null) {
|
||||
|
||||
@ -4,4 +4,10 @@ export class UpdateProductPrices {
|
||||
date: string;
|
||||
menuCategoryId?: string;
|
||||
items: UpdateProductPricesItem[];
|
||||
|
||||
public constructor(init?: Partial<UpdateProductPrices>) {
|
||||
this.date = '';
|
||||
this.items = [];
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user