Moved from tslint to eslint as tslint was depreciated.
Added prettier and also prettied all the typescript files using prettier ESLint is using the AirBnB rules which are the most strict to lint the files.
This commit is contained in:
@ -5,19 +5,31 @@
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<div
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput #nameElement placeholder="Name" formControlName="name">
|
||||
<input matInput #nameElement placeholder="Name" formControlName="name" />
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<mat-divider></mat-divider>
|
||||
<div formArrayName="permissions">
|
||||
<div fxLayout="row" *ngFor="let p of item.permissions; index as i" [formGroupName]="i" fxLayout="row"
|
||||
fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<mat-checkbox formControlName="permission" fxFlex>{{p.name}}</mat-checkbox>
|
||||
<div
|
||||
fxLayout="row"
|
||||
*ngFor="let p of item.permissions; index as i"
|
||||
[formGroupName]="i"
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-checkbox formControlName="permission" fxFlex>{{ p.name }}</mat-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {RoleDetailComponent} from './role-detail.component';
|
||||
import { RoleDetailComponent } from './role-detail.component';
|
||||
|
||||
describe('RoleDetailComponent', () => {
|
||||
let component: RoleDetailComponent;
|
||||
@ -8,9 +8,8 @@ describe('RoleDetailComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [RoleDetailComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [RoleDetailComponent],
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
|
||||
import {RoleService} from '../role.service';
|
||||
import {Role} from '../role';
|
||||
import {ToasterService} from '../../core/toaster.service';
|
||||
import {ConfirmDialogComponent} from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { RoleService } from '../role.service';
|
||||
import { Role } from '../role';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import {FormArray, FormBuilder, FormGroup} from '@angular/forms';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-role-detail',
|
||||
templateUrl: './role-detail.component.html',
|
||||
styleUrls: ['./role-detail.component.css']
|
||||
styleUrls: ['./role-detail.component.css'],
|
||||
})
|
||||
export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
@ -24,7 +24,7 @@ export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private dialog: MatDialog,
|
||||
private ser: RoleService
|
||||
private ser: RoleService,
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
@ -32,23 +32,25 @@ export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
permissions: this.fb.array([])
|
||||
permissions: this.fb.array([]),
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: Role }) => {
|
||||
this.item = data.item;
|
||||
this.form.get('name').setValue(this.item.name);
|
||||
this.form.setControl('permissions', this.fb.array(
|
||||
this.item.permissions.map(
|
||||
x => this.fb.group({
|
||||
permission: x.enabled
|
||||
})
|
||||
)
|
||||
));
|
||||
});
|
||||
this.route.data.subscribe((data: { item: Role }) => {
|
||||
this.item = data.item;
|
||||
this.form.get('name').setValue(this.item.name);
|
||||
this.form.setControl(
|
||||
'permissions',
|
||||
this.fb.array(
|
||||
this.item.permissions.map((x) =>
|
||||
this.fb.group({
|
||||
permission: x.enabled,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
@ -58,35 +60,33 @@ export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/roles');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/roles');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/roles');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.delete(this.item.id).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/roles');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete Role?', content: 'Are you sure? This cannot be undone.'}
|
||||
data: { title: 'Delete Role?', content: 'Are you sure? This cannot be undone.' },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
|
||||
@ -1,15 +1,18 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {ClientListResolverService} from './role-list-resolver.service';
|
||||
import { ClientListResolverService } from './role-list-resolver.service';
|
||||
|
||||
describe('ClientListResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ClientListResolverService]
|
||||
providers: [ClientListResolverService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ClientListResolverService], (service: ClientListResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
it('should be created', inject(
|
||||
[ClientListResolverService],
|
||||
(service: ClientListResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
},
|
||||
));
|
||||
});
|
||||
|
||||
@ -1,16 +1,14 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {Role} from './role';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {RoleService} from './role.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { Role } from './role';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { RoleService } from './role.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RoleListResolver implements Resolve<Role[]> {
|
||||
|
||||
constructor(private ser: RoleService, private router: Router) {
|
||||
}
|
||||
constructor(private ser: RoleService, private router: Router) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Role[]> {
|
||||
return this.ser.list();
|
||||
|
||||
@ -1,33 +1,29 @@
|
||||
import {DataSource} from '@angular/cdk/collections';
|
||||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {merge, Observable, of as observableOf} from 'rxjs';
|
||||
import {Role} from '../role';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { merge, Observable, of as observableOf } from 'rxjs';
|
||||
import { Role } from '../role';
|
||||
|
||||
export class RoleListDatasource extends DataSource<Role> {
|
||||
|
||||
constructor(private paginator: MatPaginator, private sort: MatSort, public data: Role[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<Role[]> {
|
||||
const dataMutations = [
|
||||
observableOf(this.data),
|
||||
this.paginator.page,
|
||||
this.sort.sortChange
|
||||
];
|
||||
const dataMutations = [observableOf(this.data), this.paginator.page, this.sort.sortChange];
|
||||
|
||||
// Set the paginators length
|
||||
this.paginator.length = this.data.length;
|
||||
|
||||
return merge(...dataMutations).pipe(map(() => {
|
||||
return this.getPagedData(this.getSortedData([...this.data]));
|
||||
}));
|
||||
return merge(...dataMutations).pipe(
|
||||
map(() => {
|
||||
return this.getPagedData(this.getSortedData([...this.data]));
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
disconnect() {}
|
||||
|
||||
private getPagedData(data: Role[]) {
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
|
||||
@ -8,11 +8,12 @@
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"><a [routerLink]="['/roles', row.id]">{{row.name}}</a></mat-cell>
|
||||
<mat-cell *matCellDef="let row"
|
||||
><a [routerLink]="['/roles', row.id]">{{ row.name }}</a></mat-cell
|
||||
>
|
||||
</ng-container>
|
||||
|
||||
<!-- Permissions Column -->
|
||||
@ -20,20 +21,22 @@
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Permissions</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">
|
||||
<ul>
|
||||
<li *ngFor="let permission of row.permissions">{{permission}}</li>
|
||||
<li *ngFor="let permission of row.permissions">{{ permission }}</li>
|
||||
</ul>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
||||
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
|
||||
</mat-table>
|
||||
|
||||
<mat-paginator #paginator
|
||||
[length]="dataSource.data.length"
|
||||
[pageIndex]="0"
|
||||
[pageSize]="50"
|
||||
[pageSizeOptions]="[25, 50, 100, 250]">
|
||||
<mat-paginator
|
||||
#paginator
|
||||
[length]="dataSource.data.length"
|
||||
[pageIndex]="0"
|
||||
[pageSize]="50"
|
||||
[pageSizeOptions]="[25, 50, 100, 250]"
|
||||
>
|
||||
</mat-paginator>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
|
||||
import { ComponentFixture, fakeAsync, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {RoleListComponent} from './role-list.component';
|
||||
import { RoleListComponent } from './role-list.component';
|
||||
|
||||
describe('RoleListComponent', () => {
|
||||
let component: RoleListComponent;
|
||||
@ -8,9 +8,8 @@ describe('RoleListComponent', () => {
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [RoleListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [RoleListComponent],
|
||||
}).compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(RoleListComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import {RoleListDatasource} from './role-list-datasource';
|
||||
import {Role} from '../role';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import { RoleListDatasource } from './role-list-datasource';
|
||||
import { Role } from '../role';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-role-list',
|
||||
templateUrl: './role-list.component.html',
|
||||
styleUrls: ['./role-list.component.css']
|
||||
styleUrls: ['./role-list.component.css'],
|
||||
})
|
||||
export class RoleListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||
@ -18,14 +18,12 @@ export class RoleListComponent implements OnInit {
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'permissions'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {
|
||||
}
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: Role[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.route.data.subscribe((data: { list: Role[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new RoleListDatasource(this.paginator, this.sort, this.list);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,15 +1,18 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {RoleResolverService} from './role-resolver.service';
|
||||
import { RoleResolverService } from './role-resolver.service';
|
||||
|
||||
describe('RoleResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [RoleDetailResolverService]
|
||||
providers: [RoleDetailResolverService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([RoleDetailResolverService], (service: RoleDetailResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
it('should be created', inject(
|
||||
[RoleDetailResolverService],
|
||||
(service: RoleDetailResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
},
|
||||
));
|
||||
});
|
||||
|
||||
@ -1,16 +1,14 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {Role} from './role';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {RoleService} from './role.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { Role } from './role';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { RoleService } from './role.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RoleResolver implements Resolve<Role> {
|
||||
|
||||
constructor(private ser: RoleService, private router: Router) {
|
||||
}
|
||||
constructor(private ser: RoleService, private router: Router) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Role> {
|
||||
const id = route.paramMap.get('id');
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {RoleRoutingModule} from './role-routing.module';
|
||||
import { RoleRoutingModule } from './role-routing.module';
|
||||
|
||||
describe('RoleRoutingModule', () => {
|
||||
let roleRoutingModule: RoleRoutingModule;
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {RoleListResolver} from './role-list-resolver.service';
|
||||
import {RoleResolver} from './role-resolver.service';
|
||||
import {RoleListComponent} from './role-list/role-list.component';
|
||||
import {RoleDetailComponent} from './role-detail/role-detail.component';
|
||||
import {AuthGuard} from '../auth/auth-guard.service';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { RoleListResolver } from './role-list-resolver.service';
|
||||
import { RoleResolver } from './role-resolver.service';
|
||||
import { RoleListComponent } from './role-list/role-list.component';
|
||||
import { RoleDetailComponent } from './role-detail/role-detail.component';
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
|
||||
const roleRoutes: Routes = [
|
||||
{
|
||||
@ -13,49 +13,39 @@ const roleRoutes: Routes = [
|
||||
component: RoleListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Users'
|
||||
permission: 'Users',
|
||||
},
|
||||
resolve: {
|
||||
list: RoleListResolver
|
||||
}
|
||||
list: RoleListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: RoleDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Users'
|
||||
permission: 'Users',
|
||||
},
|
||||
resolve: {
|
||||
item: RoleResolver,
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: RoleDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Users'
|
||||
permission: 'Users',
|
||||
},
|
||||
resolve: {
|
||||
item: RoleResolver
|
||||
}
|
||||
}
|
||||
item: RoleResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(roleRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
RoleListResolver,
|
||||
RoleResolver
|
||||
]
|
||||
imports: [CommonModule, RouterModule.forChild(roleRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [RoleListResolver, RoleResolver],
|
||||
})
|
||||
export class RoleRoutingModule {
|
||||
}
|
||||
export class RoleRoutingModule {}
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import {RoleModule} from './role.module';
|
||||
import { RoleModule } from './role.module';
|
||||
|
||||
describe('RoleModule', () => {
|
||||
let roleModule: RoleModule;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import {RoleListComponent} from './role-list/role-list.component';
|
||||
import {RoleDetailComponent} from './role-detail/role-detail.component';
|
||||
import {RoleRoutingModule} from './role-routing.module';
|
||||
import { RoleListComponent } from './role-list/role-list.component';
|
||||
import { RoleDetailComponent } from './role-detail/role-detail.component';
|
||||
import { RoleRoutingModule } from './role-routing.module';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
@ -14,10 +14,10 @@ import { MatPaginatorModule } from '@angular/material/paginator';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSortModule } from '@angular/material/sort';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import {CdkTableModule} from '@angular/cdk/table';
|
||||
import {ReactiveFormsModule} from '@angular/forms';
|
||||
import {SharedModule} from '../shared/shared.module';
|
||||
import {FlexLayoutModule} from '@angular/flex-layout';
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
@ -36,12 +36,8 @@ import {FlexLayoutModule} from '@angular/flex-layout';
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
SharedModule,
|
||||
RoleRoutingModule
|
||||
RoleRoutingModule,
|
||||
],
|
||||
declarations: [
|
||||
RoleListComponent,
|
||||
RoleDetailComponent
|
||||
]
|
||||
declarations: [RoleListComponent, RoleDetailComponent],
|
||||
})
|
||||
export class RoleModule {
|
||||
}
|
||||
export class RoleModule {}
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {RoleService} from './role.service';
|
||||
import { RoleService } from './role.service';
|
||||
|
||||
describe('RoleService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [RoleService]
|
||||
providers: [RoleService],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -6,45 +6,48 @@ import { Observable } from 'rxjs/internal/Observable';
|
||||
import { Role } from './role';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
const url = '/api/roles';
|
||||
const serviceName = 'RoleService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RoleService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<Role> {
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<Role>>this.http.get<Role>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<Role>>(
|
||||
this.http
|
||||
.get<Role>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<Role[]> {
|
||||
return <Observable<Role[]>>this.http.get<Role[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
return <Observable<Role[]>>(
|
||||
this.http
|
||||
.get<Role[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list')))
|
||||
);
|
||||
}
|
||||
|
||||
save(role: Role): Observable<Role> {
|
||||
return <Observable<Role>>this.http.post<Role>(`${url}`, role, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
return <Observable<Role>>(
|
||||
this.http
|
||||
.post<Role>(`${url}`, role, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save')))
|
||||
);
|
||||
}
|
||||
|
||||
update(role: Role): Observable<Role> {
|
||||
return <Observable<Role>>this.http.put<Role>(`${url}/${role.id}`, role, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
return <Observable<Role>>(
|
||||
this.http
|
||||
.put<Role>(`${url}/${role.id}`, role, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update')))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(role: Role): Observable<Role> {
|
||||
@ -56,9 +59,10 @@ export class RoleService {
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Role> {
|
||||
return <Observable<Role>>this.http.delete<Role>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
return <Observable<Role>>(
|
||||
this.http
|
||||
.delete<Role>(`${url}/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user