Split 'My Enterprises' dashboard item into Hubs and Producers

This commit is contained in:
Rob H
2014-05-22 15:28:25 +10:00
parent 3bf21d42dd
commit ed3c23cd90
7 changed files with 160 additions and 40 deletions

View File

@@ -0,0 +1,5 @@
Admin.controller "enterprisesDashboard", [
"$scope"
($scope) ->
$scope.activeTab = "hubs"
]

View File

@@ -4,7 +4,23 @@ div.dashboard_item
.centered
text-align: center
.text-icon
margin-top: 7px
display: block
font-size: 16px
font-weight: bold
color: #fff
padding: 0px 6px
border-radius: 10px
&.green
background-color: #9fc820
&.red
background-color: #DA5354
&.orange
background-color: #DA7F52
div.header
height: 50px
border-radius: 6px 6px 0px 0px
border: 1px solid #5498da
position: relative
@@ -26,12 +42,36 @@ div.dashboard_item
h3
color: #DA7F52
h3
padding: 10px 5px 10px 3%
h3.alpha
height: 100%
padding: 10px 5px 0px 3%
a
border-radius: 0px 4px 0px 0px
margin-left: 8px
height: 100%
padding: 15px 2px 0px 2px
.tabs
height: 30px
border: solid #5498da
border-width: 0px 0px 1px 0px
margin-top: 3px
div.dashboard_tab
cursor: pointer
height: 30px
color: #fff
background-color: #5498da
padding: 5px 5px 0px 5px
text-align: center
font-weight: bold
border: solid #5498da
border-width: 1px 1px 0px 1px
&:hover
background-color: #9fc820
&.selected
color: #5498da
background-color: #fff
.list
max-height: 250px
@@ -95,10 +135,13 @@ div.dashboard_item
color: #fff
.icon-ok-sign
color: #fff
.text-icon
&.green
color: #9fc820
background-color: #fff
a.button
color: #fff
padding: 15px 15px
font-size: 110%
font-weight: bold
text-align: center
@@ -111,4 +154,5 @@ div.dashboard_item
&:hover
background-color: #9fc820
&.bottom
border-radius: 0px 0px 6px 6px
border-radius: 0px 0px 6px 6px
padding: 15px 15px

View File

@@ -123,6 +123,14 @@ class Enterprise < ActiveRecord::Base
self.supplied_products.where('count_on_hand > 0').present?
end
def supplied_and_active_products_on_hand
self.supplied_products.where('spree_products.count_on_hand > 0').active
end
def active_products_in_order_cycles
self.supplied_and_active_products_on_hand.in_an_active_order_cycle
end
def to_param
"#{id}-#{name.parameterize}"
end

View File

