Users
This commit is contained in:
parent
2b2624c9c2
commit
93743bdc8e
|
@ -80,11 +80,11 @@ def includeme(config):
|
||||||
config.add_route("v1_taxes_list", "/v1/taxes")
|
config.add_route("v1_taxes_list", "/v1/taxes")
|
||||||
|
|
||||||
config.add_route('v1_users_new', '/v1/users/new')
|
config.add_route('v1_users_new', '/v1/users/new')
|
||||||
config.add_route('v1_users_list', '/v1/users/list')
|
|
||||||
config.add_route('v1_users_id', '/v1/users/{id}')
|
config.add_route('v1_users_id', '/v1/users/{id}')
|
||||||
|
config.add_route('v1_users_list', '/v1/users')
|
||||||
config.add_route('users_new', '/users/new')
|
config.add_route('users_new', '/users/new')
|
||||||
config.add_route('users_list', '/users/list')
|
|
||||||
config.add_route('users_id', '/users/{id}')
|
config.add_route('users_id', '/users/{id}')
|
||||||
|
config.add_route('users_list', '/users')
|
||||||
|
|
||||||
config.add_route('v1_roles_new', '/v1/roles/new')
|
config.add_route('v1_roles_new', '/v1/roles/new')
|
||||||
config.add_route('v1_roles_id', '/v1/roles/{id}')
|
config.add_route('v1_roles_id', '/v1/roles/{id}')
|
||||||
|
|
|
@ -9,7 +9,7 @@ from barker.exceptions import ValidationFailure
|
||||||
from barker.models import Role, User
|
from barker.models import Role, User
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='PUT', route_name='v1_users_new', renderer='json', permission='Users', trans=True)
|
@view_config(request_method='POST', route_name='v1_users_new', renderer='json', permission='Users', trans=True)
|
||||||
def save(request):
|
def save(request):
|
||||||
json = request.json_body
|
json = request.json_body
|
||||||
item = User(json['name'], json['password'], json['lockedOut'])
|
item = User(json['name'], json['password'], json['lockedOut'])
|
||||||
|
@ -21,15 +21,15 @@ def save(request):
|
||||||
return user_info(item, roles)
|
return user_info(item, roles)
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='POST', route_name='v1_users_id', renderer='json', permission='Users', trans=True)
|
@view_config(request_method='PUT', route_name='v1_users_id', renderer='json', permission='Users', trans=True)
|
||||||
def update(request):
|
def update(request):
|
||||||
json = request.json_body
|
json = request.json_body
|
||||||
id = request.matchdict['id']
|
id_ = request.matchdict['id']
|
||||||
p = re.compile('^[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}$')
|
p = re.compile('^[A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}$')
|
||||||
if p.match(id):
|
if p.match(id_):
|
||||||
item = request.dbsession.query(User).filter(User.id == uuid.UUID(id)).one()
|
item = request.dbsession.query(User).filter(User.id == uuid.UUID(id_)).one()
|
||||||
else:
|
else:
|
||||||
item = request.dbsession.query(User).filter(User.name.ilike(id)).first()
|
item = request.dbsession.query(User).filter(User.name.ilike(id_)).first()
|
||||||
if item is None:
|
if item is None:
|
||||||
raise ValidationFailure('User name / id not found')
|
raise ValidationFailure('User name / id not found')
|
||||||
if request.has_permission('Users'):
|
if request.has_permission('Users'):
|
||||||
|
|
|
@ -37,6 +37,10 @@ const routes: Routes = [
|
||||||
path: 'taxes',
|
path: 'taxes',
|
||||||
loadChildren: () => import('./taxes/taxes.module').then(mod => mod.TaxesModule)
|
loadChildren: () => import('./taxes/taxes.module').then(mod => mod.TaxesModule)
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'users',
|
||||||
|
loadChildren: () => import('./users/users.module').then(mod => mod.UsersModule)
|
||||||
|
},
|
||||||
{path: 'login', component: LoginComponent},
|
{path: 'login', component: LoginComponent},
|
||||||
{path: 'logout', component: LogoutComponent},
|
{path: 'logout', component: LogoutComponent},
|
||||||
{path: '', component: HomeComponent},
|
{path: '', component: HomeComponent},
|
||||||
|
|
|
@ -21,7 +21,6 @@ import { HomeComponent } from "./home/home.component";
|
||||||
import {CoreModule} from "./core/core.module";
|
import {CoreModule} from "./core/core.module";
|
||||||
import {ReactiveFormsModule} from "@angular/forms";
|
import {ReactiveFormsModule} from "@angular/forms";
|
||||||
import {SharedModule} from "./shared/shared.module";
|
import {SharedModule} from "./shared/shared.module";
|
||||||
import {UserModule} from "./user/user.module";
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
|
@ -47,8 +46,7 @@ import {UserModule} from "./user/user.module";
|
||||||
LayoutModule,
|
LayoutModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
CoreModule,
|
CoreModule,
|
||||||
SharedModule,
|
SharedModule
|
||||||
UserModule
|
|
||||||
],
|
],
|
||||||
providers: [],
|
providers: [],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot} from '@angular/router';
|
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
|
||||||
import {AuthService} from './auth.service';
|
import { AuthService } from './auth.service';
|
||||||
import {Observable} from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import {map} from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import {ToasterService} from '../core/toaster.service';
|
import { ToasterService } from '../core/toaster.service';
|
||||||
import {User} from '../user/user';
|
import { User } from '../core/user';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {HttpClient, HttpHeaders} from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import {Observable} from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import {catchError, tap} from 'rxjs/operators';
|
import { catchError, tap } from 'rxjs/operators';
|
||||||
import {Subject} from 'rxjs/internal/Subject';
|
import { Subject } from 'rxjs/internal/Subject';
|
||||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||||
import {User} from '../user/user';
|
import { User } from '../core/user';
|
||||||
|
|
||||||
|
|
||||||
const httpOptions = {
|
const httpOptions = {
|
||||||
|
|
|
@ -7,17 +7,17 @@
|
||||||
</a>
|
</a>
|
||||||
</mat-card-title-group>
|
</mat-card-title-group>
|
||||||
<mat-card-content>
|
<mat-card-content>
|
||||||
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
|
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
||||||
|
|
||||||
<!-- Name Column -->
|
<!-- Name Column -->
|
||||||
<ng-container matColumnDef="name">
|
<ng-container matColumnDef="name">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef>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>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Permissions Column -->
|
<!-- Permissions Column -->
|
||||||
<ng-container matColumnDef="permissions">
|
<ng-container matColumnDef="permissions">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Permissions</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef>Permissions</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row">
|
<mat-cell *matCellDef="let row">
|
||||||
<ul>
|
<ul>
|
||||||
<li *ngFor="let permission of row.permissions">{{permission}}</li>
|
<li *ngFor="let permission of row.permissions">{{permission}}</li>
|
||||||
|
@ -28,12 +28,5 @@
|
||||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
<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-table>
|
||||||
|
|
||||||
<mat-paginator #paginator
|
|
||||||
[length]="dataSource.data.length"
|
|
||||||
[pageIndex]="0"
|
|
||||||
[pageSize]="50"
|
|
||||||
[pageSizeOptions]="[25, 50, 100, 250]">
|
|
||||||
</mat-paginator>
|
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
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 '../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
|
|
||||||
];
|
|
||||||
|
|
||||||
// Set the paginators length
|
|
||||||
this.paginator.length = this.data.length;
|
|
||||||
|
|
||||||
return merge(...dataMutations).pipe(map(() => {
|
|
||||||
return this.getPagedData(this.getSortedData([...this.data]));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
disconnect() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private getPagedData(data: User[]) {
|
|
||||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
|
||||||
return data.splice(startIndex, this.paginator.pageSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
private getSortedData(data: User[]) {
|
|
||||||
if (!this.sort.active || this.sort.direction === '') {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return data.sort((a, b) => {
|
|
||||||
const isAsc = this.sort.direction === 'asc';
|
|
||||||
switch (this.sort.active) {
|
|
||||||
case 'name':
|
|
||||||
return compare(a.name, b.name, isAsc);
|
|
||||||
case 'id':
|
|
||||||
return compare(+a.id, +b.id, isAsc);
|
|
||||||
default:
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Simple sort comparator for example ID/Name columns (for user-side sorting). */
|
|
||||||
function compare(a, b, isAsc) {
|
|
||||||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
|
||||||
}
|
|
|
@ -25,11 +25,11 @@
|
||||||
<mat-checkbox formControlName="lockedOut">Is Locked Out?</mat-checkbox>
|
<mat-checkbox formControlName="lockedOut">Is Locked Out?</mat-checkbox>
|
||||||
</div>
|
</div>
|
||||||
<mat-divider></mat-divider>
|
<mat-divider></mat-divider>
|
||||||
<div formArrayName="roles">
|
<div formArrayName="groups">
|
||||||
<div fxLayout="row" *ngFor="let r of item.roles; index as i" [formGroupName]="i" fxLayout="row"
|
<div fxLayout="row" *ngFor="let g of item.groups; index as i" [formGroupName]="i" fxLayout="row"
|
||||||
fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||||
fxLayoutGap.lt-md="0px">
|
fxLayoutGap.lt-md="0px">
|
||||||
<mat-checkbox formControlName="role" fxFlex>{{r.name}}</mat-checkbox>
|
<mat-checkbox formControlName="group" fxFlex>{{g.name}}</mat-checkbox>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
|
@ -0,0 +1,25 @@
|
||||||
|
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
|
import {UserDetailComponent} from './user-detail.component';
|
||||||
|
|
||||||
|
describe('UserDetailComponent', () => {
|
||||||
|
let component: UserDetailComponent;
|
||||||
|
let fixture: ComponentFixture<UserDetailComponent>;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
declarations: [UserDetailComponent]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(UserDetailComponent);
|
||||||
|
component = fixture.componentInstance;
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create', () => {
|
||||||
|
expect(component).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -2,7 +2,7 @@ import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import {ActivatedRoute, Router} from '@angular/router';
|
||||||
|
|
||||||
import {UserService} from '../user.service';
|
import {UserService} from '../user.service';
|
||||||
import {User} from '../user';
|
import {User} from '../../core/user';
|
||||||
import {ToasterService} from '../../core/toaster.service';
|
import {ToasterService} from '../../core/toaster.service';
|
||||||
import {ConfirmDialogComponent} from '../../shared/confirm-dialog/confirm-dialog.component';
|
import {ConfirmDialogComponent} from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
@ -73,7 +73,7 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(result) => {
|
(result) => {
|
||||||
this.toaster.show('Success', '');
|
this.toaster.show('Success', '');
|
||||||
this.router.navigateByUrl('/users/list');
|
this.router.navigateByUrl('/users');
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
this.toaster.show('Danger', error.error);
|
this.toaster.show('Danger', error.error);
|
||||||
|
@ -86,7 +86,7 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(result) => {
|
(result) => {
|
||||||
this.toaster.show('Success', '');
|
this.toaster.show('Success', '');
|
||||||
this.router.navigateByUrl('/Users');
|
this.router.navigateByUrl('/users');
|
||||||
},
|
},
|
||||||
(error) => {
|
(error) => {
|
||||||
this.toaster.show('Danger', error.error);
|
this.toaster.show('Danger', error.error);
|
|
@ -0,0 +1,15 @@
|
||||||
|
import {inject, TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
|
import {UserListResolver} from './user-list-resolver.service';
|
||||||
|
|
||||||
|
describe('UserListResolver', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [UserListResolver]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', inject([UserListResolver], (service: UserListResolver) => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
}));
|
||||||
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||||
import {User} from './user';
|
import {User} from '../core/user';
|
||||||
import {Observable} from 'rxjs/internal/Observable';
|
import {Observable} from 'rxjs/internal/Observable';
|
||||||
import {UserService} from './user.service';
|
import {UserService} from './user.service';
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
import { DataSource } from '@angular/cdk/collections';
|
||||||
|
import { Observable, of as observableOf } from 'rxjs';
|
||||||
|
import { User } from '../../core/user';
|
||||||
|
|
||||||
|
export class UserListDataSource extends DataSource<User> {
|
||||||
|
|
||||||
|
constructor(public data: User[]) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(): Observable<User[]> {
|
||||||
|
return observableOf(this.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,17 +7,17 @@
|
||||||
</a>
|
</a>
|
||||||
</mat-card-title-group>
|
</mat-card-title-group>
|
||||||
<mat-card-content>
|
<mat-card-content>
|
||||||
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
|
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
|
||||||
|
|
||||||
<!-- Name Column -->
|
<!-- Name Column -->
|
||||||
<ng-container matColumnDef="name">
|
<ng-container matColumnDef="name">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row"><a [routerLink]="['/users', row.name]">{{row.name}}</a></mat-cell>
|
<mat-cell *matCellDef="let row"><a [routerLink]="['/users', row.name]">{{row.name}}</a></mat-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Locked Out Column -->
|
<!-- Locked Out Column -->
|
||||||
<ng-container matColumnDef="lockedOut">
|
<ng-container matColumnDef="lockedOut">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Is Locked Out?</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef>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>
|
</ng-container>
|
||||||
|
|
||||||
|
@ -34,12 +34,5 @@
|
||||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
<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-table>
|
||||||
|
|
||||||
<mat-paginator #paginator
|
|
||||||
[length]="dataSource.data.length"
|
|
||||||
[pageIndex]="0"
|
|
||||||
[pageSize]="50"
|
|
||||||
[pageSizeOptions]="[25, 50, 100, 250]">
|
|
||||||
</mat-paginator>
|
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
</mat-card>
|
</mat-card>
|
|
@ -1,9 +1,7 @@
|
||||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { MatPaginator } from '@angular/material/paginator';
|
import { UserListDataSource } from './user-list-datasource';
|
||||||
import { MatSort } from '@angular/material/sort';
|
import { User } from '../../core/user';
|
||||||
import {UserListDataSource} from './user-list-datasource';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
import {User} from '../user';
|
|
||||||
import {ActivatedRoute} from '@angular/router';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-user-list',
|
selector: 'app-user-list',
|
||||||
|
@ -11,8 +9,6 @@ import {ActivatedRoute} from '@angular/router';
|
||||||
styleUrls: ['./user-list.component.css']
|
styleUrls: ['./user-list.component.css']
|
||||||
})
|
})
|
||||||
export class UserListComponent implements OnInit {
|
export class UserListComponent implements OnInit {
|
||||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
|
||||||
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
|
||||||
dataSource: UserListDataSource;
|
dataSource: UserListDataSource;
|
||||||
list: User[];
|
list: User[];
|
||||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||||
|
@ -26,6 +22,6 @@ export class UserListComponent implements OnInit {
|
||||||
.subscribe((data: { list: User[] }) => {
|
.subscribe((data: { list: User[] }) => {
|
||||||
this.list = data.list;
|
this.list = data.list;
|
||||||
});
|
});
|
||||||
this.dataSource = new UserListDataSource(this.paginator, this.sort, this.list);
|
this.dataSource = new UserListDataSource(this.list);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
import {inject, TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
|
import {UserResolver} from './user-resolver.service';
|
||||||
|
|
||||||
|
describe('UserResolver', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [UserResolver]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', inject([UserResolver], (service: UserResolver) => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
}));
|
||||||
|
});
|
|
@ -1,6 +1,6 @@
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||||
import {User} from './user';
|
import {User} from '../core/user';
|
||||||
import {Observable} from 'rxjs/internal/Observable';
|
import {Observable} from 'rxjs/internal/Observable';
|
||||||
import {UserService} from './user.service';
|
import {UserService} from './user.service';
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import {inject, TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
|
import {UserService} from './user.service';
|
||||||
|
|
||||||
|
describe('UserService', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
providers: [UserService]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', inject([UserService], (service: UserService) => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
}));
|
||||||
|
});
|
|
@ -3,7 +3,7 @@ import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||||
import {catchError} from 'rxjs/operators';
|
import {catchError} from 'rxjs/operators';
|
||||||
import {Observable} from 'rxjs/internal/Observable';
|
import {Observable} from 'rxjs/internal/Observable';
|
||||||
import {User} from './user';
|
import {User} from '../core/user';
|
||||||
|
|
||||||
const httpOptions = {
|
const httpOptions = {
|
||||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||||
|
@ -28,7 +28,7 @@ export class UserService {
|
||||||
|
|
||||||
list(): Observable<User[]> {
|
list(): Observable<User[]> {
|
||||||
const options = {params: new HttpParams().set('l', '')};
|
const options = {params: new HttpParams().set('l', '')};
|
||||||
return <Observable<User[]>>this.http.get<User[]>(`${url}/list`, options)
|
return <Observable<User[]>>this.http.get<User[]>(url, options)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'list'))
|
catchError(this.log.handleError(serviceName, 'list'))
|
||||||
);
|
);
|
||||||
|
@ -36,21 +36,21 @@ export class UserService {
|
||||||
|
|
||||||
listOfNames(): Observable<string[]> {
|
listOfNames(): Observable<string[]> {
|
||||||
const options = {params: new HttpParams().set('n', '')};
|
const options = {params: new HttpParams().set('n', '')};
|
||||||
return <Observable<string[]>>this.http.get<string[]>(`${url}/list`, options)
|
return <Observable<string[]>>this.http.get<string[]>(url, options)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'list'))
|
catchError(this.log.handleError(serviceName, 'list'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
save(user: User): Observable<User> {
|
save(user: User): Observable<User> {
|
||||||
return <Observable<User>>this.http.put<User>(`${url}/new`, user, httpOptions)
|
return <Observable<User>>this.http.post<User>(`${url}/new`, user, httpOptions)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'save'))
|
catchError(this.log.handleError(serviceName, 'save'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(user: User): Observable<User> {
|
update(user: User): Observable<User> {
|
||||||
return <Observable<User>>this.http.post<User>(`${url}/${user.id}`, user, httpOptions)
|
return <Observable<User>>this.http.put<User>(`${url}/${user.id}`, user, httpOptions)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(this.log.handleError(serviceName, 'update'))
|
catchError(this.log.handleError(serviceName, 'update'))
|
||||||
);
|
);
|
|
@ -0,0 +1,13 @@
|
||||||
|
import {UsersRoutingModule} from './users-routing.module';
|
||||||
|
|
||||||
|
describe('UsersRoutingModule', () => {
|
||||||
|
let userRoutingModule: UsersRoutingModule;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
userRoutingModule = new UsersRoutingModule();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create an instance', () => {
|
||||||
|
expect(userRoutingModule).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -9,7 +9,7 @@ import {AuthGuard} from '../auth/auth-guard.service';
|
||||||
|
|
||||||
const userRoutes: Routes = [
|
const userRoutes: Routes = [
|
||||||
{
|
{
|
||||||
path: 'users/list',
|
path: '',
|
||||||
component: UserListComponent,
|
component: UserListComponent,
|
||||||
canActivate: [AuthGuard],
|
canActivate: [AuthGuard],
|
||||||
data: {
|
data: {
|
||||||
|
@ -20,7 +20,7 @@ const userRoutes: Routes = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'users/new',
|
path: 'new',
|
||||||
component: UserDetailComponent,
|
component: UserDetailComponent,
|
||||||
canActivate: [AuthGuard],
|
canActivate: [AuthGuard],
|
||||||
data: {
|
data: {
|
||||||
|
@ -31,7 +31,7 @@ const userRoutes: Routes = [
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'users/:id',
|
path: ':id',
|
||||||
component: UserDetailComponent,
|
component: UserDetailComponent,
|
||||||
canActivate: [AuthGuard],
|
canActivate: [AuthGuard],
|
||||||
resolve: {
|
resolve: {
|
||||||
|
@ -54,5 +54,5 @@ const userRoutes: Routes = [
|
||||||
UserResolver
|
UserResolver
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class UserRoutingModule {
|
export class UsersRoutingModule {
|
||||||
}
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
import {UsersModule} from './users.module';
|
||||||
|
|
||||||
|
describe('UsersModule', () => {
|
||||||
|
let userModule: UsersModule;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
userModule = new UsersModule();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create an instance', () => {
|
||||||
|
expect(userModule).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
|
@ -3,7 +3,7 @@ import {CommonModule} from '@angular/common';
|
||||||
|
|
||||||
import {UserListComponent} from './user-list/user-list.component';
|
import {UserListComponent} from './user-list/user-list.component';
|
||||||
import {UserDetailComponent} from './user-detail/user-detail.component';
|
import {UserDetailComponent} from './user-detail/user-detail.component';
|
||||||
import {UserRoutingModule} from './user-routing.module';
|
import {UsersRoutingModule} from './users-routing.module';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatCardModule } from '@angular/material/card';
|
import { MatCardModule } from '@angular/material/card';
|
||||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||||
|
@ -36,12 +36,12 @@ import {FlexLayoutModule} from '@angular/flex-layout';
|
||||||
MatTableModule,
|
MatTableModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
SharedModule,
|
SharedModule,
|
||||||
UserRoutingModule
|
UsersRoutingModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
UserListComponent,
|
UserListComponent,
|
||||||
UserDetailComponent
|
UserDetailComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class UserModule {
|
export class UsersModule {
|
||||||
}
|
}
|
Loading…
Reference in New Issue