From 5417242b8562a5ac742a993f4ea041f26f185fa2 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 31 Jul 2014 12:00:43 +1000 Subject: [PATCH 1/4] Remove image decorator - image sizes are already configurable from spree config --- app/models/spree/image_decorator.rb | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 app/models/spree/image_decorator.rb diff --git a/app/models/spree/image_decorator.rb b/app/models/spree/image_decorator.rb deleted file mode 100644 index db6cddc449..0000000000 --- a/app/models/spree/image_decorator.rb +++ /dev/null @@ -1,8 +0,0 @@ -Spree::Image.class_eval do - has_attached_file :attachment, - :styles => { :mini => '48x48>', :small => '114x114#', :product => '240x240>', :large => '600x600>' }, - :default_style => :product, - :url => '/spree/products/:id/:style/:basename.:extension', - :path => ':rails_root/public/spree/products/:id/:style/:basename.:extension', - :convert_options => { :all => '-strip -auto-orient -quality 75' } -end From a26450d17398c3235836482d073c9938b809a8a5 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 31 Jul 2014 14:58:18 +1000 Subject: [PATCH 2/4] Remove unused spree searcher class - causing intermittent test failures --- config/initializers/spree.rb | 2 - lib/open_food_network/searcher.rb | 37 --------------- spec/lib/open_food_network/searcher_spec.rb | 52 --------------------- 3 files changed, 91 deletions(-) delete mode 100644 lib/open_food_network/searcher.rb delete mode 100644 spec/lib/open_food_network/searcher_spec.rb diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index 0460865c7e..bbee30379a 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -8,13 +8,11 @@ require 'spree/product_filters' -require 'open_food_network/searcher' Spree.config do |config| config.shipping_instructions = true config.checkout_zone = 'Australia' config.address_requires_state = true - config.searcher_class = OpenFoodNetwork::Searcher # 12 should be Australia. Hardcoded for CI (Jenkins), where countries are not pre-loaded. config.default_country_id = 12 diff --git a/lib/open_food_network/searcher.rb b/lib/open_food_network/searcher.rb deleted file mode 100644 index 83781ea475..0000000000 --- a/lib/open_food_network/searcher.rb +++ /dev/null @@ -1,37 +0,0 @@ -require 'spree/core/search/base' - -module OpenFoodNetwork - class Searcher < Spree::Core::Search::Base - - # Do not perform pagination - def retrieve_products - @products_scope = get_base_scope - curr_page = page || 1 - - @products = @products_scope.includes([:master]) - end - - def get_base_scope - base_scope = super - - # The concern of separating products by distributor and order cycle is dealt with in - # a few other places: OpenFoodNetwork::SplitProductsByDistribution (for splitting the main - # product display) and Spree::BaseHelper decorator (for taxon counts). - - base_scope = base_scope.in_supplier_or_distributor(enterprise_id) if enterprise_id - base_scope = base_scope.in_supplier(supplier_id) if supplier_id - base_scope = base_scope.in_distributor(distributor_id) if distributor_id - - base_scope - end - - - def prepare(params) - super(params) - @properties[:enterprise_id] = params[:enterprise_id] - @properties[:supplier_id] = params[:supplier_id] - @properties[:distributor_id] = params[:distributor_id] - end - - end -end diff --git a/spec/lib/open_food_network/searcher_spec.rb b/spec/lib/open_food_network/searcher_spec.rb deleted file mode 100644 index 2fb83ed309..0000000000 --- a/spec/lib/open_food_network/searcher_spec.rb +++ /dev/null @@ -1,52 +0,0 @@ -require 'spec_helper' -require 'open_food_network/searcher' - -module OpenFoodNetwork - describe Searcher do - it "searches by supplier" do - # Given products under two suppliers - s1 = create(:supplier_enterprise) - s2 = create(:supplier_enterprise) - p1 = create(:product, :supplier => s1) - p2 = create(:product, :supplier => s2) - - # When we search for one supplier, we should see only products from that supplier - searcher = Searcher.new(:supplier_id => s1.id.to_s) - products = searcher.retrieve_products - products.should == [p1] - end - - it "searches by distributor" do - # Given products under two distributors - d1 = create(:distributor_enterprise) - d2 = create(:distributor_enterprise) - p1 = create(:product, :distributors => [d1]) - p2 = create(:product, :distributors => [d2]) - - # When we search for one distributor, we should see only products from that distributor - searcher = Searcher.new(:distributor_id => d1.id.to_s) - products = searcher.retrieve_products - products.should == [p1] - end - - it "searches by supplier or distributor" do - # Given products under some suppliers and distributors - s0 = create(:supplier_enterprise) - s1 = create(:supplier_enterprise) - d1 = create(:distributor_enterprise) - p1 = create(:product, :supplier => s1) - p2 = create(:product, :distributors => [d1]) - p3 = create(:product, :supplier => s0) - - # When we search by the supplier enterprise, we should see the supplied products - searcher = Searcher.new(:enterprise_id => s1.id.to_s) - products = searcher.retrieve_products - products.should == [p1] - - # When we search by the distributor enterprise, we should see the distributed products - searcher = Searcher.new(:enterprise_id => d1.id.to_s) - products = searcher.retrieve_products - products.should == [p2] - end - end -end From 7ca618fb2925ff33fdf1a13dc4fdb776a8023b19 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 31 Jul 2014 11:11:34 +1000 Subject: [PATCH 3/4] Moving to state_name --- app/serializers/api/address_serializer.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/serializers/api/address_serializer.rb b/app/serializers/api/address_serializer.rb index 18483da312..66e4267e1f 100644 --- a/app/serializers/api/address_serializer.rb +++ b/app/serializers/api/address_serializer.rb @@ -1,10 +1,12 @@ class Api::AddressSerializer < ActiveModel::Serializer - cached - delegate :cache_key, to: :object + #cached + #delegate :cache_key, to: :object - attributes :id, :zipcode, :city, :state, :state_id + attributes :id, :zipcode, :city, :state_name, :state_id, + :phone, :firstname, :lastname, :address1, :address2, :city, :country_id, + :zipcode - def state + def state_name object.state.andand.abbr end end From 6b00b1c14c2a5e9169c951c347c1b87e65c6de44 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Thu, 31 Jul 2014 15:38:15 +1000 Subject: [PATCH 4/4] MOAR COMMENTS --- .../directives/fill_vertical.js.coffee | 3 +-- .../darkswarm/directives/flash.js.coffee | 6 +++++- .../darkswarm/directives/focus.js.coffee | 6 +++--- .../darkswarm/directives/loading.js.coffee | 3 +-- .../darkswarm/directives/modal.js.coffee | 17 ++++++++++------- .../darkswarm/directives/render_svg.js.coffee | 4 ++++ .../directives/scroll_after_load.js.coffee | 1 + .../darkswarm/directives/scrollto.js.coffee | 2 ++ .../directives/shipping_type_selector.js.coffee | 1 + .../directives/taxon_selector.js.coffee | 11 +++++++++-- 10 files changed, 37 insertions(+), 17 deletions(-) diff --git a/app/assets/javascripts/darkswarm/directives/fill_vertical.js.coffee b/app/assets/javascripts/darkswarm/directives/fill_vertical.js.coffee index a8a2fbeebc..c9d05428ce 100644 --- a/app/assets/javascripts/darkswarm/directives/fill_vertical.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/fill_vertical.js.coffee @@ -1,10 +1,9 @@ Darkswarm.directive "fillVertical", ($window)-> + # Makes something fill the window vertically. Used on the Google Map. restrict: 'A' - link: (scope, element, attrs)-> setSize = -> element.css "height", ($window.innerHeight - element.offset().top) setSize() - angular.element($window).bind "resize", -> setSize() diff --git a/app/assets/javascripts/darkswarm/directives/flash.js.coffee b/app/assets/javascripts/darkswarm/directives/flash.js.coffee index b5c9aaddd8..74f6571f73 100644 --- a/app/assets/javascripts/darkswarm/directives/flash.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/flash.js.coffee @@ -1,5 +1,6 @@ Darkswarm.directive "ofnFlash", (flash, $timeout, RailsFlashLoader)-> - # Mappings between flash types (left) and Foundation classes + # Our own flash class. Uses the "flash" service (third party), and a directive + # called RailsFlashLoader to render typePairings = info: "info" error: "alert" @@ -13,6 +14,8 @@ Darkswarm.directive "ofnFlash", (flash, $timeout, RailsFlashLoader)-> link: ($scope, element, attr) -> $scope.flashes = [] + + # Callback when a new flash message is pushed to flash service show = (message, type)=> if message $scope.flashes.push({message: message, type: typePairings[type]}) @@ -21,5 +24,6 @@ Darkswarm.directive "ofnFlash", (flash, $timeout, RailsFlashLoader)-> $scope.delete = -> $scope.flashes.shift() + # Register our callback (above) with flash service flash.subscribe(show) RailsFlashLoader.initFlash() diff --git a/app/assets/javascripts/darkswarm/directives/focus.js.coffee b/app/assets/javascripts/darkswarm/directives/focus.js.coffee index c481702d6c..3c3bb4f05a 100644 --- a/app/assets/javascripts/darkswarm/directives/focus.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/focus.js.coffee @@ -1,9 +1,9 @@ Darkswarm.directive "ofnFocus", -> + # Takes an expression attrs.ofnFocus + # Watches value of expression, triggers element.focus() when value is truthy + # Used to automatically focus on specific inputs in various circumstances restrict: "A" link: (scope, element, attrs) -> scope.$watch attrs.ofnFocus, ((focus) -> focus and element.focus() - return ), true - - return diff --git a/app/assets/javascripts/darkswarm/directives/loading.js.coffee b/app/assets/javascripts/darkswarm/directives/loading.js.coffee index febe56de9b..c7191b4fe2 100644 --- a/app/assets/javascripts/darkswarm/directives/loading.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/loading.js.coffee @@ -1,4 +1,5 @@ Darkswarm.directive "loading", (Loading)-> + # Triggers a screen-wide "loading" thing when Ajaxy stuff is happening scope: {} restrict: 'E' templateUrl: 'loading.html' @@ -6,5 +7,3 @@ Darkswarm.directive "loading", (Loading)-> $scope.Loading = Loading $scope.show = -> $scope.Loading.message? - - link: ($scope, element, attr)-> diff --git a/app/assets/javascripts/darkswarm/directives/modal.js.coffee b/app/assets/javascripts/darkswarm/directives/modal.js.coffee index d727fa64c9..7c1babe215 100644 --- a/app/assets/javascripts/darkswarm/directives/modal.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/modal.js.coffee @@ -1,16 +1,19 @@ Darkswarm.directive "ofnModal", ($modal)-> + # Generic modal! Uses transclusion so designer-types can do stuff like: + # %ofn-modal + # CONTENT + # Only works for simple cases, so roll your own when necessary! restrict: 'E' replace: true transclude: true - scope: {} + scope: true template: "{{title}}" + # Instead of using ng-transclude we compile the transcluded template to a string + # This compiled template is sent to the $modal service! Such magic! + # In theory we could compile the template directly inside link rather than onclick, but it's performant so meh! link: (scope, elem, attrs, ctrl, transclude)-> scope.title = attrs.title - contents = null elem.on "click", => - # We're using an isolate scope, which is a child of the original scope - # We have to compile the transclude against the original scope, not the isolate - transclude scope.$parent, (clone)-> - contents = clone - scope.modalInstance = $modal.open(controller: ctrl, template: contents, scope: scope.$parent) + transclude scope, (clone)-> + scope.modalInstance = $modal.open(controller: ctrl, template: clone, scope: scope) diff --git a/app/assets/javascripts/darkswarm/directives/render_svg.js.coffee b/app/assets/javascripts/darkswarm/directives/render_svg.js.coffee index 86ffea8c5b..c53448473d 100644 --- a/app/assets/javascripts/darkswarm/directives/render_svg.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/render_svg.js.coffee @@ -1,7 +1,11 @@ Darkswarm.directive "renderSvg", ()-> + # Magical directive that'll render SVGs from URLs + # If only there were a neater way of doing this restrict: 'E' priority: 99 template: "" + + # Fetch SVG via ajax, inject into page using DOM link: (scope, elem, attr)-> if /.svg/.test attr.path # Only do this if we've got an svg $.ajax diff --git a/app/assets/javascripts/darkswarm/directives/scroll_after_load.js.coffee b/app/assets/javascripts/darkswarm/directives/scroll_after_load.js.coffee index ab2e0a6e3d..55c5a311da 100644 --- a/app/assets/javascripts/darkswarm/directives/scroll_after_load.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/scroll_after_load.js.coffee @@ -1,4 +1,5 @@ Darkswarm.directive 'scrollAfterLoad', ($timeout, $location, $document)-> + # Scroll to an element on page load restrict: "A" link: (scope, element, attr) -> if scope.$last is true diff --git a/app/assets/javascripts/darkswarm/directives/scrollto.js.coffee b/app/assets/javascripts/darkswarm/directives/scrollto.js.coffee index 3db3446596..a63337dc70 100644 --- a/app/assets/javascripts/darkswarm/directives/scrollto.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/scrollto.js.coffee @@ -1,4 +1,6 @@ Darkswarm.directive "ofnScrollTo", ($location, $anchorScroll)-> + # Onclick sets $location.hash to attrs.ofnScrollTo + # Then triggers anchorScroll restrict: 'A' link: (scope, element, attrs)-> element.bind 'click', (ev)-> diff --git a/app/assets/javascripts/darkswarm/directives/shipping_type_selector.js.coffee b/app/assets/javascripts/darkswarm/directives/shipping_type_selector.js.coffee index 3f752f8a3d..07656d84b7 100644 --- a/app/assets/javascripts/darkswarm/directives/shipping_type_selector.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/shipping_type_selector.js.coffee @@ -1,4 +1,5 @@ Darkswarm.directive "shippingTypeSelector", (FilterSelectorsService)-> + # Builds selector for shipping types restrict: 'E' replace: true templateUrl: 'shipping_type_selector.html' diff --git a/app/assets/javascripts/darkswarm/directives/taxon_selector.js.coffee b/app/assets/javascripts/darkswarm/directives/taxon_selector.js.coffee index a682176d77..633ecd22f4 100644 --- a/app/assets/javascripts/darkswarm/directives/taxon_selector.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/taxon_selector.js.coffee @@ -1,4 +1,6 @@ Darkswarm.directive "taxonSelector", (FilterSelectorsService)-> + # Automatically builds activeSelectors for taxons + # Lots of magic here restrict: 'E' replace: true scope: @@ -8,7 +10,7 @@ Darkswarm.directive "taxonSelector", (FilterSelectorsService)-> link: (scope, elem, attr)-> selectors_by_id = {} - selectors = ["foo"] + selectors = null # To get scoping/closure right scope.emit = -> scope.results = selectors.filter (selector)-> @@ -16,6 +18,7 @@ Darkswarm.directive "taxonSelector", (FilterSelectorsService)-> .map (selector)-> selector.taxon.id + # Build hash of unique taxons, each of which gets an ActiveSelector scope.selectors = -> taxons = {} selectors = [] @@ -25,7 +28,11 @@ Darkswarm.directive "taxonSelector", (FilterSelectorsService)-> if object.supplied_taxons for taxon in object.supplied_taxons taxons[taxon.id] = taxon - + + # Generate a selector for each taxon. + # NOTE: THESE ARE MEMOIZED to stop new selectors from being created constantly, otherwise function always returns non-identical results + # This means the $digest cycle can never close and times out + # See http://stackoverflow.com/questions/19306452/how-to-fix-10-digest-iterations-reached-aborting-error-in-angular-1-2-fil for id, taxon of taxons if selector = selectors_by_id[id] selectors.push selector