end of day commit
This commit is contained in:
@@ -14,9 +14,9 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
end
|
||||
def check_active_list_state
|
||||
if session[:active_list_id]
|
||||
if current_user.try(:active_list_id)
|
||||
unless active_list.active?
|
||||
session[:active_list_id] = nil
|
||||
current_user.list_is_closed!
|
||||
redirect_to user_root_path, alert: t('messages.the_list_has_been_closed', list: List.model_name.human)
|
||||
end
|
||||
end
|
||||
@@ -24,8 +24,8 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def active_list
|
||||
return nil unless session[:active_list_id].present?
|
||||
@active_list ||= List.find(session[:active_list_id])
|
||||
return nil unless current_user.try(:active_list_id).present?
|
||||
@active_list ||= List.find(current_user.active_list_id)
|
||||
end
|
||||
alias :active_list_object :active_list
|
||||
helper_method :active_list_object
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
class DashboardController < ApplicationController
|
||||
|
||||
before_filter :check_active_list_state, except: :home
|
||||
def home
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -16,9 +13,17 @@ class DashboardController < ApplicationController
|
||||
end
|
||||
|
||||
|
||||
def supplier_home
|
||||
redirect_to active_orders_supplier_path(Supplier.first)
|
||||
# GET /select_qr_image
|
||||
# GET /select_qr_image.png
|
||||
# GET /select_qr_image.svg
|
||||
def table_qr_image
|
||||
@table = Table.find(params[:table_id])
|
||||
code = {table_id: @table.id}.to_json
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.svg { render :qrcode => code, :level => :l, :unit => 10, table_number: @table.number }
|
||||
format.png { render qrcode: code, table_number: @table.number }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
module Suppliers
|
||||
class ApplicationController < ::ApplicationController
|
||||
before_filter :authenticate_supplier!
|
||||
layout 'tablet'
|
||||
|
||||
end
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
module Suppliers
|
||||
class ProductCategoriesController < Suppliers::ApplicationController
|
||||
|
||||
# GET /product_categories
|
||||
# GET /product_categories.json
|
||||
def index
|
||||
@product_categories = current_supplier.product_categories
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @product_categories }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /product_categories/1
|
||||
# GET /product_categories/1.json
|
||||
def show
|
||||
@product_category = ProductCategory.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @product_category }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /product_categories/new
|
||||
# GET /product_categories/new.json
|
||||
def new
|
||||
@product_category = ProductCategory.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @product_category }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /product_categories/1/edit
|
||||
def edit
|
||||
@product_category = ProductCategory.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /product_categories
|
||||
# POST /product_categories.json
|
||||
def create
|
||||
@product_category = ProductCategory.new(params[:product_category])
|
||||
@product_category.supplier = current_supplier
|
||||
|
||||
respond_to do |format|
|
||||
if @product_category.save
|
||||
format.html { redirect_to [:suppliers, @product_category], notice: t('action.create.successfull', model: ProductCategory.model_name.human) }
|
||||
format.json { render json: @product_category, status: :created, location: @product_category }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: @product_category.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /product_categories/1
|
||||
# PUT /product_categories/1.json
|
||||
def update
|
||||
@product_category = ProductCategory.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @product_category.update_attributes(params[:product_category])
|
||||
format.html { redirect_to [:suppliers, @product_category], notice: t('action.update.successfull', model: ProductCategory.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @product_category.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /product_categories/1
|
||||
# DELETE /product_categories/1.json
|
||||
def destroy
|
||||
@product_category = ProductCategory.find(params[:id])
|
||||
@product_category.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to suppliers_product_categories_url, notice: t('action.destroy.successfull', model: ProductCategory.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,88 @@
|
||||
module Suppliers
|
||||
class ProductsController < Suppliers::ApplicationController
|
||||
|
||||
# GET /products
|
||||
# GET /products.json
|
||||
def index
|
||||
@products = current_supplier.products
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.json { render json: @products }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /products/1
|
||||
# GET /products/1.json
|
||||
def show
|
||||
@product = Product.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.json { render json: @product }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /products/new
|
||||
# GET /products/new.json
|
||||
def new
|
||||
@product = Product.new
|
||||
@product.product_category_id = params[:product_category_id].presence
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.json { render json: @product }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /products/1/edit
|
||||
def edit
|
||||
@product = Product.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /products
|
||||
# POST /products.json
|
||||
def create
|
||||
@product = Product.new(params[:product])
|
||||
@product.supplier = current_supplier
|
||||
|
||||
respond_to do |format|
|
||||
if @product.save
|
||||
format.html { redirect_to [:suppliers, @product], notice: t('action.create.successfull', model: Product.model_name.human) }
|
||||
format.json { render json: @product, status: :created, location: @product }
|
||||
else
|
||||
format.html { render action: "new" }
|
||||
format.json { render json: @product.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /products/1
|
||||
# PUT /products/1.json
|
||||
def update
|
||||
@product = Product.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @product.update_attributes(params[:product])
|
||||
format.html { redirect_to [:suppliers, @product], notice: t('action.update.successfull', model: Product.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
else
|
||||
format.html { render action: "edit" }
|
||||
format.json { render json: @product.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /products/1
|
||||
# DELETE /products/1.json
|
||||
def destroy
|
||||
@product = Product.find(params[:id])
|
||||
@product.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to suppliers_products_url, notice: t('action.destroy.successfull', model: Product.model_name.human) }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -82,19 +82,6 @@ class TablesController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
# GET /tables/qrcode
|
||||
# GET /tables/qrcode.png
|
||||
# GET /tables/qrcode.svg
|
||||
def qrcode
|
||||
@table = Table.find(params[:id])
|
||||
code = @table.id
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.svg { render :qrcode => code, :level => :l, :unit => 10 }
|
||||
format.png { render qrcode: code }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_relation_options
|
||||
|
||||
@@ -9,6 +9,7 @@ class UserController < ApplicationController
|
||||
end
|
||||
|
||||
# POST /user/create_list {table_id: 1234}
|
||||
#DEPRICATED
|
||||
def create_list
|
||||
@table = Table.find(params[:table_id])
|
||||
if @table.occupied?
|
||||
@@ -17,11 +18,8 @@ class UserController < ApplicationController
|
||||
format.json { render json: js_alert(t('messages.table_is_occupied'))}
|
||||
end
|
||||
else
|
||||
@list = List.new(table: @table, supplier_id: @table.supplier_id)
|
||||
@list.add_user current_user
|
||||
#@list.add_user(current_user)
|
||||
@list.save
|
||||
session[:active_list_id] = @list.id
|
||||
if @list = List.from_table( @table, current_user )
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html { redirect_to user_list_products_path }
|
||||
format.json { render json: js_notice('table_created')}
|
||||
@@ -31,9 +29,15 @@ class UserController < ApplicationController
|
||||
|
||||
def table_info
|
||||
@table = Table.find(params[:table_id])
|
||||
res = {}
|
||||
res[:ocupied] = @table.occupied?
|
||||
if list.present?
|
||||
res[:other_supplier] = true if list.supplier_id != @table.supplier_id
|
||||
res[:current_table_id] = list.table_id
|
||||
end
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {occupied: @table.occupied?}
|
||||
render json: res
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -56,6 +60,22 @@ class UserController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def list_products_for_table
|
||||
@table = Table.find(params[:table_id])
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
render layout: 'phone'
|
||||
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({}){|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
|
||||
@@ -97,7 +117,7 @@ class UserController < ApplicationController
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
if !list.try(:active?)
|
||||
session[:active_list_id] = nil
|
||||
current_user.list_is_closed!
|
||||
render json: {list_active: false}
|
||||
return
|
||||
else
|
||||
@@ -144,8 +164,8 @@ 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
|
||||
if params[:list_closed].present? && current_user.active_list_id == @list.id
|
||||
current_user.list_is_closed!
|
||||
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)
|
||||
@@ -154,7 +174,19 @@ class UserController < ApplicationController
|
||||
|
||||
|
||||
def order_selected_products
|
||||
@list = list
|
||||
if list.present?
|
||||
@list = list
|
||||
else
|
||||
@table = Table.find(params[:table_id])
|
||||
if @table.occupied?
|
||||
#TODO handle placint order on occupied table
|
||||
else
|
||||
if @list = List.from_table( @table, current_user )
|
||||
else
|
||||
#TODO handle second list creation for user
|
||||
end
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
redirect_to(root_path, alert: t('messages.cannot_order_on_non_active_list')) and return unless @list.active?
|
||||
@@ -168,4 +200,14 @@ class UserController < ApplicationController
|
||||
end
|
||||
end
|
||||
end
|
||||
def move_table
|
||||
return unless list.present?
|
||||
@table = Table.find(params[:table_id])
|
||||
if @table.occupied?
|
||||
render json: {occupied: true}
|
||||
else
|
||||
list.move_to_table @table
|
||||
render json: {occupied: false}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user