Renamed groups to roles in the frontend
Working: Account Cost Centre Employee Product Group Product Role User Client
This commit is contained in:
@ -55,8 +55,8 @@ const appRoutes: Routes = [
|
||||
loadChildren: () => import('./employee-functions/employee-functions.module').then(mod => mod.EmployeeFunctionsModule)
|
||||
},
|
||||
{
|
||||
path: 'groups',
|
||||
loadChildren: () => import('./group/group.module').then(mod => mod.GroupModule)
|
||||
path: 'roles',
|
||||
loadChildren: () => import('./role/role.module').then(mod => mod.RoleModule)
|
||||
},
|
||||
{
|
||||
path: 'incentive',
|
||||
|
||||
@ -15,13 +15,14 @@ export class AuthGuard implements CanActivate {
|
||||
|
||||
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
|
||||
const user = this.authService.user;
|
||||
const permission = route.data['permission'].replace(/ /g, '-').toLowerCase();
|
||||
const permission = (route.data['permission'] === undefined) ? route.data['permission'] : route.data['permission']
|
||||
.replace(/ /g, '-')
|
||||
.toLowerCase();
|
||||
if (!user) {
|
||||
// not logged in so redirect to login page with the return url
|
||||
this.router.navigate(['/login'], {queryParams: {returnUrl: state.url}});
|
||||
return false;
|
||||
}
|
||||
console.log(permission, user.perms.indexOf(permission));
|
||||
if (permission !== undefined && user.perms.indexOf(permission) === -1) {
|
||||
this.toaster.show('Danger', 'You do not have the permission to access this area.');
|
||||
return false;
|
||||
|
||||
@ -27,8 +27,7 @@ export class ClientService {
|
||||
}
|
||||
|
||||
list(): Observable<Client[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<Client[]>>this.http.get<Client[]>(url, options)
|
||||
return <Observable<Client[]>>this.http.get<Client[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
|
||||
@ -19,7 +19,7 @@ export class AccountService {
|
||||
}
|
||||
|
||||
get(id: string): Observable<Account> {
|
||||
const getUrl: string = (id === null) ? `${url}/` : `${url}/${id}`;
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<Account>>this.http.get<Account>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
@ -33,16 +33,16 @@ export class AccountService {
|
||||
);
|
||||
}
|
||||
|
||||
paymentAutocomplete(term: string): Observable<Account[]> {
|
||||
const options = {params: new HttpParams().set('q', term).set('t', '1')};
|
||||
paymentAutocomplete(query: string): Observable<Account[]> {
|
||||
const options = {params: new HttpParams().set('q', query).set('t', '1')};
|
||||
return <Observable<Account[]>>this.http.get<Account[]>(`${url}/query`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
receiptAutocomplete(term: string): Observable<Account[]> {
|
||||
const options = {params: new HttpParams().set('q', term).set('t', '1')};
|
||||
receiptAutocomplete(query: string): Observable<Account[]> {
|
||||
const options = {params: new HttpParams().set('q', query).set('t', '1')};
|
||||
return <Observable<Account[]>>this.http.get<Account[]>(`${url}/query`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
@ -50,7 +50,7 @@ export class AccountService {
|
||||
}
|
||||
|
||||
save(account: Account): Observable<Account> {
|
||||
return <Observable<Account>>this.http.post<Account>(`${url}/`, account, httpOptions)
|
||||
return <Observable<Account>>this.http.post<Account>(`${url}`, account, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
@ -78,8 +78,8 @@ export class AccountService {
|
||||
);
|
||||
}
|
||||
|
||||
autocomplete(term: string): Observable<Account[]> {
|
||||
const options = {params: new HttpParams().set('q', term)};
|
||||
autocomplete(query: string): Observable<Account[]> {
|
||||
const options = {params: new HttpParams().set('q', query)};
|
||||
return <Observable<Account[]>>this.http.get<Account[]>(`${url}/query`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'autocomplete'))
|
||||
@ -87,8 +87,8 @@ export class AccountService {
|
||||
}
|
||||
|
||||
balance(id: string, date: string): Observable<any> {
|
||||
const options = {params: new HttpParams().set('b', 'true').set('d', date)};
|
||||
return <Observable<any>>this.http.get<any>(`${url}/${id}`, options)
|
||||
const options = {params: new HttpParams().set('d', date)};
|
||||
return <Observable<any>>this.http.get<any>(`${url}/${id}/balance`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'balance'))
|
||||
);
|
||||
|
||||
@ -67,7 +67,7 @@
|
||||
<a mat-menu-item (click)="logout()">Logout {{(auth.currentUser | async)?.name}}</a>
|
||||
<a mat-menu-item routerLink="/users/me">Change Password</a>
|
||||
<a mat-menu-item routerLink="/users">Users</a>
|
||||
<a mat-menu-item routerLink="/groups">Groups</a>
|
||||
<a mat-menu-item routerLink="/roles">Roles</a>
|
||||
<a mat-menu-item routerLink="/clients">Clients</a>
|
||||
<a mat-menu-item routerLink="/settings">Settings</a>
|
||||
</mat-menu>
|
||||
|
||||
@ -19,7 +19,7 @@ export class CostCentreService {
|
||||
}
|
||||
|
||||
get(id: string): Observable<CostCentre> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<CostCentre>>this.http.get<CostCentre>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
@ -27,15 +27,14 @@ export class CostCentreService {
|
||||
}
|
||||
|
||||
list(): Observable<CostCentre[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<CostCentre[]>>this.http.get<CostCentre[]>(url, options)
|
||||
return <Observable<CostCentre[]>>this.http.get<CostCentre[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
save(costCentre: CostCentre): Observable<CostCentre> {
|
||||
return <Observable<CostCentre>>this.http.post<CostCentre>(`${url}/new`, costCentre, httpOptions)
|
||||
return <Observable<CostCentre>>this.http.post<CostCentre>(`${url}`, costCentre, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
|
||||
@ -19,7 +19,7 @@ export class EmployeeService {
|
||||
}
|
||||
|
||||
get(id: string): Observable<Employee> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<Employee>>this.http.get<Employee>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
@ -27,15 +27,14 @@ export class EmployeeService {
|
||||
}
|
||||
|
||||
list(): Observable<Employee[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<Employee[]>>this.http.get<Employee[]>(url, options)
|
||||
return <Observable<Employee[]>>this.http.get<Employee[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
save(employee: Employee): Observable<Employee> {
|
||||
return <Observable<Employee>>this.http.post<Employee>(`${url}/new`, employee, httpOptions)
|
||||
return <Observable<Employee>>this.http.post<Employee>(`${url}`, employee, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
@ -65,7 +64,7 @@ export class EmployeeService {
|
||||
|
||||
autocomplete(term: string): Observable<Employee[]> {
|
||||
const options = {params: new HttpParams().set('q', term)};
|
||||
return <Observable<Employee[]>>this.http.get<Employee[]>(url, options)
|
||||
return <Observable<Employee[]>>this.http.get<Employee[]>(`${url}/query`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'autocomplete'))
|
||||
);
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {GroupResolverService} from './group-resolver.service';
|
||||
|
||||
describe('GroupResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [GroupDetailResolverService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([GroupDetailResolverService], (service: GroupDetailResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@ -1,13 +0,0 @@
|
||||
import {UserRoutingModule} from './group-routing.module';
|
||||
|
||||
describe('UserRoutingModule', () => {
|
||||
let groupRoutingModule: UserRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
groupRoutingModule = new UserRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(groupRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -1,13 +0,0 @@
|
||||
import {GroupModule} from './group.module';
|
||||
|
||||
describe('GroupModule', () => {
|
||||
let groupModule: GroupModule;
|
||||
|
||||
beforeEach(() => {
|
||||
groupModule = new GroupModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(groupModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -1,15 +0,0 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {GroupService} from './group.service';
|
||||
|
||||
describe('GroupService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [GroupService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([GroupService], (service: GroupService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@ -1,73 +0,0 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {Group} from './group';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
const url = '/api/groups';
|
||||
const serviceName = 'GroupService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GroupService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
get(id: string): Observable<Group> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
||||
return <Observable<Group>>this.http.get<Group>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<Group[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<Group[]>>this.http.get<Group[]>(url, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
listOfNames(): Observable<string[]> {
|
||||
const options = {params: new HttpParams().set('n', '')};
|
||||
return <Observable<string[]>>this.http.get<string[]>(url, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
save(group: Group): Observable<Group> {
|
||||
return <Observable<Group>>this.http.post<Group>(`${url}/new`, group, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
}
|
||||
|
||||
update(group: Group): Observable<Group> {
|
||||
return <Observable<Group>>this.http.put<Group>(`${url}/${group.id}`, group, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(group: Group): Observable<Group> {
|
||||
if (!group.id) {
|
||||
return this.save(group);
|
||||
} else {
|
||||
return this.update(group);
|
||||
}
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Group> {
|
||||
return <Observable<Group>>this.http.delete<Group>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -19,7 +19,7 @@ export class ProductGroupService {
|
||||
}
|
||||
|
||||
get(id: string): Observable<ProductGroup> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<ProductGroup>>this.http.get<ProductGroup>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
@ -27,15 +27,14 @@ export class ProductGroupService {
|
||||
}
|
||||
|
||||
list(): Observable<ProductGroup[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<ProductGroup[]>>this.http.get<ProductGroup[]>(url, options)
|
||||
return <Observable<ProductGroup[]>>this.http.get<ProductGroup[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
save(productGroup: ProductGroup): Observable<ProductGroup> {
|
||||
return <Observable<ProductGroup>>this.http.post<ProductGroup>(`${url}/new`, productGroup, httpOptions)
|
||||
return <Observable<ProductGroup>>this.http.post<ProductGroup>(`${url}`, productGroup, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
</mat-form-field>
|
||||
<mat-form-field cdk-overlay-origin="">
|
||||
<mat-label>Yield</mat-label>
|
||||
<input matInput type="number" placeholder="Tield" formControlName="productYield">
|
||||
<input matInput type="number" placeholder="Yield" formControlName="productYield">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
|
||||
@ -19,7 +19,7 @@ export class ProductService {
|
||||
}
|
||||
|
||||
get(id: string): Observable<Product> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<Product>>this.http.get<Product>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
@ -27,15 +27,14 @@ export class ProductService {
|
||||
}
|
||||
|
||||
list(): Observable<Product[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(url, options)
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'getList'))
|
||||
);
|
||||
}
|
||||
|
||||
save(product: Product): Observable<Product> {
|
||||
return <Observable<Product>>this.http.post<Product>(`${url}/new`, product, httpOptions)
|
||||
return <Observable<Product>>this.http.post<Product>(`${url}`, product, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
@ -63,19 +62,11 @@ export class ProductService {
|
||||
);
|
||||
}
|
||||
|
||||
autocomplete(term: string): Observable<Product[]> {
|
||||
const options = {params: new HttpParams().set('t', term)};
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(url, options)
|
||||
autocomplete(query: string): Observable<Product[]> {
|
||||
const options = {params: new HttpParams().set('q', query)};
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(`${url}/query`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'autocomplete'))
|
||||
);
|
||||
}
|
||||
|
||||
balance(id: string, date: string): Observable<number> {
|
||||
const options = {params: new HttpParams().set('b', 'true').set('d', date)};
|
||||
return <Observable<number>>this.http.get<number>(`${url}/${id}`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'balance'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Group</mat-card-title>
|
||||
<mat-card-title>Role</mat-card-title>
|
||||
</mat-card-title-group>
|
||||
<mat-card-content>
|
||||
<form [formGroup]="form" fxLayout="column">
|
||||
@ -1,20 +1,20 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {GroupDetailComponent} from './group-detail.component';
|
||||
import {RoleDetailComponent} from './role-detail.component';
|
||||
|
||||
describe('GroupDetailComponent', () => {
|
||||
let component: GroupDetailComponent;
|
||||
let fixture: ComponentFixture<GroupDetailComponent>;
|
||||
describe('RoleDetailComponent', () => {
|
||||
let component: RoleDetailComponent;
|
||||
let fixture: ComponentFixture<RoleDetailComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [GroupDetailComponent]
|
||||
declarations: [RoleDetailComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(GroupDetailComponent);
|
||||
fixture = TestBed.createComponent(RoleDetailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
@ -1,22 +1,22 @@
|
||||
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
|
||||
import {GroupService} from '../group.service';
|
||||
import {Group} from '../group';
|
||||
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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-group-detail',
|
||||
templateUrl: './group-detail.component.html',
|
||||
styleUrls: ['./group-detail.component.css']
|
||||
selector: 'app-role-detail',
|
||||
templateUrl: './role-detail.component.html',
|
||||
styleUrls: ['./role-detail.component.css']
|
||||
})
|
||||
export class GroupDetailComponent implements OnInit, AfterViewInit {
|
||||
export class RoleDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
form: FormGroup;
|
||||
item: Group;
|
||||
item: Role;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@ -24,7 +24,7 @@ export class GroupDetailComponent implements OnInit, AfterViewInit {
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private dialog: MatDialog,
|
||||
private ser: GroupService
|
||||
private ser: RoleService
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
@ -38,7 +38,7 @@ export class GroupDetailComponent implements OnInit, AfterViewInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: Group }) => {
|
||||
.subscribe((data: { item: Role }) => {
|
||||
this.item = data.item;
|
||||
this.form.get('name').setValue(this.item.name);
|
||||
this.form.setControl('permissions', this.fb.array(
|
||||
@ -62,7 +62,7 @@ export class GroupDetailComponent implements OnInit, AfterViewInit {
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/groups');
|
||||
this.router.navigateByUrl('/roles');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
@ -75,7 +75,7 @@ export class GroupDetailComponent implements OnInit, AfterViewInit {
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/groups');
|
||||
this.router.navigateByUrl('/roles');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
@ -86,7 +86,7 @@ export class GroupDetailComponent implements OnInit, AfterViewInit {
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete Group?', 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) => {
|
||||
@ -96,7 +96,7 @@ export class GroupDetailComponent implements OnInit, AfterViewInit {
|
||||
});
|
||||
}
|
||||
|
||||
getItem(): Group {
|
||||
getItem(): Role {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
const array = this.form.get('permissions') as FormArray;
|
||||
@ -1,6 +1,6 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ClientListResolverService} from './group-list-resolver.service';
|
||||
import {ClientListResolverService} from './role-list-resolver.service';
|
||||
|
||||
describe('ClientListResolverService', () => {
|
||||
beforeEach(() => {
|
||||
@ -1,18 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {Group} from './group';
|
||||
import {Role} from './role';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {GroupService} from './group.service';
|
||||
import {RoleService} from './role.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GroupListResolver implements Resolve<Group[]> {
|
||||
export class RoleListResolver implements Resolve<Role[]> {
|
||||
|
||||
constructor(private ser: GroupService, private router: Router) {
|
||||
constructor(private ser: RoleService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Group[]> {
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Role[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
@ -3,15 +3,15 @@ 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 {Group} from '../group';
|
||||
import {Role} from '../role';
|
||||
|
||||
export class GroupListDataSource extends DataSource<Group> {
|
||||
export class RoleListDatasource extends DataSource<Role> {
|
||||
|
||||
constructor(private paginator: MatPaginator, private sort: MatSort, public data: Group[]) {
|
||||
constructor(private paginator: MatPaginator, private sort: MatSort, public data: Role[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<Group[]> {
|
||||
connect(): Observable<Role[]> {
|
||||
const dataMutations = [
|
||||
observableOf(this.data),
|
||||
this.paginator.page,
|
||||
@ -29,12 +29,12 @@ export class GroupListDataSource extends DataSource<Group> {
|
||||
disconnect() {
|
||||
}
|
||||
|
||||
private getPagedData(data: Group[]) {
|
||||
private getPagedData(data: Role[]) {
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
return data.splice(startIndex, this.paginator.pageSize);
|
||||
}
|
||||
|
||||
private getSortedData(data: Group[]) {
|
||||
private getSortedData(data: Role[]) {
|
||||
if (!this.sort.active || this.sort.direction === '') {
|
||||
return data;
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Groups</mat-card-title>
|
||||
<a mat-button [routerLink]="['/groups', 'new']">
|
||||
<mat-card-title>Roles</mat-card-title>
|
||||
<a mat-button [routerLink]="['/roles', 'new']">
|
||||
<mat-icon>add_box</mat-icon>
|
||||
Add
|
||||
</a>
|
||||
@ -12,7 +12,7 @@
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"><a [routerLink]="['/groups', 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 -->
|
||||
@ -1,18 +1,18 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {GroupListComponent} from './group-list.component';
|
||||
import {RoleListComponent} from './role-list.component';
|
||||
|
||||
describe('GroupListComponent', () => {
|
||||
let component: GroupListComponent;
|
||||
let fixture: ComponentFixture<GroupListComponent>;
|
||||
describe('RoleListComponent', () => {
|
||||
let component: RoleListComponent;
|
||||
let fixture: ComponentFixture<RoleListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [GroupListComponent]
|
||||
declarations: [RoleListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(GroupListComponent);
|
||||
fixture = TestBed.createComponent(RoleListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
@ -1,20 +1,20 @@
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import {GroupListDataSource} from './group-list-datasource';
|
||||
import {Group} from '../group';
|
||||
import {RoleListDatasource} from './role-list-datasource';
|
||||
import {Role} from '../role';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-group-list',
|
||||
templateUrl: './group-list.component.html',
|
||||
styleUrls: ['./group-list.component.css']
|
||||
selector: 'app-role-list',
|
||||
templateUrl: './role-list.component.html',
|
||||
styleUrls: ['./role-list.component.css']
|
||||
})
|
||||
export class GroupListComponent implements OnInit {
|
||||
export class RoleListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
||||
dataSource: GroupListDataSource;
|
||||
list: Group[];
|
||||
dataSource: RoleListDatasource;
|
||||
list: Role[];
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'permissions'];
|
||||
|
||||
@ -23,9 +23,9 @@ export class GroupListComponent implements OnInit {
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: Group[] }) => {
|
||||
.subscribe((data: { list: Role[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new GroupListDataSource(this.paginator, this.sort, this.list);
|
||||
this.dataSource = new RoleListDatasource(this.paginator, this.sort, this.list);
|
||||
}
|
||||
}
|
||||
15
overlord/src/app/role/role-resolver.service.spec.ts
Normal file
15
overlord/src/app/role/role-resolver.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {RoleResolverService} from './role-resolver.service';
|
||||
|
||||
describe('RoleResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [RoleDetailResolverService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([RoleDetailResolverService], (service: RoleDetailResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@ -1,18 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {Group} from './group';
|
||||
import {Role} from './role';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {GroupService} from './group.service';
|
||||
import {RoleService} from './role.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GroupResolver implements Resolve<Group> {
|
||||
export class RoleResolver implements Resolve<Role> {
|
||||
|
||||
constructor(private ser: GroupService, private router: Router) {
|
||||
constructor(private ser: RoleService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Group> {
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Role> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
13
overlord/src/app/role/role-routing.module.spec.ts
Normal file
13
overlord/src/app/role/role-routing.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import {RoleRoutingModule} from './role-routing.module';
|
||||
|
||||
describe('RoleRoutingModule', () => {
|
||||
let roleRoutingModule: RoleRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
roleRoutingModule = new RoleRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(roleRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -1,44 +1,44 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {GroupListResolver} from './group-list-resolver.service';
|
||||
import {GroupResolver} from './group-resolver.service';
|
||||
import {GroupListComponent} from './group-list/group-list.component';
|
||||
import {GroupDetailComponent} from './group-detail/group-detail.component';
|
||||
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 groupRoutes: Routes = [
|
||||
const roleRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: GroupListComponent,
|
||||
component: RoleListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Users'
|
||||
},
|
||||
resolve: {
|
||||
list: GroupListResolver
|
||||
list: RoleListResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: GroupDetailComponent,
|
||||
component: RoleDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Users'
|
||||
},
|
||||
resolve: {
|
||||
item: GroupResolver,
|
||||
item: RoleResolver,
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: GroupDetailComponent,
|
||||
component: RoleDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Users'
|
||||
},
|
||||
resolve: {
|
||||
item: GroupResolver
|
||||
item: RoleResolver
|
||||
}
|
||||
}
|
||||
];
|
||||
@ -46,16 +46,16 @@ const groupRoutes: Routes = [
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(groupRoutes)
|
||||
RouterModule.forChild(roleRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
GroupListResolver,
|
||||
GroupResolver
|
||||
RoleListResolver,
|
||||
RoleResolver
|
||||
]
|
||||
})
|
||||
export class GroupRoutingModule {
|
||||
export class RoleRoutingModule {
|
||||
}
|
||||
13
overlord/src/app/role/role.module.spec.ts
Normal file
13
overlord/src/app/role/role.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import {RoleModule} from './role.module';
|
||||
|
||||
describe('RoleModule', () => {
|
||||
let roleModule: RoleModule;
|
||||
|
||||
beforeEach(() => {
|
||||
roleModule = new RoleModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(roleModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -1,9 +1,9 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
import {GroupListComponent} from './group-list/group-list.component';
|
||||
import {GroupDetailComponent} from './group-detail/group-detail.component';
|
||||
import {GroupRoutingModule} from './group-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';
|
||||
@ -36,12 +36,12 @@ import {FlexLayoutModule} from '@angular/flex-layout';
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
SharedModule,
|
||||
GroupRoutingModule
|
||||
RoleRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
GroupListComponent,
|
||||
GroupDetailComponent
|
||||
RoleListComponent,
|
||||
RoleDetailComponent
|
||||
]
|
||||
})
|
||||
export class GroupModule {
|
||||
export class RoleModule {
|
||||
}
|
||||
15
overlord/src/app/role/role.service.spec.ts
Normal file
15
overlord/src/app/role/role.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {RoleService} from './role.service';
|
||||
|
||||
describe('RoleService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [RoleService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([RoleService], (service: RoleService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
64
overlord/src/app/role/role.service.ts
Normal file
64
overlord/src/app/role/role.service.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {Role} from './role';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
const url = '/api/roles';
|
||||
const serviceName = 'RoleService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoleService {
|
||||
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}`))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<Role[]> {
|
||||
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'))
|
||||
);
|
||||
}
|
||||
|
||||
update(role: Role): Observable<Role> {
|
||||
return <Observable<Role>>this.http.put<Role>(`${url}/${role.id}`, role, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(role: Role): Observable<Role> {
|
||||
if (!role.id) {
|
||||
return this.save(role);
|
||||
} else {
|
||||
return this.update(role);
|
||||
}
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Role> {
|
||||
return <Observable<Role>>this.http.delete<Role>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
export class Group {
|
||||
export class Role {
|
||||
id: string;
|
||||
name: string;
|
||||
permissions: Permission[];
|
||||
@ -29,7 +29,7 @@
|
||||
<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="group" fxFlex>{{r.name}}</mat-checkbox>
|
||||
<mat-checkbox formControlName="role" fxFlex>{{r.name}}</mat-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@ -114,7 +114,7 @@ export class UserDetailComponent implements OnInit, AfterViewInit {
|
||||
this.item.lockedOut = formModel.lockedOut;
|
||||
const array = this.form.get('roles') as FormArray;
|
||||
this.item.roles.forEach((item, index) => {
|
||||
item.enabled = array.controls[index].value.group;
|
||||
item.enabled = array.controls[index].value.role;
|
||||
});
|
||||
return this.item;
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
<!-- 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.name]">{{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 -->
|
||||
|
||||
@ -19,7 +19,7 @@ export class UserService {
|
||||
}
|
||||
|
||||
get(id: string): Observable<User> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${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}`))
|
||||
@ -27,23 +27,21 @@ export class UserService {
|
||||
}
|
||||
|
||||
list(): Observable<User[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<User[]>>this.http.get<User[]>(url, options)
|
||||
return <Observable<User[]>>this.http.get<User[]>(`${url}/list`)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
listOfNames(): Observable<string[]> {
|
||||
const options = {params: new HttpParams().set('n', '')};
|
||||
return <Observable<string[]>>this.http.get<string[]>(url, options)
|
||||
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}/new`, user, httpOptions)
|
||||
return <Observable<User>>this.http.post<User>(`${url}`, user, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user