move to evented mustache system
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user