icons and entity category logic

This commit is contained in:
Rafael Schouten
2014-09-18 15:14:55 +10:00
parent d75076e1c9
commit bd922085c4
4 changed files with 25 additions and 21 deletions

View File

@@ -1,12 +1,9 @@
.highlight
.highlight{ng: {class: "enterprise.has_shopfront"}}
.highlight-top
%p.right
{{ [enterprise.address.city, enterprise.address.state_name] | printArray}}
%h3{"ng-if" => "enterprise.is_distributor"}
%h3
%a{"bo-href" => "enterprise.path", "ofn-empties-cart" => "enterprise", bindonce: true}
%i.ofn-i_040-hub
%i{ng: {class: "enterprise.icon_font"}}
%span {{ enterprise.name }}
%h3{"ng-if" => "!enterprise.is_distributor"}
%i.ofn-i_036-producers
%span {{ enterprise.name }}
%img.hero-img{"ng-src" => "{{enterprise.promo_image}}"}

View File

@@ -210,6 +210,18 @@ class Enterprise < ActiveRecord::Base
Spree::Variant.joins(:product => :product_distributions).where('product_distributions.distributor_id=?', self.id)
end
# Make this a real database attridbute later.
def sells
case type
when "full"
"all"
when "single"
"own"
when "profile"
"none"
end
end
def enterprise_category
# Explanation: I added and extra flag then pared it back to a combo, before realising we allready had one.
# Short version: meets front end and back end needs, without changing much at all.
@@ -221,15 +233,8 @@ class Enterprise < ActiveRecord::Base
# Make this crazy logic human readable so we can argue about it sanely.
# This can be simplified later, like this for readablitlty during changes.
category = is_primary_producer ? "producer_" : "non_producer_"
case type
when "full"
category << "sell_all_"
when "single"
category << "sell_own_"
when "profile"
category << "cant_sell_"
end
category << (can_supply ? "can_supply" : "cant_supply")
category << "sell_" + sells
category << (supplies ? "can_supply" : "cant_supply")
# Map backend cases to front end cases.
case category
@@ -261,12 +266,11 @@ class Enterprise < ActiveRecord::Base
end
end
# TODO: Remove this when flags on enterprises are switched over
# Obviously this duplicates is_producer currently
def can_supply
def supplies
is_primary_producer && type != "profile" #and has distributors?
end
# Return all taxons for all distributed products
def distributed_taxons
Spree::Taxon.

View File

@@ -32,18 +32,21 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
object.enterprise_category
end
# TODO: Remove this when flags on enterprises are switched over
def has_shopfront
object.is_distributor && object.type != 'profile'
end
def profile_only
object.type = 'profile'
end
# Map svg icons.
def icon
icons = {
"hub" => "/assets/map_005-hub.svg",
"hub_profile" => "/assets/map_006-hub-profile.svg",
"producer_hub" => "/assets/map_005-hub.svg",
"prodshop_shop" => "/assets/map_003-producer-shop.svg",
"producer_shop" => "/assets/map_003-producer-shop.svg",
"producer" => "map_001-producer-only.svg",
"producer_profile" => "/assets/map_002-producer-only-profile.svg",
}

View File

@@ -1,4 +1,4 @@
.row.active_table_row{"ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'has_shopfront' : producer.has_shopfront}"}
.row.active_table_row{"ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'has_shopfront' : producer.}"}
.columns.small-12.medium-4.large-4.skinny-head
/ This needs logic to show profile only icon when available %i.ofn-i_060-producer-reversed
%i{ng: {class: "producer.producer_icon_font"}}