From aae1689a27a082c111e93ed43e3810eef848d9d7 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 16 Jun 2016 11:00:20 +1000 Subject: [PATCH] Show product properties on producers page --- .../darkswarm/producer_node.css.sass | 17 +++++++---------- .../stylesheets/darkswarm/taxons.css.sass | 4 ++-- app/serializers/api/enterprise_serializer.rb | 7 ++++++- app/serializers/api/property_serializer.rb | 2 +- app/views/producers/_fat.html.haml | 6 ++++++ spec/features/consumer/producers_spec.rb | 11 +++++++++-- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/app/assets/stylesheets/darkswarm/producer_node.css.sass b/app/assets/stylesheets/darkswarm/producer_node.css.sass index 7bac2dde6d..78209845c5 100644 --- a/app/assets/stylesheets/darkswarm/producer_node.css.sass +++ b/app/assets/stylesheets/darkswarm/producer_node.css.sass @@ -5,7 +5,7 @@ .active_table .active_table_node // Header row - @media all and (max-width: 640px) + @media all and (max-width: 640px) .skinny-head background-color: $clr-turquoise-light @include border-radius-mixed(0.5em, 0.5em, 0, 0) @@ -16,7 +16,7 @@ .follow-icons &, & * font-size: 1.5rem - + // Producer icons i.ofn-i_059-producer, i.ofn-i_060-producer-reversed @@ -41,11 +41,11 @@ &:hover, &:focus, &:active &.secondary color: #666 - .hub-name, .button-address + .hub-name, .button-address border-bottom: 1px solid #999 &.primary color: $clr-brick-bright - .hub-name, .button-address + .hub-name, .button-address border-bottom: 1px solid $clr-brick-bright p.word-wrap @@ -53,7 +53,7 @@ &:last-child margin-bottom: 1rem - .fat-taxons + .fat-taxons, .fat-properties background-color: $clr-turquoise-light .producer-name @@ -72,7 +72,7 @@ max-height: 160px width: auto &.left - padding: 0.25rem 1rem 0.25rem 0 + padding: 0.25rem 1rem 0.25rem 0 &.right padding: 0.25rem 0.5rem 0.25rem 2rem @@ -87,10 +87,7 @@ &.closed .active_table_row.closed border: 1px solid transparent - @media all and (max-width: 640px) + @media all and (max-width: 640px) border-color: $clr-turquoise-light &:hover, &:active, &:focus border-color: $clr-turquoise - - - diff --git a/app/assets/stylesheets/darkswarm/taxons.css.sass b/app/assets/stylesheets/darkswarm/taxons.css.sass index 4f23a8bc3a..1d1e5b652f 100644 --- a/app/assets/stylesheets/darkswarm/taxons.css.sass +++ b/app/assets/stylesheets/darkswarm/taxons.css.sass @@ -1,7 +1,7 @@ @import branding @import mixins -.fat-taxons +.fat-taxons, .fat-properties display: inline-block line-height: 1 margin-right: 0.5rem @@ -29,7 +29,7 @@ svg path fill: $disabled-dark - + .product-header render-svg svg diff --git a/app/serializers/api/enterprise_serializer.rb b/app/serializers/api/enterprise_serializer.rb index 3210c1d2af..b0f4438e90 100644 --- a/app/serializers/api/enterprise_serializer.rb +++ b/app/serializers/api/enterprise_serializer.rb @@ -47,7 +47,7 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer attributes :taxons, :supplied_taxons has_one :address, serializer: Api::AddressSerializer - + has_many :properties, serializer: Api::PropertySerializer def taxons ids_to_objs options[:data].distributed_taxons[object.id] @@ -57,6 +57,11 @@ class Api::CachedEnterpriseSerializer < ActiveModel::Serializer ids_to_objs options[:data].supplied_taxons[object.id] end + def properties + # This results in 2 queries per enterprise + Spree::Property.applied_by(object) + end + def pickup services = options[:data].shipping_method_services[object.id] services ? services[:pickup] : false diff --git a/app/serializers/api/property_serializer.rb b/app/serializers/api/property_serializer.rb index ce04480d30..7da4fce990 100644 --- a/app/serializers/api/property_serializer.rb +++ b/app/serializers/api/property_serializer.rb @@ -1,3 +1,3 @@ class Api::PropertySerializer < ActiveModel::Serializer - + attributes :id, :name, :presentation end diff --git a/app/views/producers/_fat.html.haml b/app/views/producers/_fat.html.haml index 6b665b4f34..0fc082b361 100644 --- a/app/views/producers/_fat.html.haml +++ b/app/views/producers/_fat.html.haml @@ -20,6 +20,12 @@ %render-svg{path: "{{taxon.icon}}"} %span{"ng-bind" => "::taxon.name"} + %div + %label Product properties + %p.trans-sentence + %span.fat-properties{"ng-repeat" => "property in producer.properties"} + %span{"ng-bind" => "property.presentation"} + %div.show-for-medium-up{"ng-if" => "producer.supplied_taxons.length==0"}   diff --git a/spec/features/consumer/producers_spec.rb b/spec/features/consumer/producers_spec.rb index 20676c7dbc..4f3b4f7067 100644 --- a/spec/features/consumer/producers_spec.rb +++ b/spec/features/consumer/producers_spec.rb @@ -21,7 +21,13 @@ feature %q{ let(:shop) { create(:distributor_enterprise) } let!(:er) { create(:enterprise_relationship, parent: shop, child: producer1) } - before { visit producers_path } + before do + product1.set_property 'Organic', 'NASAA 12345' + product2.set_property 'Biodynamic', 'ABC123' + + visit producers_path + end + it "filters by taxon" do toggle_filters @@ -41,7 +47,8 @@ feature %q{ it "shows all producers with expandable details" do page.should have_content producer1.name expand_active_table_node producer1.name - page.should have_content producer1.supplied_taxons.first.name.split.map(&:capitalize).join(' ') + page.should have_content 'Fruit' + page.should have_content 'Organic' end it "doesn't show invisible producers" do