many changes
This commit is contained in:
@@ -19,7 +19,7 @@ class DashboardController < ApplicationController
|
||||
|
||||
# Testing action
|
||||
def select_qrcode
|
||||
@tables = Table.all.sample(2)
|
||||
@tables = Table.all.sample(2) | List.active.map(&:table)
|
||||
render layout: 'phone'
|
||||
end
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ module Suppliers
|
||||
# GET /product_categories
|
||||
# GET /product_categories.json
|
||||
def index
|
||||
@product_categories = current_supplier.product_categories
|
||||
@product_categories = current_supplier.product_categories.sort_by(&:position)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
@@ -83,5 +83,14 @@ module Suppliers
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
# POST /supplier/product_categories/sort
|
||||
# params ~= product_category: ['abc', 'def', 'another id', ...]
|
||||
def sort
|
||||
@product_categories = ProductCategory.find(params[:product_category])
|
||||
1.upto(@product_categories.size){|i| @product_categories[i-1].position = i}
|
||||
CouchPotato.database.couchrest_database.bulk_save(@product_categories)
|
||||
render nothing: true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ module Suppliers
|
||||
# GET /products
|
||||
# GET /products.json
|
||||
def index
|
||||
@products = current_supplier.products
|
||||
@products = ProductDecorator.decorate(current_supplier.products)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
@@ -15,7 +15,7 @@ module Suppliers
|
||||
# GET /products/1
|
||||
# GET /products/1.json
|
||||
def show
|
||||
@product = Product.find(params[:id])
|
||||
@product = ProductDecorator.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
@@ -27,7 +27,6 @@ module Suppliers
|
||||
# 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
|
||||
|
||||
@@ -85,11 +85,17 @@ class UserController < ApplicationController
|
||||
handle_message_params
|
||||
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({table_number: list.table_number, supplier_name: @supplier.name}){|h, p| n = p.product_category.try(:name) || 'other'; h[n] ||= []; h[n] << p; h}
|
||||
h = ProductCategory.for_user(current_user, table: list.table, list: list) # list is performance parameter
|
||||
render json: h
|
||||
#products = list.supplier.products
|
||||
#product_categories = list.supplier.product_categories
|
||||
#other = product_categories.find(&:other?) || (product_categories << ProductCategory.other).last # Container for non categorized products
|
||||
|
||||
#product_categories.sort_by!{|p| p.product_category.try(:position) || 90000}
|
||||
#h = {table_number: list.table_number, supplier_name: @supplier.name}
|
||||
#h[:categories] = product_categories.map{|pc| {pc.name => pc.product_ids.map{|p| p.as_json}}}
|
||||
#){|h, p| n = p.product_category.try(:name) || 'other'; h[n] ||= []; h[n] << p; h}
|
||||
#render json: h
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -100,15 +106,7 @@ class UserController < ApplicationController
|
||||
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}
|
||||
h = ProductCategory.for_user(current_user, table: @table)
|
||||
render json: h
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user