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

View File

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

View File

@ -11,15 +11,16 @@ import { DeviceListDataSource } from './device-list-datasource';
styleUrls: ['./device-list.component.css'],
})
export class DeviceListComponent implements OnInit {
dataSource: DeviceListDataSource;
list: Device[];
list: Device[] = [];
dataSource: DeviceListDataSource = new DeviceListDataSource(this.list);
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['name', 'section', 'enabled', 'creationDate', 'last'];
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.route.data.subscribe((data: { list: Device[] }) => {
this.route.data.subscribe((value) => {
const data = value as { list: Device[] };
this.list = data.list;
});
this.dataSource = new DeviceListDataSource(this.list);

View File

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