Moved to Angular 6.0
---- Pending * Table width for the points column in incentive * Linting * keyboard navigation where it was used earlier * can remove the unused totals calculated serverside in productledger * spinner and loading bars * Activate Guard for Employee Function tabs * Progress for Fingerprint uploads * deleted reconcile and receipe features as they were not being used * focus the right control on component load
This commit is contained in:
@ -0,0 +1,3 @@
|
||||
.example-card {
|
||||
max-width: 400px;
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Product Group</mat-card-title>
|
||||
</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">
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput #nameElement placeholder="Name" formControlName="name" (keyup.enter)="save()">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button (click)="save()" color="primary">Save</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
||||
@ -0,0 +1,25 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ProductGroupDetailComponent} from './product-group-detail.component';
|
||||
|
||||
describe('ProductGroupDetailComponent', () => {
|
||||
let component: ProductGroupDetailComponent;
|
||||
let fixture: ComponentFixture<ProductGroupDetailComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ProductGroupDetailComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ProductGroupDetailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,73 @@
|
||||
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||
|
||||
import {ProductGroupService} from '../product-group.service';
|
||||
import {ProductGroup} from '../product-group';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {ToasterService} from '../../core/toaster.service';
|
||||
import {FormBuilder, FormGroup} from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-product-group-detail',
|
||||
templateUrl: './product-group-detail.component.html',
|
||||
styleUrls: ['./product-group-detail.component.css']
|
||||
})
|
||||
export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement') nameElement: ElementRef;
|
||||
form: FormGroup;
|
||||
item: ProductGroup;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: ProductGroupService
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
name: ''
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: ProductGroup }) => {
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: ProductGroup) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
name: this.item.name,
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/ProductGroups');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getItem(): ProductGroup {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ProductGroupListResolverService} from './product-group-list-resolver.service';
|
||||
|
||||
describe('ProductGroupListResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProductGroupListResolverService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ProductGroupListResolverService], (service: ProductGroupListResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@ -0,0 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {ProductGroup} from './product-group';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {ProductGroupService} from './product-group.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProductGroupListResolver implements Resolve<ProductGroup[]> {
|
||||
|
||||
constructor(private ser: ProductGroupService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<ProductGroup[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
import {DataSource} from '@angular/cdk/collections';
|
||||
import {MatPaginator, MatSort} from '@angular/material';
|
||||
import {map} from 'rxjs/operators';
|
||||
import {merge, Observable, of as observableOf} from 'rxjs';
|
||||
import {ProductGroup} from '../product-group';
|
||||
|
||||
export class ProductGroupListDataSource extends DataSource<ProductGroup> {
|
||||
|
||||
constructor(private paginator: MatPaginator, private sort: MatSort, public data: ProductGroup[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<ProductGroup[]> {
|
||||
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: ProductGroup[]) {
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
return data.splice(startIndex, this.paginator.pageSize);
|
||||
}
|
||||
|
||||
private getSortedData(data: ProductGroup[]) {
|
||||
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 client-side sorting). */
|
||||
function compare(a, b, isAsc) {
|
||||
return (a < b ? -1 : 1) * (isAsc ? 1 : -1);
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Product Groups</mat-card-title>
|
||||
<a mat-button [routerLink]="['/ProductGroup']">
|
||||
<mat-icon>add_box</mat-icon>
|
||||
Add
|
||||
</a>
|
||||
</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]="['/ProductGroup', row.id]">{{row.name}}</a></mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Is Fixture Column -->
|
||||
<ng-container matColumnDef="isFixture">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Is Fixture?</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.isFixture}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-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>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
@ -0,0 +1,23 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ProductGroupListComponent} from './product-group-list.component';
|
||||
|
||||
describe('ProductGroupListComponent', () => {
|
||||
let component: ProductGroupListComponent;
|
||||
let fixture: ComponentFixture<ProductGroupListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ProductGroupListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ProductGroupListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should compile', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,30 @@
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import {MatPaginator, MatSort} from '@angular/material';
|
||||
import {ProductGroupListDataSource} from './product-group-list-datasource';
|
||||
import {ProductGroup} from '../product-group';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-product-group-list',
|
||||
templateUrl: './product-group-list.component.html',
|
||||
styleUrls: ['./product-group-list.component.css']
|
||||
})
|
||||
export class ProductGroupListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator) paginator: MatPaginator;
|
||||
@ViewChild(MatSort) sort: MatSort;
|
||||
dataSource: ProductGroupListDataSource;
|
||||
list: ProductGroup[];
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'isFixture'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: ProductGroup[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new ProductGroupListDataSource(this.paginator, this.sort, this.list);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ProductGroupResolverService} from './product-group-resolver.service';
|
||||
|
||||
describe('ProductGroupResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProductGroupDetailResolverService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ProductGroupDetailResolverService], (service: ProductGroupDetailResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
@ -0,0 +1,19 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {ProductGroupService} from './product-group.service';
|
||||
import {ProductGroup} from './product-group';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProductGroupResolver implements Resolve<ProductGroup> {
|
||||
|
||||
constructor(private ser: ProductGroupService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<ProductGroup> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import {ProductGroupRoutingModule} from './product-group-routing.module';
|
||||
|
||||
describe('ProductGroupRoutingModule', () => {
|
||||
let productGroupRoutingModule: ProductGroupRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
productGroupRoutingModule = new ProductGroupRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(productGroupRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,61 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {ProductGroupListResolver} from './product-group-list-resolver.service';
|
||||
import {ProductGroupResolver} from './product-group-resolver.service';
|
||||
import {ProductGroupListComponent} from './product-group-list/product-group-list.component';
|
||||
import {ProductGroupDetailComponent} from './product-group-detail/product-group-detail.component';
|
||||
import {AuthGuard} from '../auth/auth-guard.service';
|
||||
|
||||
const productGroupRoutes: Routes = [
|
||||
{
|
||||
path: 'ProductGroups',
|
||||
component: ProductGroupListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Cost Centres'
|
||||
},
|
||||
resolve: {
|
||||
list: ProductGroupListResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'ProductGroup',
|
||||
component: ProductGroupDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Cost Centres'
|
||||
},
|
||||
resolve: {
|
||||
item: ProductGroupResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'ProductGroup/:id',
|
||||
component: ProductGroupDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Cost Centres'
|
||||
},
|
||||
resolve: {
|
||||
item: ProductGroupResolver
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(productGroupRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
ProductGroupListResolver,
|
||||
ProductGroupResolver
|
||||
]
|
||||
})
|
||||
export class ProductGroupRoutingModule {
|
||||
}
|
||||
13
overlord/src/app/product-group/product-group.module.spec.ts
Normal file
13
overlord/src/app/product-group/product-group.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import {ProductGroupModule} from './product-group.module';
|
||||
|
||||
describe('ProductGroupModule', () => {
|
||||
let productGroupModule: ProductGroupModule;
|
||||
|
||||
beforeEach(() => {
|
||||
productGroupModule = new ProductGroupModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(productGroupModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
44
overlord/src/app/product-group/product-group.module.ts
Normal file
44
overlord/src/app/product-group/product-group.module.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
import {ProductGroupListComponent} from './product-group-list/product-group-list.component';
|
||||
import {ProductGroupDetailComponent} from './product-group-detail/product-group-detail.component';
|
||||
import {ProductGroupRoutingModule} from './product-group-routing.module';
|
||||
import {
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatPaginatorModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSortModule,
|
||||
MatTableModule
|
||||
} from '@angular/material';
|
||||
import {CdkTableModule} from '@angular/cdk/table';
|
||||
import {FlexLayoutModule, FlexModule} from '@angular/flex-layout';
|
||||
import {ReactiveFormsModule} from '@angular/forms';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexModule,
|
||||
FlexLayoutModule,
|
||||
MatTableModule,
|
||||
MatPaginatorModule,
|
||||
MatSortModule,
|
||||
MatCardModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatInputModule,
|
||||
MatButtonModule,
|
||||
MatIconModule,
|
||||
ReactiveFormsModule,
|
||||
ProductGroupRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
ProductGroupListComponent,
|
||||
ProductGroupDetailComponent
|
||||
]
|
||||
})
|
||||
export class ProductGroupModule {
|
||||
}
|
||||
15
overlord/src/app/product-group/product-group.service.spec.ts
Normal file
15
overlord/src/app/product-group/product-group.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ProductGroupService} from './product-group.service';
|
||||
|
||||
describe('ProductGroupService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProductGroupService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ProductGroupService], (service: ProductGroupService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
65
overlord/src/app/product-group/product-group.service.ts
Normal file
65
overlord/src/app/product-group/product-group.service.ts
Normal file
@ -0,0 +1,65 @@
|
||||
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 {ProductGroup} from './product-group';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
const url = '/api/ProductGroup';
|
||||
const serviceName = 'ProductGroupService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProductGroupService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
get(id: string): Observable<ProductGroup> {
|
||||
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}`))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<ProductGroup[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<ProductGroup[]>>this.http.get<ProductGroup[]>(url, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
save(productGroup: ProductGroup): Observable<ProductGroup> {
|
||||
return <Observable<ProductGroup>>this.http.post<ProductGroup>(url, productGroup, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
}
|
||||
|
||||
update(productGroup: ProductGroup): Observable<ProductGroup> {
|
||||
return <Observable<ProductGroup>>this.http.put<ProductGroup>(`${url}/${productGroup.id}`, productGroup, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(productGroup: ProductGroup): Observable<ProductGroup> {
|
||||
if (!productGroup.id) {
|
||||
return this.save(productGroup);
|
||||
} else {
|
||||
return this.update(productGroup);
|
||||
}
|
||||
}
|
||||
|
||||
delete(id: string): Observable<ProductGroup> {
|
||||
return <Observable<ProductGroup>>this.http.delete<ProductGroup>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
}
|
||||
}
|
||||
5
overlord/src/app/product-group/product-group.ts
Normal file
5
overlord/src/app/product-group/product-group.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export class ProductGroup {
|
||||
id: string;
|
||||
name: string;
|
||||
isFixture: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user