From 3b5d411a892d8e55acb7808c9af9118dff234708 Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Fri, 15 Aug 2014 16:53:36 +0200 Subject: [PATCH] Everything is green --- .../app/views/section_table_view.js.coffee | 8 ++-- .../foundation1/qsupplier.js.coffee.erb | 48 +++++++++++-------- .../application_controller.js.coffee | 4 +- app/models/list.rb | 9 ++-- app/models/order.rb | 4 +- .../suppliers/application/_top_menu.html.slim | 6 +-- config/environments/development.rb | 1 - spec/acceptance/suppliers/dashboard.feature | 14 +++++- .../acceptance/suppliers/section_view.feature | 3 +- spec/acceptance_steps/global_list_steps.rb | 6 +-- .../suppliers/dashboard_steps.rb | 12 ++--- spec/models/order_spec.rb | 8 ++-- spec/support/ember_helpers.rb | 2 +- wip.md | 13 ++--- 14 files changed, 76 insertions(+), 62 deletions(-) diff --git a/app/assets/javascripts/supplier/app/views/section_table_view.js.coffee b/app/assets/javascripts/supplier/app/views/section_table_view.js.coffee index 8adbb642..26b2f9c2 100644 --- a/app/assets/javascripts/supplier/app/views/section_table_view.js.coffee +++ b/app/assets/javascripts/supplier/app/views/section_table_view.js.coffee @@ -15,12 +15,12 @@ App.SectionTableView = Ember.View.extend DragNDrop.Draggable, ).property('content.id') offsetX: (-> return 0 unless section_width = @get('content.section.width') - ((@get('content.position_x') || 0) * @get('containerWidth') / section_width) - 40 + ((@get('content.position_x') || 0) * @get('containerWidth') / section_width) ).property('content.section.width', 'content.position_x', 'containerWidth') offsetY: (-> return 0 unless section_height = @get('content.section.height') # debugger if @get('content.number') == 11 - ((@content.get('position_y') || 0) * @get('containerHeight') / section_height) - 20 + ((@content.get('position_y') || 0) * @get('containerHeight') / section_height) ).property('content.section.height', 'content.position_y', 'containerHeight') style: (-> @@ -35,8 +35,8 @@ App.SectionTableView = Ember.View.extend DragNDrop.Draggable, #@$el.css 'left', position.left #@$el.css 'top', position.top @content.setProperties - position_x: position.left*@content.get('section').get('width') / @containerWidth() - position_y: position.top *@content.get('section').get('height') / @containerHeight() + position_x: position.left*@get('content.section.width') / @get('containerWidth') + position_y: position.top *@get('content.section.height') / @get('containerHeight') #@content.get('transaction').commit() @content.save() containerWidth: (-> @get('parentView.element_width') ).property('parentView.element_width') diff --git a/app/assets/javascripts/supplier/foundation1/qsupplier.js.coffee.erb b/app/assets/javascripts/supplier/foundation1/qsupplier.js.coffee.erb index 3825c01d..fc22e879 100644 --- a/app/assets/javascripts/supplier/foundation1/qsupplier.js.coffee.erb +++ b/app/assets/javascripts/supplier/foundation1/qsupplier.js.coffee.erb @@ -6,27 +6,33 @@ root.Qsupplier= <% if Rails.env.test? %> window.faye_log ||= [] faye_message = {} - faye_message[e.event] = e.data + faye_message[e.event] = JSON.parse(JSON.stringify(e.data)) faye_log.push faye_message <% elsif Rails.env.development? %> console.log "Event: #{e.event}" console.log e.data <% end %> - if(e.event == 'new_order') - if App - App.store().pushPayload(e.data) - # Fix for ember pushPayload bug not creating the proper relations/triggers - setTimeout -> - if order = App.store().all('order').findProperty('id', e.data.order.id) - # console.log "Ugly ember fix for adding order #{e.data.order.id} as relation to its list" - list = order.get('list') - list.get('orders').addRecord order - if table = list.get('table') - if table.get('active_list') - table.get('active_list').then (table_list)-> - table.set 'active_list', list if table_list isnt list - , 200 - else if(e.event == 'list_needs_help') + if e.data + if e.data.supplier_orders_placed_count == 0 or e.data.supplier_orders_placed_count + $('.supplier-orders-placed-count-number').text(e.data.supplier_orders_placed_count) + if e.data.supplier_orders_in_process_count == 0 or e.data.supplier_orders_in_process_count + $('.supplier-orders-in-process-count-number').text(e.data.supplier_orders_in_process_count) + + # if(e.event == 'new_order') + # if App + # App.store().pushPayload(e.data) + # # Fix for ember pushPayload bug not creating the proper relations/triggers + # setTimeout -> + # if order = App.store().all('order').findProperty('id', e.data.order.id) + # # console.log "Ugly ember fix for adding order #{e.data.order.id} as relation to its list" + # list = order.get('list') + # list.get('orders').addRecord order + # if table = list.get('table') + # if table.get('active_list') + # table.get('active_list').then (table_list)-> + # table.set 'active_list', list if table_list isnt list + # , 200 + if(e.event == 'list_needs_help') if App and list = App.List.findCached(e.data.id) list.markNeedsHelp() # old stuff @@ -43,8 +49,12 @@ root.Qsupplier= if list = App.List.findCached(e.data.id) list.markIsPaid() else if e.event == 'list_update' - if App - list = App.List.updateOrAdd(e.data.list) + App.store().pushPayload('list', e.data) + App.store().findById('list', e.data.list.id).then (list)-> + list.get('table').then (table)->table.set('active_list', list) + + # if App + # list = App.List.updateOrAdd(e.data.list) else if e.event == 'list_closed' if App and list = App.List.findCached(e.data.id) list.markClosed() @@ -89,8 +99,6 @@ root.Qsupplier= else if e.event == 'order_cancelled' if App and order = App.Order.findCached(e.data.id) order.markCancelled() - $('.supplier-orders-placed-count-number').text(e.data.orders_placed_count) if e.data.orders_placed_count == 0 or e.data.orders_placed_count - $('.supplier-orders-in-process-count-number').text(e.data.orders_in_process_count) if e.data.orders_in_process_count == 0 or e.data.orders_in_process_count # old stuff 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 d44d0876..a33475cf 100644 --- a/app/assets/javascripts/user/app/controllers/application_controller.js.coffee +++ b/app/assets/javascripts/user/app/controllers/application_controller.js.coffee @@ -42,8 +42,8 @@ App.ApplicationController = Ember.Controller.extend 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 + @events.orders_placed_count.call(@, count: data.supplier_orders_placed_count) if data.supplier_orders_placed_count == 0 or data.supplier_orders_placed_count + @events.orders_in_process_count.call(@, count: data.supplier_orders_in_process_count) if data.supplier_orders_in_process_count == 0 or data.supplier_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/models/list.rb b/app/models/list.rb index ae6f42f1..0855c756 100644 --- a/app/models/list.rb +++ b/app/models/list.rb @@ -146,12 +146,13 @@ class List self.user_requests_closing = false # if a user requested closing, not needed anymore self.closed_at = Time.now if save + broadcast_info = supplier_counter_info.merge(id: id) for user in users user.active_list_id = nil user.save - broadcast_user user.id, 'list_closed', id: id + broadcast_user user.id, 'list_closed', broadcast_info end - broadcast_supplier supplier_id, 'list_closed', id: id + broadcast_supplier supplier_id, 'list_closed', broadcast_info end end @@ -275,8 +276,8 @@ class List broadcast_users 'new_order', order: order.with_products_as_json, total_amount: price broadcast_users 'orders_placed_count', count: orders_placed_count - broadcast_supplier supplier.id, 'list_update', active_model_serializer.new(self).as_json - broadcast_supplier supplier.id, 'new_order', OrderSerializer.new(order) + broadcast_supplier supplier.id, 'list_update', SupplierListSerializer.new(self).as_json + # broadcast_supplier supplier.id, 'new_order', OrderSerializer.new(order) broadcast_supplier supplier.id, 'orders_placed_count', count: orders_placed_count order end diff --git a/app/models/order.rb b/app/models/order.rb index f06752f0..70ac35c2 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -113,10 +113,10 @@ class Order broadcast_options = {id: id} if original_state.placed? reduced_count = supplier.decrement_orders_placed_count! - broadcast_options[:orders_placed_count] = reduced_count + broadcast_options[:supplier_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 + broadcast_options[:supplier_orders_in_process_count] = reduced_count end list.broadcast_users 'order_cancelled', broadcast_options broadcast_supplier supplier_id, 'order_cancelled', broadcast_options diff --git a/app/views/suppliers/application/_top_menu.html.slim b/app/views/suppliers/application/_top_menu.html.slim index ef86624d..1f7ded30 100644 --- a/app/views/suppliers/application/_top_menu.html.slim +++ b/app/views/suppliers/application/_top_menu.html.slim @@ -8,9 +8,9 @@ header.top-menu = link_to image_tag('icons/logo-small.png'), supplier_root_path, class: 'top-menu-root' = link_to ProductCategory.model_name.human_plural, suppliers_product_categories_path, data: {t: 'models.plural.product_category'}, class: 'top-menu-product_categories' = link_to Product.model_name.human_plural, suppliers_products_path, data: {t: 'models.plural.product'}, class: 'top-menu-products' - = link_to Section.model_name.human_plural, suppliers_sections_path, data: {t: 'models.plural.section'}, class: 'top-menu-sections' - = link_to Table.model_name.human_plural, suppliers_tables_path, data: {t: 'models.plural.table'}, class: 'top-menu-tables' - = link_to List.model_name.human_plural, suppliers_lists_path, data: {t: 'models.plural.list'}, class: 'top-menu-lists' + = link_to Section.model_name.human_plural, "/supplier#/sections", data: {t: 'models.plural.section'}, class: 'top-menu-sections' + = link_to Table.model_name.human_plural, "/supplier#/tables", data: {t: 'models.plural.table'}, class: 'top-menu-tables' + = link_to List.model_name.human_plural, "/supplier#/lists", data: {t: 'models.plural.list'}, class: 'top-menu-lists' section.extra-info .supplier-info-row .supplier-name= current_supplier.name.presence || current_supplier.email diff --git a/config/environments/development.rb b/config/environments/development.rb index 360c84c3..f6d40573 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -59,4 +59,3 @@ Qwaiter::Application.configure do # Raises helpful error messages. config.assets.raise_runtime_errors = true end -STDOUT.sync = true diff --git a/spec/acceptance/suppliers/dashboard.feature b/spec/acceptance/suppliers/dashboard.feature index ec5f76d4..fecf3c2f 100644 --- a/spec/acceptance/suppliers/dashboard.feature +++ b/spec/acceptance/suppliers/dashboard.feature @@ -3,6 +3,7 @@ Feature: Supplier main board @javascript Scenario: the active list should be present and contained in row having its id Given there is an active list and order + And there is another section with table And I am signed in as supplier When I visit the supplier root path @@ -51,13 +52,14 @@ Feature: Supplier main board @javascript Scenario: Selecting a specific section limits the result to the lists and orders of those sections Given there is an active list and order + And there is another section with table And I am signed in as supplier And a new order on a table in another section is created Then I should see the list and the new list And I should see the order and the new order When I select the section in the supplier dashboard Then I should see the list and order but not the new list and new order - When I select the new section in the supplier dashboard + When I select the other section in the supplier dashboard Then I should see the new list and new order but not the list and order When I reset the section selector in the supplier dashboard Then I should see the list and the new list @@ -77,7 +79,7 @@ Feature: Supplier main board Given there is an active list and order And there is another section with table And I am signed in as supplier - # wait until page is fully loaded + # wait until page is fully loaded, could be a pure ruby command inside a within :selector statement since the browser will wait for the selector to be present and then the lists are loaded And I wait 4 seconds When the active list changes to another table in another section And I wait 2 seconds @@ -92,3 +94,11 @@ Feature: Supplier main board 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 + + @javascript + Scenario: Closing list with active orders updates supplier counters + Given there is an active list and order + And I am signed in as supplier + When I click on the close list button in the supplier dashboard + And confirm the supplier close list modal + Then the supplier placed orders counter should be reduced diff --git a/spec/acceptance/suppliers/section_view.feature b/spec/acceptance/suppliers/section_view.feature index b5e5d54f..541920f4 100644 --- a/spec/acceptance/suppliers/section_view.feature +++ b/spec/acceptance/suppliers/section_view.feature @@ -42,13 +42,14 @@ Feature: Supplier section view @javascript Scenario: Selecting a specific section limits the result to the lists and orders of those sections Given there is an active list and order + And there is another section with table And I am signed in as supplier And a new order on a table in another section is created Then I should see the list and the new list And I should see the order and the new order When I select the section in the supplier dashboard Then I should see the list and order but not the new list and new order - When I select the new section in the supplier dashboard + When I select the other section in the supplier dashboard Then I should see the new list and new order but not the list and order When I reset the section selector in the supplier dashboard Then I should see the list and the new list diff --git a/spec/acceptance_steps/global_list_steps.rb b/spec/acceptance_steps/global_list_steps.rb index 2269aabb..88064a57 100644 --- a/spec/acceptance_steps/global_list_steps.rb +++ b/spec/acceptance_steps/global_list_steps.rb @@ -27,9 +27,9 @@ step "the list should be marked as closed" do end step 'a new order on a table in another section is created' do - @new_section = create :section, title: 'Terrace', supplier: @supplier - @new_table = create :table, number: 59, section: @new_section, supplier: @supplier - @new_list = create :list, section: @new_section, table: @new_table, supplier: @supplier, user_ids: [@user.id] + # @new_section = create :section, title: 'Terrace', supplier: @supplier + # @new_table = create :table, number: 59, section: @new_section, supplier: @supplier + @new_list = create :list, section: @other_section, table: @other_table, supplier: @supplier, user_ids: [@user.id] @new_order = @new_list.place_order(products: {@product.id => 3}, user: @user) end diff --git a/spec/acceptance_steps/suppliers/dashboard_steps.rb b/spec/acceptance_steps/suppliers/dashboard_steps.rb index 9f84438b..9fd0fefc 100644 --- a/spec/acceptance_steps/suppliers/dashboard_steps.rb +++ b/spec/acceptance_steps/suppliers/dashboard_steps.rb @@ -67,15 +67,15 @@ end step "the new order on a table in another section should be present in the supplier dashboard" do el = find(".order-row-#{@new_order.id}") - el.find('.table_number').text.should == @new_table.number.to_s - el.find('.section_title').text.should == @new_section.title + el.find('.table_number').text.should == @other_table.number.to_s + el.find('.section_title').text.should == @other_section.title end step "the new list should appear in the supplier dashboard" do el = find(".list-row-#{@new_list.id}") el.find('.total_list_amount').text.should =~ /6.66/ - el.find('.section_title').text.should == 'Terrace' - el.find('.table_number').text.should == @new_table.number.to_s + el.find('.section_title').text.should == @other_section.title + el.find('.table_number').text.should == @other_table.number.to_s end step "I click on the close list button in the supplier dashboard" do @@ -114,8 +114,8 @@ step "I select the section in the supplier dashboard" do find(%|.section_selector option[value="#{@section.id}"]|).select_option end -step "I select the new section in the supplier dashboard" do - find(%|.section_selector option[value="#{@new_section.id}"]|).select_option +step "I select the other section in the supplier dashboard" do + find(%|.section_selector option[value="#{@other_section.id}"]|).select_option end step "I reset the section selector in the supplier dashboard" do diff --git a/spec/models/order_spec.rb b/spec/models/order_spec.rb index 0f831f04..a207accf 100644 --- a/spec/models/order_spec.rb +++ b/spec/models/order_spec.rb @@ -129,25 +129,25 @@ describe Order do 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) + expect{ order.cancel! }.to broadcast_to_user(user.id).message( 'order_cancelled' ).with(id: order.id, supplier_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) + expect{ order.cancel! }.to broadcast_to_supplier(supplier.id).message( 'order_cancelled' ).with(id: order.id, supplier_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) + expect{ order.cancel! }.to broadcast_to_user(user.id).message( 'order_cancelled' ).with(id: order.id, supplier_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) + expect{ order.cancel! }.to broadcast_to_supplier(supplier.id).message( 'order_cancelled' ).with(id: order.id, supplier_orders_in_process_count: 6) supplier.orders_placed_count.should == 11 # should not be reduced end end diff --git a/spec/support/ember_helpers.rb b/spec/support/ember_helpers.rb index 41535418..bbef7a2f 100644 --- a/spec/support/ember_helpers.rb +++ b/spec/support/ember_helpers.rb @@ -20,6 +20,6 @@ module SpecEmberHelpers end def faye_log - page.evaluate_script(%|window.faye_log|) + JSON.parse(page.evaluate_script(%|JSON.stringify(window.faye_log)|)) end end diff --git a/wip.md b/wip.md index c8a2d366..ccac59db 100644 --- a/wip.md +++ b/wip.md @@ -16,15 +16,8 @@ Supplier - form action button looks (Roos) - Dashboard - Empty state - - Closing list confirmation modal -- Lists - - Add list link - Section table view - - click on table side menu buttons - add order vinkjes management (post release) - - Edit mode section is out of order and styling -- Settings checken -- Event stream to ember? (After release!!!) - Add qr print functionality offering to send the stickers - Supplier sidebar open/close message seems untranslated @@ -43,9 +36,7 @@ Bugs ---- - Dragging supplier table from one section to the other fails -- 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 ============ @@ -58,3 +49,7 @@ Supplier -------- - tables#index Make table actions available +- Products to ember +- Product categories to ember +- Event stream to ember +- Section view, add go to list button right next to edit section button