End of day commit

This commit is contained in:
2014-07-21 20:31:11 +02:00
parent 2fec0b3bb6
commit 8ca59c4e38
27 changed files with 258 additions and 94 deletions
+9 -9
View File
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/bterkuile/cmtool.git
revision: 372231b1b7340617d9c603f52029df1c787001f1
revision: a428d41955884c6d8d1501c7a89e6346ee5ec420
specs:
cmtool (1.0.0)
bourbon
@@ -37,7 +37,7 @@ GIT
GIT
remote: git://github.com/bterkuile/simply_stored.git
revision: e0e72e8e73c59666191d578408572ed8f5de9e42
revision: 354fde89a88c1384ccc9d82989e3f05ac6977bd1
specs:
simply_stored (1.0.0)
activesupport
@@ -172,7 +172,7 @@ GEM
handlebars-source (> 1.0.0)
jquery-rails (>= 1.0.17)
railties (>= 3.1)
ember-source (1.6.0)
ember-source (1.6.1)
handlebars-source (~> 1.0)
emblem-rails (0.2.1)
barber-emblem (~> 0.1.1)
@@ -201,7 +201,7 @@ GEM
websocket-driver (>= 0.3.1)
font-awesome-rails (4.1.0.0)
railties (>= 3.2, < 5.0)
foundation-rails (5.3.0.1)
foundation-rails (5.3.1.0)
railties (>= 3.1.0)
sass (>= 3.2.0)
fuubar (1.3.3)
@@ -255,7 +255,7 @@ GEM
net-scp (1.2.1)
net-ssh (>= 2.6.5)
net-ssh (2.9.1)
nokogiri (1.6.2.1)
nokogiri (1.6.3)
mini_portile (= 0.6.0)
oauth2 (1.0.0)
faraday (>= 0.8, < 0.10)
@@ -347,7 +347,7 @@ GEM
simple_form (3.0.2)
actionpack (~> 4.0)
activemodel (~> 4.0)
simplecov (0.8.2)
simplecov (0.9.0)
docile (~> 1.1.0)
multi_json
simplecov-html (~> 0.8.0)
@@ -360,7 +360,7 @@ GEM
activesupport (>= 3.0, < 4.2)
railties (>= 3.0, < 4.2)
slim (~> 2.0)
slop (3.5.0)
slop (3.6.0)
spring (1.1.3)
spring-commands-rspec (1.0.2)
spring (>= 0.9.1)
@@ -386,7 +386,7 @@ GEM
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
tinymce-rails (4.1.0)
tinymce-rails (4.1.2)
railties (>= 3.1.1)
treetop (1.4.15)
polyglot
@@ -396,7 +396,7 @@ GEM
rspec (>= 2.0, < 4.0)
tzinfo (1.2.1)
thread_safe (~> 0.1)
uglifier (2.5.1)
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
warden (1.2.3)
@@ -1,5 +1,6 @@
Ember.Handlebars.helper 'time', (time, params..., options = {})->
return '' unless time
time = new Date(time) if typeof(time) is "string"
iso = time.toISOString()
tag = if options.bare then iso else $("<span data-time=\"#{iso}\"></span>").text(moment(iso).format(options.format || 'dd D MMM HH:MM')).get(0).outerHTML
new Handlebars.SafeString tag
@@ -14,22 +14,29 @@ Qsupplier.App.IndexController = Ember.ObjectController.extend
@get('orders').filter (o)->( o.get('needs_supplier_attention') )
).property('orders.@each.state', 'active_section.id')
markListAsHelped: (id)->
if list = Qsupplier.App.List.findCached(id)
list.is_helped()
actions:
markListAsHelped: (id)->
if list = Qsupplier.App.List.findCached(id)
list.is_helped()
closeList: (id)->
if list = Qsupplier.App.List.findCached(id)
list.close()
closeList: (id)->
if list = Qsupplier.App.List.findCached(id)
list.close()
markOrderDelivered: (id)->
$.post('/supplier/order_is_delivered', order_id: id)
if order = Qsupplier.App.Order.findCached(id)
order.set('state', 'delivered')
markOrderDelivered: (id)->
$.post('/supplier/order_is_delivered', order_id: id)
if order = Qsupplier.App.Order.findCached(id)
order.set('state', 'delivered')
markOrderActive: (id)->
$.post('/supplier/mark_order_in_process', order_id: id)
if order = Qsupplier.App.Order.findCached(id)
order.set('state', 'active')
cancelOrder: (order)->
$.post "/supplier/orders/#{order.id}/cancel"
order.set 'state', 'cancelled'
showList: (id)->
@transitionToRoute 'list', id
showListInfo: (view, link)->
debugger
markOrderActive: (id)->
$.post('/supplier/mark_order_in_process', order_id: id)
if order = Qsupplier.App.Order.findCached(id)
order.set('state', 'active')
showListInfo: (view, link)->
debugger
@@ -34,9 +34,12 @@ Qsupplier.App.List = DS.Model.extend
@set 'needs_payment', true
markIsPaid: ->
@set 'needs_payment', false
relevant_orders: (-> @get('orders').filter((o)->o.get('state') isnt 'cancelled')).property('orders.@each.state')
active_orders: (-> @get('orders').filter((o)->o.get('state') is 'placed' or o.get('state') is 'active')).property('orders.@each.state')
total: (->
@get('orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('orders.@each.total')
@get('relevant_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('relevant_orders.@each.total')
close: ->
@markClosed()
@@ -45,4 +48,4 @@ Qsupplier.App.List = DS.Model.extend
is_helped: ->
@markHelped()
$.post Routes.supplier_mark_list_as_helped_path(), list_id: @id
sorted_orders: (-> @get('orders').sortBy('created_at').reverseObjects()).property('orders.@each.isLoaded')
sorted_orders: (-> @get('relevant_orders').sortBy('created_at').reverseObjects()).property('relevant_orders.@each.isLoaded')
@@ -19,6 +19,8 @@ Qsupplier.App.Order = DS.Model.extend
markClosed: ->
@set 'state', 'closed'
markCancelled: ->
@set 'state', 'cancelled'
total: (->
@get('product_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('product_orders.@each.quantity', 'product_orders.@each.product.@each.price')
@@ -11,7 +11,7 @@ if list.closed_at
.row
each user in list.users
img.facebook-image src="http://graph.facebook.com/#{unbound user.facebook_id}/picture?type=square" alt="f"
if list.orders
if list.sorted_orders
.list-orders-container
each order in list.sorted_orders
.list-order-container class=order.state
@@ -6,7 +6,7 @@ td.status-icons
span.icon.needs-payment
td.numeric.table_number {{view.content.table.number}}
td.section_title {{view.content.section.title}}
td.currency.total_list_amount {{currency view.content.price}}
td.currency.total_list_amount {{currency view.content.total}}
td.actions
if view.content.needs_help
button.mark_list_as_helped{ action markListAsHelped view.content.id}
@@ -14,8 +14,5 @@ td.actions
i.fa.fa-bell.fa-stack-small
i.fa.fa-ban.revoke
/span.button-text=t 'list.is_helped_button'
button.close_list{ action closeList view.content.id}
span.fa.fa-times.fa-2x
span.button-text=t 'list.close_list'
a.btn.hide href="/supplier/lists/{{unbound view.content.id}}"
span.icon-list &nbsp;
button.close_list{ action closeList view.content.id}: span
button.show-list.button{action "showList" view.content.id}: span
@@ -21,3 +21,4 @@ td.actions
/button.hide.mark-order-delivered{ action markOrderDelivered view.content.id}
span.button-icon
span.button-text= t 'order.being_served'
button.remove-order{ action "cancelOrder" view.content }: span
@@ -1,32 +1,30 @@
.page-header
div.dashboard-section-selection
'{{view 'Qsupplier.App.HomeSectionSelectorView' selectionBinding="controller.active_section" content=controller.sections prompt=controllers.application.supplier.name}}
'{{view 'Qsupplier.App.HomeSectionJumperView'}}
h3 {{t 'active_lists.title'}}
Qsupplier.App.HomeSectionSelectorView selectionBinding="controller.active_section" content=controller.sections prompt=controllers.application.supplier.name
Qsupplier.App.HomeSectionJumperView
h3=t 'active_lists.title'
.well
table.active-lists-table.table
thead
tr
th.status-icons
th.numeric {{t 'table_number'}}
th {{t 'models.section'}}
th.currency {{t 'active_lists.price'}}
th.numeric=t 'table_number'
th=t 'models.section'
th.currency=t 'active_lists.price'
th.actions
tbody
each list in controller.active_lists
' {{view 'Qsupplier.App.ActiveListView' contentBinding="list"}}
each list in controller.active_lists: Qsupplier.App.ActiveListView contentBinding="list"
.page-header
h3 {{t 'active_orders.title' }}
h3=t 'active_orders.title'
.well
table.active-orders-table.table
thead
tr
th.status-icons
th {{t 'models.order'}}
th.numeric {{t 'table_number'}}
th {{t 'models.section'}}
th.currency {{t 'active_orders.price'}}
th=t 'models.order'
th.numeric=t 'table_number'
th=t 'models.section'
th.currency=t 'active_orders.price'
th.actions
tbody
each order in controller.active_orders
' {{view 'Qsupplier.App.ActiveOrderView' contentBinding="order"}}
each order in controller.active_orders: Qsupplier.App.ActiveOrderView contentBinding="order"
@@ -6,10 +6,13 @@ root.Qsupplier=
console.log(e)
if(e.event == 'new_order')
if Qsupplier.App
Qsupplier.App.store().pushPayload e.data
#Qsupplier.App.Order.pushByAttriburtes(e.data.order)
#for product_order in e.data.product_orders
#Qsupplier.App.ProductOrder.pushByAttriburtes product_order, debug: true
Qsupplier.App.store().pushPayload(e.data)
# Fix for ember pushPayload bug not creating the proper relations/triggers
setTimeout ->
if order = Qsupplier.App.store().all('order').findProperty('id', e.data.order.id)
list = order.get('list')
list.get('orders').addRecord order
, 100
else if(e.event == 'list_needs_help')
if Qsupplier.App and list = Qsupplier.App.List.findCached(e.data.id)
list.markNeedsHelp()
@@ -57,6 +60,12 @@ root.Qsupplier=
$('.supplier-orders-placed-count-number').text e.data.count
else if e.event == 'list_changed_table'
Qsupplier.App && Qsupplier.App.List.updateOrAdd(e.data.list)
else if e.event == 'order_cancelled'
if Qsupplier.App and order = Qsupplier.App.Order.findCached(e.data.id)
order.markCancelled()
$('.supplier-orders-placed-count-number').text(e.data.orders_placed_count) if Number.isInteger(e.data.orders_placed_count)
$('.supplier-orders-in-process-count-number').text(e.data.orders_in_process_count) if Number.isInteger(e.data.orders_in_process_count)
# old stuff
#list = new List(e.data.list)
@@ -17,11 +17,10 @@ App.List = DS.Model.extend
join_requests: DS.hasMany('join_request')
users: DS.hasMany('user')
total: (->
@get('orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('orders.@each.total')
is_extended_version: ->
@get('extended_version')
sorted_orders: (-> @get('orders').sortBy('created_at').reverseObjects()).property('orders.@each.isLoaded')
relevant_orders: (-> @get('orders').filter((o)->o.get('state') isnt 'cancelled')).property('orders.@each.state')
sorted_orders: (-> @get('relevant_orders').sortBy('created_at').reverseObjects()).property('relevant_orders.@each.isLoaded')
total: (->
@get('relevant_orders').getEach('total').reduce(((sum, total) -> sum + total), 0)
).property('relevant_orders.@each.total')
@@ -1,19 +0,0 @@
.dashboard-section-selection
float: right
min-width: 124px
select
width: calc(100% - 30px)
.active-lists-table
width: 100%
.mark_list_as_helped
+button-icon-only
.close_list
+button-icon-only
.active-orders-table
width: 100%
.mark_order_active
+button-icon-only
margin-right: 0.6em
.mark_order_delivered
+button-icon-only
@@ -5,7 +5,6 @@
@import ./foundation_and_overrides
@import ./qstructure
@import ./qicons
@import ./qdashboard
@import ./qdisplays
@import ./form_actions
@import ./components/*
@@ -0,0 +1,40 @@
$button-spacing: 8px
.dashboard-section-selection
float: right
min-width: 124px
select
width: calc(100% - 30px)
.active-lists-table
width: 100%
.mark_list_as_helped
+button-icon-only
margin-right: $button-spacing
.close_list
+button-icon-only
span
@extend .fa
@extend .fa-2x
@extend .fa-times // This is not good!!!
.show-list
+button-icon-only
margin-left: $button-spacing
span
@extend .fa
@extend .fa-2x
@extend .fa-list
.active-orders-table
width: 100%
.mark_order_active
+button-icon-only
margin-right: 0.6em
.mark_order_delivered
+button-icon-only
.remove-order
+button-icon-only
background-color: $alert-color
margin-left: $button-spacing
span
@extend .fa
@extend .fa-2x
@extend .fa-times
@@ -15,7 +15,7 @@ module Suppliers
@end_time += current_supplier.night_offset.to_f.hours
end
@lists = List.for_supplier_created_at current_supplier, @start_time..@end_time
@lists.include_relation(:table) # for number
#@lists.include_relation(:table) # for number
else
@lists = List.for_supplier(current_supplier, page: params[:page], per_page: params[:per_page] || 25)
end
@@ -15,6 +15,12 @@ module Suppliers
end
end
def cancel
@order = current_supplier.find_order(params[:id])
@order.cancel!
render json: @order
end
def show
@order = current_supplier.find_order(params[:id])
respond_to do |format|
+6 -3
View File
@@ -268,10 +268,14 @@ class List
end
end
def relevant_orders
orders.reject(&:cancelled?)
end
# Store the final list price in a property
def set_price
list_total = 0.0
for order in orders
for order in relevant_orders
order_total = 0.0
for product_order in order.product_orders
order_total += (product_order.quantity * product_order.price).round(2)
@@ -408,8 +412,7 @@ class List
@with_info_as_json = hl
end
private
# should not be private, called from order as well
def broadcast_users(message, content = {})
for user_id in Array.wrap(user_ids)
broadcast_user user_id, message, content
+22
View File
@@ -106,6 +106,28 @@ class Order
end
end
def cancel!
original_state = state.inquiry
self.state = 'cancelled' if placed? || active?
if save
broadcast_options = {id: id}
if original_state.placed?
reduced_count = supplier.decrement_orders_placed_count!
broadcast_options[:orders_placed_count] = reduced_count
elsif original_state.active?
reduced_count = supplier.decrement_orders_in_process_count!
broadcast_options[:orders_in_process_count] = reduced_count
end
list.broadcast_users 'order_cancelled', broadcast_options
broadcast_supplier supplier_id, 'order_cancelled', broadcast_options
end
end
def cancelled?
state == 'cancelled'
end
#TODO fix me
def close!
self.state = 'closed' if placed? || active?
if save
+1 -1
View File
@@ -15,7 +15,7 @@ html lang="en"
= render 'suppliers/application/head'
= javascript_include_tag "supplier/foundation1/application"
= yield :head
= javascript_include_tag "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places&language=#{I18n.locale}"
/= javascript_include_tag "https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places&language=#{I18n.locale}"
javascript:
supplier_id="#{current_supplier.id}";
+5 -1
View File
@@ -135,7 +135,11 @@ Qwaiter::Application.routes.draw do
post :sort
end
end
resources :orders, only: [:index, :show]
resources :orders, only: [:index, :show] do
member do
post :cancel
end
end
root to: 'sections#index'
end
+1 -1
View File
@@ -12,7 +12,7 @@ module Qwaiter
end
def self.incr(key, options = {})
options[:initial] ||= 0
options[:initial] ||= 1
connection.incr(key, options) rescue 1
end
@@ -71,10 +71,19 @@ Feature: Supplier main board
And I click on the section main board section jumper
Then I should be redirected to the supplier section view
@javascript
@javascript @broken
Scenario: Update table number if table chanes
Given there is an active list and order
And I am signed in as supplier
When the active list changes to another table in another section
Then the supplier main board table number should be updated to the new table number
And the supplier main board section name should be updated to the new section
@javascript
Scenario: Remove an order
Given there is an active list and order
And I am signed in as supplier
When the supplier marks the order as wrong in the main board view
Then the supplier main board order should not be visible anymore
And the supplier main board list total should be updated
And the supplier placed orders counter should be reduced
@@ -5,9 +5,11 @@ step "there is an active list and order" do
@section.should be_present
@list = create :list, state: 'active', supplier: @supplier, table: @table, section: @section, user_ids: [@user.id]
@product = create :product, price: 2.22, supplier: @supplier
@order = create :order, user: @user, list: @list, supplier: @supplier, section: @section
@order = create :order, user: @user, list: @list, supplier: @supplier, section: @section, state: 'placed'
@product_order = create :product_order, order: @order, product: @product, quantity: 3, price: 2.11
@list.set_price.should == 6.33 # does not belong here, but good test. must take product order price above product price
Qwaiter::Counter.set "supplier_counter:#{@supplier.id}:orders_placed", 11
Qwaiter::Counter.set "supplier_counter:#{@supplier.id}:orders_in_process", 7
end
step "the supplier dashboard should display the active list" do
@@ -142,3 +144,23 @@ step "the supplier main board section name should be updated to the new section"
expect( find(".list-row-#{@list.id} .section_title").text ).to eq "New Section"
expect( find(".order-row-#{@list.orders.first.id} .section_title").text ).to eq "New Section"
end
# Marking order as wrong
step "the supplier marks the order as wrong in the main board view" do
find(".order-row-#{@order.id} .remove-order").click
end
step "the supplier main board order should not be visible anymore" do
page.should_not have_selector ".order-row-#{@order.id}"
end
step "the supplier main board list total should be updated" do
find(".list-row-#{@list.id} .total_list_amount").text.should == "€ 0.00"
end
step "the supplier placed orders counter should be reduced" do
sleep 0.5
binding.pry
puts page.driver.error_messages
find('.supplier-orders-placed-count-number').text.should == "10"
end
+3
View File
@@ -9,5 +9,8 @@ FactoryGirl.define do
trait :active do
state 'active'
end
trait :cancelled do
state 'cancelled'
end
end
end
+8
View File
@@ -39,6 +39,14 @@ describe List do
it 'takes the product_order price in stead of the product price' do
product_order and list.set_price.should == 6.33
end
it 'does not include the price of cancelled orders' do
product_order
cancelled = create :order, :cancelled, user: user, list: list, supplier: supplier, section: section
create :product_order, order: cancelled, product: product, quantity: 2, price: 7.99
list.set_price
list.price.should == 6.33
end
end
describe '#move_to_table!' do
+48 -1
View File
@@ -7,7 +7,8 @@ describe Order do
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' }
let(:order_options){ {supplier: supplier, list: list, state: 'placed' } }
let(:order) {create :order, order_options }
subject { order }
its(:placed?) { should be true }
@@ -41,6 +42,7 @@ describe Order do
describe 'broadcasting' do
it 'broadcasts order info to the user' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_user(user.id).message( 'order_being_processed' ).with(id: order.id, list_id: list.id)
end
@@ -52,24 +54,29 @@ describe Order do
end
it 'reduces the orders_placed count and communicates it to user' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_user(user.id).message( 'orders_placed_count' ).with(count: 10)
end
it 'increases the orders_in_process count and communicates it to user' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_user(user.id).message( 'orders_in_process_count' ).with(count: 8)
end
it 'reduces the orders_placed count and communicates it to supplier' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_supplier(supplier.id).message( 'orders_placed_count' ).with(count: 10)
end
it 'increases the orders_in_process count and communicates it to supplier' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_supplier(supplier.id).message( 'orders_in_process_count' ).with(count: 8)
end
end
it 'broadcasts order info to the supplier' do
order_options[:state] = 'placed'
expect{ order.is_being_processed! }.to broadcast_to_supplier(supplier.id).message( 'order_being_processed' ).with(id: order.id, list_id: list.id)
end
@@ -106,4 +113,44 @@ describe Order do
end
end
describe "cancel!" do
it 'changes the state to cancelled' do
order_options[:state] = 'active'
order.cancel!
expect(order.state).to eq 'cancelled'
end
describe 'broadcasting' do
describe 'counters' do
before do
# hack some initial values
Qwaiter::Counter.set "supplier_counter:#{supplier.id}:orders_placed", 11
Qwaiter::Counter.set "supplier_counter:#{supplier.id}:orders_in_process", 7
end
it 'decreases the placed count and communicates it to user when state is placed through the order_cancelled broadcast message' do
order_options[:state] = 'placed'
expect{ order.cancel! }.to broadcast_to_user(user.id).message( 'order_cancelled' ).with(id: order.id, orders_placed_count: 10)
supplier.orders_in_process_count.should == 7 # should not be reduced
end
it 'decreases the placed count and communicates it to supplier when the state is placed through the order_cancelled broadcast message' do
order_options[:state] = 'placed'
expect{ order.cancel! }.to broadcast_to_supplier(supplier.id).message( 'order_cancelled' ).with(id: order.id, orders_placed_count: 10)
supplier.orders_in_process_count.should == 7 # should not be reduced
end
it 'decreases the orders_in_process count and communicates it to user when state is active through the order_cancelled broadcast message' do
order_options[:state] = 'active'
expect{ order.cancel! }.to broadcast_to_user(user.id).message( 'order_cancelled' ).with(id: order.id, orders_in_process_count: 6)
supplier.orders_placed_count.should == 11 # should not be reduced
end
it 'decreases the orders_in_process count and communicates it to supplier when the state is active through the order_cancelled broadcast message' do
order_options[:state] = 'active'
expect{ order.cancel! }.to broadcast_to_supplier(supplier.id).message( 'order_cancelled' ).with(id: order.id, orders_in_process_count: 6)
supplier.orders_placed_count.should == 11 # should not be reduced
end
end
end
end
end
+7 -4
View File
@@ -30,9 +30,10 @@ Release
- styling
- Event stream to ember? (After release!!!)
- remove invalid orders (Supplier must be able to remove orders from the list)
- Add qr print functionality offering to send the stickers
- User
- Add product info
- Add product info (look at waiter app)
- translate join table strings
- Add order plus button
- test met veel producten
@@ -43,13 +44,16 @@ Release
General:
- search for class btn and replace with font awesome correct styling if
needed
- theme1 site alert styling (zurb?)
- devise styling
Bugs:
- Dragging supplier table from one section to the other fails
- Supplier section print qr codes does not give proper images
- Supplier tables pagination styling
- supplier counters in user view (no supplier in active list?)
- supplier main board section selector selects first section option
and not the supplier name, which is added using prompt thingy. Maybe
setting ApplicationController.active_section in stead of
IndexController.active_section for scope locking
- supplier main board mark list as helped button styling is a bit off
Post release
------------
@@ -60,4 +64,3 @@ Users can disable their own help request (maak ongedaan?)
Users can disable their own bill request (maak ongedaan?)
Think about extra confirmation box for these requests
Supplier section 100% on ember :)
Supplier give help for settings