updates for qr handling

This commit is contained in:
2012-08-27 15:46:18 +02:00
parent c087aa0267
commit 157b2406a0
14 changed files with 79 additions and 36 deletions
-10
View File
@@ -23,16 +23,6 @@ root.Qrammer =
clear_active_list: -> clear_active_list: ->
window.active_products_list = {} window.active_products_list = {}
$('#active-order-table').hide() $('#active-order-table').hide()
handle_response: (res) ->
if(typeof(res) == 'string')
return unless res.length
if res[0] == '{'
res = JSON.parse(res)
else
eval(res)
return
window.location = '/' if res['message'] && !res['ok']
window.location = '/user/active_list' if res['ok']
load_active_orders: () -> load_active_orders: () ->
$.get('/supplier/active_orders.json', (res) -> $.get('/supplier/active_orders.json', (res) ->
body = $('#active-orders-table tbody') body = $('#active-orders-table tbody')
+20 -3
View File
@@ -3,7 +3,7 @@ root.Quser=
handle_active_list: (callback) -> handle_active_list: (callback) ->
$.get('/user/list_info.json', (res) -> $.get('/user/list_info.json', (res) ->
if !res.list_active if !res.list_active
window.location = '/phone_home?list_closed=true' window.location = '/user?list_closed=true'
return return
window.active_list = res window.active_list = res
callback.call() if callback callback.call() if callback
@@ -60,10 +60,20 @@ root.Quser=
foot.append('<tr><td></td><td class="currency"><strong>'+Qrammer.currency(res.total_amount)+'</strong></td></tr>') foot.append('<tr><td></td><td class="currency"><strong>'+Qrammer.currency(res.total_amount)+'</strong></td></tr>')
) )
order_selected_products: ()-> order_selected_products: ()->
h = {list_id: active_list_id} h = {}
for product_id, info of window.active_products_list for product_id, info of window.active_products_list
h['products['+product_id+']'] = info.number h['products['+product_id+']'] = info.number
$.post('/user/order_selected_products', h, ((res) -> Qrammer.handle_response(res)), 'json') $.post('/user/order_selected_products', h, ((res) -> Quser.handle_response(res)), 'json')
handle_response: (res) ->
if(typeof(res) == 'string')
return unless res.length
if res[0] == '{'
res = JSON.parse(res)
else
eval(res)
return
window.location = '/user' if res['message'] && !res['ok']
window.location = res.location || '/user/list_products' if res['ok']
build_product_list: -> build_product_list: ->
table = $('#active-order-table') table = $('#active-order-table')
tbody = table.find('tbody') tbody = table.find('tbody')
@@ -118,6 +128,13 @@ root.Quser=
body.append(row) body.append(row)
) )
actions_for_table: (table_id)->
$.get('/user/table_info.json?table_id='+table_id, (res)->
if res.occupied
alert('Table is occupied')
else
$.post('/user/create_list.json', {table_id: table_id}, (res)-> Quser.handle_response(res))
, 'json')
add_product: (product, count) -> add_product: (product, count) ->
count ||= 1 count ||= 1
window.active_products_list = {} unless window.active_products_list window.active_products_list = {} unless window.active_products_list
+8 -4
View File
@@ -30,10 +30,14 @@ class ApplicationController < ActionController::Base
alias :active_list_object :active_list alias :active_list_object :active_list
helper_method :active_list_object helper_method :active_list_object
def js_alert(message) def js_alert(*args)
{ok: false, message: message}.to_json options = args.extract_options!
message = args.first || ''
{ok: false, message: message}.merge(options).to_json
end end
def js_notice(message) def js_notice(*args)
{ok: true, message: message}.to_json options = args.extract_options!
message = args.first || ''
{ok: true, message: message}.merge(options).to_json
end end
end end
+3
View File
@@ -1,6 +1,9 @@
class SupplierController < ApplicationController class SupplierController < ApplicationController
before_filter :authenticate_supplier! before_filter :authenticate_supplier!
def home
render layout: 'tablet'
end
# GET /suppliers/1/active_orders # GET /suppliers/1/active_orders
# GET /suppliers/1/active_orders.json # GET /suppliers/1/active_orders.json
def active_orders def active_orders
+4 -2
View File
@@ -86,10 +86,12 @@ class TablesController < ApplicationController
# GET /tables/qrcode.png # GET /tables/qrcode.png
# GET /tables/qrcode.svg # GET /tables/qrcode.svg
def qrcode def qrcode
@table = Table.find(params[:id])
code = @table.id
respond_to do |format| respond_to do |format|
format.html format.html
format.svg { render :qrcode => request.url, :level => :l, :unit => 10 } format.svg { render :qrcode => code, :level => :l, :unit => 10 }
format.png { render qrcode: request.url } format.png { render qrcode: code }
end end
end end
+28 -11
View File
@@ -12,14 +12,29 @@ class UserController < ApplicationController
def create_list def create_list
@table = Table.find(params[:table_id]) @table = Table.find(params[:table_id])
if @table.occupied? if @table.occupied?
redirect_to root_path, alert: t('table.is_occupied') respond_to do |format|
format.html { redirect_to root_path, alert: t('table.is_occupied') }
format.json { render json: js_alert(t('messages.table_is_occupied'))}
end
else else
@list = List.new(table: @table, supplier_id: @table.supplier_id) @list = List.new(table: @table, supplier_id: @table.supplier_id)
@list.add_user current_user @list.add_user current_user
#@list.add_user(current_user) #@list.add_user(current_user)
@list.save @list.save
session[:active_list_id] = @list.id session[:active_list_id] = @list.id
redirect_to user_list_products_path respond_to do |format|
format.html { redirect_to user_list_products_path }
format.json { render json: js_notice('table_created')}
end
end
end
def table_info
@table = Table.find(params[:table_id])
respond_to do |format|
format.json do
render json: {occupied: @table.occupied?}
end
end end
end end
@@ -81,8 +96,13 @@ class UserController < ApplicationController
def list_info def list_info
respond_to do |format| respond_to do |format|
format.json do format.json do
render json: {list_active: false} and return unless list.present? if !list.try(:active?)
render json: list.as_json.merge(list_active: true) session[:active_list_id] = nil
render json: {list_active: false}
return
else
render json: list.as_json.merge(list_active: list.active? )
end
end end
end end
end end
@@ -94,7 +114,7 @@ class UserController < ApplicationController
render json: {list_active: false} and return unless list.present? render json: {list_active: false} and return unless list.present?
list.needs_help = true list.needs_help = true
list.save list.save
render json: list.as_json.merge(list_active: true) render json: list.as_json.merge(list_active: list.active?)
end end
end end
end end
@@ -106,7 +126,7 @@ class UserController < ApplicationController
render json: {list_active: false} and return unless list.present? render json: {list_active: false} and return unless list.present?
list.needs_payment = true list.needs_payment = true
list.save list.save
render json: list.as_json.merge(list_active: true) render json: list.as_json.merge(list_active: list.active?)
end end
end end
end end
@@ -134,20 +154,17 @@ class UserController < ApplicationController
def order_selected_products def order_selected_products
@list = list
respond_to do |format| respond_to do |format|
format.html do 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? 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] @list.place_order current_user, params[:products]
redirect_to root_path, notice: t('messages.order_is_placed') redirect_to root_path, notice: t('messages.order_is_placed')
end end
format.js do 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? render js: js_alert(t('messages.cannot_order_on_non_active_list')) and return unless @list.active?
@list.place_order current_user, params[:products] @list.place_order current_user, params[:products]
render js: js_notice( t('messages.order_is_placed') ) render js: js_notice( t('messages.order_is_placed'), location: user_active_list_path )
end end
end end
end end
+2 -2
View File
@@ -12,12 +12,12 @@ class Table
view :active_lists, type: :custom, map_function: %|function(doc){ view :active_lists, type: :custom, map_function: %|function(doc){
if(doc.ruby_class == 'List' && doc.state == 'active'){ if(doc.ruby_class == 'List' && doc.state == 'active'){
emit(doc._id, 1); emit(doc.table_id, 1);
} }
}|, reduce_function: '_sum' }|, reduce_function: '_sum'
def occupied? def occupied?
not self.class.database.view(self.class.active_lists(key: list_id, reduce: true)).zero? not self.class.database.view(self.class.active_lists(key: id, reduce: true)).zero?
end end
end end
+1 -1
View File
@@ -1,4 +1,4 @@
.page-header= title 'Select Qr code' .page-header= title 'Select Qr code'
ul#qr-list ul#qr-list
- for table in @tables - for table in @tables
li= link_to image_tag(url_for(qrcode_table_path(table, format: :png))), user_create_list_path(table_id: table.id) li= link_to_function image_tag(url_for(qrcode_table_path(table, format: :png))), %|Quser.actions_for_table('#{table.id}')|
+1 -1
View File
@@ -33,7 +33,7 @@ html lang="en"
ul.nav#top-navigation-list ul.nav#top-navigation-list
- if list_open? - if list_open?
li= link_to 'Move table', '#' li= link_to 'Move table', '#'
li= link_to 'View history', user_history_path li= link_to 'View history', user_list_history_path
.container .container
+2
View File
@@ -0,0 +1,2 @@
= render template: 'supplier/active_lists'
= render template: 'supplier/active_orders'
+2
View File
@@ -4,5 +4,7 @@ ul.nav.nav-tabs.nav-stacked
li= link_to 'Active list', user_active_list_path li= link_to 'Active list', user_active_list_path
- else - else
li= link_to 'Join table with Qr scan', '/select_qrcode' li= link_to 'Join table with Qr scan', '/select_qrcode'
li
button.btn.btn-primary onClick="QMobile.scanQr()" Scan Qr
li= link_to 'Subscribe to list', '#' li= link_to 'Subscribe to list', '#'
li= link_to 'Check out menu', '#' li= link_to 'Check out menu', '#'
+1 -1
View File
@@ -11,11 +11,11 @@ en:
errors: errors:
title: There are problems found during saving (%{count}) title: There are problems found during saving (%{count})
messages: messages:
cannot_order_without_list_id: You cannot place an order without specifying a list
cannot_order_on_non_active_list: You cannot place an order on a closed list cannot_order_on_non_active_list: You cannot place an order on a closed list
order_is_placed: Your order has been received in good order order_is_placed: Your order has been received in good order
the_list_has_been_closed: The %{list} has been closed the_list_has_been_closed: The %{list} has been closed
illegal_history_list_attempt: The list you want to access is not yours illegal_history_list_attempt: The list you want to access is not yours
table_is_occupied: The table you want to sit on is already occupied
action: action:
index: index:
label: Listing %{models} label: Listing %{models}
+3 -1
View File
@@ -18,9 +18,10 @@ Qrammer::Application.routes.draw do
resources :products resources :products
resources :product_categories resources :product_categories
get '/supplier' => 'supplier#active_orders', as: :supplier_root get '/supplier' => 'supplier#home', as: :supplier_root
get '/supplier/active_orders' => 'supplier#active_orders', as: :supplier_active_orders get '/supplier/active_orders' => 'supplier#active_orders', as: :supplier_active_orders
get '/supplier/active_lists' => 'supplier#active_lists', as: :supplier_active_lists get '/supplier/active_lists' => 'supplier#active_lists', as: :supplier_active_lists
get 'supplier/lists/:list_id' => 'supplier#show_list', as: :supplier_show_list
post '/supplier/close_list' => 'supplier#close_list', as: :supplier_close_list post '/supplier/close_list' => 'supplier#close_list', as: :supplier_close_list
post '/supplier/mark_list_as_helped' => 'supplier#mark_list_as_helped', as: :supplier_mark_list_as_helped post '/supplier/mark_list_as_helped' => 'supplier#mark_list_as_helped', as: :supplier_mark_list_as_helped
@@ -38,6 +39,7 @@ Qrammer::Application.routes.draw do
match '/user/list_history' => 'user#list_history', as: :user_list_history match '/user/list_history' => 'user#list_history', as: :user_list_history
match '/user/list_history/:list_id' => 'user#history_list', as: :user_history_list match '/user/list_history/:list_id' => 'user#history_list', as: :user_history_list
post '/user/order_selected_products' => 'user#order_selected_products', as: :user_order_selected_products post '/user/order_selected_products' => 'user#order_selected_products', as: :user_order_selected_products
get '/user/table_info' => 'user#table_info', as: :user_table_info
match '/show_products' => 'dashboard#show_products', as: :user_products match '/show_products' => 'dashboard#show_products', as: :user_products
+4
View File
@@ -37,4 +37,8 @@ Actielijst:
- Plaats omgevingen in ihpone / ipad omgeving (gerelateerd) - Plaats omgevingen in ihpone / ipad omgeving (gerelateerd)
- Barman en vaste tafels - Barman en vaste tafels
Jukebox koppeling
Wireless wachtwoord via qr code
handle closed list on list update for user list handle closed list on list update for user list