Ember temp commit

This commit is contained in:
2013-09-24 08:47:30 +02:00
parent ebbb5dedfc
commit 5650ada04c
71 changed files with 595 additions and 66 deletions
+28 -20
View File
@@ -1,15 +1,16 @@
class List
include SimplyStored::Couch
include ActiveModel::SerializerSupport
per_page_method :limit_value #kaminari
property :state, default: 'active' # active, #closed
property :needs_help, type: :boolean, default: false
property :needs_payment, type: :boolean, default: false
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
property :is_paid, type: :boolean, default: false
property :paid_at, type: Time
has_many :orders, dependent: :destroy
belongs_to :table
@@ -121,11 +122,6 @@ 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
@@ -142,6 +138,16 @@ class List
end
end
def needs_help!
self.needs_help = true
if save
for user_id in user_ids
broadcast_user user_id, 'list_needs_help', id: id
end
broadcast_supplier(supplier_id, 'list_needs_help', id: id)
end
end
def is_helped!
self.needs_help = false
if save
@@ -162,6 +168,18 @@ class List
end
end
def is_paid!
self.is_paid = true
self.paid_at ||= Time.now
if save
for user_id in user_ids
broadcast_user user_id, 'list_is_paid', id: id
end
broadcast_supplier supplier_id, 'list_is_paid', id: id
end
end
def move_to_table! to_table
UserTableMove.create list: self, from_table_id: table_id, to_table: to_table
from_table = self.table_id.try(:dup)
@@ -180,16 +198,6 @@ class List
end
end
def needs_help!
self.needs_help = true
if save
for user_id in user_ids
broadcast_user user_id, 'list_needs_help', id: id
end
broadcast_supplier(supplier_id, 'list_needs_help', id: id)
end
end
def approve_join_request_for_user!(user)
if join_requests.include?(user.id)
join_requests.delete(user.id)
@@ -271,8 +279,8 @@ class List
for user_id in user_ids
broadcast_user user_id, 'new_order', order: order.with_products_as_json, total_amount: price
end
broadcast_supplier supplier.id, 'new_order', order.with_products_as_json
broadcast_supplier supplier.id, 'list_update', with_info_as_json
broadcast_supplier supplier.id, 'list_update', list: with_info_as_json
broadcast_supplier supplier.id, 'new_order', order: order.with_products_as_json
order
end
+11 -1
View File
@@ -27,6 +27,14 @@ class Order
view :by_supplier_id_and_id, key: [:supplier_id, :_id] # Do not comment me out
def self.for_supplier(supplier, options = {})
total_entries = database.view(by_supplier_id_and_id({startkey: ["#{supplier.id}\u9999"], endkey: [supplier.id], include_docs: false, reduce: true, descending: true}))
options[:total_entries] = total_entries
with_pagination_options(options) do |options|
database.view(by_supplier_id_and_id({startkey: ["#{supplier.id}\u9999"], endkey: [supplier.id], include_docs: true, reduce: false, descending: true}.merge(options)))
end
end
# Return all currently active orders for a given supplier
def self.active_for_supplier(supplier_id)
database.view(active_for_supplier_view(startkey: [supplier_id], endkey: [supplier_id, {}], reduce: false, include_docs: true))
@@ -92,6 +100,7 @@ class Order
def as_json(*args)
h = super.with_indifferent_access
h[:id] = h[:_id]
h[:table_number] = table_number
h[:section_title] = list.table.section.try(:title)
h
@@ -105,7 +114,8 @@ class Order
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}
# Use product order id as id since the price can be different for products and the state should be preserved
ho[:products] << {name: product_order.product.name, id: product_order.id, number: product_order.amount, price: product_order.price}
end
ho[:total_amount] = order_total.round(2)
@with_products_as_json = ho
+7 -2
View File
@@ -1,6 +1,7 @@
class Section
include SimplyStored::Couch
include Qwaiter::Distribution
include ActiveModel::SerializerSupport
property :title
property :path, type: Array, default: [[0.0, 0.0], [20.0, 30.0]] # default width 20m height 30m
@@ -61,10 +62,14 @@ class Section
end
end
def as_json
super.merge(width: width, height: height)
def tables_with_active_list_id
Table.enrich_active_list_id(tables)
end
#def as_json(*)
#super.merge(width: width, height: height)
#end
def for_tables_as_json
return @for_tables_as_json if @for_tables_as_json.present?
h = as_json
+8
View File
@@ -1,5 +1,6 @@
class Table
include SimplyStored::Couch
include ActiveModel::SerializerSupport
per_page_method :limit_value #kaminari
property :number, type: Fixnum, default: 1
@@ -41,10 +42,15 @@ class Table
end
end
def serializable_hash
attributes
end
def occupied?
return @is_occupied if instance_variable_defined?(:'@is_occupied')
@is_occupied = !self.class.database.view(List.active_by_table_id_view(key: id, reduce: true)).zero?
end
def occupied=(val) end
def self.enrich_active_list_id(tables)
if tables.is_a?(Array)
@@ -77,9 +83,11 @@ class Table
def width
2.0
end
def width=(val) end
# Method returning the sections table height
def height
2.0
end
def height=(val) end
end