diff --git a/app/assets/stylesheets/admin/openfoodnetwork.css.scss b/app/assets/stylesheets/admin/openfoodnetwork.css.scss index 8f429e4431..2e03a9e2eb 100644 --- a/app/assets/stylesheets/admin/openfoodnetwork.css.scss +++ b/app/assets/stylesheets/admin/openfoodnetwork.css.scss @@ -98,6 +98,20 @@ form.order_cycle { */ } +table#listing_order_cycles { + tr.open td { + background-color: #d9fccb; + } + + tr.upcoming td { + background-color: #fbfccb; + } + + tr.closed td { + background-color: #eee; + } +} + table#listing_payment_methods { table-layout: fixed; diff --git a/app/controllers/admin/order_cycles_controller.rb b/app/controllers/admin/order_cycles_controller.rb index bfca1a347d..26627caeed 100644 --- a/app/controllers/admin/order_cycles_controller.rb +++ b/app/controllers/admin/order_cycles_controller.rb @@ -70,7 +70,11 @@ module Admin protected def collection - OrderCycle.managed_by(spree_current_user) + ocs = OrderCycle.managed_by(spree_current_user) + + ocs.soonest_closing + + ocs.soonest_opening + + ocs.most_recently_closed end private diff --git a/app/helpers/order_cycles_helper.rb b/app/helpers/order_cycles_helper.rb index f8706329da..af5f16e10c 100644 --- a/app/helpers/order_cycles_helper.rb +++ b/app/helpers/order_cycles_helper.rb @@ -17,6 +17,17 @@ module OrderCyclesHelper end end + def order_cycle_status_class(order_cycle) + if order_cycle.upcoming? + 'upcoming' + elsif order_cycle.open? + 'open' + elsif order_cycle.closed? + 'closed' + end + end + + def distributor_options(distributors, current_distributor, order_cycle) options = distributors.map { |d| [d.name, d.id, {:class => order_cycle_local_remote_class(d, order_cycle).strip}] } options_for_select(options, current_distributor) diff --git a/app/views/admin/order_cycles/index.html.haml b/app/views/admin/order_cycles/index.html.haml index 26316a7af6..570d23f677 100644 --- a/app/views/admin/order_cycles/index.html.haml +++ b/app/views/admin/order_cycles/index.html.haml @@ -30,7 +30,8 @@ %tbody = f.fields_for :collection do |order_cycle_form| - order_cycle = order_cycle_form.object - %tr + - klass = "order-cycle-#{order_cycle.id} #{order_cycle_status_class order_cycle}" + %tr{class: klass} %td= link_to order_cycle.name, main_app.edit_admin_order_cycle_path(order_cycle) %td= order_cycle_form.text_field :orders_open_at, :class => 'datetimepicker', :value => order_cycle.orders_open_at %td= order_cycle_form.text_field :orders_close_at, :class => 'datetimepicker', :value => order_cycle.orders_close_at diff --git a/spec/features/admin/order_cycles_spec.rb b/spec/features/admin/order_cycles_spec.rb index ac111b70b2..efbbda00aa 100644 --- a/spec/features/admin/order_cycles_spec.rb +++ b/spec/features/admin/order_cycles_spec.rb @@ -18,26 +18,50 @@ feature %q{ scenario "listing order cycles" do - # Given an order cycle - oc = create(:order_cycle) + # Given some order cycles (created in an arbitrary order) + oc4 = create(:simple_order_cycle, name: '4', + orders_open_at: 2.day.from_now, orders_close_at: 1.month.from_now) + oc2 = create(:simple_order_cycle, name: '2', orders_close_at: 1.month.from_now) + oc6 = create(:simple_order_cycle, name: '6', + orders_open_at: 1.month.ago, orders_close_at: 3.weeks.ago) + oc3 = create(:simple_order_cycle, name: '3', + orders_open_at: 1.day.from_now, orders_close_at: 1.month.from_now) + oc5 = create(:simple_order_cycle, name: '5', + orders_open_at: 1.month.ago, orders_close_at: 2.weeks.ago) + oc1 = create(:order_cycle, name: '1') # When I go to the admin order cycles page login_to_admin_section click_link 'Order Cycles' - # Then I should see the basic fields - page.should have_selector 'a', text: oc.name + # Then the order cycles should be ordered correctly + page.all('#listing_order_cycles tr td:first-child').map(&:text).should == + ['1', '2', '3', '4', '5', '6'] - page.should have_selector "input[value='#{oc.orders_open_at}']" - page.should have_selector "input[value='#{oc.orders_close_at}']" - page.should have_content oc.coordinator.name + # And the rows should have the correct classes + page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc1.id}.open" + page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc2.id}.open" + page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc3.id}.upcoming" + page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc4.id}.upcoming" + page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc5.id}.closed" + page.should have_selector "#listing_order_cycles tr.order-cycle-#{oc6.id}.closed" - # And I should see the suppliers and distributors - oc.suppliers.each { |s| page.should have_content s.name } - oc.distributors.each { |d| page.should have_content d.name } + # And I should see all the details for an order cycle + within('table#listing_order_cycles tbody tr:first-child') do + # Then I should see the basic fields + page.should have_selector 'a', text: oc1.name - # And I should see the number of variants - page.should have_selector 'td.products', text: '2 variants' + page.should have_selector "input[value='#{oc1.orders_open_at}']" + page.should have_selector "input[value='#{oc1.orders_close_at}']" + page.should have_content oc1.coordinator.name + + # And I should see the suppliers and distributors + oc1.suppliers.each { |s| page.should have_content s.name } + oc1.distributors.each { |d| page.should have_content d.name } + + # And I should see the number of variants + page.should have_selector 'td.products', text: '2 variants' + end end scenario "creating an order cycle", js: true do