Strict done!!
This commit is contained in:
@ -1,5 +1,11 @@
|
||||
export class Permission {
|
||||
id: string;
|
||||
id: string | undefined;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
|
||||
public constructor(init?: Partial<Permission>) {
|
||||
this.name = '';
|
||||
this.enabled = true;
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -16,7 +16,7 @@ import { RoleService } from '../role.service';
|
||||
export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
|
||||
form: FormGroup;
|
||||
item: Role;
|
||||
item: Role = new Role();
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@ -37,7 +37,7 @@ export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
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(
|
||||
@ -53,7 +53,7 @@ export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
if (this.nameElement) this.nameElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
@ -70,7 +70,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');
|
||||
|
||||
@ -51,8 +51,6 @@ export class RoleListDatasource extends DataSource<Role> {
|
||||
switch (sort.active) {
|
||||
case 'name':
|
||||
return compare(a.name, b.name, isAsc);
|
||||
case 'id':
|
||||
return compare(+a.id, +b.id, isAsc);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -15,8 +15,8 @@ import { RoleListDatasource } from './role-list-datasource';
|
||||
export class RoleListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator, { static: true }) paginator?: MatPaginator;
|
||||
@ViewChild(MatSort, { static: true }) sort?: MatSort;
|
||||
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'];
|
||||
|
||||
@ -28,6 +28,6 @@ export class RoleListComponent implements OnInit {
|
||||
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new RoleListDatasource(this.paginator, this.sort, this.list);
|
||||
this.dataSource = new RoleListDatasource(this.list, this.paginator, this.sort);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,13 @@
|
||||
import { Permission } from './permission';
|
||||
|
||||
export class Role {
|
||||
id: string;
|
||||
id: string | undefined;
|
||||
name: string;
|
||||
permissions: Permission[];
|
||||
|
||||
public constructor(init?: Partial<Role>) {
|
||||
this.name = '';
|
||||
this.permissions = [];
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user