diff --git a/app/assets/javascripts/supplier/app/adapters/application.js.coffee b/app/assets/javascripts/supplier/app/adapters/application.js.coffee index 7cf86371..3e027bd4 100644 --- a/app/assets/javascripts/supplier/app/adapters/application.js.coffee +++ b/app/assets/javascripts/supplier/app/adapters/application.js.coffee @@ -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" diff --git a/app/assets/javascripts/supplier/app/store.js.coffee b/app/assets/javascripts/supplier/app/store.js.coffee index 91ceef32..a77be262 100644 --- a/app/assets/javascripts/supplier/app/store.js.coffee +++ b/app/assets/javascripts/supplier/app/store.js.coffee @@ -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' diff --git a/app/controllers/suppliers/employee_shifts_controller.rb b/app/controllers/suppliers/employee_shifts_controller.rb index 39e1058e..b60d48a6 100644 --- a/app/controllers/suppliers/employee_shifts_controller.rb +++ b/app/controllers/suppliers/employee_shifts_controller.rb @@ -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 diff --git a/app/controllers/suppliers/employees_controller.rb b/app/controllers/suppliers/employees_controller.rb index 4698ec74..600011f0 100644 --- a/app/controllers/suppliers/employees_controller.rb +++ b/app/controllers/suppliers/employees_controller.rb @@ -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 diff --git a/app/controllers/suppliers/lists_controller.rb b/app/controllers/suppliers/lists_controller.rb index a2d63a14..19c87774 100644 --- a/app/controllers/suppliers/lists_controller.rb +++ b/app/controllers/suppliers/lists_controller.rb @@ -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 diff --git a/app/controllers/suppliers/pages_controller.rb b/app/controllers/suppliers/pages_controller.rb index 423fbd10..a3c9f500 100644 --- a/app/controllers/suppliers/pages_controller.rb +++ b/app/controllers/suppliers/pages_controller.rb @@ -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 diff --git a/app/controllers/suppliers/section_areas_controller.rb b/app/controllers/suppliers/section_areas_controller.rb index 3c625a68..b2d5105e 100644 --- a/app/controllers/suppliers/section_areas_controller.rb +++ b/app/controllers/suppliers/section_areas_controller.rb @@ -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 diff --git a/app/controllers/suppliers/section_elements_controller.rb b/app/controllers/suppliers/section_elements_controller.rb index d0caf4e2..f78de0f7 100644 --- a/app/controllers/suppliers/section_elements_controller.rb +++ b/app/controllers/suppliers/section_elements_controller.rb @@ -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 diff --git a/app/controllers/suppliers/sections_controller.rb b/app/controllers/suppliers/sections_controller.rb index 2e3f0ef5..468ac14e 100644 --- a/app/controllers/suppliers/sections_controller.rb +++ b/app/controllers/suppliers/sections_controller.rb @@ -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} diff --git a/app/controllers/suppliers/suppliers_controller.rb b/app/controllers/suppliers/suppliers_controller.rb index 86ae85b9..d88aed22 100644 --- a/app/controllers/suppliers/suppliers_controller.rb +++ b/app/controllers/suppliers/suppliers_controller.rb @@ -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 diff --git a/app/controllers/suppliers/svg_elements_controller.rb b/app/controllers/suppliers/svg_elements_controller.rb index d4e29d98..cac3a222 100644 --- a/app/controllers/suppliers/svg_elements_controller.rb +++ b/app/controllers/suppliers/svg_elements_controller.rb @@ -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 diff --git a/app/controllers/suppliers/tables_controller.rb b/app/controllers/suppliers/tables_controller.rb index 13a70e3a..24ef44bd 100644 --- a/app/controllers/suppliers/tables_controller.rb +++ b/app/controllers/suppliers/tables_controller.rb @@ -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 diff --git a/app/serializers/order_serializer.rb b/app/serializers/order_serializer.rb deleted file mode 100644 index 7cd55dce..00000000 --- a/app/serializers/order_serializer.rb +++ /dev/null @@ -1,6 +0,0 @@ -class OrderSerializer < Qwaiter::Serializer - attributes :state, :list_id, :section_id, :table_id #, :price - - has_many :product_orders - -end diff --git a/app/serializers/product_order_serializer.rb b/app/serializers/product_order_serializer.rb deleted file mode 100644 index 9d2c11b8..00000000 --- a/app/serializers/product_order_serializer.rb +++ /dev/null @@ -1,4 +0,0 @@ -# Used for user ember1 -class ProductOrderSerializer < Qwaiter::Serializer - attributes :quantity, :price, :product_name, :product_variant -end diff --git a/app/serializers/product_serializer.rb b/app/serializers/product_serializer.rb deleted file mode 100644 index fae7b8d8..00000000 --- a/app/serializers/product_serializer.rb +++ /dev/null @@ -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 diff --git a/app/serializers/suppliers/employee_serializer.rb b/app/serializers/suppliers/employee_serializer.rb index 65788b5e..8394758d 100644 --- a/app/serializers/suppliers/employee_serializer.rb +++ b/app/serializers/suppliers/employee_serializer.rb @@ -1,3 +1,4 @@ -class Suppliers::EmployeeSerializer < Qwaiter::Serializer +class Suppliers::EmployeeSerializer + include Qwaiter::SupplierBaseSerializer attributes :name, :email, :manager, :active, :color end diff --git a/app/serializers/suppliers/employee_shift_serializer.rb b/app/serializers/suppliers/employee_shift_serializer.rb index 5e8ebcd7..5f0d241d 100644 --- a/app/serializers/suppliers/employee_shift_serializer.rb +++ b/app/serializers/suppliers/employee_shift_serializer.rb @@ -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 diff --git a/app/serializers/suppliers/extended_section_serializer.rb b/app/serializers/suppliers/extended_section_serializer.rb index 0cbd1ce3..4a3c3a94 100644 --- a/app/serializers/suppliers/extended_section_serializer.rb +++ b/app/serializers/suppliers/extended_section_serializer.rb @@ -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 diff --git a/app/serializers/suppliers/extended_table_serializer.rb b/app/serializers/suppliers/extended_table_serializer.rb deleted file mode 100644 index 55194583..00000000 --- a/app/serializers/suppliers/extended_table_serializer.rb +++ /dev/null @@ -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 diff --git a/app/serializers/suppliers/join_request_serializer.rb b/app/serializers/suppliers/join_request_serializer.rb new file mode 100644 index 00000000..6b9d54e2 --- /dev/null +++ b/app/serializers/suppliers/join_request_serializer.rb @@ -0,0 +1,5 @@ +class Suppliers::JoinRequestSerializer + include Qwaiter::SupplierBaseSerializer + has_one :user, serializer: Suppliers::SupplierSerializer + has_one :list, serializer: Suppliers::ListSerializer +end diff --git a/app/serializers/suppliers/list_serializer.rb b/app/serializers/suppliers/list_serializer.rb index d2082547..5cc5145c 100644 --- a/app/serializers/suppliers/list_serializer.rb +++ b/app/serializers/suppliers/list_serializer.rb @@ -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 diff --git a/app/serializers/suppliers/order_serializer.rb b/app/serializers/suppliers/order_serializer.rb new file mode 100644 index 00000000..30053c30 --- /dev/null +++ b/app/serializers/suppliers/order_serializer.rb @@ -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 diff --git a/app/serializers/suppliers/page_serializer.rb b/app/serializers/suppliers/page_serializer.rb index cc54f327..56585d09 100644 --- a/app/serializers/suppliers/page_serializer.rb +++ b/app/serializers/suppliers/page_serializer.rb @@ -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 diff --git a/app/serializers/product_category_serializer.rb b/app/serializers/suppliers/product_category_serializer.rb similarity index 60% rename from app/serializers/product_category_serializer.rb rename to app/serializers/suppliers/product_category_serializer.rb index 4fd01f89..1ad921c6 100644 --- a/app/serializers/product_category_serializer.rb +++ b/app/serializers/suppliers/product_category_serializer.rb @@ -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 diff --git a/app/serializers/suppliers/product_order_serializer.rb b/app/serializers/suppliers/product_order_serializer.rb new file mode 100644 index 00000000..68e7338c --- /dev/null +++ b/app/serializers/suppliers/product_order_serializer.rb @@ -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 diff --git a/app/serializers/suppliers/product_serializer.rb b/app/serializers/suppliers/product_serializer.rb new file mode 100644 index 00000000..12b26120 --- /dev/null +++ b/app/serializers/suppliers/product_serializer.rb @@ -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 diff --git a/app/serializers/suppliers/section_area_serializer.rb b/app/serializers/suppliers/section_area_serializer.rb index 1ad64194..3d0dd095 100644 --- a/app/serializers/suppliers/section_area_serializer.rb +++ b/app/serializers/suppliers/section_area_serializer.rb @@ -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 diff --git a/app/serializers/suppliers/section_element_serializer.rb b/app/serializers/suppliers/section_element_serializer.rb index 22d9b03f..732c24d9 100644 --- a/app/serializers/suppliers/section_element_serializer.rb +++ b/app/serializers/suppliers/section_element_serializer.rb @@ -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 diff --git a/app/serializers/suppliers/section_serializer.rb b/app/serializers/suppliers/section_serializer.rb index cbe7c294..9c25bce9 100644 --- a/app/serializers/suppliers/section_serializer.rb +++ b/app/serializers/suppliers/section_serializer.rb @@ -1,4 +1,4 @@ -class Suppliers::SectionSerializer < Qwaiter::Serializer - root :section +class Suppliers::SectionSerializer + include Qwaiter::SupplierBaseSerializer attributes :title, :path, :width, :height end diff --git a/app/serializers/suppliers/supplier_serializer.rb b/app/serializers/suppliers/supplier_serializer.rb index 0c3e9417..c0833c72 100644 --- a/app/serializers/suppliers/supplier_serializer.rb +++ b/app/serializers/suppliers/supplier_serializer.rb @@ -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 diff --git a/app/serializers/suppliers/svg_element_serializer.rb b/app/serializers/suppliers/svg_element_serializer.rb index d1929104..063f51c3 100644 --- a/app/serializers/suppliers/svg_element_serializer.rb +++ b/app/serializers/suppliers/svg_element_serializer.rb @@ -1,3 +1,4 @@ -class Suppliers::SvgElementSerializer < Qwaiter::Serializer +class Suppliers::SvgElementSerializer + include Qwaiter::SupplierBaseSerializer attributes :name, :box_width, :box_height, :dpm, :svg end diff --git a/app/serializers/suppliers/table_serializer.rb b/app/serializers/suppliers/table_serializer.rb new file mode 100644 index 00000000..6b5df80a --- /dev/null +++ b/app/serializers/suppliers/table_serializer.rb @@ -0,0 +1,4 @@ +class Suppliers::TableSerializer + include Qwaiter::SupplierBaseSerializer + attributes :number, :width, :height, :position_x, :position_y, :section_id#, :active_list_id +end diff --git a/app/serializers/suppliers/user_serializer.rb b/app/serializers/suppliers/user_serializer.rb index eb4f966c..7253ab8e 100644 --- a/app/serializers/suppliers/user_serializer.rb +++ b/app/serializers/suppliers/user_serializer.rb @@ -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 diff --git a/app/views/suppliers/application/_head.html.erb b/app/views/suppliers/application/_head.html.erb index a36c82b6..12f6ec89 100644 --- a/app/views/suppliers/application/_head.html.erb +++ b/app/views/suppliers/application/_head.html.erb @@ -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 %>'; diff --git a/lib/qwaiter.rb b/lib/qwaiter.rb index 6abaf04d..b6e925c4 100644 --- a/lib/qwaiter.rb +++ b/lib/qwaiter.rb @@ -5,6 +5,7 @@ module Qwaiter autoload :Distribution autoload :Serializer autoload :UserBaseSerializer + autoload :SupplierBaseSerializer autoload :Counter autoload :Broadcaster autoload :Couchbase diff --git a/lib/qwaiter/supplier_base_serializer.rb b/lib/qwaiter/supplier_base_serializer.rb new file mode 100644 index 00000000..c7a64a90 --- /dev/null +++ b/lib/qwaiter/supplier_base_serializer.rb @@ -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