End of evening commit, changing supplier to JSONAPI

This commit is contained in:
2015-09-08 23:22:13 +02:00
parent 3cb7fd2a6f
commit 9c1945252d
36 changed files with 195 additions and 230 deletions
@@ -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' 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 #App.ApplicationStore = DS.Store
#adapter: DS.ActiveModelAdapter.extend #adapter: DS.ActiveModelAdapter.extend
#namespace: 'supplier' #namespace: 'supplier'
@@ -7,17 +7,17 @@ module Suppliers
@employee_shifts.select! do |shift| @employee_shifts.select! do |shift|
current_supplier.employee_ids.include?(shift.employee.try(:id)) current_supplier.employee_ids.include?(shift.employee.try(:id))
end 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 end
def create def create
@employee_shift.supplier = current_supplier @employee_shift.supplier = current_supplier
@employee_shift.save @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 end
def update def update
@employee_shift.update employee_shift_params @employee_shift.update employee_shift_params
render json: @employee_shift, serializer: Suppliers::EmployeeShiftSerializer render json: JSONAPI::Serializer.serialize(@employee_shift, serializer: Suppliers::EmployeeShiftSerializer)
end end
def destroy def destroy
@@ -8,13 +8,13 @@ module Suppliers
# GET /employees.json # GET /employees.json
def index def index
@employees = current_supplier.employees @employees = current_supplier.employees
render json: @employees, each_serializer: Suppliers::EmployeeSerializer render json: JSONAPI::Serializer.serialize(@employees, serializer: Suppliers::EmployeeSerializer, is_collection: true)
end end
# GET /employees/1 # GET /employees/1
# GET /employees/1.json # GET /employees/1.json
def show def show
render json: @employee, serializer: Suppliers::EmployeeSerializer render json: JSONAPI::Serializer.serialize(@employee, serializer: Suppliers::EmployeeSerializer)
end end
# POST /employees # POST /employees
+22 -43
View File
@@ -21,7 +21,16 @@ module Suppliers
end end
@lists.include_relation(:table, :users, orders: {product_orders: :product}) @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 end
@@ -47,26 +56,14 @@ module Suppliers
@lists = List.for_supplier_created_at current_supplier, @start_time..@end_time @lists = List.for_supplier_created_at current_supplier, @start_time..@end_time
@lists.include_relation(:table) # for number @lists.include_relation(:table) # for number
respond_to do |format| render json: JSONAPI::Serializer.serialize(@lists, serializer: Suppliers::ListSerializer, is_collection: true, include: %w[table])
format.html # index.html.erb
format.json { render json: @lists }
end
end end
# GET /lists/1 # GET /lists/1
# GET /lists/1.json # GET /lists/1.json
def show def show
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| render json: JSONAPI::Serializer.serialize(@list, serializer: Suppliers::ListSerializer)
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
end end
# GET /lists/1/extra_info # GET /lists/1/extra_info
@@ -83,10 +80,7 @@ module Suppliers
@list.section_id = params[:section_id].presence @list.section_id = params[:section_id].presence
@tables = current_supplier.active_tables @tables = current_supplier.active_tables
respond_to do |format| render json: @list
format.html # new.html.erb
format.json { render json: @list }
end
end end
# POST /lists # POST /lists
@@ -95,17 +89,10 @@ module Suppliers
@list = List.new(list_params) @list = List.new(list_params)
@list.supplier = current_supplier @list.supplier = current_supplier
respond_to do |format| if @list.save
if @list.save render json: @list
format.html { redirect_to [:suppliers, @list.section || @list], notice: t('action.create.successfull', model: List.model_name.human) } else
format.json { render json: @list, status: :created, location: @list } render json: {errors: @list.errors}, status: :unprocessable_entity
else
format.html do
@tables = current_supplier.active_tables
render action: "new"
end
format.json { render json: {errors: @list.errors}, status: :unprocessable_entity }
end
end end
end end
@@ -120,14 +107,10 @@ module Suppliers
def update def update
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| if @list.update_attributes(list_params)
if @list.update_attributes(list_params) render json: @list
format.html { redirect_to [:suppliers, @list], notice: t('action.update.successfull', model: List.model_name.human) } else
format.json { render json: @list } render json: {errors: @list.errors}, status: :unprocessable_entity
else
format.html { render action: "edit" }
format.json { render json: {errors: @list.errors}, status: :unprocessable_entity }
end
end end
end end
@@ -136,11 +119,7 @@ module Suppliers
def destroy def destroy
@list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @list = List.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
@list.destroy @list.destroy
head :ok
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
end end
# POST /supplier/lists/1/close # POST /supplier/lists/1/close
def close def close
@@ -3,11 +3,11 @@ module Suppliers
prepend_before_action :find_page, only: [:show] prepend_before_action :find_page, only: [:show]
def index def index
@pages = Page.all_for_suppliers(locale: params[:locale]) @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 end
def show def show
render json: @page, serializer: Suppliers::PageSerializer render json: JSONAPI::Serializer.serialize(@page, serializer: Suppliers::PageSerializer)
end end
private private
@@ -2,13 +2,13 @@ module Suppliers
class SectionAreasController < Suppliers::ApplicationController class SectionAreasController < Suppliers::ApplicationController
def index def index
@section_areas = SectionArea.for_supplier(current_supplier) @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 end
def create def create
@section_area.supplier = current_supplier @section_area.supplier = current_supplier
if @section_area.save if @section_area.save
render json: @section_area, serializer: Suppliers::SectionAreaSerializer render json: JSONAPI::Serializer.serialize(@section_area, serializer: Suppliers::SectionAreaSerializer)
else else
render json: {errors: @section.errors}, status: :unprocessable_entity render json: {errors: @section.errors}, status: :unprocessable_entity
end end
@@ -16,7 +16,7 @@ module Suppliers
def update def update
if @section_area.update_attributes section_area_params 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 else
render json: {errors: @section.errors}, status: :unprocessable_entity render json: {errors: @section.errors}, status: :unprocessable_entity
end end
@@ -2,13 +2,13 @@ module Suppliers
class SectionElementsController < Suppliers::ApplicationController class SectionElementsController < Suppliers::ApplicationController
def index def index
@section_elements = SectionElement.for_supplier(current_supplier) @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 end
def create def create
@section_element.supplier = current_supplier @section_element.supplier = current_supplier
if @section_element.save if @section_element.save
render json: @section_element, serializer: Suppliers::SectionElementSerializer render json: JSONAPI::Serializer.serialize(@section_element, serializer: Suppliers::SectionElementSerializer)
else else
render json: {errors: @section.errors}, status: :unprocessable_entity render json: {errors: @section.errors}, status: :unprocessable_entity
end end
@@ -16,7 +16,7 @@ module Suppliers
def update def update
if @section_element.update_attributes section_element_params 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 else
render json: {errors: @section.errors}, status: :unprocessable_entity render json: {errors: @section.errors}, status: :unprocessable_entity
end end
@@ -17,7 +17,7 @@ module Suppliers
# end # end
# end # end
# end # end
render json: @sections, each_serializer: Suppliers::ExtendedSectionSerializer render json: JSONAPI::Serializer.serialize(@sections, serializer: Suppliers::ExtendedSectionSerializer, is_collection: true)
end end
# GET /sections/1 # GET /sections/1
@@ -55,14 +55,10 @@ module Suppliers
@section = Section.new(section_params) @section = Section.new(section_params)
@section.supplier = current_supplier @section.supplier = current_supplier
respond_to do |format| if @section.save
if @section.save render json: @section, serializer: Suppliers::SectionSerializer, status: :created
format.html { redirect_to [:suppliers, @section], notice: t('action.create.successfull', model: Section.model_name.human) } else
format.json { render json: @section, serializer: Suppliers::SectionSerializer, status: :created } render json: {errors: @section.errors}, status: :unprocessable_entity
else
format.html { render action: "new" }
format.json { render json: {errors: @section.errors}, status: :unprocessable_entity }
end
end end
end end
@@ -71,14 +67,10 @@ module Suppliers
def update def update
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| if @section.update_attributes(section_params)
if @section.update_attributes(section_params) head :ok
format.html { redirect_to [:suppliers, @section], notice: t('action.update.successfull', model: Section.model_name.human) } else
format.json { head :no_content } render json: {errors: @section.errors}, status: :unprocessable_entity
else
format.html { render action: "edit" }
format.json { render json: {errors: @section.errors}, status: :unprocessable_entity }
end
end end
end end
@@ -88,10 +80,7 @@ module Suppliers
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
@section.destroy @section.destroy
respond_to do |format| head :ok
format.html { redirect_to suppliers_sections_url, notice: t('action.destroy.successfull', model: Section.model_name.human) }
format.json { head :no_content }
end
end end
# GET /sections/1/manage_tables # GET /sections/1/manage_tables
@@ -99,10 +88,7 @@ module Suppliers
def manage_tables def manage_tables
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| render json: @section
format.html # show.html.erb
format.json { render json: @section }
end
end end
# GET /sections/1/tables_view # GET /sections/1/tables_view
@@ -111,12 +97,7 @@ module Suppliers
@section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @section = Section.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
@tables = @section.tables_with_active_list_id @tables = @section.tables_with_active_list_id
respond_to do |format| render json: @section
format.html # show.html.erb
format.json do
render json: @section.for_tables_as_json
end
end
end end
# POST /sections/1/add_tables {number_start: 1423, number_end: 234234} # POST /sections/1/add_tables {number_start: 1423, number_end: 234234}
@@ -134,8 +115,7 @@ module Suppliers
added_tables << table added_tables << table
end end
@section.arrange_tables_in_grid added_tables @section.arrange_tables_in_grid added_tables
table_json = ActiveModel::ArraySerializer.new(@section.tables, each_serializer: SupplierTableSerializer, root: false).as_json render json: JSONAPI::Serializer.serialize(@section.tables, serializer: Supplier::TableSerializer, is_collection: true, include: %w[section])
render json: {tables: table_json}
end end
# POST /sections/1/arrange_tables {number_start: 1423, number_end: 234234} # POST /sections/1/arrange_tables {number_start: 1423, number_end: 234234}
@@ -6,13 +6,13 @@ module Suppliers
def show def show
[current_supplier].include_relations(sections: :tables, product_categories: {products: :product_variants}) [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 end
def update def update
@supplier = current_supplier @supplier = current_supplier
current_supplier.update_attributes(supplier_params) 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 end
def switch_to def switch_to
@@ -2,7 +2,7 @@ module Suppliers
class SvgElementsController < Suppliers::ApplicationController class SvgElementsController < Suppliers::ApplicationController
def index def index
@svg_elements = SvgElement.active @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 end
end end
+12 -32
View File
@@ -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 = 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) @tables.include_relation(:section)
respond_to do |format| render json: @tables
format.html # index.html.erb
format.json { render json: @tables }
end
end end
# GET /tables/1 # GET /tables/1
@@ -17,10 +14,7 @@ module Suppliers
def show def show
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| render json: @table
format.html # show.html.erb
format.json { render json: @table }
end
end end
# GET /tables/new # GET /tables/new
@@ -29,10 +23,7 @@ module Suppliers
@table = Table.new @table = Table.new
@table.section_id = params[:section_id].presence @table.section_id = params[:section_id].presence
respond_to do |format| render json: @table
format.html # new.html.erb
format.json { render json: @table }
end
end end
# GET /tables/1/edit # GET /tables/1/edit
@@ -46,14 +37,10 @@ module Suppliers
@table = Table.new(table_params) @table = Table.new(table_params)
@table.supplier = current_supplier @table.supplier = current_supplier
respond_to do |format| if @table.save
if @table.save render json: @table, status: :created
format.html { redirect_to [:suppliers, @table.section || @table], notice: t('action.create.successfull', model: Table.model_name.human) } else
format.json { render json: @table, status: :created } render json: {errors: @table.errors}, status: :unprocessable_entity
else
format.html { render action: "new" }
format.json { render json: {errors: @table.errors}, status: :unprocessable_entity }
end
end end
end end
@@ -62,14 +49,10 @@ module Suppliers
def update def update
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
respond_to do |format| if @table.update_attributes(table_params)
if @table.update_attributes(table_params) render json: @table
format.html { redirect_to [:suppliers, @table.section || @table], notice: t('action.update.successfull', model: Table.model_name.human) } else
format.json { render json: @table } render json: {errors: @table.errors}, status: :unprocessable_entity
else
format.html { render action: "edit" }
format.json { render json: {errors: @table.errors}, status: :unprocessable_entity }
end
end end
end end
@@ -79,10 +62,7 @@ module Suppliers
@table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id]) @table= Table.find_by_supplier_id_and_id!(current_supplier.id, params[:id])
@table.destroy @table.destroy
respond_to do |format| head :ok
format.html { redirect_to suppliers_tables_url, notice: t('action.destroy.successfull', model: Table.model_name.human) }
format.json { head :no_content }
end
end end
def qr_codes def qr_codes
-6
View File
@@ -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
-14
View File
@@ -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 attributes :name, :email, :manager, :active, :color
end end
@@ -1,6 +1,5 @@
class Suppliers::EmployeeShiftSerializer < Qwaiter::Serializer class Suppliers::EmployeeShiftSerializer
self.root = :employee_shift include Qwaiter::SupplierBaseSerializer
#embed :ids, include: true
attributes :start_from, :end_on, :employee_id, :supplier_id attributes :start_from, :end_on, :employee_id, :supplier_id
#has_one :supplier has_one :supplier, serializer: Suppliers::SupplierSerializer
end end
@@ -1,5 +1,4 @@
class Suppliers::ExtendedSectionSerializer < Qwaiter::Serializer #class Suppliers::ExtendedSectionSerializer < Qwaiter::Serializer
root 'section' # attributes :title, :path, :width, :height
attributes :title, :path, :width, :height # has_many :tables, serializer: Suppliers::TableSerializer
has_many :tables, serializer: Suppliers::ExtendedTableSerializer #end
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
+7 -16
View File
@@ -1,18 +1,9 @@
class Suppliers::ListSerializer < Qwaiter::Serializer class Suppliers::ListSerializer
# user ids for facebook pictures include Qwaiter::SupplierBaseSerializer
self.root = :list attributes :state, :needs_help, :needs_payment, :user_requests_closing, :is_paid, :price, :closed_at
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
#def has_active_orders has_many :orders, serializer: Suppliers::OrderSerializer
#object.has_active_orders? has_many :join_requests, serializer: Suppliers::JoinRequestSerializer
#end has_many :users, serializer: Suppliers::UserSerializer
def extended_version has_one :table, serializer: Suppliers::TableSerializer
true
end
end 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
+5 -10
View File
@@ -1,11 +1,6 @@
class Suppliers::PageSerializer < Qwaiter::Serializer class Suppliers::PageSerializer
self.root = :page include Qwaiter::SupplierBaseSerializer
attributes :name, :title, :body, :locale, :position attributes :title, :body, :locale, :position
def name attribute(:name) { object.name.to_s.sub /^suppliers-/, '' }
object.name.to_s.sub /^suppliers-/, '' attribute(:id) { object.name.to_s.sub /^suppliers-/, '' }
end
def id
name
end
end end
@@ -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, 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, :active_on_thursday, :active_on_friday, :active_on_saturday, :full_day, :start_from, :end_on,
:position :position
has_many :products has_many :products, serializer: Suppliers::ProductSerializer
end 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 class Suppliers::SectionAreaSerializer
attributes :title, :width, :height, :position_x, :position_y, :section_id, :rounded include Qwaiter::SupplierBaseSerializer
attributes :title, :width, :height, :position_x, :position_y, :rounded
has_one :section, serializer: Suppliers::SectionSerializer
end end
@@ -1,3 +1,4 @@
class Suppliers::SectionElementSerializer < Qwaiter::Serializer 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 end
@@ -1,4 +1,4 @@
class Suppliers::SectionSerializer < Qwaiter::Serializer class Suppliers::SectionSerializer
root :section include Qwaiter::SupplierBaseSerializer
attributes :title, :path, :width, :height attributes :title, :path, :width, :height
end end
@@ -1,12 +1,9 @@
class Suppliers::SupplierSerializer < Qwaiter::Serializer class Suppliers::SupplierSerializer
self.root = :supplier include Qwaiter::SupplierBaseSerializer
attributes :extended_version, :open, :name, :email, :lat, :lng, :time_zone, :address, :house_number, :house_number_addition, :postal_code, :city, :country, 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 :facebook_promotion_url, :iens_profile, :week_starts_on_monday, :orders_in_process_count, :orders_placed_count
def extended_version has_many :sections, serializer: Suppliers::SectionSerializer
true has_many :product_categories, serializer: Suppliers::ProductCategorySerializer
end
has_many :sections, serializer: Suppliers::ExtendedSectionSerializer
has_many :product_categories
has_many :employees, serializer: Suppliers::EmployeeSerializer has_many :employees, serializer: Suppliers::EmployeeSerializer
end end
@@ -1,3 +1,4 @@
class Suppliers::SvgElementSerializer < Qwaiter::Serializer class Suppliers::SvgElementSerializer
include Qwaiter::SupplierBaseSerializer
attributes :name, :box_width, :box_height, :dpm, :svg attributes :name, :box_width, :box_height, :dpm, :svg
end 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
+4 -11
View File
@@ -1,12 +1,5 @@
class Suppliers::UserSerializer < Qwaiter::Serializer class Suppliers::UserSerializer
self.root = :user include Qwaiter::SupplierBaseSerializer
attributes :email, :provider, :uid, :name, :avatar, :list_id attributes :email, :provider, :uid, :avatar
attribute(:name) { object.supplier_name }
def list_id
object.active_list_id
end
def name
object.supplier_name
end
end end
@@ -2,7 +2,7 @@
//var $locale = '<%= I18n.locale %>'; //var $locale = '<%= I18n.locale %>';
//var supplier_id = '<%= current_supplier.id %>'; //var supplier_id = '<%= current_supplier.id %>';
var supplier_object=<%= {id: current_supplier.id}.to_json.html_safe %>; 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 data_host = '';
var $asset_path = '/assets/'; var $asset_path = '/assets/';
var event_host = '<%= Qwaiter.event_host %>'; var event_host = '<%= Qwaiter.event_host %>';
+1
View File
@@ -5,6 +5,7 @@ module Qwaiter
autoload :Distribution autoload :Distribution
autoload :Serializer autoload :Serializer
autoload :UserBaseSerializer autoload :UserBaseSerializer
autoload :SupplierBaseSerializer
autoload :Counter autoload :Counter
autoload :Broadcaster autoload :Broadcaster
autoload :Couchbase autoload :Couchbase
+43
View File
@@ -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