From b678a2f7fd73a72a0072dcc71d4755e1a91180d9 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 27 Jun 2014 11:34:02 +1000 Subject: [PATCH 01/11] Move navigation spec to services dir --- .../unit/darkswarm/{ => services}/navigation.js.coffee | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/javascripts/unit/darkswarm/{ => services}/navigation.js.coffee (100%) diff --git a/spec/javascripts/unit/darkswarm/navigation.js.coffee b/spec/javascripts/unit/darkswarm/services/navigation.js.coffee similarity index 100% rename from spec/javascripts/unit/darkswarm/navigation.js.coffee rename to spec/javascripts/unit/darkswarm/services/navigation.js.coffee From 4075854440730beba19fc0aa395f53ea31f3896e Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 27 Jun 2014 11:51:53 +1000 Subject: [PATCH 02/11] Navigation.go supports full URLs --- .../darkswarm/services/navigation.js.coffee | 8 ++++--- .../darkswarm/services/navigation.js.coffee | 21 +++++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/darkswarm/services/navigation.js.coffee b/app/assets/javascripts/darkswarm/services/navigation.js.coffee index cf64cd1666..fd59d0f348 100644 --- a/app/assets/javascripts/darkswarm/services/navigation.js.coffee +++ b/app/assets/javascripts/darkswarm/services/navigation.js.coffee @@ -1,4 +1,4 @@ -Darkswarm.factory 'Navigation', ($location) -> +Darkswarm.factory 'Navigation', ($location, $window) -> new class Navigation path: null @@ -10,7 +10,6 @@ Darkswarm.factory 'Navigation', ($location) -> $location.path(@path) toggle: (path = false)=> - console.log "toggling" @path = path || @path if $location.path() == @path $location.path("/") @@ -18,4 +17,7 @@ Darkswarm.factory 'Navigation', ($location) -> @navigate(path) go: (path)-> - window.location.pathname = path + if path.match /^http/ + $window.location.href = path + else + $window.location.pathname = path diff --git a/spec/javascripts/unit/darkswarm/services/navigation.js.coffee b/spec/javascripts/unit/darkswarm/services/navigation.js.coffee index 3701a7bded..8b5912bff8 100644 --- a/spec/javascripts/unit/darkswarm/services/navigation.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/navigation.js.coffee @@ -1,11 +1,28 @@ describe 'Navigation service', -> Navigation = null - + window = + location: + href: null + pathname: null + beforeEach -> - module 'Darkswarm' + module 'Darkswarm', ($provide) -> + $provide.value "$window", window + null inject ($injector)-> Navigation = $injector.get("Navigation") + it "caches the path provided", -> Navigation.navigate "/foo" expect(Navigation.path).toEqual "/foo" + + describe "redirecting", -> + it "redirects to full URLs", -> + Navigation.go "http://google.com" + expect(window.location.href).toEqual "http://google.com" + + it "redirects to paths", -> + Navigation.go "/woo/yeah" + expect(window.location.pathname).toEqual "/woo/yeah" + \ No newline at end of file From aa5767cd3022e56875e6ddd329b3ed27c8d644cc Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 27 Jun 2014 11:52:36 +1000 Subject: [PATCH 03/11] Remove paypal image button from checkout, fix redirect to paypal --- app/controllers/checkout_controller.rb | 3 +-- app/views/spree/checkout/payment/_paypalexpress.html.haml | 0 config/routes.rb | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 app/views/spree/checkout/payment/_paypalexpress.html.haml diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 884a5da2f4..77137f5940 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -138,9 +138,8 @@ class CheckoutController < Spree::CheckoutController render :edit and return end - redirect_to(main_app.shop_paypal_payment_url(@order, :payment_method_id => payment_method.id)) + render json: {path: main_app.paypal_payment_url(@order, :payment_method_id => payment_method.id)}, status: 200 true - end # Overriding to customize the cancel url diff --git a/app/views/spree/checkout/payment/_paypalexpress.html.haml b/app/views/spree/checkout/payment/_paypalexpress.html.haml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/config/routes.rb b/config/routes.rb index d166116086..51826d6777 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,7 +16,7 @@ Openfoodnetwork::Application.routes.draw do get '/checkout', :to => 'checkout#edit' , :as => :checkout put '/checkout', :to => 'checkout#update' , :as => :update_checkout - get "/checkout/paypal_payment", to: 'checkout#paypal_payment', as: :paypal_payment + get '/checkout/paypal_payment/:order_id', to: 'checkout#paypal_payment', as: :paypal_payment resources :enterprises do collection do From 5a235be110b48991f476405c590f6fc8ef9a6138 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 27 Jun 2014 11:56:09 +1000 Subject: [PATCH 04/11] Fix regressed JS spec --- spec/javascripts/unit/darkswarm/services/map_spec.js.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee index c10c2c22f8..3ef21705d3 100644 --- a/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/map_spec.js.coffee @@ -7,6 +7,7 @@ describe "Hubs service", -> active: false orders_close_at: new Date() type: "hub" + visible: true } ] From 03c84cbfe5078b748f1b422268c23cbf7c9cfc71 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 27 Jun 2014 12:43:08 +1000 Subject: [PATCH 05/11] Fixing missing taxon icons --- app/serializers/api/taxon_serializer.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/serializers/api/taxon_serializer.rb b/app/serializers/api/taxon_serializer.rb index dc32347dd9..a907532a6b 100644 --- a/app/serializers/api/taxon_serializer.rb +++ b/app/serializers/api/taxon_serializer.rb @@ -1,3 +1,7 @@ class Api::TaxonSerializer < ActiveModel::Serializer - attributes :id, :name, :permalink + attributes :id, :name, :permalink, :icon + + def icon + object.icon(:original) + end end From e4c8c19fea02db8a3297d7cb677391cb9ed24042 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 27 Jun 2014 14:07:12 +1000 Subject: [PATCH 06/11] Tweaking the producer modal --- .../darkswarm/directives/producer_modal.js.coffee | 4 +++- app/views/groups/index.html.haml | 1 + app/views/home/_fat.html.haml | 2 +- app/views/shop/products/_summary.html.haml | 5 +++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/darkswarm/directives/producer_modal.js.coffee b/app/assets/javascripts/darkswarm/directives/producer_modal.js.coffee index d64b2663f7..a8d8253289 100644 --- a/app/assets/javascripts/darkswarm/directives/producer_modal.js.coffee +++ b/app/assets/javascripts/darkswarm/directives/producer_modal.js.coffee @@ -1,7 +1,9 @@ Darkswarm.directive "producerModal", ($modal)-> restrict: 'E' replace: true - template: "{{enterprise.name}}" + template: "" + transclude: true link: (scope, elem, attrs, ctrl)-> elem.on "click", => scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'producer_modal.html', scope: scope) + diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml index dd37a32b78..059abfe882 100644 --- a/app/views/groups/index.html.haml +++ b/app/views/groups/index.html.haml @@ -42,6 +42,7 @@ %li{"ng-repeat" => "enterprise in group.enterprises", "scroll-after-load" => true} %hub-modal{"ng-if" => "enterprise.is_distributor"} %producer-modal{"ng-if" => "!enterprise.is_distributor", "show-hub-actions" => 'true'} + {{ enterprise.name }} .row.group_footer .small-12.columns diff --git a/app/views/home/_fat.html.haml b/app/views/home/_fat.html.haml index 8de0524ea3..16dc3eaafb 100644 --- a/app/views/home/_fat.html.haml +++ b/app/views/home/_fat.html.haml @@ -28,7 +28,7 @@ Our producers %ul.bullet-list %li{"ng-repeat" => "enterprise in hub.producers"} - %producer-modal + %producer-modal {{ enterprise.name }} .row.active_table_row.link{"ng-show" => "open()"} .cta-container.columns.small-12 diff --git a/app/views/shop/products/_summary.html.haml b/app/views/shop/products/_summary.html.haml index ec018065c8..71982ae682 100644 --- a/app/views/shop/products/_summary.html.haml +++ b/app/views/shop/products/_summary.html.haml @@ -1,10 +1,11 @@ .row.summary .small-1.columns - %img{"bo-src" => "product.master.images[0].small_url"} + %producer-modal + %img{"bo-src" => "product.master.images[0].small_url"} .small-4.columns.summary-header %render-svg{path: "{{product.primary_taxon.icon}}"} - = render partial: "modals/product" + %producer-modal {{ enterprise.name }} .small-5.columns %i.ofn-i_036-producers From 8bd8d811b193f7eb56809e0be3f1d91393418bc8 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 27 Jun 2014 14:51:55 +1000 Subject: [PATCH 07/11] Unbreaking the groups page --- .../darkswarm/filters/filter_groups.js.coffee | 10 ++++++++++ app/views/groups/index.html.haml | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/darkswarm/filters/filter_groups.js.coffee diff --git a/app/assets/javascripts/darkswarm/filters/filter_groups.js.coffee b/app/assets/javascripts/darkswarm/filters/filter_groups.js.coffee new file mode 100644 index 0000000000..e6572ec5c2 --- /dev/null +++ b/app/assets/javascripts/darkswarm/filters/filter_groups.js.coffee @@ -0,0 +1,10 @@ +Darkswarm.filter "groups", (Matcher)-> + (groups, text)-> + groups ||= [] + text ?= "" + + groups.filter (group)=> + Matcher.match([ + group.name, group.description, group.long_description + ], text) || group.enterprises.some (e)-> + Matcher.match [e.name], text diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml index 059abfe882..f2ae6e550a 100644 --- a/app/views/groups/index.html.haml +++ b/app/views/groups/index.html.haml @@ -20,7 +20,7 @@ "ng-debounce" => "150", "ofn-disable-enter" => true} - .group{"ng-repeat" => "group in Groups.groups | filter:query | orderBy:order", + .group{"ng-repeat" => "group in Groups.groups | groups:query | orderBy:order", name: "group{{group.id}}", id: "group{{group.id}}"} .row.pad-top{bindonce: true} From e8ba36041b5147c0d34b3dc390b65f9b2d64196e Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 27 Jun 2014 15:01:12 +1000 Subject: [PATCH 08/11] Tests and patch for group filter --- .../darkswarm/filters/filter_groups.js.coffee | 2 +- .../filters/filter_groups_spec.js.coffee | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 spec/javascripts/unit/darkswarm/filters/filter_groups_spec.js.coffee diff --git a/app/assets/javascripts/darkswarm/filters/filter_groups.js.coffee b/app/assets/javascripts/darkswarm/filters/filter_groups.js.coffee index e6572ec5c2..b209068dcf 100644 --- a/app/assets/javascripts/darkswarm/filters/filter_groups.js.coffee +++ b/app/assets/javascripts/darkswarm/filters/filter_groups.js.coffee @@ -5,6 +5,6 @@ Darkswarm.filter "groups", (Matcher)-> groups.filter (group)=> Matcher.match([ - group.name, group.description, group.long_description + group.name, group.long_description ], text) || group.enterprises.some (e)-> Matcher.match [e.name], text diff --git a/spec/javascripts/unit/darkswarm/filters/filter_groups_spec.js.coffee b/spec/javascripts/unit/darkswarm/filters/filter_groups_spec.js.coffee new file mode 100644 index 0000000000..e7e2614f7f --- /dev/null +++ b/spec/javascripts/unit/darkswarm/filters/filter_groups_spec.js.coffee @@ -0,0 +1,34 @@ +describe "filtering Groups", -> + filterGroups = null + groups = [{ + name: "test" + long_description: "roger" + enterprises: [{ + name: "kittens" + }, { + name: "kittens" + }] + }, { + name: "blankness" + long_description: "in the sky" + enterprises: [{ + name: "ponies" + }, { + name: "ponies" + }] + } + ] + + beforeEach -> + module 'Darkswarm' + inject ($filter) -> + filterGroups = $filter('groups') + + it "filters by name", -> + expect(filterGroups(groups, "test")[0]).toBe groups[0] + + it "filters by description", -> + expect(filterGroups(groups, "sky")[0]).toBe groups[1] + + it "filters by enterprise name", -> + expect(filterGroups(groups, "ponies")[0]).toBe groups[1] From 7b673870cd9a8bc6cac5c156902c322bd136362d Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 27 Jun 2014 15:04:56 +1000 Subject: [PATCH 09/11] Adding bulk icons --- app/views/shop/products/_master.html.haml | 2 +- app/views/shop/products/_variants.html.haml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/shop/products/_master.html.haml b/app/views/shop/products/_master.html.haml index 4c00365f71..92a17be43d 100644 --- a/app/views/shop/products/_master.html.haml +++ b/app/views/shop/products/_master.html.haml @@ -1,5 +1,5 @@ .small-1.columns - %span.bulk{"bo-if" => "product.group_buy"} bulk + %i.ofn-i_056-bulk{"bo-if" => "product.group_buy"}   .small-4.columns diff --git a/app/views/shop/products/_variants.html.haml b/app/views/shop/products/_variants.html.haml index fed7753ff3..5d6a59535e 100644 --- a/app/views/shop/products/_variants.html.haml +++ b/app/views/shop/products/_variants.html.haml @@ -2,7 +2,7 @@ "ng-repeat" => "variant in product.variants"} .small-1.columns - %span.bulk{"bo-if" => "product.group_buy"} bulk + %i.ofn-i_056-bulk{"bo-if" => "product.group_buy"}   .small-4.columns From f316b8dec53213ccb678f8e99f2fb21a5b10a9a1 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 27 Jun 2014 15:15:41 +1000 Subject: [PATCH 10/11] Adding product modals in new format --- .../darkswarm/directives/product_modal.js.coffee | 9 +++++++++ app/assets/javascripts/templates/product_modal.html.haml | 9 +++++++++ app/views/shop/products/_summary.html.haml | 6 +++--- spec/features/consumer/shopping/shopping_spec.rb | 3 +++ spec/support/request/ui_component_helper.rb | 8 ++++++-- 5 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 app/assets/javascripts/darkswarm/directives/product_modal.js.coffee create mode 100644 app/assets/javascripts/templates/product_modal.html.haml diff --git a/app/assets/javascripts/darkswarm/directives/product_modal.js.coffee b/app/assets/javascripts/darkswarm/directives/product_modal.js.coffee new file mode 100644 index 0000000000..428fde3633 --- /dev/null +++ b/app/assets/javascripts/darkswarm/directives/product_modal.js.coffee @@ -0,0 +1,9 @@ +Darkswarm.directive "productModal", ($modal)-> + restrict: 'E' + replace: true + template: "" + transclude: true + link: (scope, elem, attrs, ctrl)-> + elem.on "click", => + scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'product_modal.html', scope: scope) + diff --git a/app/assets/javascripts/templates/product_modal.html.haml b/app/assets/javascripts/templates/product_modal.html.haml new file mode 100644 index 0000000000..1f0c1a7564 --- /dev/null +++ b/app/assets/javascripts/templates/product_modal.html.haml @@ -0,0 +1,9 @@ +.row + .columns.small-12.large-6 + %img.product-img{"ng-src" => "{{product.master.images[0].large_url}}", "ng-if" => "product.master.images[0]"} + .columns.small-12.large-6.product-header + %h2 + %render-svg{path: "{{product.primary_taxon.icon}}"} + {{product.name}} + %p {{product.description}} +%ng-include{src: "'partials/close.html'"} diff --git a/app/views/shop/products/_summary.html.haml b/app/views/shop/products/_summary.html.haml index 71982ae682..b21b535315 100644 --- a/app/views/shop/products/_summary.html.haml +++ b/app/views/shop/products/_summary.html.haml @@ -1,15 +1,15 @@ .row.summary .small-1.columns - %producer-modal + %product-modal %img{"bo-src" => "product.master.images[0].small_url"} .small-4.columns.summary-header %render-svg{path: "{{product.primary_taxon.icon}}"} - %producer-modal {{ enterprise.name }} + %product-modal {{ product.name }} .small-5.columns %i.ofn-i_036-producers - = render partial: "modals/producer" + %producer-modal {{ enterprise.name }} .small-2.columns.summary-price.text-right.price %span{"ng-if" => "hasVariants"} diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index e75f7f6f21..377f56c102 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -79,6 +79,9 @@ feature "As a consumer I want to shop with a distributor", js: true do page.should have_content product.name page.should have_content product.master.display_name page.should have_content product.master.display_as + + open_product_modal product + modal_should_be_open_for product end end end diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index ebf95548d6..32d6abd77e 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -38,13 +38,17 @@ module UIComponentHelper have_selector ".login-modal" end + def open_product_modal(product) + find("a", text: product.name).click + end + def open_enterprise_modal(enterprise) find("a", text: enterprise.name).click end - def modal_should_be_open_for(enterprise) + def modal_should_be_open_for(object) within ".reveal-modal" do - page.should have_content enterprise.name + page.should have_content object.name end end From ce3cb7890b19f1fae6fe843b198103af699e3924 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Fri, 27 Jun 2014 15:16:08 +1000 Subject: [PATCH 11/11] Removing old product modal --- app/views/modals/_product.html.haml | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 app/views/modals/_product.html.haml diff --git a/app/views/modals/_product.html.haml b/app/views/modals/_product.html.haml deleted file mode 100644 index 6d50f9c09d..0000000000 --- a/app/views/modals/_product.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -%ofn-modal{title: "{{product.name}}"} - .row - .columns.small-12.large-6 - %img.product-img{"ng-src" => "{{product.master.images[0].large_url}}", "ng-if" => "product.master.images[0]"} - .columns.small-12.large-6.product-header - %h2 - %render-svg{path: "{{product.primary_taxon.icon}}"} - {{product.name}} - %p {{product.description}} - %a.close-reveal-modal{"ng-click" => "$close()"} - %i.ofn-i_009-close