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,31 +5,60 @@
|
||||
</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>
|
||||
<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>Password</mat-label>
|
||||
<input matInput placeholder="Password" formControlName="password" [type]="hide ? 'password' : 'text'">
|
||||
<mat-icon matSuffix (click)="hide = !hide">{{hide ? 'visibility' : 'visibility_off'}}</mat-icon>
|
||||
</mat-form-field>
|
||||
<input
|
||||
matInput
|
||||
placeholder="Password"
|
||||
formControlName="password"
|
||||
[type]="hide ? 'password' : 'text'"
|
||||
/>
|
||||
<mat-icon matSuffix (click)="hide = !hide">{{
|
||||
hide ? 'visibility' : 'visibility_off'
|
||||
}}</mat-icon>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<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-checkbox formControlName="lockedOut">Is Locked Out?</mat-checkbox>
|
||||
</div>
|
||||
<mat-divider></mat-divider>
|
||||
<div formArrayName="roles">
|
||||
<div fxLayout="row" *ngFor="let r of item.roles; index as i" [formGroupName]="i" fxLayout="row"
|
||||
fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<mat-checkbox formControlName="role" fxFlex>{{r.name}}</mat-checkbox>
|
||||
<div
|
||||
fxLayout="row"
|
||||
*ngFor="let r of item.roles; index as i"
|
||||
[formGroupName]="i"
|
||||
fxLayout="row"
|
||||
fxLayoutAlign="space-around start"
|
||||
fxLayout.lt-md="column"
|
||||
fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px"
|
||||
>
|
||||
<mat-checkbox formControlName="role" fxFlex>{{ r.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 {UserDetailComponent} from './user-detail.component';
|
||||
import { UserDetailComponent } from './user-detail.component';
|
||||
|
||||
describe('UserDetailComponent', () => {
|
||||
let component: UserDetailComponent;
|
||||
@@ -8,9 +8,8 @@ describe('UserDetailComponent', () => {
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [UserDetailComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
declarations: [UserDetailComponent],
|
||||
}).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 {UserService} from '../user.service';
|
||||
import {User} from '../../core/user';
|
||||
import {ToasterService} from '../../core/toaster.service';
|
||||
import {ConfirmDialogComponent} from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { UserService } from '../user.service';
|
||||
import { User } from '../../core/user';
|
||||
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-user-detail',
|
||||
templateUrl: './user-detail.component.html',
|
||||
styleUrls: ['./user-detail.component.css']
|
||||
styleUrls: ['./user-detail.component.css'],
|
||||
})
|
||||
export class UserDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
@@ -25,7 +25,7 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private dialog: MatDialog,
|
||||
private ser: UserService
|
||||
private ser: UserService,
|
||||
) {
|
||||
this.hide = true;
|
||||
this.createForm();
|
||||
@@ -36,15 +36,14 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
|
||||
name: '',
|
||||
password: '',
|
||||
lockedOut: '',
|
||||
roles: this.fb.array([])
|
||||
roles: this.fb.array([]),
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: User }) => {
|
||||
this.showItem(data.item);
|
||||
});
|
||||
this.route.data.subscribe((data: { item: User }) => {
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: User) {
|
||||
@@ -52,16 +51,18 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
|
||||
this.form.get('name').setValue(item.name);
|
||||
this.form.get('password').setValue('');
|
||||
this.form.get('lockedOut').setValue(item.lockedOut);
|
||||
this.form.setControl('roles', this.fb.array(
|
||||
item.roles.map(
|
||||
x => this.fb.group({
|
||||
role: x.enabled
|
||||
})
|
||||
)
|
||||
));
|
||||
this.form.setControl(
|
||||
'roles',
|
||||
this.fb.array(
|
||||
item.roles.map((x) =>
|
||||
this.fb.group({
|
||||
role: x.enabled,
|
||||
}),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
@@ -69,35 +70,33 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/users');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.saveOrUpdate(this.getItem()).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/users');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/users');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.delete(this.item.id).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/users');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete User?', content: 'Are you sure? This cannot be undone.'}
|
||||
data: { title: 'Delete User?', 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 './user-list-resolver.service';
|
||||
import { ClientListResolverService } from './user-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 {User} from '../core/user';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {UserService} from './user.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { User } from '../core/user';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { UserService } from './user.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UserListResolver implements Resolve<User[]> {
|
||||
|
||||
constructor(private ser: UserService, private router: Router) {
|
||||
}
|
||||
constructor(private ser: UserService, private router: Router) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<User[]> {
|
||||
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 {User} from '../../core/user';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { merge, Observable, of as observableOf } from 'rxjs';
|
||||
import { User } from '../../core/user';
|
||||
|
||||
export class UserListDataSource extends DataSource<User> {
|
||||
|
||||
constructor(private paginator: MatPaginator, private sort: MatSort, public data: User[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<User[]> {
|
||||
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: User[]) {
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
|
||||
@@ -8,17 +8,18 @@
|
||||
</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]="['/users', row.id]">{{row.name}}</a></mat-cell>
|
||||
<mat-cell *matCellDef="let row"
|
||||
><a [routerLink]="['/users', row.id]">{{ row.name }}</a></mat-cell
|
||||
>
|
||||
</ng-container>
|
||||
|
||||
<!-- Locked Out Column -->
|
||||
<ng-container matColumnDef="lockedOut">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Is Locked Out?</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.lockedOut}}</mat-cell>
|
||||
<mat-cell *matCellDef="let row">{{ row.lockedOut }}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Groups Column -->
|
||||
@@ -26,20 +27,22 @@
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Groups</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">
|
||||
<ul>
|
||||
<li *ngFor="let group of row.groups">{{group}}</li>
|
||||
<li *ngFor="let group of row.groups">{{ group }}</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,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 {UserListDataSource} from './user-list-datasource';
|
||||
import {User} from '../../core/user';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
import { UserListDataSource } from './user-list-datasource';
|
||||
import { User } from '../../core/user';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-list',
|
||||
templateUrl: './user-list.component.html',
|
||||
styleUrls: ['./user-list.component.css']
|
||||
styleUrls: ['./user-list.component.css'],
|
||||
})
|
||||
export class UserListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||
@@ -18,14 +18,12 @@ export class UserListComponent implements OnInit {
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'lockedOut', 'groups'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {
|
||||
}
|
||||
constructor(private route: ActivatedRoute) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: User[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.route.data.subscribe((data: { list: User[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new UserListDataSource(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 {UserResolverService} from './user-resolver.service';
|
||||
import { UserResolverService } from './user-resolver.service';
|
||||
|
||||
describe('UserResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [UserDetailResolverService]
|
||||
providers: [UserDetailResolverService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([UserDetailResolverService], (service: UserDetailResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
it('should be created', inject(
|
||||
[UserDetailResolverService],
|
||||
(service: UserDetailResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
},
|
||||
));
|
||||
});
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {User} from '../core/user';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {UserService} from './user.service';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { User } from '../core/user';
|
||||
import { Observable } from 'rxjs/internal/Observable';
|
||||
import { UserService } from './user.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UserResolver implements Resolve<User> {
|
||||
|
||||
constructor(private ser: UserService, private router: Router) {
|
||||
}
|
||||
constructor(private ser: UserService, private router: Router) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<User> {
|
||||
const id = route.paramMap.get('id');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {UserRoutingModule} from './user-routing.module';
|
||||
import { UserRoutingModule } from './user-routing.module';
|
||||
|
||||
describe('UserRoutingModule', () => {
|
||||
let userRoutingModule: UserRoutingModule;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {UserListResolver} from './user-list-resolver.service';
|
||||
import {UserResolver} from './user-resolver.service';
|
||||
import {UserListComponent} from './user-list/user-list.component';
|
||||
import {UserDetailComponent} from './user-detail/user-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 { UserListResolver } from './user-list-resolver.service';
|
||||
import { UserResolver } from './user-resolver.service';
|
||||
import { UserListComponent } from './user-list/user-list.component';
|
||||
import { UserDetailComponent } from './user-detail/user-detail.component';
|
||||
import { AuthGuard } from '../auth/auth-guard.service';
|
||||
|
||||
const userRoutes: Routes = [
|
||||
{
|
||||
@@ -13,46 +13,36 @@ const userRoutes: Routes = [
|
||||
component: UserListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Users'
|
||||
permission: 'Users',
|
||||
},
|
||||
resolve: {
|
||||
list: UserListResolver
|
||||
}
|
||||
list: UserListResolver,
|
||||
},
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: UserDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Users'
|
||||
permission: 'Users',
|
||||
},
|
||||
resolve: {
|
||||
item: UserResolver,
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: UserDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
resolve: {
|
||||
item: UserResolver
|
||||
}
|
||||
}
|
||||
item: UserResolver,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(userRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
UserListResolver,
|
||||
UserResolver
|
||||
]
|
||||
imports: [CommonModule, RouterModule.forChild(userRoutes)],
|
||||
exports: [RouterModule],
|
||||
providers: [UserListResolver, UserResolver],
|
||||
})
|
||||
export class UserRoutingModule {
|
||||
}
|
||||
export class UserRoutingModule {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {UserModule} from './user.module';
|
||||
import { UserModule } from './user.module';
|
||||
|
||||
describe('UserModule', () => {
|
||||
let userModule: UserModule;
|
||||
|
||||
@@ -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 {UserListComponent} from './user-list/user-list.component';
|
||||
import {UserDetailComponent} from './user-detail/user-detail.component';
|
||||
import {UserRoutingModule} from './user-routing.module';
|
||||
import { UserListComponent } from './user-list/user-list.component';
|
||||
import { UserDetailComponent } from './user-detail/user-detail.component';
|
||||
import { UserRoutingModule } from './user-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,
|
||||
UserRoutingModule
|
||||
UserRoutingModule,
|
||||
],
|
||||
declarations: [
|
||||
UserListComponent,
|
||||
UserDetailComponent
|
||||
]
|
||||
declarations: [UserListComponent, UserDetailComponent],
|
||||
})
|
||||
export class UserModule {
|
||||
}
|
||||
export class UserModule {}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import {UserService} from './user.service';
|
||||
import { UserService } from './user.service';
|
||||
|
||||
describe('UserService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [UserService]
|
||||
providers: [UserService],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -6,52 +6,56 @@ import { Observable } from 'rxjs/internal/Observable';
|
||||
import { User } from '../core/user';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
|
||||
};
|
||||
const url = '/api/users';
|
||||
const serviceName = 'UserService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class UserService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string): Observable<User> {
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<User>>this.http.get<User>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
const getUrl: string = id === null ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<User>>(
|
||||
this.http
|
||||
.get<User>(getUrl)
|
||||
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`)))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<User[]> {
|
||||
return <Observable<User[]>>this.http.get<User[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
return <Observable<User[]>>(
|
||||
this.http
|
||||
.get<User[]>(`${url}/list`)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'list')))
|
||||
);
|
||||
}
|
||||
|
||||
listOfNames(): Observable<string[]> {
|
||||
return <Observable<string[]>>this.http.get<string[]>(`${url}/active`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
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.post<User>(`${url}`, user, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
return <Observable<User>>(
|
||||
this.http
|
||||
.post<User>(`${url}`, user, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'save')))
|
||||
);
|
||||
}
|
||||
|
||||
update(user: User): Observable<User> {
|
||||
return <Observable<User>>this.http.put<User>(`${url}/${user.id}`, user, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
return <Observable<User>>(
|
||||
this.http
|
||||
.put<User>(`${url}/${user.id}`, user, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'update')))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(user: User): Observable<User> {
|
||||
@@ -63,9 +67,10 @@ export class UserService {
|
||||
}
|
||||
|
||||
delete(id: string): Observable<User> {
|
||||
return <Observable<User>>this.http.delete<User>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
return <Observable<User>>(
|
||||
this.http
|
||||
.delete<User>(`${url}/${id}`, httpOptions)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete')))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user