Tax done
This commit is contained in:
@ -9,6 +9,14 @@ const routes: Routes = [
|
||||
path: 'guest-book',
|
||||
loadChildren: () => import('./guest-book/guest-book.module').then(mod => mod.GuestBookModule)
|
||||
},
|
||||
{
|
||||
path: 'products',
|
||||
loadChildren: () => import('./product/product.module').then(mod => mod.ProductModule)
|
||||
},
|
||||
{
|
||||
path: 'product-groups',
|
||||
loadChildren: () => import('./product-group/product-group.module').then(mod => mod.ProductGroupModule)
|
||||
},
|
||||
{
|
||||
path: 'running-tables',
|
||||
loadChildren: () => import('./running-tables/running-tables.module').then(mod => mod.RunningTablesModule)
|
||||
@ -17,6 +25,10 @@ const routes: Routes = [
|
||||
path: 'tables',
|
||||
loadChildren: () => import('./tables/tables.module').then(mod => mod.TableModule)
|
||||
},
|
||||
{
|
||||
path: 'taxes',
|
||||
loadChildren: () => import('./taxes/taxes.module').then(mod => mod.TaxesModule)
|
||||
},
|
||||
{path: 'login', component: LoginComponent},
|
||||
{path: 'logout', component: LogoutComponent},
|
||||
{path: '', component: HomeComponent},
|
||||
|
||||
10
bookie/src/app/core/product-group.ts
Normal file
10
bookie/src/app/core/product-group.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export class ProductGroup {
|
||||
id: string;
|
||||
name: string;
|
||||
discountLimit: number;
|
||||
isModifierCompulsory: boolean;
|
||||
groupModifier: string;
|
||||
isActive: boolean;
|
||||
isFixture: boolean;
|
||||
sortOrder: number;
|
||||
}
|
||||
17
bookie/src/app/core/product.ts
Normal file
17
bookie/src/app/core/product.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import {ProductGroup} from './product-group';
|
||||
import {Tax} from "./tax";
|
||||
|
||||
export class Product {
|
||||
id: string;
|
||||
code: number;
|
||||
name: string;
|
||||
units: string;
|
||||
productGroup: ProductGroup;
|
||||
tax: Tax;
|
||||
price: number;
|
||||
hasHappyHour: boolean;
|
||||
isNotAvailable: boolean;
|
||||
quantity: number;
|
||||
isActive: boolean;
|
||||
sortOrder: number;
|
||||
}
|
||||
6
bookie/src/app/core/tax.ts
Normal file
6
bookie/src/app/core/tax.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export class Tax {
|
||||
id: string;
|
||||
name: string;
|
||||
rate: number;
|
||||
isFixture: boolean;
|
||||
}
|
||||
@ -10,6 +10,9 @@
|
||||
<a mat-raised-button routerLink="/tables">
|
||||
Tables
|
||||
</a>
|
||||
<a mat-raised-button routerLink="/taxes">
|
||||
Taxes
|
||||
</a>
|
||||
<a mat-raised-button routerLink="/logout" *ngIf="nameObject | async as name">
|
||||
<mat-icon>account_box</mat-icon>
|
||||
Logout {{name}}
|
||||
|
||||
@ -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 '../../core/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', { static: true }) 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('/product-groups');
|
||||
},
|
||||
(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 '../core/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,59 @@
|
||||
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 {ProductGroup} from '../../core/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]="['/product-groups', 'new']">
|
||||
<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]="['/product-groups', 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,31 @@
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import {ProductGroupListDataSource} from './product-group-list-datasource';
|
||||
import {ProductGroup} from '../../core/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, { static: true }) paginator: MatPaginator;
|
||||
@ViewChild(MatSort, { static: true }) 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 '../core/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();
|
||||
});
|
||||
});
|
||||
61
bookie/src/app/product-group/product-group-routing.module.ts
Normal file
61
bookie/src/app/product-group/product-group-routing.module.ts
Normal file
@ -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: '',
|
||||
component: ProductGroupListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Cost Centres'
|
||||
},
|
||||
resolve: {
|
||||
list: ProductGroupListResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: ProductGroupDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Cost Centres'
|
||||
},
|
||||
resolve: {
|
||||
item: ProductGroupResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':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
bookie/src/app/product-group/product-group.module.spec.ts
Normal file
13
bookie/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();
|
||||
});
|
||||
});
|
||||
41
bookie/src/app/product-group/product-group.module.ts
Normal file
41
bookie/src/app/product-group/product-group.module.ts
Normal file
@ -0,0 +1,41 @@
|
||||
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 } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
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 {FlexLayoutModule} from '@angular/flex-layout';
|
||||
import {ReactiveFormsModule} from '@angular/forms';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatTableModule,
|
||||
MatPaginatorModule,
|
||||
MatSortModule,
|
||||
MatCardModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatInputModule,
|
||||
MatButtonModule,
|
||||
MatIconModule,
|
||||
ReactiveFormsModule,
|
||||
ProductGroupRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
ProductGroupListComponent,
|
||||
ProductGroupDetailComponent
|
||||
]
|
||||
})
|
||||
export class ProductGroupModule {
|
||||
}
|
||||
15
bookie/src/app/product-group/product-group.service.spec.ts
Normal file
15
bookie/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
bookie/src/app/product-group/product-group.service.ts
Normal file
65
bookie/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 '../core/product-group';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
const url = '/api/product-groups';
|
||||
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}/new` : `${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}/new`, 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'))
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,77 @@
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Product</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>Code</mat-label>
|
||||
<input matInput placeholder="Code" formControlName="code">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<mat-form-field fxFlex="75">
|
||||
<mat-label>Name</mat-label>
|
||||
<input matInput #nameElement placeholder="Name" formControlName="name">
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex="25">
|
||||
<mat-label>Units</mat-label>
|
||||
<input matInput placeholder="Units" formControlName="units">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Fraction</mat-label>
|
||||
<input matInput type="number" placeholder="Fraction" formControlName="fraction">
|
||||
</mat-form-field>
|
||||
<mat-form-field cdk-overlay-origin="">
|
||||
<mat-label>Fraction Units</mat-label>
|
||||
<input matInput placeholder="Fraction Units" formControlName="fractionUnits">
|
||||
</mat-form-field>
|
||||
<mat-form-field cdk-overlay-origin="">
|
||||
<mat-label>Yield</mat-label>
|
||||
<input matInput type="number" placeholder="Tield" formControlName="productYield">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>{{item.isPurchased ? 'Purchase Price' : 'Cost Price' }}</mat-label>
|
||||
<input matInput type="number" placeholder="{{item.isPurchased ? 'Purchase Price' : 'Cost Price' }}"
|
||||
formControlName="price">
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex [hidden]="!item.isSold">
|
||||
<mat-label>Sale Price</mat-label>
|
||||
<input matInput type="number" placeholder="Sale Price" formControlName="salePrice">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<mat-checkbox formControlName="isPurchased">Is Purchased?</mat-checkbox>
|
||||
<mat-checkbox formControlName="isSold">Is Sold?</mat-checkbox>
|
||||
<mat-checkbox formControlName="isActive">Is Active?</mat-checkbox>
|
||||
</div>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Product Type</mat-label>
|
||||
<mat-select placeholder="Product Group" formControlName="productGroup">
|
||||
<mat-option *ngFor="let pg of productGroups" [value]="pg.id">
|
||||
{{ pg.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button color="primary" (click)="save()">Save</button>
|
||||
<button mat-raised-button color="warn" (click)="confirmDelete()" *ngIf="!!item.id">Delete</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
||||
@ -0,0 +1,25 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ProductDetailComponent} from './product-detail.component';
|
||||
|
||||
describe('ProductDetailComponent', () => {
|
||||
let component: ProductDetailComponent;
|
||||
let fixture: ComponentFixture<ProductDetailComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ProductDetailComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(ProductDetailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,132 @@
|
||||
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||
import {ToasterService} from '../../core/toaster.service';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {ProductService} from '../product.service';
|
||||
import {Product} from '../../core/product';
|
||||
import {ProductGroup} from '../../core/product-group';
|
||||
import {ConfirmDialogComponent} from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import {FormBuilder, FormGroup} from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-product-detail',
|
||||
templateUrl: './product-detail.component.html',
|
||||
styleUrls: ['./product-detail.component.css']
|
||||
})
|
||||
export class ProductDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
form: FormGroup;
|
||||
productGroups: ProductGroup[];
|
||||
item: Product;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private dialog: MatDialog,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: ProductService
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
code: {value: '', disabled: true},
|
||||
name: '',
|
||||
units: '',
|
||||
fraction: '',
|
||||
fractionUnits: '',
|
||||
productYield: '',
|
||||
price: '',
|
||||
salePrice: '',
|
||||
isPurchased: '',
|
||||
isSold: '',
|
||||
isActive: '',
|
||||
productGroup: ''
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: Product, productGroups: ProductGroup[] }) => {
|
||||
this.productGroups = data.productGroups;
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: Product) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
code: this.item.code || '(Auto)',
|
||||
name: this.item.name || '',
|
||||
units: this.item.units || '',
|
||||
productGroup: this.item.tax.id ? this.item.tax.id : '',
|
||||
tax: this.item.productGroup.id ? this.item.productGroup.id : '',
|
||||
price: this.item.price || '',
|
||||
hadHappyHour: this.item.hasHappyHour,
|
||||
isNotAvailable: this.item.isNotAvailable,
|
||||
quantity: this.item.quantity || '',
|
||||
isActive: this.item.isActive,
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/products');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/products');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete Product?', content: 'Are you sure? This cannot be undone.'}
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
if (result) {
|
||||
this.delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getItem(): Product {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
this.item.units = formModel.units;
|
||||
this.item.productGroup.id = formModel.productGroup;
|
||||
this.item.tax.id = formModel.tax;
|
||||
this.item.price = +formModel.price;
|
||||
this.item.hasHappyHour = formModel.hasHappyHour;
|
||||
this.item.isNotAvailable = formModel.isNotAvailable;
|
||||
this.item.quantity = +formModel.quantity;
|
||||
this.item.isActive = formModel.isActive;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
15
bookie/src/app/product/product-list-resolver.service.spec.ts
Normal file
15
bookie/src/app/product/product-list-resolver.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ProductListResolverService} from './product-list-resolver.service';
|
||||
|
||||
describe('ProductListResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProductListResolverService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ProductListResolverService], (service: ProductListResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
18
bookie/src/app/product/product-list-resolver.service.ts
Normal file
18
bookie/src/app/product/product-list-resolver.service.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
|
||||
import {Product} from '../core/product';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {ProductService} from './product.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProductListResolver implements Resolve<Product[]> {
|
||||
|
||||
constructor(private ser: ProductService) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Product[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
import {DataSource} from '@angular/cdk/collections';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import {map, tap} from 'rxjs/operators';
|
||||
import {merge, Observable, of as observableOf} from 'rxjs';
|
||||
import {Product} from '../../core/product';
|
||||
|
||||
|
||||
export class ProductListDataSource extends DataSource<Product> {
|
||||
private dataObservable: Observable<Product[]>;
|
||||
private filterValue: string;
|
||||
|
||||
constructor(private paginator: MatPaginator, private filter: Observable<string>, public data: Product[]) {
|
||||
super();
|
||||
this.filter = filter.pipe(
|
||||
tap(x => this.filterValue = x)
|
||||
);
|
||||
}
|
||||
|
||||
connect(): Observable<Product[]> {
|
||||
this.dataObservable = observableOf(this.data);
|
||||
const dataMutations = [
|
||||
this.dataObservable,
|
||||
this.filter,
|
||||
this.paginator.page
|
||||
];
|
||||
|
||||
return merge(...dataMutations).pipe(
|
||||
map((x: any) => {
|
||||
return this.getPagedData(this.getFilteredData([...this.data]));
|
||||
}),
|
||||
tap((x: Product[]) => this.paginator.length = x.length)
|
||||
);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
|
||||
private getFilteredData(data: Product[]): Product[] {
|
||||
const filter = (this.filterValue === undefined) ? '' : this.filterValue;
|
||||
return filter.split(' ').reduce((p: Product[], c: string) => {
|
||||
return p.filter(x => {
|
||||
const productString = (
|
||||
x.code + ' ' + x.name + ' ' + x.units + ' ' + x.productGroup + (x.isActive ? 'active' : 'deactive')
|
||||
).toLowerCase();
|
||||
return productString.indexOf(c) !== -1;
|
||||
}
|
||||
);
|
||||
}, Object.assign([], data));
|
||||
}
|
||||
|
||||
private getPagedData(data: Product[]) {
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
return data.splice(startIndex, this.paginator.pageSize);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,97 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Products</mat-card-title>
|
||||
<button mat-button mat-icon-button *ngIf="dataSource.data.length" (click)="exportCsv()">
|
||||
<mat-icon>save_alt</mat-icon>
|
||||
</button>
|
||||
<a mat-button [routerLink]="['/products', 'new']">
|
||||
<mat-icon>add_box</mat-icon>
|
||||
Add
|
||||
</a>
|
||||
</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>Product Type</mat-label>
|
||||
<mat-select placeholder="Product Group" formControlName="productGroup" (selectionChange)="filterOn(pg.id)">
|
||||
<mat-option>--</mat-option>
|
||||
<mat-option *ngFor="let pg of productGroups" [value]="pg.id">
|
||||
{{ pg.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
|
||||
|
||||
<!-- Name Column -->
|
||||
<ng-container matColumnDef="name">
|
||||
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row"><a [routerLink]="['/products', row.id]">{{row.name}} ({{row.units}})</a></mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Price Column -->
|
||||
<ng-container matColumnDef="price">
|
||||
<mat-header-cell *matHeaderCellDef>Price</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.price | currency:'INR'}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Product Group Column -->
|
||||
<ng-container matColumnDef="productGroup">
|
||||
<mat-header-cell *matHeaderCellDef>Product Group</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.productGroup}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Tax Column -->
|
||||
<ng-container matColumnDef="tax">
|
||||
<mat-header-cell *matHeaderCellDef>Tax</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.tax}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Info Column -->
|
||||
<ng-container matColumnDef="info">
|
||||
<mat-header-cell *matHeaderCellDef>Details</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">
|
||||
<div layout="row">
|
||||
<div flex>
|
||||
<mat-icon>
|
||||
{{ row.hasHappyHour ? "sentiment_satisfied_alt" : "sentiment_dissatisfied" }}
|
||||
</mat-icon>
|
||||
<b> {{ row.hasHappyHour ? "Happy Hour" : "Regular" }}</b>
|
||||
</div>
|
||||
<div flex>
|
||||
<mat-icon>
|
||||
{{ row.isNotAvailable ? "pause" : "play_arrow" }}
|
||||
</mat-icon>
|
||||
<b> {{ row.isNotAvailable ? "Not Available" : "Available" }}</b>
|
||||
</div>
|
||||
<div flex>
|
||||
<mat-icon>
|
||||
{{ row.isActive ? "visibility" : "visibility_off" }}
|
||||
</mat-icon>
|
||||
<b> {{ row.isActive ? "Active" : "Deactivated" }}</b>
|
||||
</div>
|
||||
</div>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Yield Column -->
|
||||
<ng-container matColumnDef="quantity">
|
||||
<mat-header-cell *matHeaderCellDef>Quantity</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.quantity | currency:'INR'}}</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]="5000"
|
||||
[pageSizeOptions]="[25, 50, 100, 250, 5000]">
|
||||
</mat-paginator>
|
||||
</mat-card-content>
|
||||
</mat-card>
|
||||
@ -0,0 +1,23 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ProductListComponent} from './product-list.component';
|
||||
|
||||
describe('ProductListComponent', () => {
|
||||
let component: ProductListComponent;
|
||||
let fixture: ComponentFixture<ProductListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [ProductListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ProductListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should compile', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,59 @@
|
||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { ProductListDataSource } from './product-list-datasource';
|
||||
import { Product } from '../../core/product';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ToCsvService } from "../../shared/to-csv.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-product-list',
|
||||
templateUrl: './product-list.component.html',
|
||||
styleUrls: ['./product-list.component.css']
|
||||
})
|
||||
export class ProductListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||
dataSource: ProductListDataSource;
|
||||
filter: Observable<string> = new Observable<string>();
|
||||
form: FormGroup;
|
||||
list: Product[];
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns: string[] = ['name', 'price', 'productGroup', 'tax', 'info', 'quantity'];
|
||||
|
||||
constructor(private route: ActivatedRoute, private fb: FormBuilder, private toCsv: ToCsvService) {
|
||||
this.form = this.fb.group({
|
||||
productGroup: ''
|
||||
});
|
||||
}
|
||||
filterOn(val: string) {
|
||||
console.log(val);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: Product[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new ProductListDataSource(this.paginator, this.filter, this.list);
|
||||
}
|
||||
|
||||
exportCsv() {
|
||||
const headers = {
|
||||
Code: 'code',
|
||||
Name: 'name',
|
||||
Units: 'units',
|
||||
Price: 'price',
|
||||
ProductGroup: 'productGroup',
|
||||
Tax: 'tax'
|
||||
};
|
||||
|
||||
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.data)], {type: 'text/csv;charset=utf-8;'});
|
||||
const link = document.createElement('a');
|
||||
link.href = window.URL.createObjectURL(csvData);
|
||||
link.setAttribute('download', 'products.csv');
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
}
|
||||
15
bookie/src/app/product/product-resolver.service.spec.ts
Normal file
15
bookie/src/app/product/product-resolver.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ProductResolverService} from './product-resolver.service';
|
||||
|
||||
describe('ProductResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProductDetailResolverService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ProductDetailResolverService], (service: ProductDetailResolverService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
19
bookie/src/app/product/product-resolver.service.ts
Normal file
19
bookie/src/app/product/product-resolver.service.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {ProductService} from './product.service';
|
||||
import {Product} from '../core/product';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ProductResolver implements Resolve<Product> {
|
||||
|
||||
constructor(private ser: ProductService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Product> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
}
|
||||
13
bookie/src/app/product/product-routing.module.spec.ts
Normal file
13
bookie/src/app/product/product-routing.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import {ProductRoutingModule} from './product-routing.module';
|
||||
|
||||
describe('ProductRoutingModule', () => {
|
||||
let productRoutingModule: ProductRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
productRoutingModule = new ProductRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(productRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
66
bookie/src/app/product/product-routing.module.ts
Normal file
66
bookie/src/app/product/product-routing.module.ts
Normal file
@ -0,0 +1,66 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
|
||||
import {ProductListResolver} from './product-list-resolver.service';
|
||||
import {ProductResolver} from './product-resolver.service';
|
||||
import {ProductDetailComponent} from './product-detail/product-detail.component';
|
||||
import {ProductListComponent} from './product-list/product-list.component';
|
||||
|
||||
import {AuthGuard} from '../auth/auth-guard.service';
|
||||
import {ProductGroupListResolver} from '../product-group/product-group-list-resolver.service';
|
||||
|
||||
const productRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: ProductListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Products'
|
||||
},
|
||||
resolve: {
|
||||
list: ProductListResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: ProductDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Products'
|
||||
},
|
||||
resolve: {
|
||||
item: ProductResolver,
|
||||
productGroups: ProductGroupListResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: ProductDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Products'
|
||||
},
|
||||
resolve: {
|
||||
item: ProductResolver,
|
||||
productGroups: ProductGroupListResolver
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(productRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
ProductListResolver,
|
||||
ProductResolver
|
||||
]
|
||||
})
|
||||
export class ProductRoutingModule {
|
||||
}
|
||||
13
bookie/src/app/product/product.module.spec.ts
Normal file
13
bookie/src/app/product/product.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import {ProductModule} from './product.module';
|
||||
|
||||
describe('ProductModule', () => {
|
||||
let productModule: ProductModule;
|
||||
|
||||
beforeEach(() => {
|
||||
productModule = new ProductModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(productModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
47
bookie/src/app/product/product.module.ts
Normal file
47
bookie/src/app/product/product.module.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
import {ProductListComponent} from './product-list/product-list.component';
|
||||
import {ProductDetailComponent} from './product-detail/product-detail.component';
|
||||
import {ProductRoutingModule} from './product-routing.module';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatOptionModule } from '@angular/material/core';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatPaginatorModule } from '@angular/material/paginator';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatSortModule } from '@angular/material/sort';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import {CdkTableModule} from '@angular/cdk/table';
|
||||
import {ReactiveFormsModule} from '@angular/forms';
|
||||
import {FlexLayoutModule} from '@angular/flex-layout';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatTableModule,
|
||||
MatPaginatorModule,
|
||||
MatSortModule,
|
||||
MatCardModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatInputModule,
|
||||
MatButtonModule,
|
||||
MatIconModule,
|
||||
MatOptionModule,
|
||||
MatSelectModule,
|
||||
MatCheckboxModule,
|
||||
ReactiveFormsModule,
|
||||
ProductRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
ProductListComponent,
|
||||
ProductDetailComponent
|
||||
]
|
||||
})
|
||||
export class ProductModule {
|
||||
}
|
||||
15
bookie/src/app/product/product.service.spec.ts
Normal file
15
bookie/src/app/product/product.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {ProductService} from './product.service';
|
||||
|
||||
describe('ProductService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [ProductService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([ProductService], (service: ProductService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
81
bookie/src/app/product/product.service.ts
Normal file
81
bookie/src/app/product/product.service.ts
Normal file
@ -0,0 +1,81 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {Product} from '../core/product';
|
||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
|
||||
const url = '/v1/products';
|
||||
const serviceName = 'ProductService';
|
||||
|
||||
@Injectable({providedIn: 'root'})
|
||||
export class ProductService {
|
||||
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
get(id: string): Observable<Product> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
||||
return <Observable<Product>>this.http.get<Product>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<Product[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(url, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'getList'))
|
||||
);
|
||||
}
|
||||
|
||||
save(product: Product): Observable<Product> {
|
||||
return <Observable<Product>>this.http.post<Product>(`${url}/new`, product, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
}
|
||||
|
||||
update(product: Product): Observable<Product> {
|
||||
return <Observable<Product>>this.http.put<Product>(`${url}/${product.id}`, product, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(product: Product): Observable<Product> {
|
||||
if (!product.id) {
|
||||
return this.save(product);
|
||||
} else {
|
||||
return this.update(product);
|
||||
}
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Product> {
|
||||
return <Observable<Product>>this.http.delete<Product>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
}
|
||||
|
||||
autocomplete(term: string): Observable<Product[]> {
|
||||
const options = {params: new HttpParams().set('t', term)};
|
||||
return <Observable<Product[]>>this.http.get<Product[]>(url, 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,10 +0,0 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { Routes, RouterModule } from '@angular/router';
|
||||
|
||||
const routes: Routes = [];
|
||||
|
||||
@NgModule({
|
||||
imports: [RouterModule.forChild(routes)],
|
||||
exports: [RouterModule]
|
||||
})
|
||||
export class ProductsRoutingModule { }
|
||||
@ -1,13 +0,0 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
|
||||
import { ProductsRoutingModule } from './products-routing.module';
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [
|
||||
CommonModule,
|
||||
ProductsRoutingModule
|
||||
]
|
||||
})
|
||||
export class ProductsModule { }
|
||||
3
bookie/src/app/taxes/tax-detail/tax-detail.component.css
Normal file
3
bookie/src/app/taxes/tax-detail/tax-detail.component.css
Normal file
@ -0,0 +1,3 @@
|
||||
.right-align {
|
||||
text-align: right;
|
||||
}
|
||||
30
bookie/src/app/taxes/tax-detail/tax-detail.component.html
Normal file
30
bookie/src/app/taxes/tax-detail/tax-detail.component.html
Normal file
@ -0,0 +1,30 @@
|
||||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Tax</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>
|
||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||
fxLayoutGap.lt-md="0px">
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Rate</mat-label>
|
||||
<input matInput type="number" placeholder="Rate" formControlName="rate" class="right-align">
|
||||
<span matSuffix>%</span>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button [disabled]="item.isFixture" color="primary" (click)="save()">Save</button>
|
||||
<button mat-raised-button [disabled]="item.isFixture" color="warn" (click)="confirmDelete()" *ngIf="!!item.id">Delete</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
||||
25
bookie/src/app/taxes/tax-detail/tax-detail.component.spec.ts
Normal file
25
bookie/src/app/taxes/tax-detail/tax-detail.component.spec.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {TaxDetailComponent} from './tax-detail.component';
|
||||
|
||||
describe('TaxDetailComponent', () => {
|
||||
let component: TaxDetailComponent;
|
||||
let fixture: ComponentFixture<TaxDetailComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [TaxDetailComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TaxDetailComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
76
bookie/src/app/taxes/tax-detail/tax-detail.component.ts
Normal file
76
bookie/src/app/taxes/tax-detail/tax-detail.component.ts
Normal file
@ -0,0 +1,76 @@
|
||||
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
||||
|
||||
import {TaxService} from '../tax.service';
|
||||
import {Tax} from '../../core/tax';
|
||||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {ToasterService} from '../../core/toaster.service';
|
||||
import {FormBuilder, FormGroup} from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'app-tax-detail',
|
||||
templateUrl: './tax-detail.component.html',
|
||||
styleUrls: ['./tax-detail.component.css']
|
||||
})
|
||||
export class TaxDetailComponent implements OnInit, AfterViewInit {
|
||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||
form: FormGroup;
|
||||
item: Tax;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private ser: TaxService
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
name: '',
|
||||
rate: ''
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: Tax }) => {
|
||||
this.showItem(data.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: Tax) {
|
||||
this.item = item;
|
||||
this.form.setValue({
|
||||
name: this.item.name || '',
|
||||
rate: this.item.rate || ''
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
setTimeout(() => {
|
||||
this.nameElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
save() {
|
||||
this.ser.saveOrUpdate(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigateByUrl('/taxes');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
getItem(): Tax {
|
||||
const formModel = this.form.value;
|
||||
this.item.name = formModel.name;
|
||||
this.item.rate = formModel.rate;
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
15
bookie/src/app/taxes/tax-list-resolver.service.spec.ts
Normal file
15
bookie/src/app/taxes/tax-list-resolver.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {TaxListResolver} from './tax-list-resolver.service';
|
||||
|
||||
describe('TaxListResolverService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [TaxListResolver]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([TaxListResolver], (service: TaxListResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
18
bookie/src/app/taxes/tax-list-resolver.service.ts
Normal file
18
bookie/src/app/taxes/tax-list-resolver.service.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {Tax} from '../core/tax';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {TaxService} from './tax.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TaxListResolver implements Resolve<Tax[]> {
|
||||
|
||||
constructor(private ser: TaxService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Tax[]> {
|
||||
return this.ser.list();
|
||||
}
|
||||
}
|
||||
59
bookie/src/app/taxes/tax-list/tax-list-datasource.ts
Normal file
59
bookie/src/app/taxes/tax-list/tax-list-datasource.ts
Normal file
@ -0,0 +1,59 @@
|
||||
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 {Tax} from '../../core/tax';
|
||||
|
||||
export class TaxListDataSource extends DataSource<Tax> {
|
||||
|
||||
constructor(private paginator: MatPaginator, private sort: MatSort, public data: Tax[]) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<Tax[]> {
|
||||
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: Tax[]) {
|
||||
const startIndex = this.paginator.pageIndex * this.paginator.pageSize;
|
||||
return data.splice(startIndex, this.paginator.pageSize);
|
||||
}
|
||||
|
||||
private getSortedData(data: Tax[]) {
|
||||
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);
|
||||
}
|
||||
41
bookie/src/app/taxes/tax-list/tax-list.component.html
Normal file
41
bookie/src/app/taxes/tax-list/tax-list.component.html
Normal file
@ -0,0 +1,41 @@
|
||||
<mat-card>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Taxes</mat-card-title>
|
||||
<a mat-button [routerLink]="['/taxes', 'new']">
|
||||
<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]="['/taxes', row.id]">{{row.name}}</a></mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Rate Column -->
|
||||
<ng-container matColumnDef="rate">
|
||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Rate</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.rate | percent:'1.2-2'}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Name 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>
|
||||
23
bookie/src/app/taxes/tax-list/tax-list.component.spec.ts
Normal file
23
bookie/src/app/taxes/tax-list/tax-list.component.spec.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {TaxListComponent} from './tax-list.component';
|
||||
|
||||
describe('TaxListComponent', () => {
|
||||
let component: TaxListComponent;
|
||||
let fixture: ComponentFixture<TaxListComponent>;
|
||||
|
||||
beforeEach(fakeAsync(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [TaxListComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(TaxListComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should compile', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
||||
31
bookie/src/app/taxes/tax-list/tax-list.component.ts
Normal file
31
bookie/src/app/taxes/tax-list/tax-list.component.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import {Component, OnInit, ViewChild} from '@angular/core';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
import {TaxListDataSource} from './tax-list-datasource';
|
||||
import {Tax} from '../../core/tax';
|
||||
import {ActivatedRoute} from '@angular/router';
|
||||
|
||||
@Component({
|
||||
selector: 'app-tax-list',
|
||||
templateUrl: './tax-list.component.html',
|
||||
styleUrls: ['./tax-list.component.css']
|
||||
})
|
||||
export class TaxListComponent implements OnInit {
|
||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
||||
@ViewChild(MatSort, { static: true }) sort: MatSort;
|
||||
dataSource: TaxListDataSource;
|
||||
list: Tax[];
|
||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||
displayedColumns = ['name', 'rate', 'isFixture'];
|
||||
|
||||
constructor(private route: ActivatedRoute) {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { list: Tax[] }) => {
|
||||
this.list = data.list;
|
||||
});
|
||||
this.dataSource = new TaxListDataSource(this.paginator, this.sort, this.list);
|
||||
}
|
||||
}
|
||||
15
bookie/src/app/taxes/tax-resolver.service.spec.ts
Normal file
15
bookie/src/app/taxes/tax-resolver.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {TaxResolver} from './tax-resolver.service';
|
||||
|
||||
describe('TaxResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [TaxResolver]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([TaxResolver], (service: TaxResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
19
bookie/src/app/taxes/tax-resolver.service.ts
Normal file
19
bookie/src/app/taxes/tax-resolver.service.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {TaxService} from './tax.service';
|
||||
import {Tax} from '../core/tax';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TaxResolver implements Resolve<Tax> {
|
||||
|
||||
constructor(private ser: TaxService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Tax> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
}
|
||||
15
bookie/src/app/taxes/tax.service.spec.ts
Normal file
15
bookie/src/app/taxes/tax.service.spec.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {TaxService} from './tax.service';
|
||||
|
||||
describe('TaxService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [TaxService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([TaxService], (service: TaxService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
||||
65
bookie/src/app/taxes/tax.service.ts
Normal file
65
bookie/src/app/taxes/tax.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 {Tax} from '../core/tax';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
const url = '/v1/taxes';
|
||||
const serviceName = 'TaxService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class TaxService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
get(id: string): Observable<Tax> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
||||
return <Observable<Tax>>this.http.get<Tax>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<Tax[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<Tax[]>>this.http.get<Tax[]>(url, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
save(tax: Tax): Observable<Tax> {
|
||||
return <Observable<Tax>>this.http.post<Tax>(`${url}/new`, tax, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
}
|
||||
|
||||
update(tax: Tax): Observable<Tax> {
|
||||
return <Observable<Tax>>this.http.put<Tax>(`${url}/${tax.id}`, tax, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(tax: Tax): Observable<Tax> {
|
||||
if (!tax.id) {
|
||||
return this.save(tax);
|
||||
} else {
|
||||
return this.update(tax);
|
||||
}
|
||||
}
|
||||
|
||||
delete(id: string): Observable<Tax> {
|
||||
return <Observable<Tax>>this.http.delete<Tax>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
}
|
||||
}
|
||||
13
bookie/src/app/taxes/taxes-routing.module.spec.ts
Normal file
13
bookie/src/app/taxes/taxes-routing.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import {TaxesRoutingModule} from './taxes-routing.module';
|
||||
|
||||
describe('TaxesRoutingModule', () => {
|
||||
let taxesRoutingModule: TaxesRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
taxesRoutingModule = new TaxesRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(taxesRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
61
bookie/src/app/taxes/taxes-routing.module.ts
Normal file
61
bookie/src/app/taxes/taxes-routing.module.ts
Normal file
@ -0,0 +1,61 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {TaxListResolver} from './tax-list-resolver.service';
|
||||
import {TaxResolver} from './tax-resolver.service';
|
||||
import {TaxListComponent} from './tax-list/tax-list.component';
|
||||
import {TaxDetailComponent} from './tax-detail/tax-detail.component';
|
||||
import {AuthGuard} from '../auth/auth-guard.service';
|
||||
|
||||
const taxesRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: TaxListComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Taxes'
|
||||
},
|
||||
resolve: {
|
||||
list: TaxListResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: TaxDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Taxes'
|
||||
},
|
||||
resolve: {
|
||||
item: TaxResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: TaxDetailComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Taxes'
|
||||
},
|
||||
resolve: {
|
||||
item: TaxResolver
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(taxesRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
TaxListResolver,
|
||||
TaxResolver
|
||||
]
|
||||
})
|
||||
export class TaxesRoutingModule {
|
||||
}
|
||||
13
bookie/src/app/taxes/taxes.module.spec.ts
Normal file
13
bookie/src/app/taxes/taxes.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import {TaxesModule} from './taxes.module';
|
||||
|
||||
describe('TaxesModule', () => {
|
||||
let taxesModule: TaxesModule;
|
||||
|
||||
beforeEach(() => {
|
||||
taxesModule = new TaxesModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(taxesModule).toBeTruthy();
|
||||
});
|
||||
});
|
||||
41
bookie/src/app/taxes/taxes.module.ts
Normal file
41
bookie/src/app/taxes/taxes.module.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
import {TaxListComponent} from './tax-list/tax-list.component';
|
||||
import {TaxDetailComponent} from './tax-detail/tax-detail.component';
|
||||
import {TaxesRoutingModule} from './taxes-routing.module';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
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 {FlexLayoutModule} from '@angular/flex-layout';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatPaginatorModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSortModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
TaxesRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
TaxListComponent,
|
||||
TaxDetailComponent
|
||||
]
|
||||
})
|
||||
export class TaxesModule {
|
||||
}
|
||||
Reference in New Issue
Block a user