refactor and fixes for mobile
This commit is contained in:
@@ -1,14 +1,23 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
layout :layout_by_resource
|
||||
|
||||
|
||||
protect_from_forgery
|
||||
|
||||
private
|
||||
|
||||
def layout_by_resource
|
||||
if devise_controller?
|
||||
"phone"
|
||||
else
|
||||
"application"
|
||||
end
|
||||
end
|
||||
def check_active_list_state
|
||||
if session[:active_list_id]
|
||||
unless active_list.active?
|
||||
session[:active_list_id] = nil
|
||||
redirect_to phone_root_path, alert: t('messages.the_list_has_been_closed', list: List.model_name.human)
|
||||
redirect_to user_root_path, alert: t('messages.the_list_has_been_closed', list: List.model_name.human)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -18,6 +27,8 @@ class ApplicationController < ActionController::Base
|
||||
return nil unless session[:active_list_id].present?
|
||||
@active_list ||= List.find(session[:active_list_id])
|
||||
end
|
||||
alias :active_list_object :active_list
|
||||
helper_method :active_list_object
|
||||
|
||||
def js_alert(message)
|
||||
{ok: false, message: message}.to_json
|
||||
@@ -25,7 +36,4 @@ class ApplicationController < ActionController::Base
|
||||
def js_notice(message)
|
||||
{ok: true, message: message}.to_json
|
||||
end
|
||||
|
||||
|
||||
helper_method :active_list
|
||||
end
|
||||
|
||||
@@ -4,10 +4,6 @@ class DashboardController < ApplicationController
|
||||
def home
|
||||
|
||||
end
|
||||
def phone_home
|
||||
flash.now[:notice] = t('messages.the_list_has_been_closed', list: List.model_name.human) if params[:list_closed].present?
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
# Testing action
|
||||
def select_qrcode
|
||||
@@ -15,41 +11,6 @@ class DashboardController < ApplicationController
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
def order_active_products_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 current_user, 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 current_user, params[:products]
|
||||
render js: js_notice( t('messages.order_is_placed') )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# GET /suppliers/1/product_list
|
||||
# GET /suppliers/1/product_list.json
|
||||
def product_list
|
||||
@supplier = active_list.supplier
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json do
|
||||
products = active_list.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
|
||||
|
||||
|
||||
def supplier_home
|
||||
redirect_to active_orders_supplier_path(Supplier.first)
|
||||
|
||||
@@ -3,6 +3,11 @@ class UserController < ApplicationController
|
||||
|
||||
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?
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
# POST /user/create_list {table_id: 1234}
|
||||
def create_list
|
||||
@table = Table.find(params[:table_id])
|
||||
@@ -18,9 +23,22 @@ class UserController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# GET /suppliers/1/product_list
|
||||
# GET /suppliers/1/product_list.json
|
||||
def list_products
|
||||
@supplier = Supplier.first
|
||||
render layout: 'phone'
|
||||
@supplier = list.supplier
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
render layout: 'phone'
|
||||
end
|
||||
format.json do
|
||||
products = list.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
|
||||
@@ -95,7 +113,9 @@ class UserController < ApplicationController
|
||||
|
||||
##
|
||||
# Displays the closed lists of the user
|
||||
# GET /user/list_history
|
||||
def list_history
|
||||
@lists = current_user.lists
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
@@ -104,8 +124,31 @@ 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
|
||||
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)
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
|
||||
def order_selected_products
|
||||
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 current_user, 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 current_user, params[:products]
|
||||
render js: js_notice( t('messages.order_is_placed') )
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user