Base progress

This commit is contained in:
2015-09-16 11:50:55 +02:00
parent ef894f9e02
commit 6a085b1ca2
52 changed files with 3686 additions and 1818 deletions
+7 -6
View File
@@ -8,12 +8,13 @@ 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: 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
render json: lists, include: %w[supplier users], meta: {total_pages: lists.total_pages, page: lists.current_page} #, root: :lists
end
#EMBER
def current
@list = current_user.active_list
params[:id] = @list.id # serializer determines collection or not based on the presence of this
show
end
@@ -21,13 +22,13 @@ module Users
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)
render json: @table
end
def show
@list ||= List.find(params[:id]) if params[:id]
render json: {}, status: :not_found and return unless @list.present? && Array.wrap(@list.user_ids).include?(current_user.id)
render json: JSONAPI::Serializer.serialize(@list, serializer: Users::ListSerializer, include: %w[supplier users join_requests join_requests.user])
render json: @list, include: %w[supplier users join_requests join_requests.user]
end
# POST /user/list_needs_payment.json
@@ -35,7 +36,7 @@ module Users
@list = active_list
render json: json_alert('messages.no_active_list', list_active: false) and return unless @list.try(:id).to_s == params[:id]
@list.needs_payment!
render json: JSONAPI::Serializer.serialize(@list, serializer: Users::ListSerializer)
render json: @list
end
# POST /user/lists/:id/move_table.json?table_id=....
@@ -80,7 +81,7 @@ module Users
def reject_join_request
render js: '' and return unless params[:user_id].present?
active_list && active_list.reject_join_request_for_user!(params[:user_id])
head :ok
head :no_content
end
# POST /user/approve_join_request?user_id=1
@@ -88,7 +89,7 @@ module Users
render js: '' and return unless params[:user_id].present?
@user = User.find(params[:user_id])
active_list && active_list.approve_join_request_for_user!(@user)
head :ok
head :no_content
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: JSONAPI::Serializer.serialize(orders, serializer: Users::OrderSerializer, include: %w[list user product_orders product_orders.order], is_collection: true)
render json: orders, include: %w[list user product_orders product_orders.order]
end
end
@@ -2,14 +2,10 @@ module Users
class ProductCategoriesController < Users::ApplicationController
#EMBER
def index
respond_to do |format|
format.json do
render json: {} and return unless params[:table_id].present?
table = Table.find(params[:table_id])
product_categories = table.supplier.product_categories.include_relation('products') # not yet implemented for many to many
render json: product_categories #, serializer: ProductCategorySerializer
end
end
render json: {} and return unless params[:table_id].present?
table = Table.find(params[:table_id])
product_categories = table.supplier.product_categories.include_relation('products') # not yet implemented for many to many
render json: product_categories #, serializer: ProductCategorySerializer
end
end
end
+8 -7
View File
@@ -10,13 +10,11 @@ module Users
table = Table.find(params[:id])
supplier = table.supplier
supplier.product_categories.include_relations(products: :product_variants)
render json: JSONAPI::Serializer.serialize(supplier, serializer: Users::SupplierSerializer, include: %w[
render json: supplier, include: %w[
product_categories
product_categories.products
product_categories.supplier
product_categories.products.product_variants
product_categories.products.product_variants.product
])
]
end
# POST /tables/:id/needs_help.json
@@ -25,7 +23,7 @@ module Users
render json: json_alert('messages.no_active_list', list_active: false) and return unless active_list.present?
active_list.needs_help!
#render json: JSONAPI::Serializer.serialize(@table, serializer: Users::TableSerializer)
render json: {}
head :no_content
end
# POST /user/tables/:id/join
@@ -35,7 +33,7 @@ module Users
if @list = @table.active_list
@list.send_table_join_request_for_user! current_user
end
head :ok
head :no_content
end
# GET /user/table_info.json
@@ -61,15 +59,18 @@ module Users
end
# Used by the user Ember app
# NOTE: ordering on a table always creates a new list or failes if the conditions for creating a new
# list are not met. To order on an already open list send the request to the lists controller
# POST /user/tables/:id/order_products
def order_products
table = Table.find(params[:id])
res = {}
res[:active_list_present] = true if active_list.present?
res[:occupied] = table.occupied?
res[:reserved] = table.reserved?
res[:supplier_closed] = table.supplier.closed?
res[:no_product_orders] = true unless product_orders = new_order_product_orders.presence
unless res[:occupied] or res[:supplier_closed] or res[:no_product_orders]
unless res[:occupied] or res[:supplier_closed] or res[:no_product_orders] or res[:active_list_present]
# Create new list
list = List.from_table( table, current_user )
res[:active_list_id] = list.id # used to set the active list in the app