From 29814125401c3ae3f8b91b9f53e82c755fdbd00a Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Wed, 23 Apr 2014 14:38:41 +1000 Subject: [PATCH] Adding some specs, next order cycle, better CSS --- .../darkswarm/active_table.css.sass | 2 + .../stylesheets/darkswarm/hub_node.css.sass | 2 +- app/models/enterprise.rb | 1 + app/views/darkswarm/_fat.html.haml | 28 +++++++++++++ app/views/darkswarm/_skinny.html.haml | 13 ++++++ app/views/darkswarm/index.html.haml | 41 +------------------ app/views/json/_hubs.rabl | 7 ++-- spec/controllers/darkswarm_controller_spec.rb | 20 ++++++++- 8 files changed, 69 insertions(+), 45 deletions(-) create mode 100644 app/views/darkswarm/_fat.html.haml create mode 100644 app/views/darkswarm/_skinny.html.haml diff --git a/app/assets/stylesheets/darkswarm/active_table.css.sass b/app/assets/stylesheets/darkswarm/active_table.css.sass index ff530d606d..497ddb07de 100644 --- a/app/assets/stylesheets/darkswarm/active_table.css.sass +++ b/app/assets/stylesheets/darkswarm/active_table.css.sass @@ -1,7 +1,9 @@ @import 'branding' +@import "compass/css3/user-interface" .active_table margin: 2em 0em + @include user-select(none) .active_table_row padding: 0.8em 0.5em display: block diff --git a/app/assets/stylesheets/darkswarm/hub_node.css.sass b/app/assets/stylesheets/darkswarm/hub_node.css.sass index 7c810c9a0d..5aca8f6d5f 100644 --- a/app/assets/stylesheets/darkswarm/hub_node.css.sass +++ b/app/assets/stylesheets/darkswarm/hub_node.css.sass @@ -19,7 +19,7 @@ hub border: 1px solid $clr-strong .active_table_row:first-child border-bottom: 1px solid $clr-strong - .active_table_row:last-child + .active_table_row.link padding: 0 background-color: $clr-strong &:hover diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index ca31f5bc8c..f063714fd8 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -47,6 +47,7 @@ class Enterprise < ActiveRecord::Base scope :with_distributed_products_outer, joins('LEFT OUTER JOIN product_distributions ON product_distributions.distributor_id = enterprises.id'). joins('LEFT OUTER JOIN spree_products ON spree_products.id = product_distributions.product_id') + scope :with_order_cycles_outer, joins("LEFT OUTER JOIN exchanges ON (exchanges.receiver_id = enterprises.id AND exchanges.incoming = 'f')"). joins('LEFT OUTER JOIN order_cycles ON (order_cycles.id = exchanges.order_cycle_id)') diff --git a/app/views/darkswarm/_fat.html.haml b/app/views/darkswarm/_fat.html.haml new file mode 100644 index 0000000000..c139cedab7 --- /dev/null +++ b/app/views/darkswarm/_fat.html.haml @@ -0,0 +1,28 @@ + +.row.active_table_row{"ng-show" => "open()"} + .columns.small-4 + %strong Shop for + %p + Organics, Test data, Food boxes, fruit, + kittens, Meat & Fish, Drinks + .columns.small-4 + %strong Delivery options + %ol + %li.pickup{"bo-if" => "hub.pickup"} Pickup + %li.delivery{"bo-if" => "hub.delivery"} Delivery + .columns.small-4 + %strong Our producers + %ol + %li Fake Name Forever + %li The Constant Gardener + %li Shiny Olives + %li Love in the Time of Cholera + +.row.active_table_row.link{"ng-show" => "open()", "ng-if" => "hub.active"} + .columns.small-11 + %a{"bo-href" => "hub.path"} + Shop at + %strong {{ hub.name }} + .columns.small-1.text-right + %a{"bo-href" => "hub.path"} + %i.fi-arrow-right diff --git a/app/views/darkswarm/_skinny.html.haml b/app/views/darkswarm/_skinny.html.haml new file mode 100644 index 0000000000..4431a12560 --- /dev/null +++ b/app/views/darkswarm/_skinny.html.haml @@ -0,0 +1,13 @@ +.row.active_table_row{"ng-click" => "toggle()", "ng-class" => "{'closed' : !open()}"} + .columns.small-4 + %strong {{ hub.name }} + .columns.small-3 + {{ hub.address.city }} + .columns.small-1 + {{ hub.address.state | uppercase }} + .columns.small-3{"bo-if" => "hub.active"} + Orders closing when? + .columns.small-3{"bo-if" => "!hub.active"} + Orders closed + .columns.small-1.text-right + %i{"ng-class" => "{'fi-arrow-down' : !open(), 'fi-arrow-up' : open()}"} diff --git a/app/views/darkswarm/index.html.haml b/app/views/darkswarm/index.html.haml index 86f0341c52..6c9261fa0a 100644 --- a/app/views/darkswarm/index.html.haml +++ b/app/views/darkswarm/index.html.haml @@ -35,45 +35,8 @@ "ng-controller" => "HubNodeCtrl", id: "{{hub.path}}"} .small-12.columns - .row.active_table_row{"ng-click" => "toggle()", "ng-class" => "{'closed' : !open()}"} - .columns.small-4 - %strong {{ hub.name }} - .columns.small-3 - {{ hub.address.city }} - .columns.small-1 - {{ hub.address.state | uppercase }} - .columns.small-3 - Orders closing when? - .columns.small-1.text-right - %i{"ng-class" => "{'fi-arrow-down' : !open(), 'fi-arrow-up' : open()}"} - - .row.active_table_row{"ng-show" => "open()"} - .columns.small-4 - %strong Shop for - %p - Organics, Test data, Food boxes, fruit, - kittens, Meat & Fish, Drinks - .columns.small-4 - %strong Delivery options - %ol - %li.pickup{"bo-if" => "hub.pickup"} Pickup - %li.delivery{"bo-if" => "hub.delivery"} Delivery - .columns.small-4 - %strong Our producers - %ol - %li Fake Name Forever - %li The Constant Gardener - %li Shiny Olives - %li Love in the Time of Cholera - - .row.active_table_row{"ng-show" => "open()"} - .columns.small-11 - %a{"bo-href" => "hub.path"} - Shop at - %strong {{ hub.name }} - .columns.small-1.text-right - %a{"bo-href" => "hub.path"} - %i.fi-arrow-right + = render partial: 'darkswarm/skinny' + = render partial: 'darkswarm/fat' .small-12.columns .row{"ng-show" => "filteredHubs.length == 0"} diff --git a/app/views/json/_hubs.rabl b/app/views/json/_hubs.rabl index ddbdbb6203..062df2b267 100644 --- a/app/views/json/_hubs.rabl +++ b/app/views/json/_hubs.rabl @@ -24,7 +24,6 @@ node :active do |hub| @active_distributors.include?(hub) end -# ALL PRODUCERS -# -# Orders closing when? -# Current order_cycle + closing when? +node :orders_close_at do |hub| + OrderCycle.with_distributor(hub).soonest_closing.first.andand.orders_close_at +end diff --git a/spec/controllers/darkswarm_controller_spec.rb b/spec/controllers/darkswarm_controller_spec.rb index 32672422f6..a1dc1dd23a 100644 --- a/spec/controllers/darkswarm_controller_spec.rb +++ b/spec/controllers/darkswarm_controller_spec.rb @@ -1,6 +1,24 @@ require 'spec_helper' describe DarkswarmController do - #let(:distributor) { create(:distributor_enterprise) } + render_views + let(:distributor) { create(:distributor_enterprise) } + + before do + controller.stub(:load_data_for_sidebar).and_return nil + Enterprise.stub(:distributors_with_active_order_cycles).and_return [distributor] + Enterprise.stub(:is_distributor).and_return [distributor] + end + it "sets active distributors" do + get :index + assigns[:active_distributors].should == [distributor] + end + + # This is done inside RABL template + it "gets the next order cycle for each hub" do + OrderCycle.stub_chain(:with_distributor, :soonest_closing, :first) + OrderCycle.should_receive(:with_distributor).with(distributor) + get :index + end end