Remove unrequired functions, add has_hub_listing

This commit is contained in:
Rob Harrington
2014-09-25 17:02:18 +10:00
parent cbc8a62686
commit 1e31dd88ee
5 changed files with 17 additions and 21 deletions

View File

@@ -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

View File

@@ -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)->

View File

@@ -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.

View File

@@ -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 = {

View File

@@ -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"}}