move to evented mustache system
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
//= require jquery_ujs
|
||||
//= require jquery-ui
|
||||
//= require twitter/bootstrap
|
||||
//= require mustache
|
||||
//= require_directory .
|
||||
//= require_self
|
||||
var path_mapping = {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
class List
|
||||
constructor: (@attributes)->
|
||||
id: -> @attributes.id || @attributes._id
|
||||
table_number: -> @attributes.table_number
|
||||
total_amount: -> @attributes.total_amount
|
||||
section_title: -> @attributes.section_title
|
||||
needs_help: -> @attributes.needs_help
|
||||
needs_payment: -> @attributes.needs_payment
|
||||
active: -> @attributes.state == 'active'
|
||||
products: -> @attributes.products || []
|
||||
|
||||
@List = List
|
||||
@@ -0,0 +1,17 @@
|
||||
class Order
|
||||
constructor: (@attributes)->
|
||||
table_number: -> @attributes.table_number
|
||||
id: -> @attributes.id || @attributes._id
|
||||
total_amount: -> @attributes.total_amount
|
||||
section_title: -> @attributes.section_title
|
||||
list_id: -> @attributes.list_id
|
||||
state: -> @attributes.state
|
||||
display: ->
|
||||
order_txts = []
|
||||
return '' unless @attributes.products
|
||||
for product in @attributes.products
|
||||
order_txts.push(product.name + ' (' + product.number + ')')
|
||||
order_txts.join(', ')
|
||||
can_process: -> @attributes.state == 'placed'
|
||||
|
||||
@Order = Order
|
||||
@@ -1,6 +1,37 @@
|
||||
root = exports ? this
|
||||
data_host = ''
|
||||
root.Qsupplier=
|
||||
watch_events: ->
|
||||
faye = new Faye.Client('http://localhost:9292/faye')
|
||||
faye.subscribe "/supplier/"+supplier_id, (e)=>
|
||||
if(e.event == 'new_order')
|
||||
body = $('#active-orders-table tbody')
|
||||
order = new Order(e.data)
|
||||
body.append @mustache('#active-order-template', order)
|
||||
else if(e.event == 'list_needs_help')
|
||||
$('#list-needs-help-indicator-'+e.data.id).removeClass('hide')
|
||||
$('#list-is-helped-button-'+e.data.id).removeClass('hide')
|
||||
else if(e.event == 'list_needs_payment')
|
||||
$('#list-needs-payment-indicator-'+e.data.id).removeClass('hide')
|
||||
else if(e.event == 'list_added')
|
||||
$('#active-lists-table tbody').append @mustache('#active-list-template', new List(e.data))
|
||||
else if e.event == 'list_update'
|
||||
list = new List(e.data)
|
||||
row = $('#list-row-'+list.id())
|
||||
content = @mustache('#active-list-template', list)
|
||||
if row.length then row.replaceWith(content) else $('#active-lists-table tbody').append(content)
|
||||
else if e.event == 'list_closed'
|
||||
$('#list-row-'+e.data.id).remove()
|
||||
$('.of-list-'+e.data.id).remove()
|
||||
else if e.event == 'list_helped'
|
||||
list_id = e.data.id
|
||||
$('#list-needs-help-indicator-'+list_id).addClass('hide')
|
||||
$('#list-is-helped-button-'+list_id).addClass('hide')
|
||||
else if e.event == 'order_being_processed'
|
||||
$('#order-in-process-button-'+e.data.id).hide()
|
||||
else if e.event == 'order_being_delivered'
|
||||
$('#order-row-'+e.data.id).remove()
|
||||
console.log(e)
|
||||
false
|
||||
move_table_to_active_section: (table_id)->
|
||||
table_container = $('#section-table-'+table_id)
|
||||
section_container = $('.section-tables-active')
|
||||
@@ -57,82 +88,37 @@ root.Qsupplier=
|
||||
)
|
||||
|
||||
load_active_lists: () ->
|
||||
$.get('/supplier/active_lists.json?section_id='+($('#current_section_selector').val() || ''), (res) ->
|
||||
$.get('/supplier/active_lists.json?section_id='+($('#current_section_selector').val() || ''), (res) =>
|
||||
body = $('#active-lists-table tbody')
|
||||
body.find('tr').remove()
|
||||
foot = $('#active-lists-table tfoot')
|
||||
for list in res.lists
|
||||
order_txts = []
|
||||
row = $('<tr></tr>').appendTo(body)
|
||||
close_btn = $('<button class="btn btn-warning">Close!</button>')
|
||||
close_callback = ( (lst, r) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/supplier/close_list', {list_id: list._id}, (res)-> r.slideUp('slow'))
|
||||
)(list, row)
|
||||
close_btn.click(close_callback)
|
||||
|
||||
needs_help_btn = $('<button class="btn btn-info">Question answered!</button>')
|
||||
needs_help_callback = ( (lst, r) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/supplier/mark_list_as_helped', {list_id: list._id}, (res)-> my_btn.remove() )
|
||||
)(list, row)
|
||||
needs_help_btn.click(needs_help_callback)
|
||||
|
||||
|
||||
icons_td = $('<td class="status-icons"></td>').appendTo(row)
|
||||
icons_td.append('<i class="icon-hand-up"></i>').append(' ') if list.needs_help # or icon-bell
|
||||
icons_td.append('<i class="icon-check"></i>') if list.needs_payment
|
||||
|
||||
row.append($('<td class="numeric"></td>').append($('<a href="/supplier/lists/'+list._id+'"></a>').text(list.table_number)))
|
||||
row.append($('<td></td>').text(list.section_title))
|
||||
row.append($('<td class="currency"></td>').html(currency(list.total_amount)))
|
||||
td_buttons = $('<td class="actions"></td>')
|
||||
td_buttons.append(needs_help_btn).append(' ') if list.needs_help
|
||||
td_buttons.append(close_btn)
|
||||
row.append(td_buttons)
|
||||
#foot.append('<tr><td></td><td class="currency"><strong>'+currency(res.total_amount)+'</strong></td></tr>');
|
||||
body.append @mustache('#active-list-template', new List(list))
|
||||
)
|
||||
mark_list_as_helped: (list_id)->
|
||||
$.post('/supplier/mark_list_as_helped', {list_id: list_id}, (res)->
|
||||
)
|
||||
close_list: (list_id)->
|
||||
$.post('/supplier/close_list', {list_id: list_id}, (res)->
|
||||
)
|
||||
|
||||
load_active_orders: () ->
|
||||
$.get('/supplier/active_orders.json?section_id='+($('#current_section_selector').val() || ''), (res) ->
|
||||
$.get('/supplier/active_orders.json?section_id='+($('#current_section_selector').val() || ''), (res) =>
|
||||
body = $('#active-orders-table tbody')
|
||||
body.find('tr').remove()
|
||||
foot = $('#active-orders-table tfoot')
|
||||
if(!res.orders && !res.orders.length)
|
||||
alert('No orders in list');
|
||||
return;
|
||||
alert('No orders in list')
|
||||
return
|
||||
for order in res.orders
|
||||
order_txts = []
|
||||
row = $('<tr></tr>').appendTo(body)
|
||||
process_btn = $('<button class="btn btn-success">In process!</button>')
|
||||
process_callback = ( (ord) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/supplier/mark_order_in_process', {order_id: ord.id}, (res)-> my_btn.remove())
|
||||
)(order)
|
||||
process_btn.click(process_callback)
|
||||
|
||||
delivered_btn = $('<button class="btn btn-inverse">Is delivered!</button>')
|
||||
delivered_callback = ( (ord, r) ->
|
||||
->
|
||||
my_btn = $(this)
|
||||
$.post('/supplier/order_is_delivered', {order_id: ord.id}, (res)-> r.slideUp('slow'))
|
||||
)(order, row)
|
||||
delivered_btn.click(delivered_callback)
|
||||
for product in order.products
|
||||
order_txts.push(product.name + ' (' + product['number'] + ')')
|
||||
row.append($('<td></td>').text(order_txts.join(', ')))
|
||||
row.append($('<td class="numeric"></td>').text(order.table_number))
|
||||
row.append($('<td></td>').text(order.section_title))
|
||||
row.append($('<td class="currency"></td>').html(currency(order.total_amount)))
|
||||
td_buttons = $('<td class="actions"></td>')
|
||||
td_buttons.append(process_btn).append(' ') if order.state == 'placed'
|
||||
td_buttons.append(delivered_btn)
|
||||
row.append(td_buttons)
|
||||
#foot.append('<tr><td></td><td class="currency"><strong>'+currency(res.total_amount)+'</strong></td></tr>');
|
||||
ord = new Order(order)
|
||||
body.append @mustache('#active-order-template', ord)
|
||||
)
|
||||
mark_order_in_process: (order_id)->
|
||||
$.post('/supplier/mark_order_in_process', {order_id: order_id})
|
||||
mark_order_delivered: (order_id)->
|
||||
$.post('/supplier/order_is_delivered', {order_id: order_id})
|
||||
|
||||
load_list: (list_id) ->
|
||||
$.get(data_host + '/supplier/lists/'+list_id+'.json', (res) ->
|
||||
body = $('#list-table tbody')
|
||||
@@ -140,23 +126,13 @@ root.Qsupplier=
|
||||
Qsupplier.build_list_table(body, foot, res)
|
||||
)
|
||||
build_list_table: (body, foot, res) ->
|
||||
body.find('tr').remove()
|
||||
foot.find('tr').remove()
|
||||
if !res.orders && !res.orders.length
|
||||
alert('No orders in list')
|
||||
return
|
||||
body.html('')
|
||||
for order in res.orders
|
||||
order_txts = []
|
||||
row = $('<tr></tr>').appendTo(body)
|
||||
row.addClass(order.state)
|
||||
#if(order.state == 'placed') row.addClass('info');
|
||||
#if(order.state == 'delivered') row.addClass('success');
|
||||
row.addClass('error') if order.state == 'cancelled'
|
||||
for product in order.products
|
||||
order_txts.push(product.name + ' (' + product['number'] + ')')
|
||||
row.append($('<td></td>').text(order_txts.join(', ')))
|
||||
row.append($('<td class="currency"></td>').html(currency(order.total_amount)))
|
||||
foot.append('<tr><td></td><td class="currency"><strong>'+currency(res.total_amount)+'</strong></td></tr>')
|
||||
body.append @mustache('#list-order-template', new Order(order))
|
||||
foot.find('.list-total').html(currency(res.total_amount))
|
||||
update_section_tables_view: (section_id)->
|
||||
$.get(data_host + '/supplier/sections/'+section_id+'/tables_view.json', (res)->
|
||||
for table in res.tables
|
||||
@@ -181,3 +157,10 @@ root.Qsupplier=
|
||||
return alert('Please fill in a positive number representing the number of tables per column') unless by_column_count && by_column_count > 0
|
||||
$.post('/supplier/sections/'+current_section_id+'/arrange_tables', {option: option, row_count: by_row_count, column_count: by_column_count}, -> window.location.reload())
|
||||
false
|
||||
mustache: (selector, locals)->
|
||||
locs = $.extend(locals,
|
||||
currency: ->
|
||||
(val)->
|
||||
currency(Mustache.render(val, this))
|
||||
)
|
||||
Mustache.to_html($(selector).html(), locs)
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
//= require twitter/bootstrap/bootstrap-typeahead
|
||||
//= require twitter/bootstrap/bootstrap-affix
|
||||
//= require qwaiter
|
||||
//= require supplier/order
|
||||
//= require mustache
|
||||
//= require_directory .
|
||||
//= require_self
|
||||
|
||||
@@ -11,11 +11,19 @@ class Quser
|
||||
formatted
|
||||
watch_events: ->
|
||||
faye = new Faye.Client('http://localhost:9292/faye')
|
||||
faye.subscribe "/user/"+QMobile.user_id(), (e)->
|
||||
debugger
|
||||
faye.subscribe "/user/"+QMobile.user_id(), (e)=>
|
||||
if(e.event == 'list_closed')
|
||||
redirect_to 'user_root', {list_closed: 'true'}
|
||||
console.log(data)
|
||||
#redirect_to 'user_root', {list_closed: 'true'}
|
||||
redirect_to 'history_list', {list_id: e.data.id, list_closed: true}
|
||||
if(e.event == 'list_helped')
|
||||
window.active_list.needs_help = false
|
||||
@list_needs_help_default_action()
|
||||
if(e.event == 'order_being_processed')
|
||||
$('#order-row-'+e.data.id).addClass('active')
|
||||
if(e.event == 'order_being_delivered')
|
||||
$('#order-row-'+e.data.id).addClass('delivered')
|
||||
console.log(e)
|
||||
false
|
||||
home_loader: ->
|
||||
$.getJSON(data_host + '/user/list_info.json?' + authentication_string, (res) => @handle_active_list_default_actions(res))
|
||||
handle_active_list: (callback) ->
|
||||
@@ -34,14 +42,12 @@ class Quser
|
||||
if(response.ok == false && response.status && response.status == 401)
|
||||
direct_to_site('obtain_user_token')
|
||||
return
|
||||
if response.table_number
|
||||
$('.table-number').text(response.table_number)
|
||||
if response.supplier_name
|
||||
$('.supplier-name').text(response.supplier_name)
|
||||
if response.not_present
|
||||
$('.home-link').hide()
|
||||
else
|
||||
$('.home-link').show()
|
||||
|
||||
$('.table-number').text(response.table_number) if response.table_number
|
||||
$('.supplier-name').text(response.supplier_name) if response.supplier_name
|
||||
|
||||
if response.not_present || response.list_active == false then $('.home-link').hide() else $('.home-link').show()
|
||||
|
||||
@list_needs_payment_default_action(response)
|
||||
@list_needs_help_default_action(response)
|
||||
# join_request_active is to ensure that there are no more modals loaded when one is still active
|
||||
@@ -126,9 +132,9 @@ class Quser
|
||||
$.post(data_host + '/user/list_needs_payment.json', authentication_object, (res) => window.active_list = res; window.Quser.list_needs_payment_default_action(res))
|
||||
load_active_list: () ->
|
||||
$.getJSON(data_host + '/user/active_list.json?'+authentication_string, (res) =>
|
||||
window.active_list = res
|
||||
window.active_list = res if res._id
|
||||
unless res.list_active
|
||||
redirect_to 'history_list', {list_id: res._id, list_closed: true}
|
||||
redirect_to 'history_list', {list_id: window.active_list._id, list_closed: true}
|
||||
return
|
||||
@handle_active_list_default_actions(res)
|
||||
body = $('#active-list-table tbody')
|
||||
@@ -146,6 +152,7 @@ class Quser
|
||||
foot = $('#history-list-table tfoot')
|
||||
@build_list_table(body, foot, res)
|
||||
$('.list-created-at').text(@format_date(res.created_at))
|
||||
$('.list-closed-at').text(@format_date(res.closed_at))
|
||||
$('.supplier-name').text(res.supplier_name)
|
||||
)
|
||||
load_list_history: ->
|
||||
@@ -196,12 +203,7 @@ class Quser
|
||||
alert('No orders in list')
|
||||
return
|
||||
m_obj = res
|
||||
for order in m_obj.orders
|
||||
order_txts = []
|
||||
for product in order.products
|
||||
order_txts.push(product.name + ' (' + product['number'] + ')')
|
||||
order.products_display = order_txts.join(', ')
|
||||
body.append @mustache('#active-list-orders-template', m_obj)
|
||||
body.append @mustache('#active-list-order-template', new Order(order)) for order in m_obj.orders
|
||||
foot.append @mustache('#active-list-orders-footer-template', m_obj)
|
||||
|
||||
order_selected_products: ()->
|
||||
@@ -211,7 +213,6 @@ class Quser
|
||||
h['table_id'] = match[1] if match
|
||||
for product_id, number of window.active_products_list
|
||||
h['products['+product_id+']'] = number
|
||||
debugger
|
||||
$.post(data_host + '/user/order_selected_products', $.extend(h, authentication_object), ((res) => @handle_response(res)), 'json')
|
||||
handle_response: (res) ->
|
||||
if(typeof(res) == 'string')
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
.list-status
|
||||
.list-needs-help-indicator
|
||||
display: inline-block
|
||||
width: 30px
|
||||
color: #400
|
||||
background-color: #aaf
|
||||
text-align: center
|
||||
margin-right: 7px
|
||||
&.hide
|
||||
display: none
|
||||
.list-needs-payment-indicator
|
||||
display: inline-block
|
||||
width: 30px
|
||||
color: #440
|
||||
background-color: #faa
|
||||
text-align: center
|
||||
margin-right: 7px
|
||||
&.hide
|
||||
display: none
|
||||
@@ -3,6 +3,7 @@
|
||||
*= require 'twitter-bootstrap/bootstrap_overrides'
|
||||
*= require 'jquery-ui-1.8.23.custom.css'
|
||||
*= require 'general'
|
||||
*= require user/active_list
|
||||
*= require_directory .
|
||||
*= require_self
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#active-list-table
|
||||
.list-table, #active-list-table
|
||||
tbody
|
||||
tr
|
||||
td
|
||||
|
||||
@@ -7,6 +7,16 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
private
|
||||
|
||||
def broadcast_user(uid, event, data = {})
|
||||
message = {channel: "/user/#{uid}", data: {event: event, data: data}}
|
||||
uri = URI.parse("http://localhost:9292/faye")
|
||||
Net::HTTP.post_form(uri, :message => message.to_json)
|
||||
end
|
||||
def broadcast_supplier(sid, event, data = {})
|
||||
message = {channel: "/supplier/#{sid}", data: {event: event, data: data}}
|
||||
uri = URI.parse("http://localhost:9292/faye")
|
||||
Net::HTTP.post_form(uri, :message => message.to_json)
|
||||
end
|
||||
def set_locale
|
||||
I18n.locale = :nl
|
||||
end
|
||||
@@ -14,7 +24,7 @@ class ApplicationController < ActionController::Base
|
||||
def layout_by_resource
|
||||
if devise_controller?
|
||||
case session[:user_return_to]
|
||||
when /\/user\// then ''
|
||||
when /\/user\// then 'obtain_token'
|
||||
when /obtain_token/ then 'obtain_token'
|
||||
else 'theme1'
|
||||
end
|
||||
@@ -50,9 +60,4 @@ class ApplicationController < ActionController::Base
|
||||
{ok: true, message: message}.merge(options).to_json
|
||||
end
|
||||
|
||||
def broadcast_user(uid, event, data = {})
|
||||
message = {channel: channel, data: {event: event, data: data}}
|
||||
uri = URI.parse("http://localhost:9292/faye")
|
||||
Net::HTTP.post_form(uri, :message => message.to_json)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,7 +19,7 @@ class DashboardController < ApplicationController
|
||||
|
||||
# Testing action
|
||||
def select_qrcode
|
||||
@tables = Table.all
|
||||
@tables = Table.all.sample(2)
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
|
||||
@@ -71,10 +71,8 @@ class SupplierController < ApplicationController
|
||||
h[:lists] = []
|
||||
grand_total = 0.0
|
||||
for list in @supplier.active_lists(section_id: params[:section_id].presence)
|
||||
hl = list.as_json
|
||||
hl[:total_amount] = list.orders.inject(0.0){|sum, o| sum + o.product_orders.inject(0.0){|s, po| s + (po.amount * po.price).round(2)}}.round(2)
|
||||
hl = list.with_info_as_json
|
||||
grand_total += hl[:total_amount]
|
||||
hl[:section_title] = list.table.section.try(:title)
|
||||
h[:lists] << hl
|
||||
end
|
||||
h[:total_amount] = grand_total.round(2)
|
||||
@@ -87,17 +85,13 @@ class SupplierController < ApplicationController
|
||||
def close_list
|
||||
@list = List.find_by_supplier_id_and_id(current_supplier.id, params[:list_id])
|
||||
@list.close!
|
||||
for user_id in @list.user_ids
|
||||
broadcast_user user_id, 'list_closed', @list
|
||||
end
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
# POST /orders/1/is_helped
|
||||
def mark_list_as_helped
|
||||
@list = List.find_by_supplier_id_and_id(current_supplier.id, params[:list_id])
|
||||
@list.needs_help = false
|
||||
@list.save
|
||||
@list.is_helped!
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
|
||||
@@ -93,6 +93,27 @@ class UserController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def list_products_for_table
|
||||
@table = Table.find(params[:table_id])
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
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({
|
||||
table_number: @table.number,
|
||||
supplier_name: @table.supplier.name,
|
||||
has_occupied_info: true,
|
||||
is_occupied: @table.occupied?
|
||||
}){|h, p| n = p.product_category.try(:name) || 'other'; h[n] ||= []; h[n] << p; h}
|
||||
render json: h
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def join_occupied_table
|
||||
@table = Table.find(params[:table_id])
|
||||
end
|
||||
@@ -149,26 +170,6 @@ class UserController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def list_products_for_table
|
||||
@table = Table.find(params[:table_id])
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
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({
|
||||
table_number: @table.number,
|
||||
supplier_name: @table.supplier.name,
|
||||
has_occupied_info: true,
|
||||
is_occupied: @table.occupied?
|
||||
}){|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
|
||||
@@ -214,6 +215,7 @@ class UserController < ApplicationController
|
||||
render json: {list_active: false} and return unless list.present?
|
||||
list.needs_help = true
|
||||
list.save
|
||||
broadcast_supplier(list.supplier_id, 'list_needs_help', id: list.id)
|
||||
render json: list.as_json.merge(list_active: list.active?)
|
||||
end
|
||||
end
|
||||
@@ -224,8 +226,7 @@ class UserController < ApplicationController
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {list_active: false} and return unless list.present?
|
||||
list.needs_payment = true
|
||||
list.save
|
||||
list.needs_payment!
|
||||
render json: list.as_json.merge(list_active: list.active?)
|
||||
end
|
||||
end
|
||||
|
||||
+46
-6
@@ -60,6 +60,7 @@ class List
|
||||
list.save
|
||||
user.active_list_id = list.id
|
||||
user.save
|
||||
#list.broadcast_supplier list.supplier_id, 'list_added', list.with_info_as_json
|
||||
list
|
||||
end
|
||||
|
||||
@@ -95,7 +96,34 @@ class List
|
||||
orders.map(&:close!)
|
||||
self.state = 'closed'
|
||||
self.closed_at = Time.now
|
||||
save
|
||||
if save
|
||||
for user in users
|
||||
user.active_list_id = nil
|
||||
user.save
|
||||
broadcast_user user.id, 'list_closed', id: id
|
||||
end
|
||||
broadcast_supplier supplier_id, 'list_closed', id: id
|
||||
end
|
||||
end
|
||||
|
||||
def is_helped!
|
||||
self.needs_help = false
|
||||
if save
|
||||
for user_id in user_ids
|
||||
broadcast_user user_id, 'list_helped', id: id
|
||||
end
|
||||
broadcast_supplier supplier_id, 'list_helped', id: id
|
||||
end
|
||||
end
|
||||
|
||||
def needs_payment!
|
||||
self.needs_payment = true
|
||||
if save
|
||||
for user_id in user_ids
|
||||
broadcast_user user_id, 'list_needs_payment', id: id
|
||||
end
|
||||
broadcast_supplier supplier_id, 'list_needs_payment', id: id
|
||||
end
|
||||
end
|
||||
|
||||
def set_price
|
||||
@@ -121,15 +149,17 @@ class List
|
||||
def place_order(user, products)
|
||||
return false unless products.any?
|
||||
return false unless user
|
||||
@order = Order.create list: self, supplier: supplier, user: user, section_id: section_id
|
||||
return unless @order.id
|
||||
order = Order.create list: self, supplier: supplier, user: user, section_id: section_id
|
||||
return unless order.id
|
||||
loaded_products = self.class.database.load_document products.keys
|
||||
products.each do |product_id, number|
|
||||
number = number.to_i
|
||||
product = loaded_products.find{|p| p.id == product_id} # to get the price
|
||||
ProductOrder.create order: @order, product_id: product_id, amount: number, price: product.price if number > 0
|
||||
ProductOrder.create order: order, product_id: product_id, amount: number, price: product.price if number > 0
|
||||
end
|
||||
@order
|
||||
broadcast_supplier supplier.id, 'new_order', order.with_products_as_json
|
||||
broadcast_supplier supplier.id, 'list_update', with_info_as_json
|
||||
order
|
||||
end
|
||||
|
||||
def move_to_table to_table
|
||||
@@ -139,7 +169,7 @@ class List
|
||||
save
|
||||
end
|
||||
|
||||
def as_json
|
||||
def as_json(*args)
|
||||
super.merge(table_number: table_number)
|
||||
end
|
||||
|
||||
@@ -152,6 +182,8 @@ class List
|
||||
list_total = 0.0
|
||||
for order in orders
|
||||
ho = {products: []}
|
||||
ho[:id] = order.id
|
||||
ho[:state] = order.state
|
||||
order_total = 0.0
|
||||
for product_order in order.product_orders
|
||||
order_total += (product_order.amount * product_order.price).round(2)
|
||||
@@ -184,4 +216,12 @@ class List
|
||||
end
|
||||
@join_requests_as_json = h
|
||||
end
|
||||
|
||||
def with_info_as_json
|
||||
return @with_info_as_json if @with_info_as_json.present?
|
||||
hl = as_json
|
||||
hl[:total_amount] = orders.inject(0.0){|sum, o| sum + o.product_orders.inject(0.0){|s, po| s + (po.amount * po.price).round(2)}}.round(2)
|
||||
hl[:section_title] = table.section.try(:title)
|
||||
@with_info_as_json = hl
|
||||
end
|
||||
end
|
||||
|
||||
+33
-2
@@ -50,16 +50,47 @@ class Order
|
||||
|
||||
def is_being_processed!
|
||||
self.state = 'active'
|
||||
save
|
||||
if save
|
||||
for user_id in list.user_ids
|
||||
broadcast_user user_id, 'order_being_processed', id: id
|
||||
end
|
||||
broadcast_supplier supplier_id, 'order_being_processed', id: id
|
||||
end
|
||||
end
|
||||
|
||||
def is_delivered!
|
||||
self.state = 'delivered'
|
||||
save
|
||||
if save
|
||||
for user_id in list.user_ids
|
||||
broadcast_user user_id, 'order_being_delivered', id: id
|
||||
end
|
||||
broadcast_supplier supplier_id, 'order_being_delivered', id: id
|
||||
end
|
||||
end
|
||||
|
||||
def close!
|
||||
self.state = 'closed' if placed? || active?
|
||||
save
|
||||
end
|
||||
|
||||
def as_json(*args)
|
||||
h = super.with_indifferent_access
|
||||
h[:table_number] = table_number
|
||||
h[:section_title] = list.table.section.try(:title)
|
||||
h
|
||||
end
|
||||
|
||||
def with_products_as_json
|
||||
return @with_products_as_json if @with_products_as_json.present?
|
||||
product_orders.include_relation(:product)
|
||||
ho = as_json
|
||||
ho[:products] = []
|
||||
order_total = 0.0
|
||||
for product_order in product_orders
|
||||
order_total += (product_order.amount * product_order.price).round(2)
|
||||
ho[:products] << {name: product_order.product.name, id: product_order.product_id, number: product_order.amount, price: product_order.price}
|
||||
end
|
||||
ho[:total_amount] = order_total.round(2)
|
||||
@with_products_as_json = ho
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<tr id="list-row-{{id}}">
|
||||
<td class="list-status">
|
||||
<span id="list-needs-help-indicator-{{id}}" class="list-needs-help-indicator {{^needs_help}}hide{{/needs_help}}">?</span>
|
||||
<span id="list-needs-payment-indicator-{{id}}" class="list-needs-payment-indicator {{^needs_payment}}hide{{/needs_payment}}">€</span>
|
||||
</td>
|
||||
<td class="numeric"><a href="/supplier/lists/{{id}}">{{table_number}}</a></td>
|
||||
<td>{{section_title}}</td>
|
||||
<td class="currency">{{#currency}}{{total_amount}}{{/currency}}</td>
|
||||
<td class="actions">
|
||||
<button id="list-is-helped-button-{{id}}" class="btn btn-info {{^needs_help}}hide{{/needs_help}}" onclick="Qsupplier.mark_list_as_helped('{{id}}')">Question answered!</button>
|
||||
<button class="btn btn-warning" onclick="Qsupplier.close_list('{{id}}')">Close!</button>
|
||||
<a href="/supplier/lists/{{id}}" class="btn icon-list"></a>
|
||||
</td>
|
||||
<tr>
|
||||
@@ -0,0 +1,10 @@
|
||||
<tr id="order-row-{{id}}" class="of-list-{{list_id}}">
|
||||
<td>{{display}}</td>
|
||||
<td class="numeric">{{table_number}}</td>
|
||||
<td>{{section_title}}</td>
|
||||
<td class="currency">{{#currency}}{{total_amount}}{{/currency}}</td>
|
||||
<td class="actions">
|
||||
<button id="order-in-process-button-{{id}}" class="btn btn-success {{^can_process}}hide{{/can_process}}" onclick="Qsupplier.mark_order_in_process('{{id}}')">In process!</button>
|
||||
<button class="btn btn-inverse" onclick="Qsupplier.mark_order_delivered('{{id}}')">Is delivered!</button>
|
||||
</td>
|
||||
<tr>
|
||||
@@ -0,0 +1,4 @@
|
||||
<tr id="order-row-{{id}}" class="{{state}}">
|
||||
<td>{{display}}</td>
|
||||
<td class="currency">{{#currency}}{{total_amount}}{{/currency}}</td>
|
||||
</tr>
|
||||
@@ -0,0 +1,4 @@
|
||||
<tr id="order-row-{{id}}" class="{{state}}">
|
||||
<td>{{display}}</td>
|
||||
<td class="currency">{{#currency}}{{total_amount}}{{/currency}}</td>
|
||||
</tr>
|
||||
@@ -1,6 +0,0 @@
|
||||
{{#orders}}
|
||||
<tr class="{{state}}">
|
||||
<td>{{products_display}}</td>
|
||||
<td class="currency">{{#currency}}{{total_amount}}{{/currency}}</td>
|
||||
</tr>
|
||||
{{/orders}}
|
||||
@@ -19,7 +19,7 @@
|
||||
<tfoot>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<button class="btn btn-primary" onClick="Quser.handle_active_list(function(){Quser.order_selected_products()})" data-t="selected_products.order"></button>
|
||||
<button class="btn btn-primary" onClick="Quser.order_selected_products()" data-t="selected_products.order"></button>
|
||||
<button class="btn btn btn-warning" onClick="Quser.clear_selected_products()" data-t="selected_products.clear"></button>
|
||||
</td>
|
||||
<td class="currency"><strong id="active-order-total">{{#currency}}{{total}}{{/currency}}</strong></td>
|
||||
|
||||
@@ -19,7 +19,7 @@ html lang="en"
|
||||
link href="/favicon.ico" rel="shortcut icon"
|
||||
javascript:
|
||||
var data_host = '#{Rails.env == 'development' ? 'http://qwaiter.dev' : 'http://data.qwaiter.com' }';
|
||||
//var data_host = 'http://localhost:3000';
|
||||
var data_host = 'http://localhost:3000';
|
||||
//data_host = 'http://192.168.1.148:3000';
|
||||
var $locale = 'en';
|
||||
var $url_vars = null;
|
||||
|
||||
@@ -11,11 +11,17 @@ html lang="en"
|
||||
/[if lt IE 9]
|
||||
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
|
||||
= stylesheet_link_tag "supplier/application", :media => "all"
|
||||
= javascript_include_tag 'http://localhost:9292/faye.js'
|
||||
link href="/images/apple-touch-icon-144x144.png" rel="apple-touch-icon-precomposed" sizes="144x144"
|
||||
link href="/images/apple-touch-icon-114x114.png" rel="apple-touch-icon-precomposed" sizes="114x114"
|
||||
link href="/images/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72"
|
||||
link href="/images/apple-touch-icon.png" rel="apple-touch-icon-precomposed"
|
||||
link href="/favicon.ico" rel="shortcut icon"
|
||||
|
||||
javascript:
|
||||
var supplier_id = '#{current_supplier.id}';
|
||||
var data_host = ''
|
||||
|
||||
= yield :head
|
||||
|
||||
body
|
||||
|
||||
@@ -10,11 +10,5 @@
|
||||
th.currency= t('supplier.active_lists.price')
|
||||
th.actions
|
||||
tbody
|
||||
- content_for :footer do
|
||||
javascript:
|
||||
var active_lists_interval;
|
||||
jQuery(function(){
|
||||
Qsupplier.load_active_lists()
|
||||
active_lists_interval = setInterval('Qsupplier.load_active_lists()', 7500);
|
||||
});
|
||||
script#active-list-template[type="text/html"]= render 'active_list.mustache'
|
||||
|
||||
|
||||
@@ -10,10 +10,4 @@
|
||||
th.currency= t('supplier.active_orders.price')
|
||||
th.actions
|
||||
tbody
|
||||
- content_for :footer do
|
||||
javascript:
|
||||
jQuery(function(){
|
||||
Qsupplier.load_active_orders()
|
||||
setInterval( 'Qsupplier.load_active_orders()', 7500);
|
||||
});
|
||||
|
||||
script#active-order-template[type="text/html"]= render 'active_order.mustache'
|
||||
|
||||
@@ -17,4 +17,7 @@
|
||||
linker.hide();
|
||||
}
|
||||
}).change();
|
||||
Qsupplier.load_active_orders()
|
||||
Qsupplier.load_active_lists()
|
||||
Qsupplier.watch_events();
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ dl.dl-horizontal
|
||||
dt= List.human_attribute_name(:created_at)
|
||||
dd= l @list.created_at, format: :short
|
||||
.well
|
||||
table#list-table.table
|
||||
table#list-table.table.list-table
|
||||
thead
|
||||
tr
|
||||
th= Order.model_name.human
|
||||
@@ -12,6 +12,11 @@ dl.dl-horizontal
|
||||
tr
|
||||
td colspan=2 = slider_image
|
||||
tfoot
|
||||
tr
|
||||
td
|
||||
td.currency
|
||||
strong.list-total
|
||||
script#list-order-template[type="text/html"]= render 'supplier/list_order.mustache'
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), suppliers_lists_path(date: @list.created_at.strftime('%Y-%m-%d')), class: 'btn'
|
||||
'
|
||||
|
||||
@@ -16,11 +16,12 @@
|
||||
tr
|
||||
td colspan=2 = slider_image
|
||||
tfoot
|
||||
script#active-list-orders-template[type="text/html"]= render 'active_list_orders.mustache'
|
||||
script#active-list-order-template[type="text/html"]= render 'active_list_order.mustache'
|
||||
script#active-list-orders-footer-template[type="text/html"]= render 'active_list_orders_footer.mustache'
|
||||
- content_for :footer do
|
||||
javascript:
|
||||
jQuery(function(){
|
||||
Quser.load_active_list();
|
||||
setInterval( "Quser.load_active_list()", 7500);
|
||||
Quser.watch_events();
|
||||
//setInterval( "Quser.load_active_list()", 7500);
|
||||
})
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
dl.dl-horizontal
|
||||
dt= List.human_attribute_name(:created_at)
|
||||
dd.list-created-at
|
||||
dt= List.human_attribute_name(:closed_at)
|
||||
dd.list-closed-at
|
||||
dt= Supplier.model_name.human
|
||||
dd.supplier-name
|
||||
.well
|
||||
table#history-list-table.table
|
||||
table#history-list-table.table.list-table
|
||||
thead
|
||||
tr
|
||||
th= Order.model_name.human
|
||||
@@ -14,7 +16,7 @@ dl.dl-horizontal
|
||||
tr
|
||||
td colspan=2 = slider_image
|
||||
tfoot
|
||||
script#active-list-orders-template[type="text/html"]= render 'active_list_orders.mustache'
|
||||
script#active-list-order-template[type="text/html"]= render 'active_list_order.mustache'
|
||||
script#active-list-orders-footer-template[type="text/html"]= render 'active_list_orders_footer.mustache'
|
||||
- content_for :footer do
|
||||
javascript:
|
||||
|
||||
@@ -20,7 +20,7 @@ script#active-order-template[type="text/html"]= render 'active_order.mustache'
|
||||
jQuery(function(){
|
||||
Quser.handle_active_list(function(){
|
||||
Quser.load_active_list_products();
|
||||
setInterval('Quser.handle_active_list()', 7500);
|
||||
Quser.watch_events();
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
require 'simply_stored/couch'
|
||||
module ModelBroadcast
|
||||
def broadcast_supplier(*args)
|
||||
ApplicationController.new.send(:broadcast_supplier, *args)
|
||||
end
|
||||
def broadcast_user(*args)
|
||||
ApplicationController.new.send(:broadcast_user, *args)
|
||||
end
|
||||
end
|
||||
SimplyStored::Couch.send(:include, ModelBroadcast)
|
||||
SimplyStored::Couch.send(:extend, ModelBroadcast)
|
||||
Reference in New Issue
Block a user