many changes
This commit is contained in:
@@ -9,13 +9,13 @@
|
||||
//
|
||||
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
|
||||
// GO AFTER THE REQUIRES BELOW.
|
||||
//
|
||||
//= require jquery
|
||||
//= require jquery_ujs
|
||||
//= require jquery-ui
|
||||
//= require twitter/bootstrap
|
||||
//= require mustache
|
||||
//= require faye
|
||||
//= require supplier/base
|
||||
//= require_directory .
|
||||
//= require_self
|
||||
var path_mapping = {
|
||||
@@ -33,8 +33,5 @@ function redirect_to(mapping, variables){
|
||||
window.location = path_mapping[mapping] + '?' + vars.join('&')
|
||||
}
|
||||
function currency(num) {
|
||||
if (isNaN(num) || num === '' || num === null) {
|
||||
num = 0.0;
|
||||
}
|
||||
return '€ ' + parseFloat(num).toFixed(2);
|
||||
return Qwaiter.currency(num);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
jQuery ->
|
||||
$('#product-category-list').sortable
|
||||
axis: 'y'
|
||||
handle: '.handle'
|
||||
update: ->
|
||||
$.post($(this).data('update-url'), $(this).sortable('serialize'))
|
||||
@@ -283,29 +283,23 @@ class Quser
|
||||
@populate_products_table('/user/list_products_for_table.json?'+authentication_string+'&table_id='+table_id)
|
||||
populate_products_table: (src)->
|
||||
$.getJSON(data_host + src, (res) =>
|
||||
if res.has_occupied_info
|
||||
include_order_buttons = !res.is_occupied
|
||||
delete(res['has_occupied_info'])
|
||||
delete(res['is_occupied'])
|
||||
else
|
||||
include_order_buttons = true
|
||||
body = $('#products-table tbody')
|
||||
if res.table_number
|
||||
$('.table-number').text(res.table_number)
|
||||
delete(res['table_number'])
|
||||
if res.supplier_name
|
||||
$('.supplier-name').text(res.supplier_name)
|
||||
delete(res['supplier_name'])
|
||||
include_order_buttons = res.my_list
|
||||
|
||||
$('.table-number').text(res.table_number) if res.table_number
|
||||
$('.supplier-name').text(res.supplier_name) if res.supplier_name
|
||||
|
||||
window.products = {}
|
||||
body = $('#products-table tbody')
|
||||
body.find('tr').remove()
|
||||
script_id = if include_order_buttons then '#products-category-for-order-template' else '#products-category-template'
|
||||
for category, products of res
|
||||
#for category, products of res
|
||||
for category in res.categories
|
||||
body.append @mustache(script_id,
|
||||
category: category,
|
||||
products: products,
|
||||
category: category.name,
|
||||
products: category.products,
|
||||
include_order_buttons: include_order_buttons
|
||||
)
|
||||
for product in products
|
||||
for product in category.products
|
||||
window.products[product._id] = product
|
||||
)
|
||||
increment_products_counter: (product_id)->
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#product-category-list
|
||||
list-style: none
|
||||
li
|
||||
clear: both
|
||||
margin-bottom: 8px
|
||||
.name
|
||||
padding: 5px 5px
|
||||
@@ -26,3 +26,7 @@ body
|
||||
border: 1px solid black
|
||||
padding: 2px
|
||||
display: inline-block
|
||||
.handle
|
||||
cursor: move
|
||||
font-size: 0.8em
|
||||
color: #777
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
class ProductDecorator < Draper::Base
|
||||
decorates :product
|
||||
|
||||
def category_links(options = {})
|
||||
if namespace = options[:namespace]
|
||||
product_categories.map{|pc| h.link_to pc.name, [namespace, pc]}.join(', ').html_safe
|
||||
else
|
||||
product_categories.map{|pc| h.link_to pc.name, pc}.join(', ').html_safe
|
||||
end
|
||||
end
|
||||
|
||||
# Accessing Helpers
|
||||
# You can access any helper via a proxy
|
||||
#
|
||||
# Normal Usage: helpers.number_to_currency(2)
|
||||
# Abbreviated : h.number_to_currency(2)
|
||||
#
|
||||
# Or, optionally enable "lazy helpers" by including this module:
|
||||
# include Draper::LazyHelpers
|
||||
# Then use the helpers with no proxy:
|
||||
# number_to_currency(2)
|
||||
|
||||
# Defining an Interface
|
||||
# Control access to the wrapped subject's methods using one of the following:
|
||||
#
|
||||
# To allow only the listed methods (whitelist):
|
||||
# allows :method1, :method2
|
||||
#
|
||||
# To allow everything except the listed methods (blacklist):
|
||||
# denies :method1, :method2
|
||||
|
||||
# Presentation Methods
|
||||
# Define your own instance methods, even overriding accessors
|
||||
# generated by ActiveRecord:
|
||||
#
|
||||
# def created_at
|
||||
# h.content_tag :span, attributes["created_at"].strftime("%a %m/%d/%y"),
|
||||
# :class => 'timestamp'
|
||||
# end
|
||||
end
|
||||
+7
-1
@@ -8,6 +8,8 @@ class List
|
||||
property :closed_at, type: Time
|
||||
property :join_requests, type: Array, default: []
|
||||
property :price, type: Float
|
||||
property :is_payed, type: :boolean, default: false
|
||||
property :payed_at, type: Time
|
||||
|
||||
has_many :orders, dependent: :destroy
|
||||
belongs_to :table
|
||||
@@ -90,6 +92,11 @@ class List
|
||||
database.view(for_supplier_view({startkey: [supplier.id, range.last], endkey: [supplier.id, range.first], include_docs: true, reduce: false, descending: true}.merge(options)))
|
||||
end
|
||||
|
||||
def mark_as_payed
|
||||
self.is_payed = true
|
||||
self.payed_at = Time.now
|
||||
end
|
||||
|
||||
def close!
|
||||
orders.include_relation(:product_orders)
|
||||
set_price
|
||||
@@ -155,7 +162,6 @@ class List
|
||||
add_user(user)
|
||||
user.save
|
||||
self.is_dirty
|
||||
binding.pry
|
||||
if save
|
||||
broadcast_user user.id, 'join_request_approved'
|
||||
end
|
||||
|
||||
+17
-1
@@ -5,10 +5,26 @@ class Product
|
||||
property :code
|
||||
property :price, type: Float
|
||||
|
||||
belongs_to :product_category
|
||||
#belongs_to :product_category
|
||||
has_and_belongs_to_many :product_categories, storing_keys: false
|
||||
belongs_to :supplier # direct! category is an aid
|
||||
has_many :product_orders
|
||||
|
||||
validates :supplier_id, presence: true
|
||||
after_save :persist_product_category_ids
|
||||
|
||||
def product_category_ids=(ids)
|
||||
@product_category_ids = ids.select(&:present?)
|
||||
end
|
||||
|
||||
private
|
||||
def persist_product_category_ids
|
||||
return unless @product_category_ids.present?
|
||||
database.load(@product_category_ids).each do |product_category|
|
||||
product_category.product_ids ||= []
|
||||
product_category.product_ids |= [id]
|
||||
product_category.save
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -5,10 +5,41 @@ class ProductCategory
|
||||
property :position, type: Fixnum, default: 0
|
||||
|
||||
belongs_to :supplier
|
||||
has_many :products
|
||||
has_and_belongs_to_many :products, storing_keys: true
|
||||
|
||||
attr_protected :supplier_id
|
||||
|
||||
validates :position, numericality: true
|
||||
validates :supplier_id, presence: true
|
||||
|
||||
def self.for_user(user, options = {})
|
||||
table = options[:table]
|
||||
raise "ProductCategory.for_user requires a table" unless table.present?
|
||||
list = options[:list] || table.active_list
|
||||
|
||||
# Get supplier objects
|
||||
products = table.supplier.products
|
||||
product_categories = table.supplier.product_categories || []
|
||||
|
||||
# sort categories
|
||||
product_categories.sort_by!{|pc| (pc.position || 90000).to_i }
|
||||
|
||||
# Append other category if not defined by supplier
|
||||
other = product_categories.find(&:other?) || (product_categories << self.other).last # Container for non categorized products
|
||||
|
||||
# Initialize base return object
|
||||
h = {table_number: table.number, supplier_name: table.supplier.name, my_list: list.try(:user_ids).to_a.include?(user.id)}
|
||||
|
||||
(products - product_categories.map(&:products).flatten).each{ |p| other.add_product(p) }
|
||||
|
||||
h[:categories] = product_categories.map{|pc| {name: pc.name, products: pc.products.to_a.map{|p| p.as_json}}}.select{|pc| pc && pc[:products].present?}
|
||||
h
|
||||
end
|
||||
|
||||
def other?
|
||||
%w[other overig].include?(name.to_s.downcase)
|
||||
end
|
||||
def self.other(options = {})
|
||||
new(options.reverse_merge(name: I18n.t('user.product_category.other_name')))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,6 +50,7 @@ html lang="en"
|
||||
//li= link_to t('supplier.menu.active_orders', orders: Order.model_name.human_plural), supplier_active_orders_path
|
||||
//li= link_to t('supplier.menu.active_lists', lists: List.model_name.human_plural), supplier_active_lists_path
|
||||
li= link_to ProductCategory.model_name.human_plural, suppliers_product_categories_path
|
||||
li= link_to ProductCategory.model_name.human_plural, suppliers_product_categories_path
|
||||
li= link_to Product.model_name.human_plural, suppliers_products_path
|
||||
li= link_to Section.model_name.human_plural, suppliers_sections_path
|
||||
li= link_to Table.model_name.human_plural, suppliers_tables_path
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
= f.label :price, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :price, class: 'text_field'
|
||||
.control-group class=(@product.errors[:product_category_id].any? ? 'error' : nil)
|
||||
/.control-group class=(@product.errors[:product_category_id].any? ? 'error' : nil)
|
||||
= f.label :product_category_id, ProductCategory.model_name.human, class: 'control-label'
|
||||
.controls
|
||||
= f.collection_select :product_category_id, @product_categories, :id, :name, include_blank: ''
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
= form_for [:suppliers, @product_category], html: {class: 'form-horizontal' } do |f|
|
||||
= simple_form_for [:suppliers, @product_category], html: {class: 'form-horizontal'} do |f|
|
||||
= render 'error_messages', target: @product_category
|
||||
.control-group class=(@product_category.errors[:name].any? ? 'error' : nil)
|
||||
= f.label :name, class: 'control-label'
|
||||
= f.input :name
|
||||
.control-group
|
||||
= hidden_field_tag 'product_category[product_ids][]', ''
|
||||
= label_tag nil, Product.model_name.human_plural, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :name, class: 'text_field'
|
||||
.control-group class=(@product_category.errors[:position].any? ? 'error' : nil)
|
||||
= f.label :position, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :position, class: 'text_field'
|
||||
- for product in current_supplier.products
|
||||
= check_box_tag "product_category[product_ids][]", product.id, @product_category.product_ids.to_a.include?(product.id), id: "product-checker-#{product.id}"
|
||||
= label_tag "product-checker-#{product.id}", product.name
|
||||
br
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
= f.button :submit, class: 'btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), suppliers_product_categories_path, class: 'btn'
|
||||
|
||||
@@ -2,25 +2,16 @@
|
||||
.page-header= title :index, model_class
|
||||
.well
|
||||
- if @product_categories.any?
|
||||
table.table
|
||||
thead
|
||||
tr
|
||||
th= model_class.human_attribute_name(:name)
|
||||
th= model_class.human_attribute_name(:position)
|
||||
th.timestamp= model_class.human_attribute_name(:created_at)
|
||||
th.actions=t 'helpers.actions'
|
||||
tbody
|
||||
- @product_categories.each do |product_category|
|
||||
tr
|
||||
td.link= link_to product_category.name, [:suppliers, product_category]
|
||||
td= product_category.position
|
||||
td.timestamp=l product_category.created_at, format: :short
|
||||
td.actions
|
||||
= link_to t('helpers.links.edit'), [:edit, :suppliers, product_category], class: 'btn btn-mini'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), [:suppliers, product_category], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
ul#product-category-list data-update-url=sort_suppliers_product_categories_path
|
||||
- for product_category in @product_categories
|
||||
= content_tag_for :li, product_category do
|
||||
span.handle [drag]
|
||||
span.name= link_to product_category.name, [:suppliers, product_category]
|
||||
.pull-right.actions
|
||||
= link_to t('helpers.links.edit'), [:edit, :suppliers, product_category], class: 'btn btn-mini'
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), [:suppliers, product_category], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-mini btn-danger'
|
||||
- else
|
||||
= no_content_given model_class
|
||||
.form-actions
|
||||
= link_to t("helpers.links.new"), new_suppliers_product_category_path, class: 'btn btn-primary'
|
||||
|
||||
|
||||
@@ -14,5 +14,5 @@ dl.dl-horizontal.show-list
|
||||
'
|
||||
= link_to t("helpers.links.destroy"), [:suppliers, @product_category], method: :delete, data: {confirm: are_you_sure? }, class: 'btn btn-danger'
|
||||
- content_for :row do
|
||||
- @products = @product_category.products
|
||||
- @products = ProductDecorator.decorate(@product_category.products)
|
||||
= render template: 'suppliers/products/index'
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
= form_for [:suppliers, @product], html: {class: 'form-horizontal' } do |f|
|
||||
= simple_form_for [:suppliers, @product], html: {class: 'form-horizontal'} do |f|
|
||||
= render 'error_messages', target: @product
|
||||
.control-group class=(@product.errors[:name].any? ? 'error' : nil)
|
||||
= f.label :name, class: 'control-label'
|
||||
= f.input :name
|
||||
= f.input :code
|
||||
= f.input :price
|
||||
.control-group
|
||||
= hidden_field_tag 'product[product_category_ids][]', []
|
||||
= label_tag nil, ProductCategory.model_name.human_plural, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :name, class: 'text_field'
|
||||
.control-group class=(@product.errors[:code].any? ? 'error' : nil)
|
||||
= f.label :code, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :code, class: 'text_field'
|
||||
.control-group class=(@product.errors[:price].any? ? 'error' : nil)
|
||||
= f.label :price, class: 'control-label'
|
||||
.controls
|
||||
= f.text_field :price, class: ['text_field', :currency]
|
||||
.control-group class=(@product.errors[:product_category_id].any? ? 'error' : nil)
|
||||
= f.label :product_category_id, ProductCategory.model_name.human, class: 'control-label'
|
||||
.controls
|
||||
= f.collection_select :product_category_id, current_supplier.product_categories, :id, :name, include_blank: ''
|
||||
- for product_category in current_supplier.product_categories
|
||||
= check_box_tag "product[product_category_ids][]", product_category.id, @product.product_categories.to_a.include?(product_category), id: "product-category-checker-#{product_category.id}"
|
||||
= label_tag "product-category-checker-#{product_category.id}", product_category.name
|
||||
br
|
||||
|
||||
.form-actions
|
||||
= f.submit nil, class: 'btn btn-primary'
|
||||
= f.button :submit, class: 'btn-primary'
|
||||
'
|
||||
= link_to t("helpers.links.cancel"), suppliers_products_path, class: 'btn'
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
th= model_class.human_attribute_name(:name)
|
||||
th= model_class.human_attribute_name(:code)
|
||||
th.currency= model_class.human_attribute_name(:price)
|
||||
th= ProductCategory.model_name.human
|
||||
th= ProductCategory.model_name.human_plural
|
||||
th.timestamp= model_class.human_attribute_name(:created_at)
|
||||
th.actions=t 'helpers.actions'
|
||||
tbody
|
||||
@@ -17,7 +17,7 @@
|
||||
td.link= link_to product.name, [:suppliers, product]
|
||||
td= product.code
|
||||
td.currency=currency product.price
|
||||
td.link= link_to_if product.product_category.present?, product.product_category.try(:name), [:suppliers, product.product_category]
|
||||
td.link= product.category_links namespace: :suppliers
|
||||
td.timestamp=l product.created_at, format: :short
|
||||
td.actions
|
||||
= link_to t('helpers.links.edit'), [:edit, :suppliers, product], class: 'btn btn-mini'
|
||||
|
||||
@@ -8,9 +8,8 @@ dl.dl-horizontal.show-list
|
||||
dd= @product.code
|
||||
dt= model_class.human_attribute_name(:price)
|
||||
dd=currency @product.price
|
||||
- if @product.product_category.present?
|
||||
dt= ProductCategory.model_name.human
|
||||
dd= link_to @product.product_category.name, @product.product_category
|
||||
dt= ProductCategory.model_name.human_plural
|
||||
dd= @product.category_links(namespace: :suppliers)
|
||||
|
||||
.form-actions
|
||||
= link_to t("helpers.links.back"), suppliers_products_path, class: 'btn'
|
||||
|
||||
Reference in New Issue
Block a user