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

View File

@ -1,5 +1,5 @@
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
import { AbstractControl, FormArray, FormBuilder, FormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
@ -14,9 +14,9 @@ import { UserService } from '../user.service';
styleUrls: ['./user-detail.component.css'],
})
export class UserDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
form: FormGroup;
item: User;
item: User = new User();
hide: boolean;
constructor(
@ -28,10 +28,7 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
private ser: UserService,
) {
this.hide = true;
this.createForm();
}
createForm() {
// Create form
this.form = this.fb.group({
name: '',
password: '',
@ -41,16 +38,17 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
}
ngOnInit() {
this.route.data.subscribe((data: { item: User }) => {
this.route.data.subscribe((value) => {
const data = value as { item: User };
this.showItem(data.item);
});
}
showItem(item: User) {
this.item = item;
this.form.get('name').setValue(item.name);
this.form.get('password').setValue('');
this.form.get('lockedOut').setValue(item.lockedOut);
(this.form.get('name') as AbstractControl).setValue(item.name);
(this.form.get('password') as AbstractControl).setValue('');
(this.form.get('lockedOut') as AbstractControl).setValue(item.lockedOut);
this.form.setControl(
'roles',
this.fb.array(
@ -65,7 +63,11 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
ngAfterViewInit() {
setTimeout(() => {
this.nameElement.nativeElement.focus();
if (this.nameElement !== undefined) {
if (this.nameElement !== undefined) {
this.nameElement.nativeElement.focus();
}
}
}, 0);
}
@ -82,7 +84,7 @@ export class UserDetailComponent 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('/users');
@ -112,9 +114,11 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
this.item.password = formModel.password;
this.item.lockedOut = formModel.lockedOut;
const array = this.form.get('roles') as FormArray;
this.item.roles.forEach((item, index) => {
item.enabled = array.controls[index].value.role;
});
if (this.item.roles !== undefined) {
this.item.roles.forEach((item, index) => {
item.enabled = array.controls[index].value.role;
});
}
return this.item;
}
}

View File

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

View File

@ -18,7 +18,7 @@ const serviceName = 'UserService';
export class UserService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
get(id: string): Observable<User> {
get(id: string | null): Observable<User> {
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
return <Observable<User>>(
this.http
@ -35,14 +35,6 @@ export class UserService {
);
}
listOfNames(): Observable<string[]> {
return <Observable<string[]>>(
this.http
.get<string[]>(`${url}/active`)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
}
save(user: User): Observable<User> {
return <Observable<User>>(
this.http