Files
mozo-backend/app/controllers/dashboard_controller.rb
T

82 lines
2.2 KiB
Ruby

class DashboardController < ApplicationController
before_filter :check_active_list_state, except: :home
def home
end
def phone_home
render layout: 'phone'
end
# Testing action
def select_qrcode
@tables = Table.all
render layout: 'phone'
end
def create_list
@table = Table.find(params[:table_id])
if @table.occupied?
redirect_to root_path, alert: t('table.is_occupied')
else
@list = List.new(table: @table)
#@list.add_user(current_user)
@list.save
session[:active_list_id] = @list.id
redirect_to action: :show_products
end
end
def show_products
@supplier = Supplier.first
render layout: 'phone'
end
def order_active_list
respond_to do |format|
format.html do
redirect_to(root_path, alert: t('messages.cannot_order_without_list_id')) and return if params[:list_id].blank?
@list = List.find(params[:list_id])
redirect_to(root_path, alert: t('messages.cannot_order_on_non_active_list')) and return unless @list.active?
@list.place_order params[:products]
redirect_to root_path, notice: t('messages.order_is_placed')
end
format.js do
render js: js_alert(t('messages.cannot_order_without_list_id')) and return if params[:list_id].blank?
@list = List.find(params[:list_id])
render js: js_alert(t('messages.cannot_order_on_non_active_list')) and return unless @list.active?
@list.place_order params[:products]
render js: js_notice( t('messages.order_is_placed') )
end
end
end
def view_active_list
redirect_to(root_path, alert: t('messages.there_is_no_list_active')) and return unless session[:active_list_id].present?
render layout: 'phone'
end
##
# Displays the closed lists of the user
def user_history
render layout: 'phone'
end
def list_info
respond_to do |format|
format.json do
render json: {list_active: false} and return unless session[:active_list_id].present?
render json: active_list.as_json.merge(list_active: true)
end
end
end
def supplier_home
redirect_to active_orders_supplier_path(Supplier.first)
end
def supplier_lists
redirect_to active_lists_supplier_path(Supplier.first)
end
end