end of day commit
This commit is contained in:
@@ -9,6 +9,7 @@ class UserController < ApplicationController
|
||||
end
|
||||
|
||||
# POST /user/create_list {table_id: 1234}
|
||||
#DEPRICATED
|
||||
def create_list
|
||||
@table = Table.find(params[:table_id])
|
||||
if @table.occupied?
|
||||
@@ -17,11 +18,8 @@ class UserController < ApplicationController
|
||||
format.json { render json: js_alert(t('messages.table_is_occupied'))}
|
||||
end
|
||||
else
|
||||
@list = List.new(table: @table, supplier_id: @table.supplier_id)
|
||||
@list.add_user current_user
|
||||
#@list.add_user(current_user)
|
||||
@list.save
|
||||
session[:active_list_id] = @list.id
|
||||
if @list = List.from_table( @table, current_user )
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to user_list_products_path }
|
||||
format.json { render json: js_notice('table_created')}
|
||||
@@ -31,9 +29,15 @@ class UserController < ApplicationController
|
||||
|
||||
def table_info
|
||||
@table = Table.find(params[:table_id])
|
||||
res = {}
|
||||
res[:ocupied] = @table.occupied?
|
||||
if list.present?
|
||||
res[:other_supplier] = true if list.supplier_id != @table.supplier_id
|
||||
res[:current_table_id] = list.table_id
|
||||
end
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {occupied: @table.occupied?}
|
||||
render json: res
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -56,6 +60,22 @@ class UserController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def list_products_for_table
|
||||
@table = Table.find(params[:table_id])
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
render layout: 'phone'
|
||||
end
|
||||
format.json do
|
||||
products = @table.supplier.products
|
||||
products.include_relation(:product_categories)
|
||||
products.sort_by!{|p| p.product_category.try(:position) || 90000}
|
||||
h = products.inject({}){|h, p| n = p.product_category.try(:name) || 'other'; h[n] ||= []; h[n] << p; h}
|
||||
render json: h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# GET /user/current_list.json
|
||||
# Information about the currently active list
|
||||
# This information includes detailed order information
|
||||
@@ -97,7 +117,7 @@ class UserController < ApplicationController
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
if !list.try(:active?)
|
||||
session[:active_list_id] = nil
|
||||
current_user.list_is_closed!
|
||||
render json: {list_active: false}
|
||||
return
|
||||
else
|
||||
@@ -144,8 +164,8 @@ class UserController < ApplicationController
|
||||
# GET /user/list_history/:list_id
|
||||
def history_list
|
||||
@list = List.find(params[:list_id])
|
||||
if params[:list_closed].present? && session[:active_list_id] == @list.id
|
||||
session[:active_list_id] = nil
|
||||
if params[:list_closed].present? && current_user.active_list_id == @list.id
|
||||
current_user.list_is_closed!
|
||||
flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human)
|
||||
end
|
||||
redirect_to user_root_path, alert: t('messages.illegal_history_list_attempt') and return unless @list.user_ids.include?(current_user.id)
|
||||
@@ -154,7 +174,19 @@ class UserController < ApplicationController
|
||||
|
||||
|
||||
def order_selected_products
|
||||
@list = list
|
||||
if list.present?
|
||||
@list = list
|
||||
else
|
||||
@table = Table.find(params[:table_id])
|
||||
if @table.occupied?
|
||||
#TODO handle placint order on occupied table
|
||||
else
|
||||
if @list = List.from_table( @table, current_user )
|
||||
else
|
||||
#TODO handle second list creation for user
|
||||
end
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to(root_path, alert: t('messages.cannot_order_on_non_active_list')) and return unless @list.active?
|
||||
@@ -168,4 +200,14 @@ class UserController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
def move_table
|
||||
return unless list.present?
|
||||
@table = Table.find(params[:table_id])
|
||||
if @table.occupied?
|
||||
render json: {occupied: true}
|
||||
else
|
||||
list.move_to_table @table
|
||||
render json: {occupied: false}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user