mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-25 05:45:15 +00:00
change enterprise category name ans use symbols instead of strings
This commit is contained in:
@@ -12,9 +12,9 @@ Darkswarm.factory 'Enterprises', (enterprises, CurrentHub, Taxons, Dereferencer,
|
||||
@dereferenceTaxons()
|
||||
@visible_enterprises = visibleFilter @enterprises
|
||||
@producers = @visible_enterprises.filter (enterprise)->
|
||||
enterprise.enterprise_category in ["producer_hub", "producer_shop", "producer"]
|
||||
enterprise.category in ["producer_hub", "producer_shop", "producer"]
|
||||
@hubs = @visible_enterprises.filter (enterprise)->
|
||||
enterprise.enterprise_category in ["hub", "hub_profile", "producer_hub", "producer_shop"]
|
||||
enterprise.category in ["hub", "hub_profile", "producer_hub", "producer_shop"]
|
||||
|
||||
dereferenceEnterprises: ->
|
||||
if CurrentHub.hub?.id
|
||||
|
||||
@@ -5,8 +5,7 @@ Darkswarm.factory 'Variants', ->
|
||||
@variants[variant.id] ||= @extend variant
|
||||
|
||||
extend: (variant)->
|
||||
# Add totalPrice and basPricePercentage methods to calculate line item values.
|
||||
# This should probably be on a line item object!
|
||||
# Add totalPrice method to calculate line item total. This should be on a line item!
|
||||
variant.totalPrice = ->
|
||||
variant.price_with_fees * variant.line_item.quantity
|
||||
variant.basePricePercentage = Math.round(variant.price / variant.price_with_fees * 100)
|
||||
|
||||
@@ -215,31 +215,26 @@ class Enterprise < ActiveRecord::Base
|
||||
not self.sells == "none"
|
||||
end
|
||||
|
||||
def is_hub
|
||||
self.enterprise_category.in Array['hub', 'hub_profile', 'producer_hub', 'producer_shop']
|
||||
end
|
||||
|
||||
# Simplify enterprise categories for frontend logic and icons, and maybe other things.
|
||||
def enterprise_category
|
||||
def category
|
||||
# Make this crazy logic human readable so we can argue about it sanely.
|
||||
# This can be simplified later, it's like this for readablitlty during changes.
|
||||
category = is_primary_producer ? "producer_" : "non_producer_"
|
||||
category << "sells_" + sells
|
||||
cat = is_primary_producer ? "producer_" : "non_producer_"
|
||||
cat << "sells_" + sells
|
||||
|
||||
# Map backend cases to front end cases.
|
||||
case category
|
||||
case cat
|
||||
when "producer_sells_any"
|
||||
"producer_hub" # Producer hub who sells own and others produce and supplies other hubs.
|
||||
:producer_hub # Producer hub who sells own and others produce and supplies other hubs.
|
||||
when "producer_sells_own"
|
||||
"producer_shop" # Producer with shopfront and supplies other hubs.
|
||||
:producer_shop # Producer with shopfront and supplies other hubs.
|
||||
when "producer_sells_none"
|
||||
"producer" # Producer only supplies through others.
|
||||
:producer # Producer only supplies through others.
|
||||
when "non_producer_sells_any"
|
||||
"hub" # Hub selling others products in order cycles.
|
||||
:hub # Hub selling others products in order cycles.
|
||||
when "non_producer_sells_own"
|
||||
"hub" # Wholesaler selling through own shopfront? Does this need a separate name? Should it exist?
|
||||
:hub # Wholesaler selling through own shopfront? Does this need a separate name? Should it exist?
|
||||
when "non_producer_sells_none"
|
||||
"hub_profile" # Hub selling outside the system.
|
||||
:hub_profile # Hub selling outside the system.
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
class Api::Admin::EnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :payment_method_ids, :shipping_method_ids
|
||||
attributes :name, :id, :is_primary_producer, :is_distributor, :sells, :category, :payment_method_ids, :shipping_method_ids
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
:long_description, :website, :instagram, :linkedin, :twitter,
|
||||
:facebook, :is_primary_producer, :is_distributor, :phone, :visible,
|
||||
:email, :hash, :logo, :promo_image, :path, :pickup, :delivery,
|
||||
:icon, :icon_font, :producer_icon_font, :enterprise_category
|
||||
:icon, :icon_font, :producer_icon_font, :category
|
||||
|
||||
has_many :distributed_taxons, key: :taxons, serializer: Api::IdSerializer
|
||||
has_many :supplied_taxons, serializer: Api::IdSerializer
|
||||
@@ -78,25 +78,25 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
# 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",
|
||||
"producer_shop" => "/assets/map_003-producer-shop.svg",
|
||||
"producer" => "/assets/map_001-producer-only.svg",
|
||||
:hub => "/assets/map_005-hub.svg",
|
||||
:hub_profile => "/assets/map_006-hub-profile.svg",
|
||||
:producer_hub => "/assets/map_005-hub.svg",
|
||||
:producer_shop => "/assets/map_003-producer-shop.svg",
|
||||
:producer => "/assets/map_001-producer-only.svg",
|
||||
}
|
||||
icons[object.enterprise_category]
|
||||
icons[object.category]
|
||||
end
|
||||
|
||||
# Choose regular icon font for enterprises.
|
||||
def icon_font
|
||||
icon_fonts = {
|
||||
"hub" => "ofn-i_063-hub",
|
||||
"hub_profile" => "ofn-i_064-hub-reversed",
|
||||
"producer_hub" => "ofn-i_063-hub",
|
||||
"producer_shop" => "ofn-i_059-producer",
|
||||
"producer" => "ofn-i_059-producer",
|
||||
:hub => "ofn-i_063-hub",
|
||||
:hub_profile => "ofn-i_064-hub-reversed",
|
||||
:producer_hub => "ofn-i_063-hub",
|
||||
:producer_shop => "ofn-i_059-producer",
|
||||
:producer => "ofn-i_059-producer",
|
||||
}
|
||||
icon_fonts[object.enterprise_category]
|
||||
icon_fonts[object.category]
|
||||
end
|
||||
|
||||
# Choose producer page icon font - yes, sadly its got to be different.
|
||||
@@ -104,12 +104,12 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
# producer-hub has a producer icon without needing to duplicate the category logic in angular.
|
||||
def producer_icon_font
|
||||
icon_fonts = {
|
||||
"hub" => "",
|
||||
"hub_profile" => "",
|
||||
"producer_hub" => "ofn-i_059-producer",
|
||||
"producer_shop" => "ofn-i_059-producer",
|
||||
"producer" => "ofn-i_059-producer",
|
||||
:hub => "",
|
||||
:hub_profile => "",
|
||||
:producer_hub => "ofn-i_059-producer",
|
||||
:producer_shop => "ofn-i_059-producer",
|
||||
:producer => "ofn-i_059-producer",
|
||||
}
|
||||
icon_fonts[object.enterprise_category]
|
||||
icon_fonts[object.category]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
- enterprise_fees_color = @enterprise_fees.count > 0 ? "blue" : "red"
|
||||
.sidebar_item.four.columns.alpha#enterprise_fees{ ng: { show: 'Enterprise.sells != "none" || Enterprise.is_primary_producer' } }
|
||||
.sidebar_item.four.columns.alpha#enterprise_fees{ ng: { show: 'Enterprise.category != "producer_hub"' } }
|
||||
.four.columns.alpha.header{ class: "#{enterprise_fees_color}" }
|
||||
%span.four.columns.alpha.centered Enterprise Fees
|
||||
.four.columns.alpha.list{ class: "#{enterprise_fees_color}" }
|
||||
|
||||
@@ -5,14 +5,14 @@ describe "Enterprises service", ->
|
||||
{id: 1, name: "test"}
|
||||
]
|
||||
enterprises = [
|
||||
{id: 1, visible: true, enterprise_category: "hub", producers: [{id: 5}], taxons: [{id: 1}]},
|
||||
{id: 2, visible: true, enterprise_category: "hub", producers: [{id: 6}]}
|
||||
{id: 3, visible: true, enterprise_category: "hub_profile"}
|
||||
{id: 4, visible: false, enterprise_category: "hub", producers: [{id: 7}]}
|
||||
{id: 5, visible: true, enterprise_category: "producer_hub", hubs: [{id: 1}]},
|
||||
{id: 6, visible: true, enterprise_category: "producer_shop", hubs: [{id: 2}]},
|
||||
{id: 7, visible: true, enterprise_category: "producer", hubs: [{id: 2}]}
|
||||
{id: 8, visible: false, enterprise_category: "producer", hubs: [{id: 2}]}
|
||||
{id: 1, visible: true, category: "hub", producers: [{id: 5}], taxons: [{id: 1}]},
|
||||
{id: 2, visible: true, category: "hub", producers: [{id: 6}]}
|
||||
{id: 3, visible: true, category: "hub_profile"}
|
||||
{id: 4, visible: false, category: "hub", producers: [{id: 7}]}
|
||||
{id: 5, visible: true, category: "producer_hub", hubs: [{id: 1}]},
|
||||
{id: 6, visible: true, category: "producer_shop", hubs: [{id: 2}]},
|
||||
{id: 7, visible: true, category: "producer", hubs: [{id: 2}]}
|
||||
{id: 8, visible: false, category: "producer", hubs: [{id: 2}]}
|
||||
]
|
||||
H1: 0
|
||||
beforeEach ->
|
||||
|
||||
@@ -528,12 +528,12 @@ describe Enterprise do
|
||||
producer_sell_all.is_primary_producer.should == true
|
||||
producer_sell_all.sells.should == "any"
|
||||
|
||||
producer_sell_all.enterprise_category.should == "producer_hub"
|
||||
producer_sell_own.enterprise_category.should == "producer_shop"
|
||||
producer_sell_none.enterprise_category.should == "producer"
|
||||
non_producer_sell_all.enterprise_category.should == "hub"
|
||||
non_producer_sell_own.enterprise_category.should == "hub"
|
||||
non_producer_sell_none.enterprise_category.should == "hub_profile"
|
||||
producer_sell_all.category.should == :producer_hub
|
||||
producer_sell_own.category.should == :producer_shop
|
||||
producer_sell_none.category.should == :producer
|
||||
non_producer_sell_all.category.should == :hub
|
||||
non_producer_sell_own.category.should == :hub
|
||||
non_producer_sell_none.category.should == :hub_profile
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user