Product Error on *ngIf, new a dealbreaker, but not sure.
This commit is contained in:
@ -7,7 +7,10 @@ from sqlalchemy import (
|
|||||||
Numeric,
|
Numeric,
|
||||||
Boolean,
|
Boolean,
|
||||||
ForeignKey,
|
ForeignKey,
|
||||||
Integer, case, JSON)
|
Integer,
|
||||||
|
case,
|
||||||
|
JSON,
|
||||||
|
)
|
||||||
from sqlalchemy.ext.hybrid import hybrid_property
|
from sqlalchemy.ext.hybrid import hybrid_property
|
||||||
from sqlalchemy.orm import relationship
|
from sqlalchemy.orm import relationship
|
||||||
from .meta import Base
|
from .meta import Base
|
||||||
@ -15,13 +18,13 @@ from barker.models.guidtype import GUID
|
|||||||
|
|
||||||
|
|
||||||
class Customer(Base):
|
class Customer(Base):
|
||||||
__tablename__ = 'customers'
|
__tablename__ = "customers"
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
company = Column('company', Unicode(255), nullable=False)
|
company = Column("company", Unicode(255), nullable=False)
|
||||||
name = Column('name', Unicode(255), nullable=False)
|
name = Column("name", Unicode(255), nullable=False)
|
||||||
phone = Column('phone', Unicode(255), nullable=False, unique=True)
|
phone = Column("phone", Unicode(255), nullable=False, unique=True)
|
||||||
address = Column('address', Unicode(255), nullable=False)
|
address = Column("address", Unicode(255), nullable=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __name__(self):
|
def __name__(self):
|
||||||
@ -36,18 +39,18 @@ class Customer(Base):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def cash(cls):
|
def cash(cls):
|
||||||
return uuid.UUID('2c716f4b-0736-429a-ad51-610d7c47cb5e')
|
return uuid.UUID("2c716f4b-0736-429a-ad51-610d7c47cb5e")
|
||||||
|
|
||||||
|
|
||||||
class FoodTable(Base):
|
class FoodTable(Base):
|
||||||
__tablename__ = 'food_tables'
|
__tablename__ = "food_tables"
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column('name', Unicode(255), nullable=False, unique=True)
|
name = Column("name", Unicode(255), nullable=False, unique=True)
|
||||||
location = Column('location', Unicode(255), nullable=False)
|
location = Column("location", Unicode(255), nullable=False)
|
||||||
|
|
||||||
is_active = Column('is_active', Boolean, nullable=False)
|
is_active = Column("is_active", Boolean, nullable=False)
|
||||||
sort_order = Column('sort_order', Numeric, nullable=False)
|
sort_order = Column("sort_order", Numeric, nullable=False)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def __name__(self):
|
def __name__(self):
|
||||||
@ -62,11 +65,11 @@ class FoodTable(Base):
|
|||||||
|
|
||||||
|
|
||||||
class Tax(Base):
|
class Tax(Base):
|
||||||
__tablename__ = 'taxes'
|
__tablename__ = "taxes"
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column('name', Unicode(255), nullable=False, unique=True)
|
name = Column("name", Unicode(255), nullable=False, unique=True)
|
||||||
rate = Column('rate', Numeric, nullable=False)
|
rate = Column("rate", Numeric, nullable=False)
|
||||||
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||||
|
|
||||||
def __init__(self, name=None, rate=None, is_fixture=False, id=None):
|
def __init__(self, name=None, rate=None, is_fixture=False, id=None):
|
||||||
@ -77,19 +80,29 @@ class Tax(Base):
|
|||||||
|
|
||||||
|
|
||||||
class ProductGroup(Base):
|
class ProductGroup(Base):
|
||||||
__tablename__ = 'product_groups'
|
__tablename__ = "product_groups"
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column('name', Unicode(255), nullable=False, unique=True)
|
name = Column("name", Unicode(255), nullable=False, unique=True)
|
||||||
discount_limit = Column('discount_limit', Numeric, nullable=False)
|
discount_limit = Column("discount_limit", Numeric, nullable=False)
|
||||||
is_modifier_compulsory = Column('is_modifier_compulsory', Boolean, nullable=False)
|
is_modifier_compulsory = Column("is_modifier_compulsory", Boolean, nullable=False)
|
||||||
group_type = Column('group_type', Unicode(255), nullable=False)
|
group_type = Column("group_type", Unicode(255), nullable=False)
|
||||||
|
|
||||||
is_active = Column('is_active', Boolean, nullable=False)
|
is_active = Column("is_active", Boolean, nullable=False)
|
||||||
is_fixture = Column('is_fixture', Boolean, nullable=False)
|
is_fixture = Column("is_fixture", Boolean, nullable=False)
|
||||||
sort_order = Column('sort_order', Numeric, nullable=False)
|
sort_order = Column("sort_order", Numeric, nullable=False)
|
||||||
|
|
||||||
def __init__(self, name, discount_limit, is_modifier_compulsory, group_type, is_active, sort_order, is_fixture=False, id=None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
name,
|
||||||
|
discount_limit,
|
||||||
|
is_modifier_compulsory,
|
||||||
|
group_type,
|
||||||
|
is_active,
|
||||||
|
sort_order,
|
||||||
|
is_fixture=False,
|
||||||
|
id=None,
|
||||||
|
):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.discount_limit = discount_limit
|
self.discount_limit = discount_limit
|
||||||
self.is_modifier_compulsory = is_modifier_compulsory
|
self.is_modifier_compulsory = is_modifier_compulsory
|
||||||
@ -101,27 +114,41 @@ class ProductGroup(Base):
|
|||||||
|
|
||||||
|
|
||||||
class Product(Base):
|
class Product(Base):
|
||||||
__tablename__ = 'products'
|
__tablename__ = "products"
|
||||||
__table_args__ = (UniqueConstraint('name', 'units'),)
|
__table_args__ = (UniqueConstraint("name", "units"),)
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column('name', Unicode(255), nullable=False)
|
name = Column("name", Unicode(255), nullable=False)
|
||||||
units = Column('units', Unicode(255), nullable=False)
|
units = Column("units", Unicode(255), nullable=False)
|
||||||
product_group_id = Column('product_group_id', GUID(), ForeignKey('product_groups.id'), nullable=False)
|
product_group_id = Column(
|
||||||
tax_id = Column('tax_id', GUID(), ForeignKey('taxes.id'), nullable=False)
|
"product_group_id", GUID(), ForeignKey("product_groups.id"), nullable=False
|
||||||
price = Column('price', Numeric, nullable=False)
|
)
|
||||||
has_happy_hour = Column('has_happy_hour', Boolean, nullable=False)
|
tax_id = Column("tax_id", GUID(), ForeignKey("taxes.id"), nullable=False)
|
||||||
is_not_available = Column('is_not_available', Boolean, nullable=False)
|
price = Column("price", Numeric, nullable=False)
|
||||||
quantity = Column('quantity', Numeric, nullable=False)
|
has_happy_hour = Column("has_happy_hour", Boolean, nullable=False)
|
||||||
|
is_not_available = Column("is_not_available", Boolean, nullable=False)
|
||||||
|
quantity = Column("quantity", Numeric, nullable=False)
|
||||||
|
|
||||||
is_active = Column('is_active', Boolean, nullable=False)
|
is_active = Column("is_active", Boolean, nullable=False)
|
||||||
sort_order = Column('sort_order', Numeric, nullable=False)
|
sort_order = Column("sort_order", Numeric, nullable=False)
|
||||||
|
|
||||||
product_group = relationship('ProductGroup', backref='products')
|
product_group = relationship("ProductGroup", backref="products")
|
||||||
tax = relationship('Tax', foreign_keys=tax_id)
|
tax = relationship("Tax", foreign_keys=tax_id)
|
||||||
|
|
||||||
def __init__(self, name=None, units=None, product_group_id=None, tax_id=None, price=None,
|
def __init__(
|
||||||
has_happy_hour=None, is_not_available=None, quantity=None, is_active=None, sort_order=None, id=None):
|
self,
|
||||||
|
name=None,
|
||||||
|
units=None,
|
||||||
|
product_group_id=None,
|
||||||
|
tax_id=None,
|
||||||
|
price=None,
|
||||||
|
has_happy_hour=None,
|
||||||
|
is_not_available=None,
|
||||||
|
quantity=None,
|
||||||
|
is_active=None,
|
||||||
|
sort_order=0,
|
||||||
|
id=None,
|
||||||
|
):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.units = units
|
self.units = units
|
||||||
self.product_group_id = product_group_id
|
self.product_group_id = product_group_id
|
||||||
@ -140,25 +167,28 @@ class Product(Base):
|
|||||||
|
|
||||||
@full_name.expression
|
@full_name.expression
|
||||||
def full_name(cls):
|
def full_name(cls):
|
||||||
return cls.name + case([(cls.units != '', ' (' + cls.units + ')')], else_='')
|
return cls.name + case([(cls.units != "", " (" + cls.units + ")")], else_="")
|
||||||
|
|
||||||
def can_delete(self, advanced_delete):
|
def can_delete(self, advanced_delete):
|
||||||
if self.is_fixture:
|
if self.is_fixture:
|
||||||
return False, "{0} is a fixture and cannot be edited or deleted.".format(self.name)
|
return (
|
||||||
|
False,
|
||||||
|
"{0} is a fixture and cannot be edited or deleted.".format(self.name),
|
||||||
|
)
|
||||||
if self.is_active:
|
if self.is_active:
|
||||||
return False, 'Product is active'
|
return False, "Product is active"
|
||||||
if len(self.inventories) > 0 and not advanced_delete:
|
if len(self.inventories) > 0 and not advanced_delete:
|
||||||
return False, 'Product has entries'
|
return False, "Product has entries"
|
||||||
return True, ''
|
return True, ""
|
||||||
|
|
||||||
|
|
||||||
class Modifier(Base):
|
class Modifier(Base):
|
||||||
__tablename__ = 'modifiers'
|
__tablename__ = "modifiers"
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column('name', Unicode(255), nullable=False, unique=True)
|
name = Column("name", Unicode(255), nullable=False, unique=True)
|
||||||
show_in_bill = Column('show_in_bill', Boolean, nullable=False)
|
show_in_bill = Column("show_in_bill", Boolean, nullable=False)
|
||||||
price = Column('price', Numeric, nullable=False)
|
price = Column("price", Numeric, nullable=False)
|
||||||
|
|
||||||
def __init__(self, name=None, show_in_bill=None, price=None, id=None):
|
def __init__(self, name=None, show_in_bill=None, price=None, id=None):
|
||||||
self.id = id
|
self.id = id
|
||||||
@ -168,17 +198,23 @@ class Modifier(Base):
|
|||||||
|
|
||||||
|
|
||||||
class ProductGroupModifier(Base):
|
class ProductGroupModifier(Base):
|
||||||
__tablename__ = 'product_group_modifiers'
|
__tablename__ = "product_group_modifiers"
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
product_group_id = Column('product_group_id', GUID(), ForeignKey('product_groups.id'))
|
product_group_id = Column(
|
||||||
modifier_id = Column('modifier_id', GUID(), ForeignKey('modifiers.id'), nullable=False)
|
"product_group_id", GUID(), ForeignKey("product_groups.id")
|
||||||
show_automatically = Column('show_automatically', Boolean, nullable=False)
|
)
|
||||||
|
modifier_id = Column(
|
||||||
|
"modifier_id", GUID(), ForeignKey("modifiers.id"), nullable=False
|
||||||
|
)
|
||||||
|
show_automatically = Column("show_automatically", Boolean, nullable=False)
|
||||||
|
|
||||||
product_group = relationship('ProductGroup', backref='modifiers')
|
product_group = relationship("ProductGroup", backref="modifiers")
|
||||||
modifier = relationship('Modifier', backref='product_groups')
|
modifier = relationship("Modifier", backref="product_groups")
|
||||||
|
|
||||||
def __init__(self, product_group_id=None, modifier_id=None, show_automatically=None, id=None):
|
def __init__(
|
||||||
|
self, product_group_id=None, modifier_id=None, show_automatically=None, id=None
|
||||||
|
):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.product_group_id = product_group_id
|
self.product_group_id = product_group_id
|
||||||
self.modifier_id = modifier_id
|
self.modifier_id = modifier_id
|
||||||
@ -186,11 +222,11 @@ class ProductGroupModifier(Base):
|
|||||||
|
|
||||||
|
|
||||||
class DbSetting(Base):
|
class DbSetting(Base):
|
||||||
__tablename__ = 'settings'
|
__tablename__ = "settings"
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column('name', Unicode(255), unique=True, nullable=False)
|
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||||
data = Column('data', JSON)
|
data = Column("data", JSON)
|
||||||
|
|
||||||
def __init__(self, id=None, name=None, data=None):
|
def __init__(self, id=None, name=None, data=None):
|
||||||
self.id = id
|
self.id = id
|
||||||
@ -199,10 +235,10 @@ class DbSetting(Base):
|
|||||||
|
|
||||||
|
|
||||||
class Location(Base):
|
class Location(Base):
|
||||||
__tablename__ = 'locations'
|
__tablename__ = "locations"
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column('name', Unicode(255), unique=True, nullable=False)
|
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||||
|
|
||||||
def __init__(self, id=None, name=None):
|
def __init__(self, id=None, name=None):
|
||||||
self.id = id
|
self.id = id
|
||||||
@ -210,13 +246,15 @@ class Location(Base):
|
|||||||
|
|
||||||
|
|
||||||
class MachineLocation(Base):
|
class MachineLocation(Base):
|
||||||
__tablename__ = 'machine_locations'
|
__tablename__ = "machine_locations"
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
machine_name = Column('machine_name', Unicode(255), unique=True, nullable=False)
|
machine_name = Column("machine_name", Unicode(255), unique=True, nullable=False)
|
||||||
location_id = Column('location_id', GUID(), ForeignKey('locations.id'), nullable=False)
|
location_id = Column(
|
||||||
|
"location_id", GUID(), ForeignKey("locations.id"), nullable=False
|
||||||
|
)
|
||||||
|
|
||||||
location = relationship('Location', backref='machines')
|
location = relationship("Location", backref="machines")
|
||||||
|
|
||||||
def __init__(self, machine_name=None, location_id=None, id=None):
|
def __init__(self, machine_name=None, location_id=None, id=None):
|
||||||
self.machine_name = machine_name
|
self.machine_name = machine_name
|
||||||
@ -225,11 +263,11 @@ class MachineLocation(Base):
|
|||||||
|
|
||||||
|
|
||||||
class Printer(Base):
|
class Printer(Base):
|
||||||
__tablename__ = 'printers'
|
__tablename__ = "printers"
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
name = Column('name', Unicode(255), unique=True, nullable=False)
|
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||||
cut_code = Column('cut_code', Unicode(255), nullable=False)
|
cut_code = Column("cut_code", Unicode(255), nullable=False)
|
||||||
|
|
||||||
def __init__(self, id=None, name=None, cut_code=None):
|
def __init__(self, id=None, name=None, cut_code=None):
|
||||||
self.id = id
|
self.id = id
|
||||||
@ -238,18 +276,22 @@ class Printer(Base):
|
|||||||
|
|
||||||
|
|
||||||
class PrintLocation(Base):
|
class PrintLocation(Base):
|
||||||
__tablename__ = 'print_locations'
|
__tablename__ = "print_locations"
|
||||||
__table_args__ = (UniqueConstraint('product_group_id', 'location_id'),)
|
__table_args__ = (UniqueConstraint("product_group_id", "location_id"),)
|
||||||
|
|
||||||
id = Column('id', GUID(), primary_key=True, default=uuid.uuid4)
|
id = Column("id", GUID(), primary_key=True, default=uuid.uuid4)
|
||||||
product_group_id = Column('product_group_id', GUID(), ForeignKey('product_groups.id'))
|
product_group_id = Column(
|
||||||
location_id = Column('location_id', GUID(), ForeignKey('locations.id'), nullable=False)
|
"product_group_id", GUID(), ForeignKey("product_groups.id")
|
||||||
printer_id = Column('printer_id', GUID(), ForeignKey('printers.id'), nullable=False)
|
)
|
||||||
copies = Column('copies', Numeric, nullable=False)
|
location_id = Column(
|
||||||
|
"location_id", GUID(), ForeignKey("locations.id"), nullable=False
|
||||||
|
)
|
||||||
|
printer_id = Column("printer_id", GUID(), ForeignKey("printers.id"), nullable=False)
|
||||||
|
copies = Column("copies", Numeric, nullable=False)
|
||||||
|
|
||||||
product_group = relationship('ProductGroup', backref='print_locations')
|
product_group = relationship("ProductGroup", backref="print_locations")
|
||||||
location = relationship('Location', backref='print_locations')
|
location = relationship("Location", backref="print_locations")
|
||||||
printer = relationship('Printer', backref='print_locations')
|
printer = relationship("Printer", backref="print_locations")
|
||||||
|
|
||||||
def __init__(self, product_group_id, location_id, printer_id, copies):
|
def __init__(self, product_group_id, location_id, printer_id, copies):
|
||||||
self.product_group_id = product_group_id
|
self.product_group_id = product_group_id
|
||||||
@ -259,13 +301,13 @@ class PrintLocation(Base):
|
|||||||
|
|
||||||
|
|
||||||
class SettleOption(Base):
|
class SettleOption(Base):
|
||||||
__tablename__ = 'settle_options'
|
__tablename__ = "settle_options"
|
||||||
|
|
||||||
id = Column('id', Integer, primary_key=True)
|
id = Column("id", Integer, primary_key=True)
|
||||||
name = Column('name', Unicode(255), unique=True, nullable=False)
|
name = Column("name", Unicode(255), unique=True, nullable=False)
|
||||||
show_in_choices = Column('show_in_choices', Boolean, nullable=False)
|
show_in_choices = Column("show_in_choices", Boolean, nullable=False)
|
||||||
group = Column('display_group', Integer, nullable=False)
|
group = Column("display_group", Integer, nullable=False)
|
||||||
is_print = Column('is_print', Boolean, nullable=False)
|
is_print = Column("is_print", Boolean, nullable=False)
|
||||||
|
|
||||||
def __init__(self, name, show_in_choices, group, is_print, id):
|
def __init__(self, name, show_in_choices, group, is_print, id):
|
||||||
self.id = id
|
self.id = id
|
||||||
|
|||||||
@ -55,10 +55,6 @@ def includeme(config):
|
|||||||
config.add_route("v1_product_groups_list", "/v1/product-groups")
|
config.add_route("v1_product_groups_list", "/v1/product-groups")
|
||||||
config.add_route("v1_product_group_types_list", "/v1/product-group-types")
|
config.add_route("v1_product_group_types_list", "/v1/product-group-types")
|
||||||
|
|
||||||
config.add_route('product_group', '/ProductGroup.json')
|
|
||||||
config.add_route('product_group_list', '/ProductGroups.json')
|
|
||||||
config.add_route('product_group_id', '/ProductGroup/{id}.json')
|
|
||||||
|
|
||||||
config.add_route('product_group_type_list', '/ProductGroupTypes.json')
|
config.add_route('product_group_type_list', '/ProductGroupTypes.json')
|
||||||
|
|
||||||
config.add_route('quantity_sold', '/QuantitySold.json')
|
config.add_route('quantity_sold', '/QuantitySold.json')
|
||||||
|
|||||||
@ -9,7 +9,13 @@ from barker.models import Product
|
|||||||
from barker.models.validation_exception import ValidationError
|
from barker.models.validation_exception import ValidationError
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='PUT', route_name='v1_products_new', renderer='json', permission='Products', trans=True)
|
@view_config(
|
||||||
|
request_method="POST",
|
||||||
|
route_name="v1_products_new",
|
||||||
|
renderer="json",
|
||||||
|
permission="Products",
|
||||||
|
trans=True,
|
||||||
|
)
|
||||||
def save(request):
|
def save(request):
|
||||||
json = request.json_body
|
json = request.json_body
|
||||||
|
|
||||||
@ -57,15 +63,20 @@ def save(request):
|
|||||||
has_happy_hour,
|
has_happy_hour,
|
||||||
is_not_available,
|
is_not_available,
|
||||||
quantity,
|
quantity,
|
||||||
is_active
|
is_active,
|
||||||
)
|
)
|
||||||
request.dbsession.add(item)
|
request.dbsession.add(item)
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
item = request.dbsession.query(Product).filter(Product.id == item.id).first()
|
return product_info(item.id, request.dbsession)
|
||||||
return product_info(item)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='POST', route_name='v1_products_id', renderer='json', permission='Products', trans=True)
|
@view_config(
|
||||||
|
request_method="PUT",
|
||||||
|
route_name="v1_products_id",
|
||||||
|
renderer="json",
|
||||||
|
permission="Products",
|
||||||
|
trans=True,
|
||||||
|
)
|
||||||
def update(request):
|
def update(request):
|
||||||
item = (
|
item = (
|
||||||
request.dbsession.query(Product)
|
request.dbsession.query(Product)
|
||||||
@ -76,30 +87,39 @@ def update(request):
|
|||||||
item.name = json["name"].strip()
|
item.name = json["name"].strip()
|
||||||
item.units = json["units"].strip()
|
item.units = json["units"].strip()
|
||||||
item.product_group_id = uuid.UUID(json["productGroup"]["id"])
|
item.product_group_id = uuid.UUID(json["productGroup"]["id"])
|
||||||
item.vat_id = uuid.UUID(json["tax"]["id"])
|
item.tax_id = uuid.UUID(json["tax"]["id"])
|
||||||
try:
|
try:
|
||||||
item.price = Decimal(json["price"])
|
item.price = Decimal(json["price"])
|
||||||
if item.price < 0:
|
if item.price < 0:
|
||||||
raise ValidationError("Price must be a decimal >= 0")
|
raise ValidationError("Price must be a decimal >= 0")
|
||||||
except (ValueError, InvalidOperation):
|
except (ValueError, InvalidOperation):
|
||||||
raise ValidationError("Price must be a decimal >= 0")
|
raise ValidationError("Price must be a decimal >= 0")
|
||||||
item.has_happy_hour = json['hasHappyHour']
|
item.has_happy_hour = json["hasHappyHour"]
|
||||||
item.is_not_available = json['isNotAvailable']
|
item.is_not_available = json["isNotAvailable"]
|
||||||
try:
|
try:
|
||||||
item.quantity = Decimal(json["quantity"])
|
item.quantity = Decimal(json["quantity"])
|
||||||
if item.price < 0:
|
if item.price < 0:
|
||||||
raise ValidationError("Quantity must be a decimal >= 0")
|
raise ValidationError("Quantity must be a decimal >= 0")
|
||||||
except (ValueError, InvalidOperation):
|
except (ValueError, InvalidOperation):
|
||||||
raise ValidationError("Quantity must be a decimal >= 0")
|
raise ValidationError("Quantity must be a decimal >= 0")
|
||||||
item.is_active = json['isActive']
|
item.is_active = json["isActive"]
|
||||||
transaction.commit()
|
transaction.commit()
|
||||||
item = request.dbsession.query(Product).filter(Product.id == item.id).first()
|
return product_info(item.id, request.dbsession)
|
||||||
return product_info(item)
|
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='DELETE', route_name='v1_products_id', renderer='json', permission='Products', trans=True)
|
@view_config(
|
||||||
|
request_method="DELETE",
|
||||||
|
route_name="v1_products_id",
|
||||||
|
renderer="json",
|
||||||
|
permission="Products",
|
||||||
|
trans=True,
|
||||||
|
)
|
||||||
def delete(request):
|
def delete(request):
|
||||||
item = request.dbsession.query(Product).filter(Product.id == uuid.UUID(request.matchdict['id'])).first()
|
item = (
|
||||||
|
request.dbsession.query(Product)
|
||||||
|
.filter(Product.id == uuid.UUID(request.matchdict["id"]))
|
||||||
|
.first()
|
||||||
|
)
|
||||||
if item is None:
|
if item is None:
|
||||||
response = Response("Product not Found")
|
response = Response("Product not Found")
|
||||||
response.status_int = 500
|
response.status_int = 500
|
||||||
@ -110,56 +130,97 @@ def delete(request):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='GET', route_name='v1_products_id', renderer='json', permission='Authenticated')
|
@view_config(
|
||||||
|
request_method="GET",
|
||||||
|
route_name="v1_products_new",
|
||||||
|
renderer="json",
|
||||||
|
permission="Authenticated",
|
||||||
|
)
|
||||||
|
def show_blank(request):
|
||||||
|
return product_info(None, request.dbsession)
|
||||||
|
|
||||||
|
|
||||||
|
@view_config(
|
||||||
|
request_method="GET",
|
||||||
|
route_name="v1_products_id",
|
||||||
|
renderer="json",
|
||||||
|
permission="Authenticated",
|
||||||
|
)
|
||||||
def show_id(request):
|
def show_id(request):
|
||||||
id_ = uuid.UUID(request.matchdict['id'])
|
id_ = uuid.UUID(request.matchdict["id"])
|
||||||
item = request.dbsession.query(Product).filter(Product.id == id_).first()
|
item = request.dbsession.query(Product).filter(Product.id == id_).first()
|
||||||
return product_info(item)
|
return product_info(item.id, request.dbsession)
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='GET', route_name='v1_products_list', renderer='json', permission='Authenticated')
|
@view_config(
|
||||||
|
request_method="GET",
|
||||||
|
route_name="v1_products_list",
|
||||||
|
renderer="json",
|
||||||
|
permission="Authenticated",
|
||||||
|
)
|
||||||
def show_list(request):
|
def show_list(request):
|
||||||
active = request.GET.get('a', None)
|
active = request.GET.get("a", None)
|
||||||
list_ = request.dbsession.query(Product)
|
list_ = request.dbsession.query(Product)
|
||||||
if active is not None:
|
if active is not None:
|
||||||
list_ = list_.filter(Product.is_active == active)
|
list_ = list_.filter(Product.is_active == active)
|
||||||
list_ = list_.order_by(Product.product_group_id, Product.sort_order).order_by(Product.name).all()
|
list_ = (
|
||||||
|
list_.order_by(Product.product_group_id, Product.sort_order)
|
||||||
|
.order_by(Product.name)
|
||||||
|
.all()
|
||||||
|
)
|
||||||
products = []
|
products = []
|
||||||
for item in list_:
|
for item in list_:
|
||||||
products.append(product_info(item))
|
products.append(product_info(item, request.dbsession))
|
||||||
return products
|
return products
|
||||||
|
|
||||||
|
|
||||||
@view_config(request_method='POST', route_name='v1_products_list', renderer='json', permission='Products', trans=True)
|
@view_config(
|
||||||
|
request_method="POST",
|
||||||
|
route_name="v1_products_list",
|
||||||
|
renderer="json",
|
||||||
|
permission="Products",
|
||||||
|
trans=True,
|
||||||
|
)
|
||||||
def sort_order(request):
|
def sort_order(request):
|
||||||
json = request.json_body
|
json = request.json_body
|
||||||
index, last_group = 0, None
|
indexes = {}
|
||||||
for item in json:
|
for item in json:
|
||||||
product_id = uuid.UUID(item['id'])
|
product_id = uuid.UUID(item["id"])
|
||||||
product_group_id = uuid.UUID(item['ProductGroupID'])
|
product_group_id = uuid.UUID(item["productGroup"]["id"])
|
||||||
if last_group != product_group_id:
|
if product_group_id in indexes:
|
||||||
index = 0
|
indexes[product_group_id] += 1
|
||||||
last_group = product_group_id
|
else:
|
||||||
request.dbsession.query(
|
indexes[product_group_id] = 0
|
||||||
Product
|
request.dbsession.query(Product).filter(Product.id == product_id).update(
|
||||||
).filter(
|
{Product.sort_order: indexes[product_group_id]}
|
||||||
Product.id == product_id
|
|
||||||
).update(
|
|
||||||
{Product.sort_order: index}
|
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def product_info(item):
|
def product_info(item, dbsession):
|
||||||
|
if item is None:
|
||||||
|
return {
|
||||||
|
"name": "",
|
||||||
|
"units": "",
|
||||||
|
"productGroup": {},
|
||||||
|
"tax": {},
|
||||||
|
"price": 0,
|
||||||
|
"hasHappyHour": False,
|
||||||
|
"isNotAvailable": False,
|
||||||
|
"isActive": True,
|
||||||
|
"sortOrder": 0,
|
||||||
|
}
|
||||||
|
if type(item) is uuid.UUID:
|
||||||
|
item = dbsession.query(Product).filter(Product.id == item).first()
|
||||||
return {
|
return {
|
||||||
'id': item.id,
|
"id": item.id,
|
||||||
'name': item.name,
|
"name": item.name,
|
||||||
'units': item.units,
|
"units": item.units,
|
||||||
'productGroup': {'id': item.product_group_id, 'name': item.product_group.name},
|
"productGroup": {"id": item.product_group_id, "name": item.product_group.name},
|
||||||
'tax': {'id': item.vat_id, 'name': item.vat.name, 'rate': item.vat.rate},
|
"tax": {"id": item.tax_id, "name": item.tax.name, "rate": item.tax.rate},
|
||||||
'price': item.price,
|
"price": item.price,
|
||||||
'hasHappyHour': item.has_happy_hour,
|
"hasHappyHour": item.has_happy_hour,
|
||||||
'isNotAvailable': item.is_not_available,
|
"isNotAvailable": item.is_not_available,
|
||||||
'isActive': item.is_active,
|
"isActive": item.is_active,
|
||||||
'sortOrder': item.sort_order
|
"sortOrder": item.sort_order,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ const routes: Routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'products',
|
path: 'products',
|
||||||
loadChildren: () => import('./product/product.module').then(mod => mod.ProductModule)
|
loadChildren: () => import('./product/products.module').then(mod => mod.ProductsModule)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'product-groups',
|
path: 'product-groups',
|
||||||
|
|||||||
@ -13,6 +13,9 @@
|
|||||||
<a mat-raised-button routerLink="/product-groups">
|
<a mat-raised-button routerLink="/product-groups">
|
||||||
Product Groups
|
Product Groups
|
||||||
</a>
|
</a>
|
||||||
|
<a mat-raised-button routerLink="/products">
|
||||||
|
Products
|
||||||
|
</a>
|
||||||
<a mat-raised-button routerLink="/taxes">
|
<a mat-raised-button routerLink="/taxes">
|
||||||
Taxes
|
Taxes
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@ -1,15 +1,19 @@
|
|||||||
import { DataSource } from '@angular/cdk/collections';
|
import { DataSource } from '@angular/cdk/collections';
|
||||||
import { Observable, of as observableOf } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { ProductGroup } from '../../core/product-group';
|
import { ProductGroup } from '../../core/product-group';
|
||||||
|
import { tap } from "rxjs/operators";
|
||||||
|
|
||||||
export class ProductGroupListDataSource extends DataSource<ProductGroup> {
|
export class ProductGroupListDataSource extends DataSource<ProductGroup> {
|
||||||
|
private data: ProductGroup[];
|
||||||
constructor(public data: ProductGroup[]) {
|
constructor(private readonly dataObs: Observable<ProductGroup[]>) {
|
||||||
super();
|
super();
|
||||||
|
this.dataObs = dataObs.pipe(
|
||||||
|
tap(x => this.data = x)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(): Observable<ProductGroup[]> {
|
connect(): Observable<ProductGroup[]> {
|
||||||
return observableOf(this.data);
|
return this.dataObs;
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
|
|||||||
@ -1,11 +1,12 @@
|
|||||||
import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { ProductGroupListDataSource } from './product-group-list-datasource';
|
import { ProductGroupListDataSource } from './product-group-list-datasource';
|
||||||
import { ProductGroup } from '../../core/product-group';
|
import { ProductGroup } from '../../core/product-group';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import {CdkDragDrop, moveItemInArray} from "@angular/cdk/drag-drop";
|
import { CdkDragDrop, moveItemInArray } from "@angular/cdk/drag-drop";
|
||||||
import {MatTable} from "@angular/material";
|
import { MatTable } from "@angular/material";
|
||||||
import {ToasterService} from "../../core/toaster.service";
|
import { ToasterService } from "../../core/toaster.service";
|
||||||
import {ProductGroupService} from "../product-group.service";
|
import { ProductGroupService } from "../product-group.service";
|
||||||
|
import { BehaviorSubject } from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-product-group-list',
|
selector: 'app-product-group-list',
|
||||||
@ -16,6 +17,7 @@ export class ProductGroupListComponent implements OnInit {
|
|||||||
@ViewChild('table', { static: true }) table: MatTable<ProductGroup>;
|
@ViewChild('table', { static: true }) table: MatTable<ProductGroup>;
|
||||||
dataSource: ProductGroupListDataSource;
|
dataSource: ProductGroupListDataSource;
|
||||||
list: ProductGroup[];
|
list: ProductGroup[];
|
||||||
|
data: BehaviorSubject<ProductGroup[]>;
|
||||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||||
displayedColumns = ['name', 'discountLimit', 'isModifierCompulsory', 'groupType', 'isActive', 'isFixture'];
|
displayedColumns = ['name', 'discountLimit', 'isModifierCompulsory', 'groupType', 'isActive', 'isFixture'];
|
||||||
|
|
||||||
@ -24,15 +26,19 @@ export class ProductGroupListComponent implements OnInit {
|
|||||||
private router: Router,
|
private router: Router,
|
||||||
private toaster: ToasterService,
|
private toaster: ToasterService,
|
||||||
private ser: ProductGroupService
|
private ser: ProductGroupService
|
||||||
) {
|
) {
|
||||||
}
|
this.data = new BehaviorSubject([]);
|
||||||
|
this.data.subscribe((data: ProductGroup[]) => {
|
||||||
|
this.list = data;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.route.data
|
this.route.data
|
||||||
.subscribe((data: { list: ProductGroup[] }) => {
|
.subscribe((data: { list: ProductGroup[] }) => {
|
||||||
this.list = data.list;
|
this.data.next(data.list);
|
||||||
});
|
});
|
||||||
this.dataSource = new ProductGroupListDataSource(this.list);
|
this.dataSource = new ProductGroupListDataSource(this.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSortOrder() {
|
updateSortOrder() {
|
||||||
@ -47,9 +53,10 @@ export class ProductGroupListComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
dropTable(event: CdkDragDrop<ProductGroup[]>) {
|
dropTable(event: CdkDragDrop<ProductGroup[]>) {
|
||||||
const prevIndex = this.list.indexOf(event.item.data);
|
const prevIndex = this.list.indexOf(event.item.data);
|
||||||
moveItemInArray(this.list, prevIndex, event.currentIndex);
|
moveItemInArray(this.list, prevIndex, event.currentIndex);
|
||||||
this.table.renderRows();
|
this.data.next(this.list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,34 +26,18 @@
|
|||||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||||
fxLayoutGap.lt-md="0px">
|
fxLayoutGap.lt-md="0px">
|
||||||
<mat-form-field fxFlex>
|
<mat-form-field fxFlex>
|
||||||
<mat-label>Fraction</mat-label>
|
<mat-label>Price</mat-label>
|
||||||
<input matInput type="number" placeholder="Fraction" formControlName="fraction">
|
<input matInput type="number" placeholder="Price" formControlName="price">
|
||||||
</mat-form-field>
|
</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-form-field fxFlex>
|
||||||
<mat-label>{{item.isPurchased ? 'Purchase Price' : 'Cost Price' }}</mat-label>
|
<mat-label>Quantity</mat-label>
|
||||||
<input matInput type="number" placeholder="{{item.isPurchased ? 'Purchase Price' : 'Cost Price' }}"
|
<input matInput type="number" placeholder="Quantity" formControlName="quantity">
|
||||||
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>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||||
fxLayoutGap.lt-md="0px">
|
fxLayoutGap.lt-md="0px">
|
||||||
<mat-checkbox formControlName="isPurchased">Is Purchased?</mat-checkbox>
|
<mat-checkbox formControlName="hasHappyHour">Has Happy Hour?</mat-checkbox>
|
||||||
<mat-checkbox formControlName="isSold">Is Sold?</mat-checkbox>
|
<mat-checkbox formControlName="isNotAvailable">Is Not Available?</mat-checkbox>
|
||||||
<mat-checkbox formControlName="isActive">Is Active?</mat-checkbox>
|
<mat-checkbox formControlName="isActive">Is Active?</mat-checkbox>
|
||||||
</div>
|
</div>
|
||||||
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
<div fxLayout="row" fxLayoutAlign="space-around start" fxLayout.lt-md="column" fxLayoutGap="20px"
|
||||||
@ -66,6 +50,14 @@
|
|||||||
</mat-option>
|
</mat-option>
|
||||||
</mat-select>
|
</mat-select>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
<mat-form-field fxFlex>
|
||||||
|
<mat-label>Tax</mat-label>
|
||||||
|
<mat-select placeholder="Tax" formControlName="tax">
|
||||||
|
<mat-option *ngFor="let t of taxes" [value]="t.id">
|
||||||
|
{{ t.name }}
|
||||||
|
</mat-option>
|
||||||
|
</mat-select>
|
||||||
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
|
|||||||
@ -1,12 +1,13 @@
|
|||||||
import {AfterViewInit, Component, ElementRef, OnInit, ViewChild} from '@angular/core';
|
import { AfterViewInit, Component, ElementRef, OnInit, ViewChild } from '@angular/core';
|
||||||
import {ToasterService} from '../../core/toaster.service';
|
import { ToasterService } from '../../core/toaster.service';
|
||||||
import {ActivatedRoute, Router} from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import {ProductService} from '../product.service';
|
import { ProductService } from '../product.service';
|
||||||
import {Product} from '../../core/product';
|
import { Product } from '../../core/product';
|
||||||
import {ProductGroup} from '../../core/product-group';
|
import { ProductGroup } from '../../core/product-group';
|
||||||
import {ConfirmDialogComponent} from '../../shared/confirm-dialog/confirm-dialog.component';
|
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
import {FormBuilder, FormGroup} from '@angular/forms';
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||||
|
import { Tax } from "../../core/tax";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-product-detail',
|
selector: 'app-product-detail',
|
||||||
@ -17,6 +18,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
|||||||
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
@ViewChild('nameElement', { static: true }) nameElement: ElementRef;
|
||||||
form: FormGroup;
|
form: FormGroup;
|
||||||
productGroups: ProductGroup[];
|
productGroups: ProductGroup[];
|
||||||
|
taxes: Tax[];
|
||||||
item: Product;
|
item: Product;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -35,22 +37,21 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
|||||||
code: {value: '', disabled: true},
|
code: {value: '', disabled: true},
|
||||||
name: '',
|
name: '',
|
||||||
units: '',
|
units: '',
|
||||||
fraction: '',
|
productGroup: '',
|
||||||
fractionUnits: '',
|
tax: '',
|
||||||
productYield: '',
|
|
||||||
price: '',
|
price: '',
|
||||||
salePrice: '',
|
hasHappyHour: '',
|
||||||
isPurchased: '',
|
isNotAvailable: '',
|
||||||
isSold: '',
|
quantity: '',
|
||||||
isActive: '',
|
isActive: ''
|
||||||
productGroup: ''
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.route.data
|
this.route.data
|
||||||
.subscribe((data: { item: Product, productGroups: ProductGroup[] }) => {
|
.subscribe((data: { item: Product, productGroups: ProductGroup[], taxes: Tax[] }) => {
|
||||||
this.productGroups = data.productGroups;
|
this.productGroups = data.productGroups;
|
||||||
|
this.taxes = data.taxes;
|
||||||
this.showItem(data.item);
|
this.showItem(data.item);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -64,7 +65,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
|
|||||||
productGroup: this.item.tax.id ? this.item.tax.id : '',
|
productGroup: this.item.tax.id ? this.item.tax.id : '',
|
||||||
tax: this.item.productGroup.id ? this.item.productGroup.id : '',
|
tax: this.item.productGroup.id ? this.item.productGroup.id : '',
|
||||||
price: this.item.price || '',
|
price: this.item.price || '',
|
||||||
hadHappyHour: this.item.hasHappyHour,
|
hasHappyHour: this.item.hasHappyHour,
|
||||||
isNotAvailable: this.item.isNotAvailable,
|
isNotAvailable: this.item.isNotAvailable,
|
||||||
quantity: this.item.quantity || '',
|
quantity: this.item.quantity || '',
|
||||||
isActive: this.item.isActive,
|
isActive: this.item.isActive,
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
import {inject, TestBed} from '@angular/core/testing';
|
import {inject, TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
import {ProductListResolverService} from './product-list-resolver.service';
|
import {ProductListResolver} from './product-list-resolver.service';
|
||||||
|
|
||||||
describe('ProductListResolverService', () => {
|
describe('ProductListResolver', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [ProductListResolverService]
|
providers: [ProductListResolver]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be created', inject([ProductListResolverService], (service: ProductListResolverService) => {
|
it('should be created', inject([ProductListResolver], (service: ProductListResolver) => {
|
||||||
expect(service).toBeTruthy();
|
expect(service).toBeTruthy();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,34 +1,37 @@
|
|||||||
import {DataSource} from '@angular/cdk/collections';
|
import { DataSource } from '@angular/cdk/collections';
|
||||||
import { MatPaginator } from '@angular/material/paginator';
|
import { map, tap } from 'rxjs/operators';
|
||||||
import {map, tap} from 'rxjs/operators';
|
import { merge, Observable } from 'rxjs';
|
||||||
import {merge, Observable, of as observableOf} from 'rxjs';
|
import { Product } from '../../core/product';
|
||||||
import {Product} from '../../core/product';
|
|
||||||
|
|
||||||
|
|
||||||
export class ProductListDataSource extends DataSource<Product> {
|
export class ProductListDataSource extends DataSource<Product> {
|
||||||
private dataObservable: Observable<Product[]>;
|
public data: Product[];
|
||||||
|
public viewData: Product[];
|
||||||
private filterValue: string;
|
private filterValue: string;
|
||||||
|
|
||||||
constructor(private paginator: MatPaginator, private filter: Observable<string>, public data: Product[]) {
|
constructor(private readonly filter: Observable<string>, private readonly dataObs: Observable<Product[]>) {
|
||||||
super();
|
super();
|
||||||
|
this.data = [];
|
||||||
|
this.viewData = [];
|
||||||
this.filter = filter.pipe(
|
this.filter = filter.pipe(
|
||||||
tap(x => this.filterValue = x)
|
tap(x => this.filterValue = x)
|
||||||
);
|
);
|
||||||
|
this.dataObs = dataObs.pipe(
|
||||||
|
tap(x => this.data = x)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(): Observable<Product[]> {
|
connect(): Observable<Product[]> {
|
||||||
this.dataObservable = observableOf(this.data);
|
|
||||||
const dataMutations = [
|
const dataMutations = [
|
||||||
this.dataObservable,
|
this.dataObs,
|
||||||
this.filter,
|
this.filter
|
||||||
this.paginator.page
|
|
||||||
];
|
];
|
||||||
|
|
||||||
return merge(...dataMutations).pipe(
|
return merge(...dataMutations).pipe(
|
||||||
map((x: any) => {
|
map((x: any) => {
|
||||||
return this.getPagedData(this.getFilteredData([...this.data]));
|
this.viewData = this.getFilteredData([...this.data]);
|
||||||
}),
|
return this.viewData;
|
||||||
tap((x: Product[]) => this.paginator.length = x.length)
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,20 +39,10 @@ export class ProductListDataSource extends DataSource<Product> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private getFilteredData(data: Product[]): Product[] {
|
private getFilteredData(data: Product[]): Product[] {
|
||||||
const filter = (this.filterValue === undefined) ? '' : this.filterValue;
|
const filter = (this.filterValue === undefined) ? "" : this.filterValue;
|
||||||
return filter.split(' ').reduce((p: Product[], c: string) => {
|
return data.filter(x => {
|
||||||
return p.filter(x => {
|
return x.productGroup.id === filter || filter === "";
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
<mat-card>
|
<mat-card>
|
||||||
<mat-card-title-group>
|
<mat-card-title-group>
|
||||||
<mat-card-title>Products</mat-card-title>
|
<mat-card-title>Products</mat-card-title>
|
||||||
<button mat-button mat-icon-button *ngIf="dataSource.data.length" (click)="exportCsv()">
|
<button mat-button (click)="updateSortOrder()" [disabled]="!(filter | async)">
|
||||||
|
Update Order
|
||||||
|
</button>
|
||||||
|
<button mat-button mat-icon-button *ngIf="dataSource.viewData.length" (click)="exportCsv()">
|
||||||
<mat-icon>save_alt</mat-icon>
|
<mat-icon>save_alt</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
<a mat-button [routerLink]="['/products', 'new']">
|
<a mat-button [routerLink]="['/products', 'new']">
|
||||||
@ -15,8 +18,8 @@
|
|||||||
fxLayoutGap.lt-md="0px">
|
fxLayoutGap.lt-md="0px">
|
||||||
<mat-form-field fxFlex>
|
<mat-form-field fxFlex>
|
||||||
<mat-label>Product Type</mat-label>
|
<mat-label>Product Type</mat-label>
|
||||||
<mat-select placeholder="Product Group" formControlName="productGroup" (selectionChange)="filterOn(pg.id)">
|
<mat-select placeholder="Product Group" formControlName="productGroup" (selectionChange)="filterOn($event)">
|
||||||
<mat-option>--</mat-option>
|
<mat-option>-- All Products --</mat-option>
|
||||||
<mat-option *ngFor="let pg of productGroups" [value]="pg.id">
|
<mat-option *ngFor="let pg of productGroups" [value]="pg.id">
|
||||||
{{ pg.name }}
|
{{ pg.name }}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
@ -24,7 +27,7 @@
|
|||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements">
|
<mat-table #table cdkDropList [dataSource]="dataSource" [cdkDropListData]="dataSource" aria-label="Elements" (cdkDropListDropped)="dropTable($event)">
|
||||||
|
|
||||||
<!-- Name Column -->
|
<!-- Name Column -->
|
||||||
<ng-container matColumnDef="name">
|
<ng-container matColumnDef="name">
|
||||||
@ -41,13 +44,13 @@
|
|||||||
<!-- Product Group Column -->
|
<!-- Product Group Column -->
|
||||||
<ng-container matColumnDef="productGroup">
|
<ng-container matColumnDef="productGroup">
|
||||||
<mat-header-cell *matHeaderCellDef>Product Group</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef>Product Group</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row">{{row.productGroup}}</mat-cell>
|
<mat-cell *matCellDef="let row">{{row.productGroup.name}}</mat-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Tax Column -->
|
<!-- Tax Column -->
|
||||||
<ng-container matColumnDef="tax">
|
<ng-container matColumnDef="tax">
|
||||||
<mat-header-cell *matHeaderCellDef>Tax</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef>Tax</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row">{{row.tax}}</mat-cell>
|
<mat-cell *matCellDef="let row">{{row.tax.rate | percent:'1.2-2'}} {{row.tax.name}}</mat-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Info Column -->
|
<!-- Info Column -->
|
||||||
@ -84,14 +87,7 @@
|
|||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
|
||||||
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
|
<mat-row *matRowDef="let row; columns: displayedColumns;" cdkDrag [cdkDragData]="row"></mat-row>
|
||||||
</mat-table>
|
</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-content>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
import { Component, OnInit, ViewChild } from '@angular/core';
|
import { Component, OnInit, ViewChild } from '@angular/core';
|
||||||
import { MatPaginator } from '@angular/material/paginator';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { ProductListDataSource } from './product-list-datasource';
|
|
||||||
import { Product } from '../../core/product';
|
|
||||||
import { ActivatedRoute } from '@angular/router';
|
|
||||||
import { FormBuilder, FormGroup } from '@angular/forms';
|
import { FormBuilder, FormGroup } from '@angular/forms';
|
||||||
import { Observable } from 'rxjs';
|
import { CdkDragDrop, moveItemInArray } from "@angular/cdk/drag-drop";
|
||||||
|
import { ProductListDataSource } from './product-list-datasource';
|
||||||
|
import { MatTable } from "@angular/material";
|
||||||
|
import { Product } from '../../core/product';
|
||||||
import { ToCsvService } from "../../shared/to-csv.service";
|
import { ToCsvService } from "../../shared/to-csv.service";
|
||||||
|
import { ToasterService } from "../../core/toaster.service";
|
||||||
|
import { ProductService } from "../product.service";
|
||||||
|
import { ProductGroup } from "../../core/product-group";
|
||||||
|
import { BehaviorSubject } from "rxjs";
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-product-list',
|
selector: 'app-product-list',
|
||||||
@ -13,29 +17,64 @@ import { ToCsvService } from "../../shared/to-csv.service";
|
|||||||
styleUrls: ['./product-list.component.css']
|
styleUrls: ['./product-list.component.css']
|
||||||
})
|
})
|
||||||
export class ProductListComponent implements OnInit {
|
export class ProductListComponent implements OnInit {
|
||||||
@ViewChild(MatPaginator, { static: true }) paginator: MatPaginator;
|
@ViewChild('table', { static: true }) table: MatTable<Product>;
|
||||||
dataSource: ProductListDataSource;
|
dataSource: ProductListDataSource;
|
||||||
filter: Observable<string> = new Observable<string>();
|
filter: BehaviorSubject<string>;
|
||||||
form: FormGroup;
|
form: FormGroup;
|
||||||
list: Product[];
|
list: Product[];
|
||||||
|
data: BehaviorSubject<Product[]>;
|
||||||
|
productGroups: ProductGroup[];
|
||||||
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
|
||||||
displayedColumns: string[] = ['name', 'price', 'productGroup', 'tax', 'info', 'quantity'];
|
displayedColumns: string[] = ['name', 'price', 'productGroup', 'tax', 'info', 'quantity'];
|
||||||
|
|
||||||
constructor(private route: ActivatedRoute, private fb: FormBuilder, private toCsv: ToCsvService) {
|
constructor(
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private fb: FormBuilder,
|
||||||
|
private router: Router,
|
||||||
|
private toaster: ToasterService,
|
||||||
|
private toCsv: ToCsvService,
|
||||||
|
private ser: ProductService
|
||||||
|
) {
|
||||||
this.form = this.fb.group({
|
this.form = this.fb.group({
|
||||||
productGroup: ''
|
productGroup: ''
|
||||||
});
|
});
|
||||||
|
this.filter = new BehaviorSubject("");
|
||||||
|
this.data = new BehaviorSubject([]);
|
||||||
|
this.data.subscribe((data: Product[]) => {
|
||||||
|
this.list = data;
|
||||||
|
})
|
||||||
}
|
}
|
||||||
filterOn(val: string) {
|
|
||||||
console.log(val);
|
filterOn(val: any) {
|
||||||
|
this.filter.next(val.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.route.data
|
this.route.data
|
||||||
.subscribe((data: { list: Product[] }) => {
|
.subscribe((data: { list: Product[], productGroups: ProductGroup[] }) => {
|
||||||
this.list = data.list;
|
this.data.next(data.list);
|
||||||
|
this.productGroups = data.productGroups;
|
||||||
});
|
});
|
||||||
this.dataSource = new ProductListDataSource(this.paginator, this.filter, this.list);
|
this.dataSource = new ProductListDataSource(this.filter, this.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSortOrder() {
|
||||||
|
this.ser.updateSortOrder(this.dataSource.viewData)
|
||||||
|
.subscribe(
|
||||||
|
(result) => {
|
||||||
|
this.toaster.show('Success', '');
|
||||||
|
this.router.navigateByUrl('/products');
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
this.toaster.show('Danger', error.error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
dropTable(event: CdkDragDrop<Product[]>) {
|
||||||
|
const prevIndex = this.list.indexOf(event.item.data);
|
||||||
|
moveItemInArray(this.list, prevIndex, event.currentIndex);
|
||||||
|
this.data.next(this.list);
|
||||||
}
|
}
|
||||||
|
|
||||||
exportCsv() {
|
exportCsv() {
|
||||||
@ -48,7 +87,7 @@ export class ProductListComponent implements OnInit {
|
|||||||
Tax: 'tax'
|
Tax: 'tax'
|
||||||
};
|
};
|
||||||
|
|
||||||
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.data)], {type: 'text/csv;charset=utf-8;'});
|
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.viewData)], {type: 'text/csv;charset=utf-8;'});
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = window.URL.createObjectURL(csvData);
|
link.href = window.URL.createObjectURL(csvData);
|
||||||
link.setAttribute('download', 'products.csv');
|
link.setAttribute('download', 'products.csv');
|
||||||
|
|||||||
@ -1,15 +1,15 @@
|
|||||||
import {inject, TestBed} from '@angular/core/testing';
|
import {inject, TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
import {ProductResolverService} from './product-resolver.service';
|
import {ProductResolver} from './product-resolver.service';
|
||||||
|
|
||||||
describe('ProductResolverService', () => {
|
describe('ProductResolver', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
providers: [ProductDetailResolverService]
|
providers: [ProductResolver]
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be created', inject([ProductDetailResolverService], (service: ProductDetailResolverService) => {
|
it('should be created', inject([ProductResolver], (service: ProductResolver) => {
|
||||||
expect(service).toBeTruthy();
|
expect(service).toBeTruthy();
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
import {ProductRoutingModule} from './product-routing.module';
|
|
||||||
|
|
||||||
describe('ProductRoutingModule', () => {
|
|
||||||
let productRoutingModule: ProductRoutingModule;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
productRoutingModule = new ProductRoutingModule();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create an instance', () => {
|
|
||||||
expect(productRoutingModule).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,66 +0,0 @@
|
|||||||
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 {
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
import {ProductModule} from './product.module';
|
|
||||||
|
|
||||||
describe('ProductModule', () => {
|
|
||||||
let productModule: ProductModule;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
productModule = new ProductModule();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create an instance', () => {
|
|
||||||
expect(productModule).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,9 +1,9 @@
|
|||||||
import {Injectable} from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {Observable} from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import {catchError} from 'rxjs/operators';
|
import { catchError } from 'rxjs/operators';
|
||||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
||||||
import {Product} from '../core/product';
|
import { Product } from '../core/product';
|
||||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||||
|
|
||||||
const httpOptions = {
|
const httpOptions = {
|
||||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||||
@ -48,6 +48,13 @@ export class ProductService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateSortOrder(list: Product[]): Observable<boolean> {
|
||||||
|
return <Observable<boolean>>this.http.post<Product[]>(url, list, httpOptions)
|
||||||
|
.pipe(
|
||||||
|
catchError(this.log.handleError(serviceName, 'updateSortOrder'))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
saveOrUpdate(product: Product): Observable<Product> {
|
saveOrUpdate(product: Product): Observable<Product> {
|
||||||
if (!product.id) {
|
if (!product.id) {
|
||||||
return this.save(product);
|
return this.save(product);
|
||||||
|
|||||||
13
bookie/src/app/product/products-routing.module.spec.ts
Normal file
13
bookie/src/app/product/products-routing.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import {ProductsRoutingModule} from './products-routing.module';
|
||||||
|
|
||||||
|
describe('ProductsRoutingModule', () => {
|
||||||
|
let productsRoutingModule: ProductsRoutingModule;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
productsRoutingModule = new ProductsRoutingModule();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create an instance', () => {
|
||||||
|
expect(productsRoutingModule).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
70
bookie/src/app/product/products-routing.module.ts
Normal file
70
bookie/src/app/product/products-routing.module.ts
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
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';
|
||||||
|
import { TaxListResolver } from "../taxes/tax-list-resolver.service";
|
||||||
|
|
||||||
|
const productRoutes: Routes = [
|
||||||
|
{
|
||||||
|
path: '',
|
||||||
|
component: ProductListComponent,
|
||||||
|
canActivate: [AuthGuard],
|
||||||
|
data: {
|
||||||
|
permission: 'Products'
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
list: ProductListResolver,
|
||||||
|
productGroups: ProductGroupListResolver
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: 'new',
|
||||||
|
component: ProductDetailComponent,
|
||||||
|
canActivate: [AuthGuard],
|
||||||
|
data: {
|
||||||
|
permission: 'Products'
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
item: ProductResolver,
|
||||||
|
productGroups: ProductGroupListResolver,
|
||||||
|
taxes: TaxListResolver
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: ':id',
|
||||||
|
component: ProductDetailComponent,
|
||||||
|
canActivate: [AuthGuard],
|
||||||
|
data: {
|
||||||
|
permission: 'Products'
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
item: ProductResolver,
|
||||||
|
productGroups: ProductGroupListResolver,
|
||||||
|
taxes: TaxListResolver
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
RouterModule.forChild(productRoutes)
|
||||||
|
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
RouterModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
ProductListResolver,
|
||||||
|
ProductResolver
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class ProductsRoutingModule {
|
||||||
|
}
|
||||||
13
bookie/src/app/product/products.module.spec.ts
Normal file
13
bookie/src/app/product/products.module.spec.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import {ProductsModule} from './products.module';
|
||||||
|
|
||||||
|
describe('ProductsModule', () => {
|
||||||
|
let productsModule: ProductsModule;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
productsModule = new ProductsModule();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create an instance', () => {
|
||||||
|
expect(productsModule).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -3,7 +3,7 @@ import {CommonModule} from '@angular/common';
|
|||||||
|
|
||||||
import {ProductListComponent} from './product-list/product-list.component';
|
import {ProductListComponent} from './product-list/product-list.component';
|
||||||
import {ProductDetailComponent} from './product-detail/product-detail.component';
|
import {ProductDetailComponent} from './product-detail/product-detail.component';
|
||||||
import {ProductRoutingModule} from './product-routing.module';
|
import {ProductsRoutingModule} from './products-routing.module';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatCardModule } from '@angular/material/card';
|
import { MatCardModule } from '@angular/material/card';
|
||||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||||
@ -15,14 +15,16 @@ import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
|
|||||||
import { MatSelectModule } from '@angular/material/select';
|
import { MatSelectModule } from '@angular/material/select';
|
||||||
import { MatSortModule } from '@angular/material/sort';
|
import { MatSortModule } from '@angular/material/sort';
|
||||||
import { MatTableModule } from '@angular/material/table';
|
import { MatTableModule } from '@angular/material/table';
|
||||||
import {CdkTableModule} from '@angular/cdk/table';
|
import { CdkTableModule } from '@angular/cdk/table';
|
||||||
import {ReactiveFormsModule} from '@angular/forms';
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
import {FlexLayoutModule} from '@angular/flex-layout';
|
import { FlexLayoutModule } from '@angular/flex-layout';
|
||||||
|
import { DragDropModule } from "@angular/cdk/drag-drop";
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
CommonModule,
|
CommonModule,
|
||||||
CdkTableModule,
|
CdkTableModule,
|
||||||
|
DragDropModule,
|
||||||
FlexLayoutModule,
|
FlexLayoutModule,
|
||||||
MatTableModule,
|
MatTableModule,
|
||||||
MatPaginatorModule,
|
MatPaginatorModule,
|
||||||
@ -36,12 +38,12 @@ import {FlexLayoutModule} from '@angular/flex-layout';
|
|||||||
MatSelectModule,
|
MatSelectModule,
|
||||||
MatCheckboxModule,
|
MatCheckboxModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
ProductRoutingModule
|
ProductsRoutingModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
ProductListComponent,
|
ProductListComponent,
|
||||||
ProductDetailComponent
|
ProductDetailComponent
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class ProductModule {
|
export class ProductsModule {
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user