Strict done!!

This commit is contained in:
2020-11-23 16:42:54 +05:30
parent af343cb7f9
commit afe746ecdc
142 changed files with 1258 additions and 907 deletions

View File

@ -17,8 +17,8 @@ import { ProductService } from '../product.service';
export class ProductDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
form: FormGroup;
productGroups: ProductGroup[];
item: Product;
productGroups: ProductGroup[] = [];
item: Product = new Product();
constructor(
private route: ActivatedRoute,
@ -73,7 +73,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
ngAfterViewInit() {
setTimeout(() => {
this.nameElement.nativeElement.focus();
if (this.nameElement) this.nameElement.nativeElement.focus();
}, 0);
}
@ -90,7 +90,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

@ -12,11 +12,11 @@ function compare(a: string | number, b: string | number, isAsc: boolean) {
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
}
export class ProductListDataSource extends DataSource<Product> {
private filterValue: string = "";
private filterValue = '';
constructor(
public data: Product[],
private filter: Observable<string>,
private readonly filter: Observable<string>,
private paginator?: MatPaginator,
private sort?: MatSort,
) {
@ -83,8 +83,6 @@ export class ProductListDataSource extends DataSource<Product> {
return compare(a.name, b.name, isAsc);
case 'productGroup':
return compare(a.productGroup.name, b.productGroup.name, isAsc);
case 'id':
return compare(+a.id, +b.id, isAsc);
default:
return 0;
}

View File

@ -1,5 +1,5 @@
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { MatPaginator } from '@angular/material/paginator';
import { MatSort } from '@angular/material/sort';
import { ActivatedRoute } from '@angular/router';
@ -20,22 +20,27 @@ export class ProductListComponent implements OnInit, AfterViewInit {
@ViewChild('filterElement', { static: true }) filterElement?: ElementRef;
@ViewChild(MatPaginator, { static: true }) paginator?: MatPaginator;
@ViewChild(MatSort, { static: true }) sort?: MatSort;
list: Product[] = [];
filter: Observable<string>;
dataSource: ProductListDataSource;
filter: Observable<any>;
form: FormGroup;
list: Product[];
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns: string[];
displayedColumns: string[] = [];
// eslint-disable-next-line no-underscore-dangle
private _showExtended: boolean;
private _showExtended = false;
constructor(private route: ActivatedRoute, private fb: FormBuilder, private toCsv: ToCsvService) {
this.showExtended = false;
this.form = this.fb.group({
filter: '',
});
this.filter = this.listenToFilterChange();
this.filter = (this.form.get('filter') as FormControl).valueChanges.pipe(
startWith(''),
debounceTime(150),
distinctUntilChanged(),
);
this.dataSource = new ProductListDataSource(this.list, this.filter);
}
get showExtended(): boolean {
@ -53,24 +58,18 @@ export class ProductListComponent implements OnInit, AfterViewInit {
}
}
listenToFilterChange() {
return this.form
.get('filter')
.valueChanges.pipe(startWith(''), debounceTime(150), distinctUntilChanged());
}
ngOnInit() {
this.route.data.subscribe((value) => {
const data = value as { list: Product[] };
this.list = data.list;
});
this.dataSource = new ProductListDataSource(this.paginator, this.sort, this.filter, this.list);
this.dataSource = new ProductListDataSource(this.list, this.filter, this.paginator, this.sort);
}
ngAfterViewInit() {
setTimeout(() => {
this.filterElement.nativeElement.focus();
if (this.filterElement) this.filterElement.nativeElement.focus();
}, 0);
}

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