diff --git a/app/assets/javascripts/supplier/app/models/list.js.coffee b/app/assets/javascripts/supplier/app/models/list.js.coffee index 4d3a9469..b0e42d0d 100644 --- a/app/assets/javascripts/supplier/app/models/list.js.coffee +++ b/app/assets/javascripts/supplier/app/models/list.js.coffee @@ -4,7 +4,8 @@ App.List = DS.Model.extend needs_help: attr 'boolean' needs_payment: attr 'boolean' user_requests_closing: attr('boolean') - users: DS.hasMany('user', async: true) + # users: DS.hasMany('user', async: true) + users: DS.hasMany('user') is_paid: attr 'boolean' #has_active_orders: attr 'boolean' diff --git a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee index ef1e293a..d44d0876 100644 --- a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee @@ -39,6 +39,11 @@ App.ApplicationController = Ember.Controller.extend data.join_request.user = user join_request = @store.createRecord 'join_request', data.join_request @transitionToRoute 'join_requests' + order_cancelled: (data)-> + if order = App.Order.findCached(data.id) + order.markCancelled() + @events.orders_placed_count.call(@, count: data.orders_placed_count) if data.orders_placed_count == 0 or data.orders_placed_count + @events.orders_in_process_count.call(@, count: data.orders_in_process_count) if data.orders_in_process_count == 0 or data.orders_in_process_count join_request_rejected: (data)-> # Remove join request from connected users join_request = @store.all('join_request').findBy 'id', data.id diff --git a/app/assets/javascripts/user/app/models/order.js.coffee b/app/assets/javascripts/user/app/models/order.js.coffee index b920d5d4..6c4a301d 100644 --- a/app/assets/javascripts/user/app/models/order.js.coffee +++ b/app/assets/javascripts/user/app/models/order.js.coffee @@ -10,3 +10,5 @@ App.Order = DS.Model.extend display: (-> @get('product_orders').map((po) -> "#{po.get('quantity')} x #{po.get('product.name')}").join(', ') ).property('product_orders.@each.quantity', 'product_orders.@each.product.@each.name') + markCancelled: -> + @set 'state', 'cancelled' diff --git a/app/assets/javascripts/user/app/modifications/model_modifications.js.coffee b/app/assets/javascripts/user/app/modifications/model_modifications.js.coffee index b9647292..c236a57b 100644 --- a/app/assets/javascripts/user/app/modifications/model_modifications.js.coffee +++ b/app/assets/javascripts/user/app/modifications/model_modifications.js.coffee @@ -4,3 +4,7 @@ DS.Model.reopen eraseRecord: -> @clearRelationships() @transitionTo('deleted.saved') +DS.Model.reopenClass + findCached: (id)-> + return null unless id + @store.all(@typeKey).findProperty('id', id) diff --git a/spec/acceptance/users/active_list.feature b/spec/acceptance/users/active_list.feature index 5b47bbfc..cfe96e83 100644 --- a/spec/acceptance/users/active_list.feature +++ b/spec/acceptance/users/active_list.feature @@ -10,3 +10,25 @@ Feature: Active list view And the user opens the side menu again And the user clicks on the active list link in the side menu Then the user should see the order in the active list view + + @javascript + Scenario: Order disappears and counter adjusts when a placed order is cancelled + Given There is an open supplier with a menu + And there is a signed in user with a placed order + And the user is on the active list page + And the supplier orders placed counter for the user should be 1 + When the order gets cancelled + And I wait 1 second + Then the user should not see the order in the active list view + And the supplier orders placed counter for the user should be 0 + + @javascript + Scenario: Order disappears and counter adjusts when an active order is cancelled + Given There is an open supplier with a menu + And there is a signed in user with an active order + And the user is on the active list page + And the supplier orders in process counter for the user should be 1 + When the order gets cancelled + And I wait 1 second + Then the user should not see the order in the active list view + And the supplier orders in process counter for the user should be 0 diff --git a/spec/acceptance_steps/global_list_steps.rb b/spec/acceptance_steps/global_list_steps.rb index fa50fc3c..2269aabb 100644 --- a/spec/acceptance_steps/global_list_steps.rb +++ b/spec/acceptance_steps/global_list_steps.rb @@ -7,14 +7,18 @@ step "the list is marked as in need of payment" do @list.needs_payment! end -step "the user has an active list" do +step "the user has an active list with a/an :order_status order" do |order_status| @list = create :list, supplier: @supplier, table: @table, user_ids: [@user.id] @product ||= create :product, supplier: @supplier, name: 'Beer', price: 2.34 - @order = create :order, supplier: @supplier, list: @list + @order = create :order, order_status.to_sym, supplier: @supplier, list: @list @product_order = create :product_order, order: @order, product: @product, quantity: 2, price: 2.34 @user.reload @user.active_list_id = @list.id @user.save + case order_status.to_sym + when :placed then @supplier.increment_orders_placed_count! + when :active then @supplier.increment_orders_in_process_count! + end end step "the list should be marked as closed" do diff --git a/spec/acceptance_steps/order_steps.rb b/spec/acceptance_steps/order_steps.rb index 57e3866e..a56e3967 100644 --- a/spec/acceptance_steps/order_steps.rb +++ b/spec/acceptance_steps/order_steps.rb @@ -47,3 +47,7 @@ end step "the user orders list gets closed" do @order.list.close! end + +step "the order gets cancelled" do + @order.cancel! +end diff --git a/spec/acceptance_steps/users/active_list_steps.rb b/spec/acceptance_steps/users/active_list_steps.rb index 8a2913fa..4eab4223 100644 --- a/spec/acceptance_steps/users/active_list_steps.rb +++ b/spec/acceptance_steps/users/active_list_steps.rb @@ -5,3 +5,11 @@ end step "the user should see the order in the active list view" do page.evaluate_script(%|$('.order-row-#{@order.id}').text()|).first(14).should == '2 x Beer€ 4.68' end + +step "the user should not see the order in the active list view" do + page.should_not have_selector ".order-row-#{@order.id}" +end + +step "the supplier counters in the user active list view should be updated" do + binding.pry +end diff --git a/spec/acceptance_steps/users/order_products_steps.rb b/spec/acceptance_steps/users/order_products_steps.rb index 6559f54c..18a9ffbb 100644 --- a/spec/acceptance_steps/users/order_products_steps.rb +++ b/spec/acceptance_steps/users/order_products_steps.rb @@ -19,14 +19,23 @@ end step "the user has an active order" do step 'there is a section' step 'there is a table' - step 'the user has an active list' + step 'the user has an active list with an active order' +end +step "the user has a placed order" do + step 'there is a section' + step 'there is a table' + step 'the user has an active list with a placed order' end step "there is a signed in user with an active order" do step "I am signed in as a user" step "the user has an active order" end +step "there is a signed in user with a placed order" do + step "I am signed in as a user" + step "the user has a placed order" +end step "the user clicks on the more info button for the product with name :product_name" do |product_name| product = @product && @product.name == product_name ? @product : Product.find_by_name(product_name) diff --git a/spec/acceptance_steps/users/supplier_steps.rb b/spec/acceptance_steps/users/supplier_steps.rb new file mode 100644 index 00000000..f33b5cf2 --- /dev/null +++ b/spec/acceptance_steps/users/supplier_steps.rb @@ -0,0 +1,7 @@ +step "the supplier orders placed counter for the user should be :count" do |count| + page.find(".supplier-orders-placed-count").text.should == count # both string values +end + +step "the supplier orders in process counter for the user should be :count" do |count| + page.find(".supplier-orders-in-process-count").text.should == count # both string values +end diff --git a/wip.md b/wip.md index 7af610bc..c8a2d366 100644 --- a/wip.md +++ b/wip.md @@ -43,9 +43,9 @@ Bugs ---- - Dragging supplier table from one section to the other fails -- Supplier tables pagination styling (make ember!) - 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 +- User order total and price not working properly Post release ============ @@ -53,3 +53,8 @@ Post release - Chromecast app Waiter app 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 :) - Do not destroy tables with active list - Test list view when table is destroyed + +Supplier +-------- + +- tables#index Make table actions available