Updated to angular 11
Now compiling with strict mode in typescript Need to error checking now
This commit is contained in:
@ -1,5 +1,12 @@
|
||||
export class Permission {
|
||||
id: string;
|
||||
id: string | undefined;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
|
||||
public constructor(init?: Partial<Permission>) {
|
||||
this.id = undefined;
|
||||
this.name = '';
|
||||
this.enabled = true;
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
|
||||
import { RoleDetailComponent } from './role-detail.component';
|
||||
|
||||
@ -6,11 +6,13 @@ describe('RoleDetailComponent', () => {
|
||||
let component: RoleDetailComponent;
|
||||
let fixture: ComponentFixture<RoleDetailComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [RoleDetailComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
beforeEach(
|
||||
waitForAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [RoleDetailComponent],
|
||||
}).compileComponents();
|
||||
}),
|
||||
);
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(RoleDetailComponent);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { FormArray, FormBuilder, FormControl, FormGroup } from '@angular/forms';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
@ -14,9 +14,9 @@ import { RoleService } from '../role.service';
|
||||
styleUrls: ['./role-detail.component.css'],
|
||||
})
|
||||
export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: FormGroup;
|
||||
item: Role;
|
||||
item: Role = new Role();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@ -26,10 +26,7 @@ export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
private dialog: MatDialog,
|
||||
private ser: RoleService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
// Create form
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
permissions: this.fb.array([]),
|
||||
@ -37,9 +34,10 @@ export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { item: Role }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { item: Role };
|
||||
this.item = data.item;
|
||||
this.form.get('name').setValue(this.item.name);
|
||||
(this.form.get('name') as FormControl).setValue(this.item.name);
|
||||
this.form.setControl(
|
||||
'permissions',
|
||||
this.fb.array(
|
||||
@ -55,7 +53,9 @@ export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
if (this.nameElement !== undefined) {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ export class RoleDetailComponent 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('/roles');
|
||||
|
||||
@ -11,15 +11,16 @@ import { RoleListDataSource } from './role-list-datasource';
|
||||
styleUrls: ['./role-list.component.css'],
|
||||
})
|
||||
export class RoleListComponent implements OnInit {
|
||||
dataSource: RoleListDataSource;
|
||||
list: Role[];
|
||||
list: Role[] = [];
|
||||
dataSource: RoleListDataSource = new RoleListDataSource(this.list);
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'permissions'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe((data: { list: Role[] }) => {
|
||||
this.route.data.subscribe((value) => {
|
||||
const data = value as { list: Role[] };
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new RoleListDataSource(this.list);
|
||||
|
||||
@ -19,7 +19,7 @@ const serviceName = 'RoleService';
|
||||
export class RoleService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<Role> {
|
||||
get(id: string | null): Observable<Role> {
|
||||
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<Role>>(
|
||||
this.http
|
||||
|
||||
@ -1,7 +1,14 @@
|
||||
import { Permission } from './permission';
|
||||
|
||||
export class Role {
|
||||
id: string;
|
||||
id: string | undefined;
|
||||
name: string;
|
||||
permissions: Permission[];
|
||||
|
||||
public constructor(init?: Partial<Role>) {
|
||||
this.id = undefined;
|
||||
this.name = '';
|
||||
this.permissions = [];
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user