Updated to angular 11

Now compiling with strict mode in typescript
Need to error checking now
This commit is contained in:
2020-11-22 10:13:37 +05:30
parent cabd6f2ea1
commit 6567f560ab
187 changed files with 1709 additions and 1184 deletions

View File

@ -1,4 +1,4 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ProductDetailComponent } from './product-detail.component';
@ -6,11 +6,13 @@ describe('ProductDetailComponent', () => {
let component: ProductDetailComponent;
let fixture: ComponentFixture<ProductDetailComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ProductDetailComponent],
}).compileComponents();
}));
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ProductDetailComponent],
}).compileComponents();
}),
);
beforeEach(() => {
fixture = TestBed.createComponent(ProductDetailComponent);

View File

@ -16,11 +16,11 @@ import { ProductService } from '../product.service';
styleUrls: ['./product-detail.component.css'],
})
export class ProductDetailComponent implements OnInit, AfterViewInit {
@ViewChild('name', { static: true }) nameElement: ElementRef;
@ViewChild('name', { static: true }) nameElement?: ElementRef;
form: FormGroup;
menuCategories: MenuCategory[];
saleCategories: SaleCategory[];
item: Product;
menuCategories: MenuCategory[] = [];
saleCategories: SaleCategory[] = [];
item: Product = new Product();
constructor(
private route: ActivatedRoute,
@ -30,10 +30,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
private toaster: ToasterService,
private ser: ProductService,
) {
this.createForm();
}
createForm() {
// Create form
this.form = this.fb.group({
code: { value: '', disabled: true },
name: '',
@ -48,13 +45,16 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
}
ngOnInit() {
this.route.data.subscribe(
(data: { item: Product; menuCategories: MenuCategory[]; saleCategories: SaleCategory[] }) => {
this.menuCategories = data.menuCategories;
this.saleCategories = data.saleCategories;
this.showItem(data.item);
},
);
this.route.data.subscribe((value) => {
const data = value as {
item: Product;
menuCategories: MenuCategory[];
saleCategories: SaleCategory[];
};
this.menuCategories = data.menuCategories;
this.saleCategories = data.saleCategories;
this.showItem(data.item);
});
}
showItem(item: Product) {
@ -74,7 +74,9 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
ngAfterViewInit() {
setTimeout(() => {
this.nameElement.nativeElement.focus();
if (this.nameElement !== undefined) {
this.nameElement.nativeElement.focus();
}
}, 0);
}
@ -91,7 +93,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
}
delete() {
this.ser.delete(this.item.id).subscribe(
this.ser.delete(this.item.id as string).subscribe(
() => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/products');

View File

@ -5,7 +5,7 @@
Update Order
</button>
<!-- This should check filtered data and not data-->
<button mat-button mat-icon-button (click)="exportCsv()" [disabled]="!(data | async).length">
<button mat-button mat-icon-button (click)="exportCsv()" [disabled]="!(data | async)?.length">
<mat-icon>save_alt</mat-icon>
</button>
<a mat-button [routerLink]="['/products', 'new']">

View File

@ -18,12 +18,12 @@ import { ProductListDataSource } from './product-list-datasource';
styleUrls: ['./product-list.component.css'],
})
export class ProductListComponent implements OnInit {
dataSource: ProductListDataSource;
filter: BehaviorSubject<string>;
filter: BehaviorSubject<string> = new BehaviorSubject('');
data: BehaviorSubject<Product[]> = new BehaviorSubject<Product[]>([]);
dataSource: ProductListDataSource = new ProductListDataSource(this.filter, this.data);
form: FormGroup;
list: Product[];
data: BehaviorSubject<Product[]>;
menuCategories: MenuCategory[];
list: Product[] = [];
menuCategories: MenuCategory[] = [];
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns: string[] = [
'name',
@ -44,8 +44,6 @@ export class ProductListComponent implements OnInit {
this.form = this.fb.group({
menuCategory: '',
});
this.filter = new BehaviorSubject(undefined);
this.data = new BehaviorSubject([]);
this.data.subscribe((data: Product[]) => {
this.list = data;
});
@ -57,7 +55,8 @@ export class ProductListComponent implements OnInit {
ngOnInit() {
this.dataSource = new ProductListDataSource(this.filter, this.data);
this.route.data.subscribe((data: { list: Product[]; menuCategories: MenuCategory[] }) => {
this.route.data.subscribe((value) => {
const data = value as { list: Product[]; menuCategories: MenuCategory[] };
this.loadData(data.list, data.menuCategories);
});
}

View File

@ -17,7 +17,7 @@ const serviceName = 'ProductService';
export class ProductService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
get(id: string): Observable<Product> {
get(id: string | null): Observable<Product> {
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
return <Observable<Product>>(
this.http