mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Remove unrequired functions, add has_hub_listing
This commit is contained in:
@@ -4,4 +4,4 @@ Darkswarm.filter 'showProfiles', ()->
|
||||
show_profiles ?= true
|
||||
|
||||
enterprises.filter (enterprise)=>
|
||||
show_profiles or not enterprise.is_profile
|
||||
show_profiles or enterprise.has_shopfront
|
||||
|
||||
@@ -2,7 +2,7 @@ Darkswarm.factory 'Hubs', ($filter, Enterprises, visibleFilter) ->
|
||||
new class Hubs
|
||||
constructor: ->
|
||||
@hubs = @order Enterprises.enterprises.filter (hub)->
|
||||
hub.is_distributor
|
||||
hub.has_hub_listing
|
||||
@visible = visibleFilter @hubs
|
||||
|
||||
order: (hubs)->
|
||||
|
||||
@@ -215,20 +215,15 @@ class Enterprise < ActiveRecord::Base
|
||||
# Type: full - single - profile becomes Sells: all - own - none
|
||||
# Remove this return later.
|
||||
return "none" if !is_distributor || type == "profile"
|
||||
return "own" if is_distributor && (suppliers != [self] || type == "full")
|
||||
"own"
|
||||
end
|
||||
|
||||
# New boolean field shows whether we can supply products into the system.
|
||||
def supplies
|
||||
is_primary_producer && type != "profile" #and has distributors?
|
||||
return "own" if suppliers == [self] || type == "single"
|
||||
"all"
|
||||
end
|
||||
|
||||
# Simplify enterprise categories for frontend logic and icons, and maybe other things.
|
||||
def enterprise_category
|
||||
# Make this crazy logic human readable so we can argue about it sanely.
|
||||
# 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 = is_primary_producer ? "producer_" : "non_producer_"
|
||||
category << "sell_" + sells
|
||||
|
||||
# Map backend cases to front end cases.
|
||||
|
||||
@@ -4,7 +4,7 @@ class Api::EnterpriseSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
|
||||
def cached_serializer_hash
|
||||
Api::CachedEnterpriseSerializer.new(object, @options).serializable_hash
|
||||
end
|
||||
@@ -18,7 +18,7 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
attributes :orders_close_at, :active
|
||||
|
||||
#TODO: Remove these later
|
||||
attributes :icon, :icon_font, :producer_icon_font, :has_shopfront, :is_profile, :enterprise_category
|
||||
attributes :icon, :icon_font, :producer_icon_font, :has_shopfront, :has_hub_listing, :enterprise_category
|
||||
|
||||
def orders_close_at
|
||||
OrderCycle.first_closing_for(object).andand.orders_close_at
|
||||
@@ -36,13 +36,14 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
object.is_distributor && object.type != 'profile'
|
||||
end
|
||||
|
||||
def is_profile
|
||||
object.sells == "none" && !object.supplies
|
||||
# Used to select enterprises for hub listing
|
||||
def has_hub_listing
|
||||
has_shopfront || object.enterprise_category == "hub_profile"
|
||||
end
|
||||
|
||||
# Map svg icons.
|
||||
def icon
|
||||
icons = {
|
||||
icons = {
|
||||
"hub" => "/assets/map_005-hub.svg",
|
||||
"hub_profile" => "/assets/map_006-hub-profile.svg",
|
||||
"producer_hub" => "/assets/map_005-hub.svg",
|
||||
@@ -67,7 +68,7 @@ class Api::UncachedEnterpriseSerializer < ActiveModel::Serializer
|
||||
end
|
||||
|
||||
# Choose producer page icon font - yes, sadly its got to be different.
|
||||
# This duplicates some code but covers the producer page edge case where
|
||||
# This duplicates some code but covers the producer page edge case where
|
||||
# producer-hub has a producer icon without needing to duplicate the category logic in angular.
|
||||
def producer_icon_font
|
||||
icon_fonts = {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.row.active_table_row{"ng-if" => "!hub.is_profile", "ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'has_shopfront' : producer.has_shopfront}", bindonce: true}
|
||||
.row.active_table_row{"ng-if" => "hub.has_shopfront", "ng-click" => "toggle()", "ng-class" => "{'closed' : !open(), 'has_shopfront' : producer.has_shopfront}", bindonce: true}
|
||||
|
||||
.columns.small-12.medium-6.large-5.skinny-head
|
||||
%a.hub{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"}
|
||||
@@ -13,18 +13,18 @@
|
||||
.columns.small-6.medium-3.large-4.text-right{"bo-if" => "hub.active"}
|
||||
%a.hub.open_closed{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"}
|
||||
%i.ofn-i_033-open-sign
|
||||
%span.margin-top{ bo: { if: "current()" } }
|
||||
%span.margin-top{ bo: { if: "current()" } }
|
||||
%em Shopping here
|
||||
%span.margin-top{ bo: { if: "!current()" } } {{ hub.orders_close_at | sensible_timeframe }}
|
||||
|
||||
.columns.small-6.medium-3.large-4.text-right{"bo-if" => "!hub.active"}
|
||||
%a.hub.open_closed{"bo-href" => "hub.path", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"}
|
||||
%i.ofn-i_032-closed-sign
|
||||
%span.margin-top{ bo: { if: "current()" } }
|
||||
%span.margin-top{ bo: { if: "current()" } }
|
||||
%em Shopping here
|
||||
%span.margin-top{ bo: { if: "!current()" } } Orders closed
|
||||
|
||||
.row.active_table_row{"ng-if" => "hub.is_profile", "ng-class" => "closed"}
|
||||
.row.active_table_row{"ng-if" => "!hub.has_shopfront", "ng-class" => "closed"}
|
||||
.columns.small-12.medium-6.large-5.skinny-head
|
||||
%a.hub{"ng-click" => "openModal(hub)", "ng-class" => "{primary: hub.active, secondary: !hub.active}", "ofn-empties-cart" => "hub"}
|
||||
%i{ng: {class: "hub.icon_font"}}
|
||||
|
||||
Reference in New Issue
Block a user