Feature:
SectionPrinter is now working Migration: Section, Printers, SectionPrinters working
This commit is contained in:
parent
142a0f5a8a
commit
7b08fe611f
|
@ -16,10 +16,10 @@ call:copyQuery m-Kots "SELECT 'INSERT INTO kots(id, voucher_id, code, food_table
|
|||
call:copyQuery n-Inventories "SELECT 'INSERT INTO inventories(id, kot_id, product_id, sort_order, quantity, price, is_happy_hour, service_charge, is_sc_taxable, service_tax_rate, vat_rate, service_tax_id, vat_id, discount) VALUES (''' + CAST(InventoryID AS Nvarchar(36)) + ''', ' + '''' + CAST(KotID AS Nvarchar(36)) + '''' + ', ' + '''' + CAST(ProductID AS Nvarchar(36)) + '''' + ', ' + CAST(SortOrder AS Nvarchar(36)) + ', ' + CAST(Quantity AS Nvarchar(36)) + ', ' + CAST(Price AS Nvarchar(36)) + ', ' + CASE WHEN IsHappyHour = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(ServiceCharge AS Nvarchar(36)) + ', ' + CASE WHEN IsScTaxable = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(ServiceTaxRate AS Nvarchar(36)) + ', ' + CAST(VatRate AS Nvarchar(36)) + ', ' + '''' + CAST(ServiceTaxID AS Nvarchar(36)) + '''' + ', ' + '''' + CAST(VatID AS Nvarchar(36)) + '''' + ', ' + CAST(Discount AS Nvarchar(36)) + ');' FROM Test.dbo.Inventories;"
|
||||
call:copyQuery o-Modifiers "SELECT 'INSERT INTO modifiers(id, name, show_in_bill, price) VALUES (''' + CAST(ModifierID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Name, '''', '''''') + '''' + ', ' + CASE WHEN ShowInBill = 1 THEN 'true' ELSE 'false' END + ', ' + CAST(Price AS Nvarchar(36)) + ');' FROM Test.dbo.Modifiers;"
|
||||
call:copyQuery p-InventoryModifiers "SELECT 'INSERT INTO inventory_modifiers(id, inventory_id, modifier_id, price) VALUES (''' + CAST(InventoryModifierID AS Nvarchar(36)) + ''', ' + '''' + CAST(InventoryID AS Nvarchar(36)) + '''' + ', ' + '''' + CAST(ModifierID AS Nvarchar(36)) + '''' + ', 0);' FROM Test.dbo.InventoryModifiers;"
|
||||
call:copyQuery q-Locations "SELECT 'INSERT INTO locations(id, name) VALUES (''' + CAST(NewID() AS Nvarchar(36)) + ''', ''' + Location + ''');' FROM Test.dbo.PrintLocations GROUP BY Location;"
|
||||
call:copyQuery q-Sections "SELECT 'INSERT INTO sections(id, name) VALUES (''' + CAST(NewID() AS Nvarchar(36)) + ''', ''' + Location + ''');' FROM Test.dbo.PrintLocations GROUP BY Location;"
|
||||
call:copyQuery r-MachineLocations "SELECT 'INSERT INTO machine_locations(id, machine_name, location_id) SELECT ''' + CAST(MachineLocationID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Machine, '''', '''''') + '''' + ', id from locations where name = ' + '''' + REPLACE(Location, '''', '''''') + '''' + ';' FROM Test.dbo.MachineLocations;"
|
||||
call:copyQuery s-Printers "SELECT 'INSERT INTO printers(id, name, cut_code) VALUES (''' + CAST(NewID() AS Nvarchar(36)) + ''', ''' + Printer + ''', ''' + CutCode + ''');' FROM Test.dbo.PrintLocations GROUP BY Printer, CutCode;"
|
||||
call:copyQuery t-PrintLocations "SELECT 'INSERT INTO print_locations(id, product_group_id, location_id, printer_id, copies) VALUES (''' + CAST(PrintLocationID AS Nvarchar(36)) + ''', ' + COALESCE('''' + CAST(ProductGroupID AS Nvarchar(36)) + '''','null') + ', ' + '(select id from locations where name = ''' + Location + ''')' + ', ' + '(select id from printers where name = ''' + Printer + ''')' + ', ' + CAST(Copies AS nvarchar(36)) + ');' FROM Test.dbo.PrintLocations;"
|
||||
call:copyQuery s-Printers "SELECT 'INSERT INTO printers(id, name, address, cut_code) VALUES (''' + CAST(NewID() AS Nvarchar(36)) + ''', ''' + Printer + ''', ''' + ''' + Printer + ''', ''' + CutCode + ''');' FROM Test.dbo.PrintLocations GROUP BY Printer, CutCode;"
|
||||
call:copyQuery t-SectionPrinters "SELECT 'INSERT INTO section_printers(id, menu_category_id, section_id, printer_id, copies) VALUES (''' + CAST(PrintLocationID AS Nvarchar(36)) + ''', ' + COALESCE('''' + CAST(ProductGroupID AS Nvarchar(36)) + '''','null') + ', ' + '(select id from sections where name = ''' + Location + ''')' + ', ' + '(select id from printers where name = ''' + Printer + ''')' + ', ' + CAST(Copies AS nvarchar(36)) + ');' FROM Test.dbo.PrintLocations;"
|
||||
call:copyQuery u-ProductGroupModifiers "SELECT 'INSERT INTO product_group_modifiers(id, product_group_id, modifier_id, show_automatically) VALUES (''' + CAST(ProductGroupModifierID AS Nvarchar(36)) + ''', ' + COALESCE('''' + CAST(ProductGroupID AS Nvarchar(36)) + '''','null') + ', ' + COALESCE('''' + CAST(ModifierID AS Nvarchar(36)) + '''','null') + ', ' + CASE WHEN ShowAutomatically = 1 THEN 'true' ELSE 'false' END + ');' FROM Test.dbo.ProductGroupModifiers;"
|
||||
call:copyQuery v-Reprints "SELECT 'INSERT INTO reprints(id, user_id, date, voucher_id) VALUES (''' + CAST(ReprintID AS Nvarchar(36)) + ''', ' + '''' + CAST(UserID AS Nvarchar(36)) + '''' + ', ' + '''' + CONVERT(Nvarchar(36), Date, 126) + '''' + ', ' + '''' + CAST(VoucherID AS Nvarchar(36)) + '''' + ');' FROM Test.dbo.Reprints;"
|
||||
call:copyQuery w-Settings "SELECT 'INSERT INTO public.settings(id, name, data) VALUES (''' + CAST(SettingID AS Nvarchar(36)) + ''', ' + '''' + REPLACE(Name, '''', '''''') + '''' + ', ' + '''' + REPLACE(Details, '''', '''''') + '''' + ');' FROM Test.dbo.Settings;"
|
||||
|
|
|
@ -81,6 +81,7 @@ def includeme(config):
|
|||
config.add_route("v1_sections_list", "/v1/sections")
|
||||
|
||||
config.add_route("section_printers", "/section-printers/{section_id}")
|
||||
config.add_route("v1_section_printers_noid", "/v1/section-printers")
|
||||
config.add_route("v1_section_printers", "/v1/section-printers/{section_id}")
|
||||
|
||||
config.add_route("devices_new", "/devices/new")
|
||||
|
|
|
@ -1,21 +1,30 @@
|
|||
import transaction
|
||||
from pyramid.response import Response
|
||||
from sqlalchemy.exc import OperationalError, IntegrityError, DBAPIError
|
||||
import transaction
|
||||
from barker.models.validation_exception import ValidationError
|
||||
|
||||
|
||||
def transactional_view(view, info):
|
||||
if info.options.get('trans'):
|
||||
if info.options.get("trans"):
|
||||
|
||||
def wrapper_view(context, request):
|
||||
try:
|
||||
response = view(context, request)
|
||||
except (
|
||||
ValueError, KeyError, AttributeError, TypeError, OperationalError, IntegrityError, DBAPIError
|
||||
ValidationError,
|
||||
ValueError,
|
||||
KeyError,
|
||||
AttributeError,
|
||||
TypeError,
|
||||
OperationalError,
|
||||
IntegrityError,
|
||||
DBAPIError,
|
||||
) as ex:
|
||||
transaction.abort()
|
||||
response = Response()
|
||||
response.status_int = 500
|
||||
response.content_type = 'application/json'
|
||||
response.json = {'Error': "Failed validation: {0!s}".format(ex)}
|
||||
response.content_type = "application/json"
|
||||
response.json = {"Error": "Failed validation: {0!s}".format(ex)}
|
||||
return response
|
||||
|
||||
return wrapper_view
|
||||
|
@ -26,4 +35,4 @@ def transactional_view(view, info):
|
|||
# return view
|
||||
|
||||
|
||||
transactional_view.options = ('trans',)
|
||||
transactional_view.options = ("trans",)
|
||||
|
|
|
@ -21,15 +21,26 @@ def save(request):
|
|||
json = request.json_body
|
||||
section_id = uuid.UUID(request.matchdict["section_id"])
|
||||
current = []
|
||||
for mcs in json:
|
||||
for mcs in json["menuCategories"]:
|
||||
menu_category = mcs.get("menuCategory", None)
|
||||
menu_category_id = (
|
||||
uuid.UUID(menu_category["id"]) if menu_category is not None else None
|
||||
uuid.UUID(menu_category["id"])
|
||||
if menu_category is not None and menu_category["id"] != ""
|
||||
else None
|
||||
)
|
||||
printer = mcs.get("printer", None)
|
||||
printer_id = uuid.UUID(printer["id"]) if printer is not None else None
|
||||
printer_id = (
|
||||
uuid.UUID(printer["id"])
|
||||
if printer is not None
|
||||
and "id" in printer
|
||||
and printer["id"] is not None
|
||||
and printer["id"] != ""
|
||||
else None
|
||||
)
|
||||
if menu_category_id is None and printer_id is None:
|
||||
raise ValidationError("Please choose a default printer")
|
||||
if printer_id is None:
|
||||
continue
|
||||
try:
|
||||
copies = int(mcs.get("copies", 0))
|
||||
if copies < 1:
|
||||
|
@ -46,8 +57,8 @@ def save(request):
|
|||
copies=copies,
|
||||
)
|
||||
.on_conflict_do_update(
|
||||
constraint=["menu_category_id", "section_id"],
|
||||
set_=dict(printerid=printer_id, copies=copies),
|
||||
index_elements=["menu_category_id", "section_id"],
|
||||
set_=dict(printer_id=printer_id, copies=copies),
|
||||
)
|
||||
)
|
||||
request.dbsession.execute(stmt)
|
||||
|
@ -61,7 +72,7 @@ def save(request):
|
|||
mark_changed(request.dbsession)
|
||||
transaction.commit()
|
||||
|
||||
return report(section_id, request.dbsession)
|
||||
return {"id": section_id, "menuCategories": report(section_id, request.dbsession)}
|
||||
|
||||
|
||||
@view_config(
|
||||
|
@ -76,7 +87,7 @@ def delete(request):
|
|||
SectionPrinter.__table__.delete(SectionPrinter.section_id == section_id)
|
||||
mark_changed(request.dbsession)
|
||||
transaction.commit()
|
||||
return report(section_id, request.dbsession)
|
||||
return {"id": "", "menuCategories": report(section_id, request.dbsession)}
|
||||
|
||||
|
||||
@view_config(
|
||||
|
@ -85,20 +96,28 @@ def delete(request):
|
|||
renderer="json",
|
||||
permission="Authenticated",
|
||||
)
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_section_printers_noid",
|
||||
renderer="json",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_id(request):
|
||||
section_id = uuid.UUID(request.matchdict["section_id"])
|
||||
return report(section_id, request.dbsession)
|
||||
section_id = request.matchdict.get("section_id", None)
|
||||
if section_id is not None:
|
||||
section_id = uuid.UUID(section_id)
|
||||
return {"id": section_id, "menuCategories": report(section_id, request.dbsession)}
|
||||
|
||||
|
||||
@view_config(
|
||||
request_method="GET",
|
||||
route_name="v1_section_printers",
|
||||
renderer="json",
|
||||
request_param="s",
|
||||
request_param="m",
|
||||
permission="Authenticated",
|
||||
)
|
||||
def show_details(request):
|
||||
section_id = uuid.UUID(request.GET["s"])
|
||||
section_id = uuid.UUID(request.matchdict["section_id"])
|
||||
menu_category_id = request.GET.get("m", None)
|
||||
if menu_category_id is not None:
|
||||
menu_category_id = uuid.UUID(menu_category_id)
|
||||
|
@ -115,28 +134,31 @@ def show_details(request):
|
|||
|
||||
def report(section_id, dbsession):
|
||||
menu_categories = (
|
||||
dbsession.query(MenuCategory.id)
|
||||
dbsession.query(MenuCategory.id, MenuCategory.name)
|
||||
.filter(MenuCategory.is_active == True)
|
||||
.order_by(MenuCategory.sort_order)
|
||||
.all()
|
||||
)
|
||||
list_ = []
|
||||
for item in [None] + menu_categories:
|
||||
for item in [(None,)] + menu_categories:
|
||||
mc = (
|
||||
dbsession.query(SectionPrinter)
|
||||
.filter(
|
||||
SectionPrinter.section_id == section_id,
|
||||
SectionPrinter.menu_category_id == id,
|
||||
SectionPrinter.menu_category_id == item[0],
|
||||
)
|
||||
.first()
|
||||
)
|
||||
list_.append(
|
||||
{
|
||||
"menuCategory": {"id": item},
|
||||
"menuCategory": {"id": "", "name": "Default"}
|
||||
if item[0] is None
|
||||
else {"id": item[0], "name": item[1]},
|
||||
"printer": {} if mc is None else {"id": mc.printer_id},
|
||||
"copies": 0 if mc is None else mc.copies,
|
||||
}
|
||||
)
|
||||
return list_
|
||||
|
||||
|
||||
def section_printer_info(item, dbsession):
|
||||
|
|
|
@ -49,6 +49,10 @@ const routes: Routes = [
|
|||
path: 'sections',
|
||||
loadChildren: () => import('./sections/sections.module').then(mod => mod.SectionsModule)
|
||||
},
|
||||
{
|
||||
path: 'section-printers',
|
||||
loadChildren: () => import('./section-printers/section-printers.module').then(mod => mod.SectionPrintersModule)
|
||||
},
|
||||
{
|
||||
path: 'tables',
|
||||
loadChildren: () => import('./tables/tables.module').then(mod => mod.TableModule)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
import {MenuCategory} from "./menu-category";
|
||||
import {Printer} from "./printer";
|
||||
|
||||
export class SectionPrinter {
|
||||
id: string;
|
||||
menuCategories: SectionPrinterItem[];
|
||||
|
||||
public constructor(init?: Partial<SectionPrinter>) {
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
export class SectionPrinterItem {
|
||||
menuCategory: MenuCategory;
|
||||
printer: Printer;
|
||||
copies: number;
|
||||
}
|
|
@ -31,6 +31,9 @@
|
|||
<a mat-raised-button routerLink="/taxes">
|
||||
Taxes
|
||||
</a>
|
||||
<a mat-raised-button routerLink="/section-printers">
|
||||
Section Printers
|
||||
</a>
|
||||
<a mat-raised-button routerLink="/printers">
|
||||
Printers
|
||||
</a>
|
||||
|
|
|
@ -4,7 +4,7 @@ import { ActivatedRoute, Router } from '@angular/router';
|
|||
import { MatDialog } from "@angular/material/dialog";
|
||||
|
||||
import { PrinterService } from '../printer.service';
|
||||
import { Printer } from '../printer';
|
||||
import { Printer } from '../../core/printer';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { ConfirmDialogComponent } from "../../shared/confirm-dialog/confirm-dialog.component";
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {Printer} from './printer';
|
||||
import {Printer} from '../core/printer';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {PrinterService} from './printer.service';
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import {DataSource} from '@angular/cdk/collections';
|
||||
import {Observable, of as observableOf} from 'rxjs';
|
||||
import {Printer} from '../printer';
|
||||
import {Printer} from '../../core/printer';
|
||||
|
||||
export class PrinterListDataSource extends DataSource<Printer> {
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { PrinterListDataSource } from './printer-list-datasource';
|
||||
import { Printer } from '../printer';
|
||||
import { Printer } from '../../core/printer';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot} from '@angular/router';
|
||||
import {PrinterService} from './printer.service';
|
||||
import {Printer} from './printer';
|
||||
import {Printer} from '../core/printer';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
|
||||
@Injectable({
|
||||
|
|
|
@ -3,7 +3,7 @@ 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';
|
||||
import {Printer} from '../core/printer';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
import { DataSource } from '@angular/cdk/collections';
|
||||
import { Observable } from 'rxjs';
|
||||
import { SectionPrinterItem } from "../core/section-printer";
|
||||
|
||||
|
||||
export class SectionPrinterDataSource extends DataSource<SectionPrinterItem> {
|
||||
|
||||
constructor(private data: Observable<SectionPrinterItem[]>) {
|
||||
super();
|
||||
}
|
||||
|
||||
connect(): Observable<SectionPrinterItem[]> {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {SectionPrinterResolver} from './section-printer-resolver.service';
|
||||
|
||||
describe('SectionPrinterResolver', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [SectionPrinterResolver]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([SectionPrinterResolver], (service: SectionPrinterResolver) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -0,0 +1,19 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, Resolve, Router, RouterStateSnapshot } from '@angular/router';
|
||||
import { SectionPrinter } from '../core/section-printer';
|
||||
import { Observable } from 'rxjs';
|
||||
import { SectionPrinterService } from './section-printer.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SectionPrinterResolver implements Resolve<SectionPrinter> {
|
||||
|
||||
constructor(private ser: SectionPrinterService, private router: Router) {
|
||||
}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<SectionPrinter> {
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
.example-card {
|
||||
max-width: 400px;
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<div fxLayout="row" fxFlex="50%" fxLayoutAlign="space-around center" class="example-card">
|
||||
<mat-card fxFlex>
|
||||
<mat-card-title-group>
|
||||
<mat-card-title>Printers for Section</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>Section</mat-label>
|
||||
<mat-select placeholder="Section" formControlName="section" (selectionChange)="show($event)">
|
||||
<mat-option *ngFor="let s of sections" [value]="s.id">
|
||||
{{ s.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<mat-divider></mat-divider>
|
||||
<mat-table #table [dataSource]="dataSource" formArrayName="menuCategories">
|
||||
|
||||
<!-- Menu Category Column -->
|
||||
<ng-container matColumnDef="menuCategory">
|
||||
<mat-header-cell *matHeaderCellDef>Menu Category</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row">{{row.menuCategory.name}}</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Printer Column -->
|
||||
<ng-container matColumnDef="printer">
|
||||
<mat-header-cell *matHeaderCellDef>Printer</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row; let i = index" [formGroupName]="i" fxFlex>
|
||||
<mat-form-field>
|
||||
<mat-label>Printer</mat-label>
|
||||
<mat-select formControlName="printer" name="printer">
|
||||
<mat-option>-- Default --</mat-option>
|
||||
<mat-option *ngFor="let p of printers" [value]="p.id">
|
||||
{{ p.name }}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<!-- Copies Column -->
|
||||
<ng-container matColumnDef="copies">
|
||||
<mat-header-cell *matHeaderCellDef>Copies</mat-header-cell>
|
||||
<mat-cell *matCellDef="let row; let i = index" [formGroupName]="i" fxFlex>
|
||||
<mat-form-field *ngIf="!!form.get('menuCategories').at(i).value.printer">
|
||||
<mat-label>Copies</mat-label>
|
||||
<input matInput type="number" placeholder="Copies" formControlName="copies">
|
||||
</mat-form-field>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||
<mat-row *matRowDef="let row; let i = index; columns: displayedColumns;"></mat-row>
|
||||
</mat-table>
|
||||
</form>
|
||||
</mat-card-content>
|
||||
<mat-card-actions>
|
||||
<button mat-raised-button color="primary" (click)="save()">Save</button>
|
||||
<button mat-raised-button color="warn" *ngIf="id" (click)="confirmDelete()">Delete</button>
|
||||
</mat-card-actions>
|
||||
</mat-card>
|
||||
</div>
|
|
@ -0,0 +1,25 @@
|
|||
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {SectionPrinterComponent} from './section-printer.component';
|
||||
|
||||
describe('SectionPrinterComponent', () => {
|
||||
let component: SectionPrinterComponent;
|
||||
let fixture: ComponentFixture<SectionPrinterComponent>;
|
||||
|
||||
beforeEach(async(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [SectionPrinterComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(SectionPrinterComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,128 @@
|
|||
import { Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Router} from '@angular/router';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { BehaviorSubject, Observable } from "rxjs";
|
||||
import { map } from 'rxjs/operators';
|
||||
import { SectionPrinter } from '../core/section-printer';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { Section } from "../core/section";
|
||||
import { Printer } from "../core/printer";
|
||||
import { SectionPrinterService } from './section-printer.service';
|
||||
import { SectionPrinterDataSource } from "./section-printer-datasource";
|
||||
|
||||
@Component({
|
||||
selector: 'app-section-printer',
|
||||
templateUrl: './section-printer.component.html',
|
||||
styleUrls: ['./section-printer.component.css']
|
||||
})
|
||||
export class SectionPrinterComponent implements OnInit {
|
||||
@ViewChild('section', {static: true}) sectionElement: ElementRef;
|
||||
form: FormGroup;
|
||||
dataSource: SectionPrinterDataSource;
|
||||
public itemObservable = new BehaviorSubject<SectionPrinter>(new SectionPrinter());
|
||||
item: SectionPrinter;
|
||||
sections: Section[];
|
||||
printers: Printer[];
|
||||
|
||||
displayedColumns = ['menuCategory', 'printer', 'copies'];
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private router: Router,
|
||||
private fb: FormBuilder,
|
||||
private toaster: ToasterService,
|
||||
private dialog: MatDialog,
|
||||
private ser: SectionPrinterService
|
||||
) {
|
||||
this.createForm();
|
||||
}
|
||||
|
||||
createForm() {
|
||||
this.form = this.fb.group({
|
||||
section: '',
|
||||
menuCategories: this.fb.array([])
|
||||
});
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { item: SectionPrinter, sections: Section[], printers: Printer[] }) => {
|
||||
this.sections = data.sections;
|
||||
this.printers = data.printers;
|
||||
this.showItem(data.item);
|
||||
this.dataSource = new SectionPrinterDataSource(this.itemObservable.pipe(map(p => p.menuCategories)));
|
||||
this.itemObservable.next(this.item);
|
||||
});
|
||||
}
|
||||
|
||||
showItem(item: SectionPrinter) {
|
||||
this.item = item;
|
||||
this.form.get('section').setValue(this.item.id);
|
||||
this.form.setControl('menuCategories', this.fb.array(
|
||||
this.item.menuCategories.map(
|
||||
x => this.fb.group({
|
||||
menuCategory: x.menuCategory.name,
|
||||
printer: x.printer.id,
|
||||
copies: "" + x.copies
|
||||
})
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
save() {
|
||||
this.ser.save(this.getItem())
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.item.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error.error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete all printers for this section?', content: 'Are you sure? This cannot be undone.'}
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
if (result) {
|
||||
this.delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
getItem(): SectionPrinter {
|
||||
const formModel = this.form.value;
|
||||
this.item.id = formModel.section;
|
||||
const array = this.form.get('menuCategories') as FormArray;
|
||||
this.item.menuCategories.forEach((item, index) => {
|
||||
const cont = array.controls[index].value;
|
||||
item.printer.id = cont.printer;
|
||||
item.copies = +cont.copies;
|
||||
});
|
||||
return this.item;
|
||||
}
|
||||
|
||||
show(val: any) {
|
||||
this.router.navigate(['/section-printers', val.value]);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
import {inject, TestBed} from '@angular/core/testing';
|
||||
|
||||
import {SectionPrinterService} from './section-printer.service';
|
||||
|
||||
describe('SectionPrinterService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [SectionPrinterService]
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject([SectionPrinterService], (service: SectionPrinterService) => {
|
||||
expect(service).toBeTruthy();
|
||||
}));
|
||||
});
|
|
@ -0,0 +1,50 @@
|
|||
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 {SectionPrinter, SectionPrinterItem} from '../core/section-printer';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
const url = '/v1/section-printers';
|
||||
const serviceName = 'SectionPrinterService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SectionPrinterService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
get(id: string): Observable<SectionPrinter> {
|
||||
const getUrl: string = (id === null) ? `${url}` : `${url}/${id}`;
|
||||
return <Observable<SectionPrinter>>this.http.get<SectionPrinter>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
}
|
||||
|
||||
item(id: string, menuCategoryId: string): Observable<SectionPrinterItem> {
|
||||
const options = {params: new HttpParams().set('m', menuCategoryId)};
|
||||
return <Observable<SectionPrinterItem>>this.http.get<SectionPrinterItem>(`${url}/${id}`, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
save(item: SectionPrinter): Observable<SectionPrinter> {
|
||||
return <Observable<SectionPrinter>>this.http.post<SectionPrinter>(`${url}/${item.id}`, item, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
}
|
||||
|
||||
delete(id: string): Observable<SectionPrinter> {
|
||||
return <Observable<SectionPrinter>>this.http.delete<SectionPrinter>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import { SectionPrintersRoutingModule } from './section-printers-routing.module';
|
||||
|
||||
describe('SectionPrintersRoutingModule', () => {
|
||||
let sectionPrintersRoutingModule: SectionPrintersRoutingModule;
|
||||
|
||||
beforeEach(() => {
|
||||
sectionPrintersRoutingModule = new SectionPrintersRoutingModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(sectionPrintersRoutingModule).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,53 @@
|
|||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {RouterModule, Routes} from '@angular/router';
|
||||
import {SectionPrinterResolver} from './section-printer-resolver.service';
|
||||
import {SectionPrinterComponent} from './section-printer.component';
|
||||
import {AuthGuard} from '../auth/auth-guard.service';
|
||||
import {SectionListResolver} from "../sections/section-list-resolver.service";
|
||||
import {PrinterListResolver} from "../printers/printer-list-resolver.service";
|
||||
|
||||
const sectionPrinterRoutes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: SectionPrinterComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Users'
|
||||
},
|
||||
resolve: {
|
||||
item: SectionPrinterResolver,
|
||||
sections: SectionListResolver,
|
||||
printers: PrinterListResolver
|
||||
}
|
||||
},
|
||||
{
|
||||
path: ':id',
|
||||
component: SectionPrinterComponent,
|
||||
canActivate: [AuthGuard],
|
||||
data: {
|
||||
permission: 'Users'
|
||||
},
|
||||
resolve: {
|
||||
item: SectionPrinterResolver,
|
||||
sections: SectionListResolver,
|
||||
printers: PrinterListResolver
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
RouterModule.forChild(sectionPrinterRoutes)
|
||||
|
||||
],
|
||||
exports: [
|
||||
RouterModule
|
||||
],
|
||||
providers: [
|
||||
SectionPrinterResolver
|
||||
]
|
||||
})
|
||||
export class SectionPrintersRoutingModule {
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import { SectionPrintersModule } from './section-printers.module';
|
||||
|
||||
describe('SectionPrintersModule', () => {
|
||||
let sectionPrintersModule: SectionPrintersModule;
|
||||
|
||||
beforeEach(() => {
|
||||
sectionPrintersModule = new SectionPrintersModule();
|
||||
});
|
||||
|
||||
it('should create an instance', () => {
|
||||
expect(sectionPrintersModule).toBeTruthy();
|
||||
});
|
||||
});
|
|
@ -0,0 +1,43 @@
|
|||
import {NgModule} from '@angular/core';
|
||||
import {CommonModule} from '@angular/common';
|
||||
|
||||
import { SectionPrinterComponent } from './section-printer.component';
|
||||
import { SectionPrintersRoutingModule } from './section-printers-routing.module';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||
import { MatDividerModule } from '@angular/material/divider';
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { MatInputModule } from '@angular/material/input';
|
||||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
import { CdkTableModule } from '@angular/cdk/table';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { SharedModule } from '../shared/shared.module';
|
||||
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
CommonModule,
|
||||
CdkTableModule,
|
||||
FlexLayoutModule,
|
||||
MatButtonModule,
|
||||
MatCardModule,
|
||||
MatCheckboxModule,
|
||||
MatDividerModule,
|
||||
MatIconModule,
|
||||
MatInputModule,
|
||||
MatProgressSpinnerModule,
|
||||
MatSelectModule,
|
||||
MatTableModule,
|
||||
ReactiveFormsModule,
|
||||
SharedModule,
|
||||
SectionPrintersRoutingModule
|
||||
],
|
||||
declarations: [
|
||||
SectionPrinterComponent
|
||||
]
|
||||
})
|
||||
export class SectionPrintersModule {
|
||||
}
|
Loading…
Reference in New Issue