JSONApi progress

This commit is contained in:
2015-09-03 20:42:48 +02:00
parent f47a8a9ed0
commit e4dde28dd0
27 changed files with 215 additions and 64 deletions
@@ -4,6 +4,7 @@ App.MenuProductCategoriesComponent = Ember.Component.extend
active_product_categories: (->
console.log "Reevaluate product categories"
list = @get('product_categories')
return [] unless list
now = new Date()
list = list.filter (product_category) =>
return false unless product_category.get("active_on_#{$day_names[now.getDay()]}")
@@ -8,7 +8,7 @@ App.TableController = Ember.Controller.extend
else
# no list and open supplier
if @get('model.occupied') then false else true
).property('globals.active_list.id', 'supplier.can_take_orders', 'model.occupied', 'model.id', 'globals.active_list.table.id')
).property('globals.active_list.id', 'model.supplier.can_take_orders', 'model.occupied', 'model.id', 'globals.active_list.table.id', 'model.supplier.id')
supplier: Ember.computed.alias 'model.supplier'
showJoinButton: Ember.computed 'globals.active_list.id', 'supplier.can_take_orders', 'model.occupied', 'model.id', 'globals.active_list.table.id', ->
return false unless @get('supplier.can_take_orders')
@@ -1,6 +1,6 @@
.row: .small-12.columns
h3
span.supplier-name= supplier.name
span.supplier-name= model.supplier.name
span.table-number
' #
= model.number
@@ -13,7 +13,7 @@
button.join-table-button{action "joinOccupiedTable"}=t 'join_request.requestor.join_this_table'
.row
if tableCanTakeOrders
.large-6.columns= menu-product-categories product_categories=supplier.product_categories orderProducts=true
.large-6.columns= menu-product-categories product_categories=model.supplier.product_categories orderProducts=true
.large-6.columns= new-product-orders-list table=model
else
.large12= menu-product-categories product_categories=supplier.product_categories orderProducts=false
.large12= menu-product-categories product_categories=model.supplier.product_categories orderProducts=false
+9 -3
View File
@@ -8,7 +8,7 @@ module Users
lists.reject!{|l| l.id == params[:exclude_list]} if params[:exclude_list].present?
lists.reject!{|l| l.id == current_user.active_list_id } if current_user && current_user.active_list_id.present? # see spec Loading lists and switching to the order products view works, lists loading may unlink active list orders
lists.include_relation(:users, :supplier)
render json: lists, each_serializer: Users::ListSerializer, meta: {total_pages: lists.total_pages, page: lists.current_page} #, root: :lists
render json: JSONAPI::Serializer.serialize(lists, serializer: Users::ListSerializer, include: %w[supplier users], is_collection: true, meta: {total_pages: lists.total_pages, page: lists.current_page}) #, root: :lists
end
#EMBER
@@ -17,11 +17,17 @@ module Users
show
end
def table
list = List.find(params[:id])
render json: {}, status: :not_found and return unless list.present?
@table = list.table
render json: JSONAPI::Serializer.serialize(@table, serializer: Users::TableSerializer)
end
def show
@list ||= List.find(params[:id])
render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id)
[@list].include_relation(:users)
render json: @list, serializer: Users::ListSerializer, include: %w[supplier users]
render json: JSONAPI::Serializer.serialize(@list, serializer: Users::ListSerializer, include: %w[supplier users])
end
end
end
+1 -1
View File
@@ -8,7 +8,7 @@ module Users
@list = List.find(params[:list_id])
render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id)
orders = @list.orders.include_relation(:product_orders)
render json: orders, each_serializer: Users::OrderSerializer, include: %w[product_orders]
render json: JSONAPI::Serializer.serialize(orders, serializer: Users::OrderSerializer, include: %w[product_orders product_orders.order], is_collection: true)
end
# Used by the user Ember app
+8 -1
View File
@@ -2,7 +2,14 @@ module Users
class TablesController < Users::ApplicationController
def show
@table = Table.find(params[:id])
render json: @table, serializer: Users::TableSerializer
render json: JSONAPI::Serializer.serialize(@table, serializer: Users::TableSerializer)
end
def supplier
table = Table.find(params[:id])
supplier = table.supplier
supplier.product_categories.include_relations(:products)
render json: JSONAPI::Serializer.serialize(supplier, serializer: Users::SupplierSerializer, include: %w[product_categories product_categories.products product_categories.supplier])
end
end
end
+8 -3
View File
@@ -1,11 +1,16 @@
class Users::ListSerializer < Qwaiter::Serializer
class Users::ListSerializer < Qwaiter::UserBaseSerializer
# user ids for facebook pictures
self.root = :list
#self.root = :list
attributes :state, :needs_help, :needs_payment, :user_requests_closing,
:is_paid, :price, :closed_at
has_many :users, serializer: Users::UserSerializer
has_many :orders, url: ->(list){ "/user/lists/#{list.id}/orders" }, serializer: OrderSerializer
has_many(:orders, serializer: OrderSerializer){}
has_one :supplier, serializer: Users::SupplierSerializer
has_one :table
def include_orders?
@_include_linkages.any?{|link| link =~ /orders/}
end
#belongs_to :table
end
+2 -2
View File
@@ -1,8 +1,8 @@
class Users::OrderSerializer < Qwaiter::Serializer
class Users::OrderSerializer < Qwaiter::UserBaseSerializer
attributes :state #, :list_id, :section_id, :table_id #, :price
has_many :product_orders, serializer: Users::ProductOrderSerializer
belongs_to :list
has_one(:list, serializer: Users::ListSerializer ) #{ List.new(id: object.list_id )}
#belongs_to :section
#belongs_to :table
end
@@ -0,0 +1,7 @@
class Users::ProductCategorySerializer < Qwaiter::UserBaseSerializer
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, serializer: Users::ProductSerializer
has_one :supplier, serializer: Users::SupplierSerializer
end
@@ -1,6 +1,6 @@
# Used for user ember1
class Users::ProductOrderSerializer < Qwaiter::Serializer
class Users::ProductOrderSerializer < Qwaiter::UserBaseSerializer
attributes :quantity, :price, :product_name, :product_variant
# belongs_to :product #DO NOT USE THIS, THIS IS NOT NEEDED
belongs_to :order
has_one :order, serializer: Users::OrderSerializer
end
@@ -0,0 +1,13 @@
class Users::ProductSerializer < Qwaiter::UserBaseSerializer
attributes :name, :price, :description, :image, :code, :position, :visible, :active, :product_category_id
has_many :product_variants, serializer: Users::ProductVariantSerializer
def image
if object.image.present?
{small: object.image.url(:small)}
else
nil
end
end
end
@@ -0,0 +1,3 @@
class Users::ProductVariantSerializer < Qwaiter::UserBaseSerializer
attributes :name
end
+7 -7
View File
@@ -1,9 +1,9 @@
class Users::SupplierSerializer < Qwaiter::Serializer
self.root = :supplier
attributes :extended_version, :open, :name
def extended_version
false
end
class Users::SupplierSerializer < Qwaiter::UserBaseSerializer
#self.root = :supplier
attributes :open, :name
has_many :product_categories, serializer: Users::ProductCategorySerializer
#def extended_version
# false
#end
end
+4 -3
View File
@@ -1,6 +1,7 @@
class Users::TableSerializer < Qwaiter::Serializer
self.root = :table
attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied, :supplier_id #, :alist_id
class Users::TableSerializer < Qwaiter::UserBaseSerializer
#self.root = :table
attributes :number, :width, :height, :position_x, :position_y, :section_id, :occupied #, :supplier_id #, :alist_id
has_one :supplier, serializer: Users::SupplierSerializer
#def list_id
#object.active_list_id || object.active_list.try(:id)
+2 -2
View File
@@ -1,5 +1,5 @@
class Users::UserSerializer < Qwaiter::Serializer
self.root = :user
class Users::UserSerializer < Qwaiter::UserBaseSerializer
#self.root = :user
attributes :email, :provider, :uid, :name, :avatar
def name