TODO: Refactor the product and productgroup tables as per the comments added.

rename the product group table to either product category or menu category
move the group_type field from productgroup to products and name it sales category eg. Food, beverage, etc. also, set the tax for sales category and not individual product
Added the printers permission to end of permissions and only for owner, set them right
This commit is contained in:
Amritanshu
2019-06-20 01:59:11 +05:30
parent c51a9bd5ff
commit 16455fdcac
38 changed files with 770 additions and 128 deletions

View File

@ -0,0 +1,3 @@
.right-align {
text-align: right;
}

View File

@ -0,0 +1,33 @@
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
<mat-card fxFlex>
<mat-card-title-group>
<mat-card-title>Printer</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">
</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>Address</mat-label>
<input matInput placeholder="Address" formControlName="address">
</mat-form-field>
<mat-form-field fxFlex>
<mat-label>Cut Code</mat-label>
<input matInput placeholder="Cut code" formControlName="cutCode">
</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>

View File

@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {PrinterDetailComponent} from './printer-detail.component';
describe('PrinterDetailComponent', () => {
let component: PrinterDetailComponent;
let fixture: ComponentFixture<PrinterDetailComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [PrinterDetailComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PrinterDetailComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,108 @@
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { MatDialog } from "@angular/material/dialog";
import { PrinterService } from '../printer.service';
import { Printer } from '../printer';
import { ToasterService } from '../../core/toaster.service';
import { ConfirmDialogComponent } from "../../shared/confirm-dialog/confirm-dialog.component";
@Component({
selector: 'app-printer-detail',
templateUrl: './printer-detail.component.html',
styleUrls: ['./printer-detail.component.css']
})
export class PrinterDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
form: FormGroup;
item: Printer;
constructor(
private route: ActivatedRoute,
private router: Router,
private dialog: MatDialog,
private fb: FormBuilder,
private toaster: ToasterService,
private ser: PrinterService
) {
this.createForm();
}
createForm() {
this.form = this.fb.group({
name: '',
address: '',
cutCode: ''
});
}
ngOnInit() {
this.route.data
.subscribe((data: { item: Printer }) => {
this.showItem(data.item);
});
}
showItem(item: Printer) {
this.item = item;
this.form.setValue({
name: this.item.name || '',
address: this.item.address || '',
cutCode: this.item.cutCode || ''
});
}
ngAfterViewInit() {
setTimeout(() => {
this.nameElement.nativeElement.focus();
}, 0);
}
save() {
this.ser.saveOrUpdate(this.getItem())
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/printers');
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
}
delete() {
this.ser.delete(this.item.id)
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigateByUrl('/printers');
},
(error) => {
this.toaster.show('Danger', error.error);
}
);
}
confirmDelete(): void {
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
width: '250px',
data: {title: 'Delete Printer?', content: 'Are you sure? This cannot be undone.'}
});
dialogRef.afterClosed().subscribe((result: boolean) => {
if (result) {
this.delete();
}
});
}
getItem(): Printer {
const formModel = this.form.value;
this.item.name = formModel.name;
this.item.address = formModel.address;
this.item.cutCode = formModel.cutCode;
return this.item;
}
}

View File

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {PrinterListResolver} from './printer-list-resolver.service';
describe('PrinterListResolverService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [PrinterListResolver]
});
});
it('should be created', inject([PrinterListResolver], (service: PrinterListResolver) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,18 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
import {Printer} from './printer';
import {Observable} from 'rxjs/internal/Observable';
import {PrinterService} from './printer.service';
@Injectable({
providedIn: 'root'
})
export class PrinterListResolver implements Resolve<Printer[]> {
constructor(private ser: PrinterService, private router: Router) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Printer[]> {
return this.ser.list();
}
}

View File

@ -0,0 +1,17 @@
import {DataSource} from '@angular/cdk/collections';
import {Observable, of as observableOf} from 'rxjs';
import {Printer} from '../printer';
export class PrinterListDataSource extends DataSource<Printer> {
constructor(public data: Printer[]) {
super();
}
connect(): Observable<Printer[]> {
return observableOf(this.data);
}
disconnect() {
}
}

View File

@ -0,0 +1,35 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Printers</mat-card-title>
<a mat-button [routerLink]="['/printers', 'new']">
<mat-icon>add_box</mat-icon>
Add
</a>
</mat-card-title-group>
<mat-card-content>
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
<mat-cell *matCellDef="let row"><a [routerLink]="['/printers', row.id]">{{row.name}}</a></mat-cell>
</ng-container>
<!-- Address Column -->
<ng-container matColumnDef="address">
<mat-header-cell *matHeaderCellDef>Address</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.address}}</mat-cell>
</ng-container>
<!-- Cut Code Column -->
<ng-container matColumnDef="cutCode">
<mat-header-cell *matHeaderCellDef>Cut Code</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.cutCode}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
</mat-card-content>
</mat-card>

View File

