End of evening commit, changing supplier to JSONAPI
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
App.ApplicationAdapter = DS.ActiveModelAdapter.extend
|
||||
#App.ApplicationAdapter = DS.ActiveModelAdapter.extend
|
||||
# namespace: 'supplier'
|
||||
# headers:
|
||||
# "Accept": "application/json, text/javascript; q=0.01"
|
||||
App.ApplicationAdapter = DS.JSONAPIAdapter.extend
|
||||
namespace: 'supplier'
|
||||
headers:
|
||||
"Accept": "application/json, text/javascript; q=0.01"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
App.ApplicationSerializer = DS.ActiveModelSerializer
|
||||
#App.ApplicationSerializer = DS.ActiveModelSerializer
|
||||
|
||||
App.ApplicationSerializer = DS.JSONAPISerializer.extend
|
||||
keyForAttribute: (attr, method)-> attr
|
||||
#App.ApplicationStore = DS.Store
|
||||
#adapter: DS.ActiveModelAdapter.extend
|
||||
#namespace: 'supplier'
|
||||
|
||||
@@ -7,17 +7,17 @@ module Suppliers
|
||||
@employee_shifts.select! do |shift|
|
||||
current_supplier.employee_ids.include?(shift.employee.try(:id))
|
||||
end
|
||||
render json: @employee_shifts, each_serializer: Suppliers::EmployeeShiftSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@employee_shifts, serializer: Suppliers::EmployeeShiftSerializer, is_collection: true, include: %w[employee supplier])
|
||||
end
|
||||
def create
|
||||
@employee_shift.supplier = current_supplier
|
||||
@employee_shift.save
|
||||
render json: @employee_shift, serializer: Suppliers::EmployeeShiftSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer, include: %w[employee supplier])
|
||||
end
|
||||
|
||||
def update
|
||||
@employee_shift.update employee_shift_params
|
||||
render json: @employee_shift, serializer: Suppliers::EmployeeShiftSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer)
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
@@ -8,13 +8,13 @@ module Suppliers
|
||||
# GET /employees.json
|
||||
def index
|
||||
@employees = current_supplier.employees
|
||||
render json: @employees, each_serializer: Suppliers::EmployeeSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@employees, serializer: Suppliers::EmployeeSerializer, is_collection: true)
|
||||
end
|
||||
|
||||
# GET /employees/1
|
||||
# GET /employees/1.json
|
||||
def show
|
||||
render json: @employee, serializer: Suppliers::EmployeeSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@employee, serializer: Suppliers::EmployeeSerializer)
|
||||
end
|
||||
|
||||
# POST /employees
|
||||
|
||||
@@ -21,7 +21,16 @@ module Suppliers
|
||||
end
|
||||
@lists.include_relation(:table, :users, orders: {product_orders: :product})
|
||||
|
||||
render json: @lists, each_serializer: Suppliers::ListSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[
|
||||
orders
|
||||
orders.product_orders
|
||||
orders.product_orders.order
|
||||
orders.product_orders.product
|
||||
users
|
||||
join_requests
|
||||
join_requests.user
|
||||
table
|
||||
])
|
||||
end
|
||||
|
||||
|
||||
@@ -47,26 +56,14 @@ module Suppliers
|
||||
@lists = List.for_supplier_created_at current_supplier, @start_time..@end_time
|
||||
@lists.include_relation(:table) # for number
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @lists }
|
||||
end
|
||||
render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[table])
|
||||
end
|
||||
|
||||
# GET /lists/1
|
||||
# GET /lists/1.json
|
||||
def show
|
||||
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
respond_to do |format|
|
||||
format.html {}
|
||||
format.json do
|
||||
if params[:old_style] then
|
||||
render json: @list.with_orders_as_json
|
||||
else
|
||||
render json: @list, serializer: Suppliers::ListSerializer
|
||||
end
|
||||
end
|
||||
end
|
||||
render json: JSONAPI::Serializer.serialize(@list, serializer: Suppliers::ListSerializer)
|
||||
end
|
||||
|
||||
# GET /lists/1/extra_info
|
||||
@@ -83,10 +80,7 @@ module Suppliers
|
||||
@list.section_id = params[:section_id].presence
|
||||
@tables = current_supplier.active_tables
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @list }
|
||||
end
|
||||
render json: @list
|
||||
end
|
||||
|
||||
# POST /lists
|
||||
@@ -95,17 +89,10 @@ module Suppliers
|
||||
@list = List.new(list_params)
|
||||
@list.supplier = current_supplier
|
||||
|
||||
respond_to do |format|
|
||||
if @list.save
|
||||
format.html { redirect_to [:suppliers, @list.section || @list], notice: t('action.create.successfull', model: List.model_name.human) }
|
||||
format.json { render json: @list, status: :created, location: @list }
|
||||
else
|
||||
format.html do
|
||||
@tables = current_supplier.active_tables
|
||||
render action: "new"
|
||||
end
|
||||
format.json { render json: {errors: @list.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @list.save
|
||||
render json: @list
|
||||
else
|
||||
render json: {errors: @list.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -120,14 +107,10 @@ module Suppliers
|
||||
def update
|
||||
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @list.update_attributes(list_params)
|
||||
format.html { redirect_to [:suppliers, @list], notice: t('action.update.successfull', model: List.model_name.human) }
|
||||
format.json { render json: @list }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: {errors: @list.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @list.update_attributes(list_params)
|
||||
render json: @list
|
||||
else
|
||||
render json: {errors: @list.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -136,11 +119,7 @@ module Suppliers
|
||||
def destroy
|
||||
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@list.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to suppliers_lists_url, notice: t('action.destroy.successfull', model: List.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
head :ok
|
||||
end
|
||||
# POST /supplier/lists/1/close
|
||||
def close
|
||||
|
||||
@@ -3,11 +3,11 @@ module Suppliers
|
||||
prepend_before_action :find_page, only: [:show]
|
||||
def index
|
||||
@pages = Page.all_for_suppliers(locale: params[:locale])
|
||||
render json: @pages, each_serializer: Suppliers::PageSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@pages, serializer: Suppliers::PageSerializer, is_collection: true)
|
||||
end
|
||||
|
||||
def show
|
||||
render json: @page, serializer: Suppliers::PageSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@page, serializer: Suppliers::PageSerializer)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -2,13 +2,13 @@ module Suppliers
|
||||
class SectionAreasController < Suppliers::ApplicationController
|
||||
def index
|
||||
@section_areas = SectionArea.for_supplier(current_supplier)
|
||||
render json: @section_areas, each_serializer: Suppliers::SectionAreaSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_areas, serializer: Suppliers::SectionAreaSerializer, is_collection: true)
|
||||
end
|
||||
|
||||
def create
|
||||
@section_area.supplier = current_supplier
|
||||
if @section_area.save
|
||||
render json: @section_area, serializer: Suppliers::SectionAreaSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_area, serializer: Suppliers::SectionAreaSerializer)
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
@@ -16,7 +16,7 @@ module Suppliers
|
||||
|
||||
def update
|
||||
if @section_area.update_attributes section_area_params
|
||||
render json: @section_area, serializer: Suppliers::SectionAreaSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_area, serializer: Suppliers::SectionAreaSerializer)
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
@@ -2,13 +2,13 @@ module Suppliers
|
||||
class SectionElementsController < Suppliers::ApplicationController
|
||||
def index
|
||||
@section_elements = SectionElement.for_supplier(current_supplier)
|
||||
render json: @section_elements, each_serializer: Suppliers::SectionElementSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_elements, serializer: Suppliers::SectionElementSerializer, is_collection: true)
|
||||
end
|
||||
|
||||
def create
|
||||
@section_element.supplier = current_supplier
|
||||
if @section_element.save
|
||||
render json: @section_element, serializer: Suppliers::SectionElementSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_element, serializer: Suppliers::SectionElementSerializer)
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
@@ -16,7 +16,7 @@ module Suppliers
|
||||
|
||||
def update
|
||||
if @section_element.update_attributes section_element_params
|
||||
render json: @section_element, serializer: Suppliers::SectionElementSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@section_element, serializer: Suppliers::SectionElementSerializer)
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ module Suppliers
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
render json: @sections, each_serializer: Suppliers::ExtendedSectionSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@sections, serializer: Suppliers::ExtendedSectionSerializer, is_collection: true)
|
||||
end
|
||||
|
||||
# GET /sections/1
|
||||
@@ -55,14 +55,10 @@ module Suppliers
|
||||
@section = Section.new(section_params)
|
||||
@section.supplier = current_supplier
|
||||
|
||||
respond_to do |format|
|
||||
if @section.save
|
||||
format.html { redirect_to [:suppliers, @section], notice: t('action.create.successfull', model: Section.model_name.human) }
|
||||
format.json { render json: @section, serializer: Suppliers::SectionSerializer, status: :created }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: {errors: @section.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @section.save
|
||||
render json: @section, serializer: Suppliers::SectionSerializer, status: :created
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -71,14 +67,10 @@ module Suppliers
|
||||
def update
|
||||
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @section.update_attributes(section_params)
|
||||
format.html { redirect_to [:suppliers, @section], notice: t('action.update.successfull', model: Section.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: {errors: @section.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @section.update_attributes(section_params)
|
||||
head :ok
|
||||
else
|
||||
render json: {errors: @section.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -88,10 +80,7 @@ module Suppliers
|
||||
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@section.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to suppliers_sections_url, notice: t('action.destroy.successfull', model: Section.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
head :ok
|
||||
end
|
||||
|
||||
# GET /sections/1/manage_tables
|
||||
@@ -99,10 +88,7 @@ module Suppliers
|
||||
def manage_tables
|
||||
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @section }
|
||||
end
|
||||
render json: @section
|
||||
end
|
||||
|
||||
# GET /sections/1/tables_view
|
||||
@@ -111,12 +97,7 @@ module Suppliers
|
||||
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@tables = @section.tables_with_active_list_id
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json do
|
||||
render json: @section.for_tables_as_json
|
||||
end
|
||||
end
|
||||
render json: @section
|
||||
end
|
||||
|
||||
# POST /sections/1/add_tables {number_start: 1423, number_end: 234234}
|
||||
@@ -134,8 +115,7 @@ module Suppliers
|
||||
added_tables << table
|
||||
end
|
||||
@section.arrange_tables_in_grid added_tables
|
||||
table_json = ActiveModel::ArraySerializer.new(@section.tables, each_serializer: SupplierTableSerializer, root: false).as_json
|
||||
render json: {tables: table_json}
|
||||
render json: JSONAPI::Serializer.serialize(@section.tables, serializer: Supplier::TableSerializer, is_collection: true, include: %w[section])
|
||||
end
|
||||
|
||||
# POST /sections/1/arrange_tables {number_start: 1423, number_end: 234234}
|
||||
|
||||
@@ -6,13 +6,13 @@ module Suppliers
|
||||
|
||||
def show
|
||||
[current_supplier].include_relations(sections: :tables, product_categories: {products: :product_variants})
|
||||
render json: current_supplier, serializer: Suppliers::SupplierSerializer #.new(current_supplier).as_json
|
||||
render json: JSONAPI::Serializer.serialize(current_supplier, serializer: Suppliers::SupplierSerializer) #.new(current_supplier).as_json
|
||||
end
|
||||
|
||||
def update
|
||||
@supplier = current_supplier
|
||||
current_supplier.update_attributes(supplier_params)
|
||||
render json: Suppliers::SupplierSerializer.new(current_supplier).as_json
|
||||
render json: JSONAPI::Serializer.serialize( current_supplier, serializer: Suppliers::SupplierSerializer)
|
||||
end
|
||||
|
||||
def switch_to
|
||||
|
||||
@@ -2,7 +2,7 @@ module Suppliers
|
||||
class SvgElementsController < Suppliers::ApplicationController
|
||||
def index
|
||||
@svg_elements = SvgElement.active
|
||||
render json: @svg_elements, each_serializer: Suppliers::SvgElementSerializer
|
||||
render json: JSONAPI::Serializer.serialize(@svg_elements, serializer: Suppliers::SvgElementSerializer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,10 +6,7 @@ module Suppliers
|
||||
@tables = Table.for_supplier(current_supplier, page: params[:page], per_page: params[:per_page] || 25, from_number: params[:from_number], to_number: params[:to_number])
|
||||
@tables.include_relation(:section)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @tables }
|
||||
end
|
||||
render json: @tables
|
||||
end
|
||||
|
||||
# GET /tables/1
|
||||
@@ -17,10 +14,7 @@ module Suppliers
|
||||
def show
|
||||
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @table }
|
||||
end
|
||||
render json: @table
|
||||
end
|
||||
|
||||
# GET /tables/new
|
||||
@@ -29,10 +23,7 @@ module Suppliers
|
||||
@table = Table.new
|
||||
@table.section_id = params[:section_id].presence
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @table }
|
||||
end
|
||||
render json: @table
|
||||
end
|
||||
|
||||
# GET /tables/1/edit
|
||||
@@ -46,14 +37,10 @@ module Suppliers
|
||||
@table = Table.new(table_params)
|
||||
@table.supplier = current_supplier
|
||||
|
||||
respond_to do |format|
|
||||
if @table.save
|
||||
format.html { redirect_to [:suppliers, @table.section || @table], notice: t('action.create.successfull', model: Table.model_name.human) }
|
||||
format.json { render json: @table, status: :created }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: {errors: @table.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @table.save
|
||||
render json: @table, status: :created
|
||||
else
|
||||
render json: {errors: @table.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -62,14 +49,10 @@ module Suppliers
|
||||
def update
|
||||
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @table.update_attributes(table_params)
|
||||
format.html { redirect_to [:suppliers, @table.section || @table], notice: t('action.update.successfull', model: Table.model_name.human) }
|
||||
format.json { render json: @table }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: {errors: @table.errors}, status: :unprocessable_entity }
|
||||
end
|
||||
if @table.update_attributes(table_params)
|
||||
render json: @table
|
||||
else
|
||||
render json: {errors: @table.errors}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
@@ -79,10 +62,7 @@ module Suppliers
|
||||
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
|
||||
@table.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to suppliers_tables_url, notice: t('action.destroy.successfull', model: Table.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
head :ok
|
||||
end
|
||||
|
||||
def qr_codes
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
class OrderSerializer < Qwaiter::Serializer
|
||||
attributes :state, :list_id, :section_id, :table_id #, :price
|
||||
|
||||
has_many :product_orders
|
||||
|
||||
end
|
||||
@@ -1,4 +0,0 @@
|
||||
# Used for user ember1
|
||||
class ProductOrderSerializer < Qwaiter::Serializer
|
||||
attributes :quantity, :price, :product_name, :product_variant
|
||||
end
|
||||
@@ -1,14 +0,0 @@
|
||||
class ProductSerializer < Qwaiter::Serializer
|
||||
root 'product'
|
||||
attributes :name, :price, :description, :image, :code, :position, :visible, :active, :product_category_id
|
||||
|
||||
has_many :product_variants
|
||||
|
||||
def image
|
||||
if object.image.present?
|
||||
{small: object.image.url(:small)}
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,3 +1,4 @@
|
||||
class Suppliers::EmployeeSerializer < Qwaiter::Serializer
|
||||
class Suppliers::EmployeeSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :name, :email, :manager, :active, :color
|
||||
end
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
class Suppliers::EmployeeShiftSerializer < Qwaiter::Serializer
|
||||
self.root = :employee_shift
|
||||
#embed :ids, include: true
|
||||
class Suppliers::EmployeeShiftSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :start_from, :end_on, :employee_id, :supplier_id
|
||||
#has_one :supplier
|
||||
has_one :supplier, serializer: Suppliers::SupplierSerializer
|
||||
end
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
class Suppliers::ExtendedSectionSerializer < Qwaiter::Serializer
|
||||
root 'section'
|
||||
attributes :title, :path, :width, :height
|
||||
has_many :tables, serializer: Suppliers::ExtendedTableSerializer
|
||||
end
|
||||
#class Suppliers::ExtendedSectionSerializer < Qwaiter::Serializer
|
||||
# attributes :title, :path, :width, :height
|
||||
# has_many :tables, serializer: Suppliers::TableSerializer
|
||||
#end
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
class Suppliers::ExtendedTableSerializer < Qwaiter::Serializer
|
||||
root :table
|
||||
attributes :number, :width, :height, :position_x, :position_y, :section_id#, :active_list_id
|
||||
|
||||
#def list_id
|
||||
#object.active_list_id || object.active_list.try(:id)
|
||||
#end
|
||||
|
||||
#def list
|
||||
#object.active_list
|
||||
#end
|
||||
|
||||
#has_one :list, key: :active_list_id, serializer: SupplierExtendedListSerializer
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class Suppliers::JoinRequestSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
has_one :user, serializer: Suppliers::SupplierSerializer
|
||||
has_one :list, serializer: Suppliers::ListSerializer
|
||||
end
|
||||
@@ -1,18 +1,9 @@
|
||||
class Suppliers::ListSerializer < Qwaiter::Serializer
|
||||
# user ids for facebook pictures
|
||||
self.root = :list
|
||||
attributes :extended_version, :state, :needs_help, :needs_payment, :user_requests_closing, :is_paid, :price,
|
||||
:table_id, :table_number, :section_id, :user_ids, :supplier_id, :closed_at
|
||||
has_many :orders
|
||||
#has_many :product_categories
|
||||
#has_one :table, serializer: SupplierTableSerializer # tables are part of the sectoins load
|
||||
has_many :join_requests
|
||||
has_many :users, serializer: Suppliers::UserSerializer
|
||||
class Suppliers::ListSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :state, :needs_help, :needs_payment, :user_requests_closing, :is_paid, :price, :closed_at
|
||||
|
||||
#def has_active_orders
|
||||
#object.has_active_orders?
|
||||
#end
|
||||
def extended_version
|
||||
true
|
||||
end
|
||||
has_many :orders, serializer: Suppliers::OrderSerializer
|
||||
has_many :join_requests, serializer: Suppliers::JoinRequestSerializer
|
||||
has_many :users, serializer: Suppliers::UserSerializer
|
||||
has_one :table, serializer: Suppliers::TableSerializer
|
||||
end
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Suppliers::OrderSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :state #, :list_id, :section_id, :table_id #, :price
|
||||
|
||||
has_one :list, serializer: Suppliers::ListSerializer
|
||||
has_many :product_orders, serializer: Suppliers::ProductOrderSerializer
|
||||
|
||||
end
|
||||
@@ -1,11 +1,6 @@
|
||||
class Suppliers::PageSerializer < Qwaiter::Serializer
|
||||
self.root = :page
|
||||
attributes :name, :title, :body, :locale, :position
|
||||
def name
|
||||
object.name.to_s.sub /^suppliers-/, ''
|
||||
end
|
||||
|
||||
def id
|
||||
name
|
||||
end
|
||||
class Suppliers::PageSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :title, :body, :locale, :position
|
||||
attribute(:name) { object.name.to_s.sub /^suppliers-/, '' }
|
||||
attribute(:id) { object.name.to_s.sub /^suppliers-/, '' }
|
||||
end
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
class ProductCategorySerializer < Qwaiter::Serializer
|
||||
class Suppliers::ProductCategorySerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :name, :supplier_id, :active_on_sunday, :active_on_monday, :active_on_tuesday, :active_on_wednesday,
|
||||
:active_on_thursday, :active_on_friday, :active_on_saturday, :full_day, :start_from, :end_on,
|
||||
:position
|
||||
has_many :products
|
||||
has_many :products, serializer: Suppliers::ProductSerializer
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class Suppliers::ProductOrderSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :quantity, :price, :product_name, :product_variant
|
||||
has_one :order, serializer: Suppliers::OrderSerializer
|
||||
has_one :product, serializer: Suppliers::ProductSerializer
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class Suppliers::ProductSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :name, :price, :description, :code, :position, :visible, :active, :product_category_id
|
||||
attribute :image do
|
||||
if object.image.present?
|
||||
{small: object.image.url(:small)}
|
||||
else
|
||||
{small: object.image.url}
|
||||
end
|
||||
end
|
||||
|
||||
has_many :product_variants, serializer: Suppliers::ProductVariantSerializer
|
||||
end
|
||||
@@ -1,3 +1,5 @@
|
||||
class Suppliers::SectionAreaSerializer < Qwaiter::Serializer
|
||||
attributes :title, :width, :height, :position_x, :position_y, :section_id, :rounded
|
||||
class Suppliers::SectionAreaSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :title, :width, :height, :position_x, :position_y, :rounded
|
||||
has_one :section, serializer: Suppliers::SectionSerializer
|
||||
end
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
class Suppliers::SectionElementSerializer < Qwaiter::Serializer
|
||||
attributes :name, :box_width, :box_height, :dpm, :svg, :position_x, :position_y, :rotation, :section_id
|
||||
attributes :name, :box_width, :box_height, :dpm, :svg, :position_x, :position_y, :rotation
|
||||
has_one :section, serializer: Suppliers::SectionSerializer
|
||||
end
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Suppliers::SectionSerializer < Qwaiter::Serializer
|
||||
root :section
|
||||
class Suppliers::SectionSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :title, :path, :width, :height
|
||||
end
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
class Suppliers::SupplierSerializer < Qwaiter::Serializer
|
||||
self.root = :supplier
|
||||
attributes :extended_version, :open, :name, :email, :lat, :lng, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country,
|
||||
class Suppliers::SupplierSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :open, :name, :email, :lat, :lng, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country,
|
||||
:facebook_promotion_url, :iens_profile, :week_starts_on_monday, :orders_in_process_count, :orders_placed_count
|
||||
|
||||
def extended_version
|
||||
true
|
||||
end
|
||||
has_many :sections, serializer: Suppliers::ExtendedSectionSerializer
|
||||
has_many :product_categories
|
||||
has_many :sections, serializer: Suppliers::SectionSerializer
|
||||
has_many :product_categories, serializer: Suppliers::ProductCategorySerializer
|
||||
has_many :employees, serializer: Suppliers::EmployeeSerializer
|
||||
end
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
class Suppliers::SvgElementSerializer < Qwaiter::Serializer
|
||||
class Suppliers::SvgElementSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :name, :box_width, :box_height, :dpm, :svg
|
||||
end
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
class Suppliers::TableSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :number, :width, :height, :position_x, :position_y, :section_id#, :active_list_id
|
||||
end
|
||||
@@ -1,12 +1,5 @@
|
||||
class Suppliers::UserSerializer < Qwaiter::Serializer
|
||||
self.root = :user
|
||||
attributes :email, :provider, :uid, :name, :avatar, :list_id
|
||||
|
||||
def list_id
|
||||
object.active_list_id
|
||||
end
|
||||
|
||||
def name
|
||||
object.supplier_name
|
||||
end
|
||||
class Suppliers::UserSerializer
|
||||
include Qwaiter::SupplierBaseSerializer
|
||||
attributes :email, :provider, :uid, :avatar
|
||||
attribute(:name) { object.supplier_name }
|
||||
end
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//var $locale = '<%= I18n.locale %>';
|
||||
//var supplier_id = '<%= current_supplier.id %>';
|
||||
var supplier_object=<%= {id: current_supplier.id}.to_json.html_safe %>;
|
||||
var employee_object=<%=raw Suppliers::EmployeeSerializer.new(current_employee, root: false).to_json %>;
|
||||
var employee_object=<%=raw current_employee.attributes.merge(id: current_employee.id).to_json %>;
|
||||
var data_host = '';
|
||||
var $asset_path = '/assets/';
|
||||
var event_host = '<%= Qwaiter.event_host %>';
|
||||
|
||||
@@ -5,6 +5,7 @@ module Qwaiter
|
||||
autoload :Distribution
|
||||
autoload :Serializer
|
||||
autoload :UserBaseSerializer
|
||||
autoload :SupplierBaseSerializer
|
||||
autoload :Counter
|
||||
autoload :Broadcaster
|
||||
autoload :Couchbase
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
module Qwaiter::SupplierBaseSerializer
|
||||
extend ActiveSupport::Concern
|
||||
include JSONAPI::Serializer
|
||||
included do
|
||||
class_attribute :related_link_for_attributes
|
||||
attribute :created_at
|
||||
attribute :updated_at
|
||||
end
|
||||
|
||||
def base_url
|
||||
nil
|
||||
end
|
||||
|
||||
def format_name(attribute_name)
|
||||
#attribute_name.to_s.dasherize
|
||||
attribute_name.to_s
|
||||
end
|
||||
|
||||
def unformat_name(attribute_name)
|
||||
#attribute_name.to_s.underscore
|
||||
attribute_name.to_s
|
||||
end
|
||||
|
||||
#alias_method :default_relationship_related_link, :relationship_related_link
|
||||
def relationship_related_link(attribute_name)
|
||||
super if related_link_for_attributes.include?(attribute_name)
|
||||
end
|
||||
|
||||
def relationship_self_link(attribute_name)
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def attributes(*attrs)
|
||||
attrs.each do |attr|
|
||||
attribute attr
|
||||
end
|
||||
end
|
||||
|
||||
def related_link_for(*attributes)
|
||||
self.related_link_for_attributes = attributes
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user