implement joining table
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
class UserController < ApplicationController
|
||||
before_filter :authenticate_user!
|
||||
layout 'phone'
|
||||
|
||||
alias :list :active_list
|
||||
|
||||
def home
|
||||
flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human) if params[:list_closed].present?
|
||||
flash.now[:notice] = t("messages.#{params[:message]}") if params[:message].present? && params[:message] =~ /^\w+$/
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
@@ -30,7 +32,7 @@ class UserController < ApplicationController
|
||||
def table_info
|
||||
@table = Table.find(params[:table_id])
|
||||
res = {}
|
||||
res[:ocupied] = @table.occupied?
|
||||
res[:occupied] = @table.occupied?
|
||||
res[:reserved] = @table.reserved?
|
||||
res[:supplier_closed] = @table.supplier.closed?
|
||||
if list.present?
|
||||
@@ -62,6 +64,62 @@ class UserController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def join_occupied_table
|
||||
@table = Table.find(params[:table_id])
|
||||
end
|
||||
|
||||
def request_to_join_occupied_table
|
||||
@table = Table.find(params[:table_id])
|
||||
if @list = @table.active_list
|
||||
unless @list.join_requests.include?(current_user.id)
|
||||
@list.join_requests << current_user.id
|
||||
@list.is_dirty
|
||||
@list.save
|
||||
end
|
||||
|
||||
end
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
def reject_join_request
|
||||
return unless params[:user_id]
|
||||
if list && list.join_requests.include?(params[:user_id])
|
||||
list.join_requests.delete(params[:user_id])
|
||||
list.is_dirty
|
||||
list.save
|
||||
end
|
||||
render js: ''
|
||||
end
|
||||
def approve_join_request
|
||||
return unless params[:user_id]
|
||||
@user = User.find(params[:user_id])
|
||||
if list && list.join_requests.include?(params[:user_id])
|
||||
list.join_requests.delete(params[:user_id])
|
||||
@user.active_list_id = list.id
|
||||
list.add_user(@user)
|
||||
@user.save
|
||||
list.is_dirty
|
||||
list.save
|
||||
end
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
# POST /user/check_table_join_status table_id:12345
|
||||
def check_table_join_status
|
||||
@table = Table.find(params[:table_id])
|
||||
if @list = @table.active_list
|
||||
if @list.user_ids.include?(current_user.id)
|
||||
render json: {approved: true}
|
||||
elsif @list.join_requests.include?(current_user.id)
|
||||
render json: {waiting: true}
|
||||
else
|
||||
render json: {rejected: true}
|
||||
end
|
||||
else
|
||||
render json: {rejected: true}
|
||||
end
|
||||
end
|
||||
|
||||
def list_products_for_table
|
||||
@table = Table.find(params[:table_id])
|
||||
respond_to do |format|
|
||||
@@ -115,6 +173,7 @@ class UserController < ApplicationController
|
||||
# GET /user/list_info.json
|
||||
# Information about the currently active list
|
||||
# Fast version to verify wether the is is still currently active
|
||||
# for handle_active_list
|
||||
def list_info
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
@@ -122,8 +181,17 @@ class UserController < ApplicationController
|
||||
current_user.list_is_closed!
|
||||
render json: {list_active: false}
|
||||
return
|
||||
else
|
||||
render json: list.as_json.merge(list_active: list.active? )
|
||||
else
|
||||
list_obj = list.as_json.merge(list_active: list.active? )
|
||||
|
||||
# Handle join requests
|
||||
if list.join_requests.any?
|
||||
list_obj[:join_requests] = []
|
||||
for user in CouchPotato.database.load_document(list.join_requests)
|
||||
list_obj[:join_requests] << {user_id: user.id, user_email: user.email}
|
||||
end
|
||||
end
|
||||
render json: list_obj
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user