@ -0,0 +1,23 @@
import {ComponentFixture, fakeAsync, TestBed} from '@angular/core/testing';
import {PrinterListComponent} from './printer-list.component';
describe('PrinterListComponent', () => {
let component: PrinterListComponent;
let fixture: ComponentFixture<PrinterListComponent>;
beforeEach(fakeAsync(() => {
TestBed.configureTestingModule({
declarations: [PrinterListComponent]
})
.compileComponents();
fixture = TestBed.createComponent(PrinterListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should compile', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,27 @@
import { Component, OnInit } from '@angular/core';
import { PrinterListDataSource } from './printer-list-datasource';
import { Printer } from '../printer';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-printer-list',
templateUrl: './printer-list.component.html',
styleUrls: ['./printer-list.component.css']
})
export class PrinterListComponent implements OnInit {
dataSource: PrinterListDataSource;
list: Printer[];
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['name', 'address', 'cutCode'];
constructor(private route: ActivatedRoute) {
}
ngOnInit() {
this.route.data
.subscribe((data: { list: Printer[] }) => {
this.list = data.list;
});
this.dataSource = new PrinterListDataSource(this.list);
}
}

View File

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {PrinterResolver} from './printer-resolver.service';
describe('PrinterResolver', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [PrinterResolver]
});
});
it('should be created', inject([PrinterResolver], (service: PrinterResolver) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,19 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
import {PrinterService} from './printer.service';
import {Printer} from './printer';
import {Observable} from 'rxjs/internal/Observable';
@Injectable({
providedIn: 'root'
})
export class PrinterResolver implements Resolve<Printer> {
constructor(private ser: PrinterService, private router: Router) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Printer> {
const id = route.paramMap.get('id');
return this.ser.get(id);
}
}

View File

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {PrinterService} from './printer.service';
describe('PrinterService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [PrinterService]
});
});
it('should be created', inject([PrinterService], (service: PrinterService) => {
expect(service).toBeTruthy();
}));
});

View 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 {Printer} from './printer';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/v1/printers';
const serviceName = 'PrinterService';
@Injectable({
providedIn: 'root'
})
export class PrinterService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
get(id: string): Observable<Printer> {
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
return <Observable<Printer>>this.http.get<Printer>(getUrl)
.pipe(
catchError(this.log.handleError(serviceName, `get id=${id}`))
);
}
list(): Observable<Printer[]> {
const options = {params: new HttpParams().set('l', '')};
return <Observable<Printer[]>>this.http.get<Printer[]>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
);
}
save(printer: Printer): Observable<Printer> {
return <Observable<Printer>>this.http.post<Printer>(`${url}/new`, printer, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'save'))
);
}
update(printer: Printer): Observable<Printer> {
return <Observable<Printer>>this.http.put<Printer>(`${url}/${printer.id}`, printer, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'update'))
);
}
saveOrUpdate(printer: Printer): Observable<Printer> {
if (!printer.id) {
return this.save(printer);
} else {
return this.update(printer);
}
}
delete(id: string): Observable<Printer> {
return <Observable<Printer>>this.http.delete<Printer>(`${url}/${id}`, httpOptions)
.pipe(
catchError(this.log.handleError(serviceName, 'delete'))
);
}
}

View File

@ -0,0 +1,6 @@
export class Printer {
id: string;
name: string;
address: string;
cutCode: string;
}

View File

@ -0,0 +1,13 @@
import {PrintersRoutingModule} from './printers-routing.module';
describe('PrintersRoutingModule', () => {
let printersRoutingModule: PrintersRoutingModule;
beforeEach(() => {
printersRoutingModule = new PrintersRoutingModule();
});
it('should create an instance', () => {
expect(printersRoutingModule).toBeTruthy();
});
});

View File

@ -0,0 +1,61 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {RouterModule, Routes} from '@angular/router';
import {PrinterListResolver} from './printer-list-resolver.service';
import {PrinterResolver} from './printer-resolver.service';
import {PrinterListComponent} from './printer-list/printer-list.component';
import {PrinterDetailComponent} from './printer-detail/printer-detail.component';
import {AuthGuard} from '../auth/auth-guard.service';
const printersRoutes: Routes = [
{
path: '',
component: PrinterListComponent,
canActivate: [AuthGuard],
data: {
permission: 'Printers'
},
resolve: {
list: PrinterListResolver
}
},
{
path: 'new',
component: PrinterDetailComponent,
canActivate: [AuthGuard],
data: {
permission: 'Printers'
},
resolve: {
item: PrinterResolver
}
},
{
path: ':id',
component: PrinterDetailComponent,
canActivate: [AuthGuard],
data: {
permission: 'Printers'
},
resolve: {
item: PrinterResolver
}
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(printersRoutes)
],
exports: [
RouterModule
],
providers: [
PrinterListResolver,
PrinterResolver
]
})
export class PrintersRoutingModule {
}

View File

@ -0,0 +1,13 @@
import {PrintersModule} from './printers.module';
describe('PrintersModule', () => {
let printersModule: PrintersModule;
beforeEach(() => {
printersModule = new PrintersModule();
});
it('should create an instance', () => {
expect(printersModule).toBeTruthy();
});
});

View File

@ -0,0 +1,37 @@
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {PrinterListComponent} from './printer-list/printer-list.component';
import {PrinterDetailComponent} from './printer-detail/printer-detail.component';
import {PrintersRoutingModule} from './printers-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 { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
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,
MatProgressSpinnerModule,
MatTableModule,
ReactiveFormsModule,
PrintersRoutingModule
],
declarations: [
PrinterListComponent,
PrinterDetailComponent
]
})
export class PrintersModule {
}