Adding properties to enterprise serialiser to allow differentiation between profile, shopfront and aggregators

This commit is contained in:
Rob H
2014-09-05 12:30:52 +10:00
parent ed0f2de2f3
commit 8f6d04a129
2 changed files with 14 additions and 2 deletions

View File

@@ -30,11 +30,12 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
cached
delegate :cache_key, to: :object
attributes :name, :id, :description, :latitude, :longitude,
:long_description, :website, :instagram, :linkedin, :twitter,
attributes :name, :id, :description, :latitude, :longitude,
:long_description, :website, :instagram, :linkedin, :twitter,
:facebook, :is_primary_producer, :is_distributor, :phone, :visible,
:email, :hash, :logo, :promo_image, :icon, :path,
:pickup, :delivery
attributes :has_shopfront, :can_aggregate
has_many :distributed_taxons, key: :taxons, serializer: Api::IdSerializer
has_many :supplied_taxons, serializer: Api::IdSerializer
@@ -77,6 +78,16 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer
end
end
# TODO: Remove this when flags on enterprises are switched over
def has_shopfront
object.type != 'profile'
end
# TODO: Remove this when flags on enterprises are switched over
def can_aggregate
object.is_distributor && !object.is_primary_producer
end
# TODO when ActiveSerializers supports URL helpers
# Then refactor. See readme https://github.com/rails-api/active_model_serializers
def path

View File

@@ -1,6 +1,7 @@
.row.active_table_row{"ng-click" => "toggle()", "ng-class" => "{'closed' : !open()}", 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"}
/%i{ ng: { class: "{'ofn-i_063-hub': hub.can_aggregate, 'ofn-i_059-producer': !hub.can_aggregate}" } }
%i.ofn-i_040-hub
%span
%strong {{ hub.name | truncate:40}}