@@ -75,6 +75,12 @@ Spree::Product.class_eval do
scope :in_order_cycle, lambda { |order_cycle| with_order_cycles_inner.
merge(Exchange.outgoing).
where('order_cycles.id = ?', order_cycle) }
scope :in_an_active_order_cycle, lambda { with_order_cycles_inner.
merge(OrderCycle.active).
merge(Exchange.outgoing).
where('order_cycles.id IS NOT NULL') }
scope :managed_by, lambda { |user|
if user.has_spree_role?('admin')
scoped

View File

@@ -1,11 +1,15 @@
%div.dashboard_item.sixteen.columns.alpha#enterprises
%div.dashboard_item.sixteen.columns.alpha#enterprises{ 'ng-app' => 'ofn.admin', 'ng-controller' => "enterprisesDashboard" }
%div.header.sixteen.columns.alpha{ :class => "#{@enterprises.count > 0 ? "" : "red"}"}
%h3.thirteen.columns.alpha My Enterprises
- if @enterprises.any?
%a.three.columns.omega.icon-plus.button.blue{ href: "#{main_app.new_admin_enterprise_path}" }
%a.three.columns.omega.icon-plus.button.blue.white-bottom{ href: "#{main_app.new_admin_enterprise_path}" }
CREATE NEW
- else
%a.with-tip{ title: "Enterprises are Producers and/or Hubs and are the basic unit of organisation within the Open Food Network." } What's this?
- if @enterprises.any?
%div.sixteen.columns.alpha.tabs
%div.dashboard_tab.eight.columns.alpha.blue{ ng: { class: "{selected: activeTab == 'hubs'}", click: "activeTab = 'hubs'" } } HUBS
%div.dashboard_tab.eight.columns.omega.blue{ ng: { class: "{selected: activeTab == 'producers'}", click: "activeTab = 'producers'" } } PRODUCERS
- if @enterprises.empty?
%div.sixteen.columns.alpha.list-item.red
%span.text.fifteen.columns.alpha You don't have any enterprises yet.
@@ -15,40 +19,69 @@
CREATE A NEW ENTERPRISE
%span.icon-arrow-right
- else
%div.sixteen.columns.alpha.list-title
%span.five.columns.alpha Name
%span.centered.three.columns Payment Methods
%span.centered.three.columns Shipping Methods
%span.centered.three.columns Enterprise Fees
%div.sixteen.columns.alpha.list
- @enterprises.each do |enterprise|
%a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" }
%span.five.columns.alpha
= enterprise.name
%span.symbol.three.columns.centered
- payment_method_count = enterprise.payment_methods.count
- if payment_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Payment Methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Payment Methods." }
- else
%span.icon-ok-sign.with-tip{ title: "#{payment_method_count} Payment Method#{payment_method_count > 1 ? "s" : ""}" }
%span.symbol.three.columns.centered
- shipping_method_count = enterprise.shipping_methods.count
- if shipping_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Shipping Methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Shipping Methods." }
-else
%span.icon-ok-sign.with-tip{ title: "#{shipping_method_count} Shipping Method#{shipping_method_count > 1 ? "s" : ""}" }
%span.symbol.three.columns.centered
- fee_count = enterprise.enterprise_fees.count
- if fee_count > 0
%span.icon-ok-sign.with-tip{ title: "#{fee_count} Fee#{fee_count > 1 ? "s" : ""}" }
- else
%span.icon-warning-sign.with-tip{ title: "#{enterprise.name} has no Enterprise Fees" }
%span.two.columns.omega.right
%span.icon-arrow-right
%div.hubs_tab{ ng: { show: "activeTab == 'hubs'"} }
%div.sixteen.columns.alpha.list-title
%span.five.columns.alpha Name
%span.centered.three.columns Payment Methods
%span.centered.three.columns Shipping Methods
%span.centered.three.columns Enterprise Fees
%div.sixteen.columns.alpha.list
- @enterprises.is_distributor.each do |enterprise|
%a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" }
%span.five.columns.alpha
= enterprise.name
%span.symbol.three.columns.centered
- payment_method_count = enterprise.payment_methods.count
- if payment_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Payment Methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Payment Methods." }
- else
%span.icon-ok-sign.with-tip{ title: "#{payment_method_count} Payment Method#{payment_method_count > 1 ? "s" : ""}" }
%span.symbol.three.columns.centered
- shipping_method_count = enterprise.shipping_methods.count
- if shipping_method_count < 1 && enterprise.is_distributor
%span.icon-remove-sign.with-tip{ title: "#{enterprise.name} has no Shipping Methods" }
- elsif enterprise.is_primary_producer
%span.icon-ok-sign.with-tip{ title: "Producers (like #{enterprise.name}) do not require Shipping Methods." }
-else
%span.icon-ok-sign.with-tip{ title: "#{shipping_method_count} Shipping Method#{shipping_method_count > 1 ? "s" : ""}" }
%span.symbol.three.columns.centered
- fee_count = enterprise.enterprise_fees.count
- if fee_count > 0
%span.icon-ok-sign.with-tip{ title: "#{fee_count} Fee#{fee_count > 1 ? "s" : ""}" }
- else
%span.icon-warning-sign.with-tip{ title: "#{enterprise.name} has no Enterprise Fees" }
%span.two.columns.omega.right
%span.icon-arrow-right
%div.producers_tab{ ng: { show: "activeTab == 'producers'"} }
%div.list-title.sixteen.columns.alpha
%span.five.columns.alpha Name
%span.centered.three.columns Total Products
%span.centered.three.columns Active Products
%span.centered.three.columns Products in OCs
%div.sixteen.columns.alpha.list
- @enterprises.is_primary_producer.each do |enterprise|
%a.sixteen.columns.alpha.list-item{ class: "#{cycle('odd','even')}", href: "#{main_app.edit_admin_enterprise_path(enterprise)}" }
%span.five.columns.alpha
= enterprise.name
%span.symbol.three.columns.centered
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.supplied_products.not_deleted.count > 0 ? "green" : "red" }" }
= enterprise.supplied_products.not_deleted.count
%span.one.column.omega &nbsp;
%span.symbol.three.columns.centered
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.supplied_and_active_products_on_hand.count > 0 ? "green" : "red" }" }
= enterprise.supplied_and_active_products_on_hand.count
%span.one.column.omega &nbsp;
%span.symbol.three.columns.centered
%span.one.column.alpha &nbsp;
%span.text-icon.one.column.centered{ class: "#{enterprise.active_products_in_order_cycles.count > 0 ? "green" : "orange" }" }
= enterprise.active_products_in_order_cycles.count
%span.one.column.omega &nbsp;
%span.two.columns.omega.right
%span.icon-arrow-right
%a.sixteen.columns.alpha.button.bottom.blue{ href: "#{main_app.admin_enterprises_path}" }
MANAGE MY ENTERPRISES
%span.icon-arrow-right

View File

@@ -338,6 +338,16 @@ describe Enterprise do
end
end
describe "supplied_and_active_products_on_hand" do
it "find only active products which are in stock" do
supplier = create(:supplier_enterprise)
inactive_product = create(:product, supplier: supplier, on_hand: 1, available_on: Date.tomorrow)
out_of_stock_product = create(:product, supplier: supplier, on_hand: 0, available_on: Date.yesterday)
p1 = create(:product, supplier: supplier, on_hand: 1, available_on: Date.yesterday)
supplier.supplied_and_active_products_on_hand.should == [p1]
end
end
describe "finding variants distributed by the enterprise" do
it "finds the master variant" do
d = create(:distributor_enterprise)

View File

@@ -230,6 +230,20 @@ module Spree
end
end
describe "in_an_active_order_cycle" do
it "shows products in order cycle distribution" do
s = create(:supplier_enterprise)
d2 = create(:distributor_enterprise)
d3 = create(:distributor_enterprise)
p1 = create(:product)
p2 = create(:product)
p3 = create(:product)
oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d2], variants: [p2.master], orders_close_at: 1.day.ago)
oc2 = create(:simple_order_cycle, suppliers: [s], distributors: [d3], variants: [p3.master], orders_close_at: Date.tomorrow)
Product.in_an_active_order_cycle.should == [p3]
end
end
describe "access roles" do
before(:each) do
@e1 = create(:enterprise)