Fix active order display in supplier side
This commit is contained in:
@@ -9,6 +9,7 @@ class List
|
|||||||
active: -> @attributes.state == 'active'
|
active: -> @attributes.state == 'active'
|
||||||
table_id: -> @attributes.table_id
|
table_id: -> @attributes.table_id
|
||||||
products: -> @attributes.products || []
|
products: -> @attributes.products || []
|
||||||
|
has_active_orders: -> @attributes.has_active_orders
|
||||||
supplier_name: -> @attributes.supplier_name
|
supplier_name: -> @attributes.supplier_name
|
||||||
created_at: -> @attributes.created_at
|
created_at: -> @attributes.created_at
|
||||||
display: ->
|
display: ->
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ root.Qsupplier=
|
|||||||
table.addClass('occupied')
|
table.addClass('occupied')
|
||||||
table.addClass('needs_help') if list.needs_help()
|
table.addClass('needs_help') if list.needs_help()
|
||||||
table.addClass('needs_payment') if list.needs_payment()
|
table.addClass('needs_payment') if list.needs_payment()
|
||||||
|
table.addClass('active_order') if list.has_active_orders()
|
||||||
else if e.event == 'list_closed'
|
else if e.event == 'list_closed'
|
||||||
$('#list-row-'+e.data.id).remove()
|
$('#list-row-'+e.data.id).remove()
|
||||||
$('.of-list-'+e.data.id).remove()
|
$('.of-list-'+e.data.id).remove()
|
||||||
@@ -52,20 +53,24 @@ root.Qsupplier=
|
|||||||
$('#order-row-'+e.data.id).remove()
|
$('#order-row-'+e.data.id).remove()
|
||||||
$('.section-table-list-'+e.data.list_id).removeClass('active_order')
|
$('.section-table-list-'+e.data.list_id).removeClass('active_order')
|
||||||
else if e.event == 'list_changed_table'
|
else if e.event == 'list_changed_table'
|
||||||
list_row = $('#list-row-'+e.data.list_id)
|
list = new List(e.data.list)
|
||||||
list_row.find('.table_number').text(e.data.table.number).addClass('changed')
|
list_row = $('#list-row-'+list.id())
|
||||||
|
list_row.find('.table_number').text(list.table_number()).addClass('changed')
|
||||||
list_row.find('.section_title').text(e.data.section_title)
|
list_row.find('.section_title').text(e.data.section_title)
|
||||||
order_rows = $('.of-list-'+e.data.list_id)
|
order_rows = $('.of-list-'+list.id())
|
||||||
order_rows.find('.table_number').text(e.data.table.number).addClass('changed')
|
order_rows.find('.table_number').text(list.table_number()).addClass('changed')
|
||||||
order_rows.find('.section_title').text(e.data.section_title)
|
order_rows.find('.section_title').text(e.data.section_title)
|
||||||
# Move properties from table in section tables view
|
# Move properties from table in section tables view
|
||||||
window.last_data = e.data
|
window.last_data = e.data
|
||||||
from_table = $('#section-table-'+e.data.from_table_id)
|
from_table = $('#section-table-'+e.data.from_table_id)
|
||||||
to_table = $('#section-table-'+e.data.table._id)
|
to_table = $('#section-table-'+list.table_id())
|
||||||
# Now switch classes
|
if to_table.length
|
||||||
from_class = from_table.attr('class')
|
to_table.addClass('section-table-list-'+list.id())
|
||||||
from_table.attr('class', to_table.attr('class'))
|
to_table.addClass('occupied')
|
||||||
to_table.attr('class', from_class)
|
to_table.addClass('needs_help') if list.needs_help()
|
||||||
|
to_table.addClass('needs_payment') if list.needs_payment()
|
||||||
|
to_table.addClass('active_order') if list.has_active_orders()
|
||||||
|
from_table.removeClass('occupied needs_help needs_payment active_order section-table-list-'+list.id())
|
||||||
|
|
||||||
|
|
||||||
console.log(e)
|
console.log(e)
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ class Quser
|
|||||||
else if(e.event == 'order_being_delivered')
|
else if(e.event == 'order_being_delivered')
|
||||||
$('#order-row-'+e.data.id).addClass('delivered')
|
$('#order-row-'+e.data.id).addClass('delivered')
|
||||||
else if(e.event == 'list_changed_table')
|
else if(e.event == 'list_changed_table')
|
||||||
$('.table-number').text(e.data.table.number)
|
list = new List(e.data.list)
|
||||||
|
$('.table-number').text(list.table_number())
|
||||||
else if(e.event == 'list_needs_help')
|
else if(e.event == 'list_needs_help')
|
||||||
window.active_list.needs_help = true
|
window.active_list.needs_help = true
|
||||||
@list_needs_help_default_action()
|
@list_needs_help_default_action()
|
||||||
|
|||||||
+13
-4
@@ -168,10 +168,15 @@ class List
|
|||||||
self.table = to_table
|
self.table = to_table
|
||||||
self.section_id = to_table.section_id
|
self.section_id = to_table.section_id
|
||||||
if save
|
if save
|
||||||
for user_id in user_ids
|
# Update the section of an order
|
||||||
broadcast_user user_id, 'list_changed_table', list_id: id, table: to_table, section_title: to_table.section.try(:title), from_table_id: from_table
|
orders.each do |order|
|
||||||
|
order.section_id = self.section_id
|
||||||
|
order.save
|
||||||
end
|
end
|
||||||
broadcast_supplier supplier_id, 'list_changed_table', list_id: id, table: to_table, section_title: to_table.section.try(:title), from_table_id: from_table
|
for user_id in user_ids
|
||||||
|
broadcast_user user_id, 'list_changed_table', list: as_json, section_title: to_table.section.try(:title), from_table_id: from_table
|
||||||
|
end
|
||||||
|
broadcast_supplier supplier_id, 'list_changed_table', list: as_json, section_title: to_table.section.try(:title), from_table_id: from_table
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -272,7 +277,7 @@ class List
|
|||||||
end
|
end
|
||||||
|
|
||||||
def as_json(*args)
|
def as_json(*args)
|
||||||
super.merge(table_number: table_number)
|
super.merge(table_number: table_number, has_active_orders: has_active_orders? )
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_orders_as_json
|
def with_orders_as_json
|
||||||
@@ -305,6 +310,10 @@ class List
|
|||||||
@with_orders_and_join_requests_as_json = with_orders_as_json.merge(join_requests_as_json)
|
@with_orders_and_join_requests_as_json = with_orders_as_json.merge(join_requests_as_json)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_active_orders?
|
||||||
|
Order.count_active_for_supplier_and_list(supplier_id, id) > 0
|
||||||
|
end
|
||||||
|
|
||||||
# Return a join requests object in the form of:
|
# Return a join requests object in the form of:
|
||||||
# {join_request: [{user_id: '1saf3...', user_email: 'info@qwaiter.com'}, [....]]}
|
# {join_request: [{user_id: '1saf3...', user_email: 'info@qwaiter.com'}, [....]]}
|
||||||
def join_requests_as_json
|
def join_requests_as_json
|
||||||
|
|||||||
+21
-6
@@ -15,25 +15,40 @@ class Order
|
|||||||
|
|
||||||
view :active_for_supplier_view, type: :custom, map_function: %[function(doc){
|
view :active_for_supplier_view, type: :custom, map_function: %[function(doc){
|
||||||
if(doc.ruby_class == 'Order' && (doc.state == 'placed' || doc.state == 'active')){
|
if(doc.ruby_class == 'Order' && (doc.state == 'placed' || doc.state == 'active')){
|
||||||
emit(doc.supplier_id, 1);
|
emit([doc.supplier_id, doc.list_id], 1);
|
||||||
}
|
}
|
||||||
}], reduce_function: '_sum'
|
}], reduce_function: '_sum'
|
||||||
|
|
||||||
view :active_for_supplier_and_section_view, type: :custom, map_function: %[function(doc){
|
view :active_for_supplier_and_section_view, type: :custom, map_function: %[function(doc){
|
||||||
if(doc.ruby_class == 'Order' && (doc.state == 'placed' || doc.state == 'active')){
|
if(doc.ruby_class == 'Order' && (doc.state == 'placed' || doc.state == 'active')){
|
||||||
emit([doc.supplier_id, doc.section_id], 1);
|
emit([doc.supplier_id, doc.section_id], 1);
|
||||||
}
|
}
|
||||||
}], reduce_function: '_sum'
|
}], reduce_function: '_sum'
|
||||||
view :by_supplier_id_and_id, key: [:supplier_id, :_id]
|
|
||||||
view :by_list_id, key: :list_id
|
#view :by_supplier_id_and_id, key: [:supplier_id, :_id]
|
||||||
|
|
||||||
# Return all currently active orders for a given supplier
|
# Return all currently active orders for a given supplier
|
||||||
def self.active_for_supplier(supplier_id)
|
def self.active_for_supplier(supplier_id)
|
||||||
database.view(active_for_supplier_view(key: supplier_id, reduce: false, include_docs: true))
|
database.view(active_for_supplier_view(startkey: [supplier_id], endkey: [supplier_id, {}], reduce: false, include_docs: true))
|
||||||
|
end
|
||||||
|
|
||||||
|
# Return all currently active orders for a given supplier and list
|
||||||
|
def self.active_for_supplier_and_list(supplier_id, list_id)
|
||||||
|
supplier_id = supplier_id.id if supplier_id.is_a?(SimplyStored::Couch)
|
||||||
|
list_id = list_id.id if list_id.is_a?(SimplyStored::Couch)
|
||||||
|
database.view(active_for_supplier_view(key: [supplier_id, list_id], reduce: false, include_docs: true))
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.count_active_for_supplier_and_list(supplier_id, list_id)
|
||||||
|
supplier_id = supplier_id.id if supplier_id.is_a?(SimplyStored::Couch)
|
||||||
|
list_id = list_id.id if list_id.is_a?(SimplyStored::Couch)
|
||||||
|
database.view(active_for_supplier_view(key: [supplier_id, list_id], reduce: true, include_docs: false))
|
||||||
end
|
end
|
||||||
|
|
||||||
# Return all currently active orders for a given section
|
# Return all currently active orders for a given section
|
||||||
def self.active_for_supplier_and_section(supplier, section_id)
|
def self.active_for_supplier_and_section(supplier, section_id)
|
||||||
supplier_id = supplier.is_a?(SimplyStored::Couch) ? supplier.id : supplier
|
supplier_id = supplier.is_a?(SimplyStored::Couch) ? supplier.id : supplier
|
||||||
|
section_id = section_id.id if section_id.is_a?(SimplyStored::Couch)
|
||||||
database.view(active_for_supplier_and_section_view(key: [supplier_id, section_id], reduce: false, include_docs: true))
|
database.view(active_for_supplier_and_section_view(key: [supplier_id, section_id], reduce: false, include_docs: true))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,5 @@
|
|||||||
Qsupplier.position_table_in_active_section(active_section_container, $(this), false);
|
Qsupplier.position_table_in_active_section(active_section_container, $(this), false);
|
||||||
});
|
});
|
||||||
Qsupplier.update_section_tables_view('#{@section.id}');
|
Qsupplier.update_section_tables_view('#{@section.id}');
|
||||||
//setInterval("Qsupplier.update_section_tables_view('#{@section.id}')", 7500);
|
|
||||||
Qsupplier.watch_events();
|
Qsupplier.watch_events();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
FactoryGirl.define do
|
||||||
|
factory :order do
|
||||||
|
association :list
|
||||||
|
association :user
|
||||||
|
association :supplier #TODO warning! this may create a different supplier than the one created by the associated table
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :user do
|
factory :user do
|
||||||
email "test@example.com"
|
sequence( :email ){|i| "test#{i}@example.com" }
|
||||||
password "secret"
|
password "secret"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
+67
-11
@@ -2,28 +2,84 @@ require 'spec_helper'
|
|||||||
|
|
||||||
|
|
||||||
describe List do
|
describe List do
|
||||||
before :each do
|
let(:supplier) { create :supplier }
|
||||||
@list = create :list
|
let(:user) { create :user }
|
||||||
end
|
let(:section) { create :section, supplier: supplier}
|
||||||
|
let(:table) { create :table, supplier: supplier}
|
||||||
|
let(:list){ create :list, supplier: supplier, table: table, user_ids: [user.id] }
|
||||||
|
subject { list }
|
||||||
describe :as_json do
|
describe :as_json do
|
||||||
it 'should include _id in as_json serialization' do
|
it 'should include _id in as_json serialization' do
|
||||||
@list.as_json.keys.map(&:to_sym).should include :_id
|
list.as_json.keys.map(&:to_sym).should include :_id
|
||||||
end
|
end
|
||||||
it 'should include table_number in as_json serialization' do
|
it 'should include table_number in as_json serialization' do
|
||||||
@list.as_json.keys.should include :table_number
|
list.as_json.keys.should include :table_number
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe :mark_as_payed do
|
describe :mark_as_payed do
|
||||||
it "should set payed_at to a time" do
|
it "should set payed_at to a time" do
|
||||||
@list.payed_at.should be_nil
|
list.payed_at.should be_nil
|
||||||
@list.mark_as_payed
|
list.mark_as_payed
|
||||||
@list.payed_at.should be_kind_of Time
|
list.payed_at.should be_kind_of Time
|
||||||
end
|
end
|
||||||
it "should set is_payed to true" do
|
it "should set is_payed to true" do
|
||||||
@list.is_payed.should be_false
|
list.is_payed.should be_false
|
||||||
@list.mark_as_payed
|
list.mark_as_payed
|
||||||
@list.is_payed.should be_true
|
list.is_payed.should be_true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#move_to_table!' do
|
||||||
|
let(:new_section) { create :section, supplier: supplier}
|
||||||
|
let(:new_table) { create :table, supplier: supplier, section: new_section}
|
||||||
|
before do
|
||||||
|
@order1 = create :order, supplier: supplier, list: list, section: section
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'adds a model to keep track of the movement' do
|
||||||
|
expect{ list.move_to_table! new_table }.to change{ UserTableMove.count }.by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "changes the table" do
|
||||||
|
expect{ list.move_to_table! new_table }.to change{ list.table_id }.to( new_table.id )
|
||||||
|
end
|
||||||
|
|
||||||
|
it "changes the section" do
|
||||||
|
expect{ list.move_to_table! new_table }.to change{ list.section_id }.to( new_section.id )
|
||||||
|
end
|
||||||
|
|
||||||
|
it "changes the section of the orders" do
|
||||||
|
expect{ list.move_to_table! new_table }.to change{ @order1.reload; @order1.section_id }.to( new_section.id )
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#has_active_orders?' do
|
||||||
|
its(:has_active_orders?) { should be_false }
|
||||||
|
|
||||||
|
it 'returns true when there are placed orders for the list' do
|
||||||
|
create :order, supplier: supplier, list: list, section: section, state: 'placed'
|
||||||
|
list.has_active_orders?.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns true when there are active orders for the list' do
|
||||||
|
create :order, supplier: supplier, list: list, section: section, state: 'active'
|
||||||
|
list.has_active_orders?.should be_true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when there are only delivered orders' do
|
||||||
|
create :order, supplier: supplier, list: list, section: section, state: 'delivered'
|
||||||
|
list.has_active_orders?.should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when there are only closed orders' do
|
||||||
|
create :order, supplier: supplier, list: list, section: section, state: 'closed'
|
||||||
|
list.has_active_orders?.should be_false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns false when there are only cancelled orders' do
|
||||||
|
create :order, supplier: supplier, list: list, section: section, state: 'cancelled'
|
||||||
|
list.has_active_orders?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
|
||||||
|
describe Order do
|
||||||
|
let(:supplier) { create :supplier }
|
||||||
|
let(:user) { create :user }
|
||||||
|
let(:section) { create :section, supplier: supplier}
|
||||||
|
let(:table) { create :table, supplier: supplier}
|
||||||
|
let(:list){ create :list, supplier: supplier, table: table, user_ids: [user.id] }
|
||||||
|
let(:order) {create :order, supplier: supplier, list: list, state: 'placed' }
|
||||||
|
subject { order }
|
||||||
|
|
||||||
|
its(:placed?) { should be_true }
|
||||||
|
its(:active?) { should be_false }
|
||||||
|
|
||||||
|
describe 'count_active_for_supplier_and_list' do
|
||||||
|
before { order }
|
||||||
|
it 'counts active orders for a list with objects' do
|
||||||
|
Order.count_active_for_supplier_and_list(supplier, list).should == 1
|
||||||
|
end
|
||||||
|
it 'counts active orders for a list with ids' do
|
||||||
|
Order.count_active_for_supplier_and_list(supplier.id, list.id).should == 1
|
||||||
|
end
|
||||||
|
it 'does not count inactive orders' do
|
||||||
|
order.close!
|
||||||
|
Order.count_active_for_supplier_and_list(supplier, list).should == 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
+1
-1
@@ -38,7 +38,7 @@ RSpec.configure do |config|
|
|||||||
|
|
||||||
# Use color in STDOUT
|
# Use color in STDOUT
|
||||||
config.color_enabled = true
|
config.color_enabled = true
|
||||||
config.fail_fast = true
|
config.fail_fast = false
|
||||||
|
|
||||||
# Use color not only in STDOUT but also in pagers and files
|
# Use color not only in STDOUT but also in pagers and files
|
||||||
config.tty = true
|
config.tty = true
|
||||||
|
|||||||
Reference in New Issue
Block a user