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 { TableDetailComponent } from './tables-detail.component';
@ -6,11 +6,13 @@ describe('TableDetailComponent', () => {
let component: TableDetailComponent;
let fixture: ComponentFixture<TableDetailComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TableDetailComponent],
}).compileComponents();
}));
beforeEach(
waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [TableDetailComponent],
}).compileComponents();
}),
);
beforeEach(() => {
fixture = TestBed.createComponent(TableDetailComponent);

View File

@ -15,10 +15,10 @@ import { TableService } from '../table.service';
styleUrls: ['./table-detail.component.css'],
})
export class TableDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
form: FormGroup;
sections: Section[];
item: Table;
sections: Section[] = [];
item: Table = new Table();
constructor(
private route: ActivatedRoute,
@ -28,10 +28,7 @@ export class TableDetailComponent implements OnInit, AfterViewInit {
private toaster: ToasterService,
private ser: TableService,
) {
this.createForm();
}
createForm() {
// Create form
this.form = this.fb.group({
name: '',
seats: '',
@ -41,7 +38,8 @@ export class TableDetailComponent implements OnInit, AfterViewInit {
}
ngOnInit() {
this.route.data.subscribe((data: { item: Table; sections: Section[] }) => {
this.route.data.subscribe((value) => {
const data = value as { item: Table; sections: Section[] };
this.showItem(data.item);
this.sections = data.sections;
});
@ -59,7 +57,9 @@ export class TableDetailComponent implements OnInit, AfterViewInit {
ngAfterViewInit() {
setTimeout(() => {
this.nameElement.nativeElement.focus();
if (this.nameElement !== undefined) {
this.nameElement.nativeElement.focus();
}
}, 0);
}
@ -76,7 +76,7 @@ export class TableDetailComponent 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('/tables');

View File

@ -5,7 +5,7 @@ import { tap } from 'rxjs/operators';
import { Table } from '../../core/table';
export class TableListDataSource extends DataSource<Table> {
private data: Table[];
private data: Table[] = [];
constructor(private readonly dataObs: Observable<Table[]>) {
super();

View File

@ -17,10 +17,10 @@ import { TableListDataSource } from './table-list-datasource';
styleUrls: ['./table-list.component.css'],
})
export class TableListComponent implements OnInit {
@ViewChild('table', { static: true }) table: MatTable<MenuCategory>;
dataSource: TableListDataSource;
list: Table[];
data: BehaviorSubject<Table[]>;
@ViewChild('table', { static: true }) table?: MatTable<MenuCategory>;
data: BehaviorSubject<Table[]> = new BehaviorSubject<Table[]>([]);
dataSource: TableListDataSource = new TableListDataSource(this.data);
list: Table[] = [];
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['name', 'seats', 'section', 'isActive'];
@ -30,14 +30,14 @@ export class TableListComponent implements OnInit {
private toaster: ToasterService,
private ser: TableService,
) {
this.data = new BehaviorSubject([]);
this.data.subscribe((data: Table[]) => {
this.list = data;
});
}
ngOnInit() {
this.route.data.subscribe((data: { list: Table[] }) => {
this.route.data.subscribe((value) => {
const data = value as { list: Table[] };
this.data.next(data.list);
});
this.dataSource = new TableListDataSource(this.data);

View File

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