Merge branch 'master' of github.com:openfoodfoundation/openfoodnetwork

This commit is contained in:
Maikel Linke
2014-06-28 19:43:01 +10:00
21 changed files with 124 additions and 39 deletions

View File

@@ -1,7 +1,9 @@
Darkswarm.directive "producerModal", ($modal)->
restrict: 'E'
replace: true
template: "<a>{{enterprise.name}}</a>"
template: "<a ng-transclude></a>"
transclude: true
link: (scope, elem, attrs, ctrl)->
elem.on "click", =>
scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'producer_modal.html', scope: scope)

View File

@@ -0,0 +1,9 @@
Darkswarm.directive "productModal", ($modal)->
restrict: 'E'
replace: true
template: "<a ng-transclude></a>"
transclude: true
link: (scope, elem, attrs, ctrl)->
elem.on "click", =>
scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'product_modal.html', scope: scope)

View File

@@ -0,0 +1,10 @@
Darkswarm.filter "groups", (Matcher)->
(groups, text)->
groups ||= []
text ?= ""
groups.filter (group)=>
Matcher.match([
group.name, group.long_description
], text) || group.enterprises.some (e)->
Matcher.match [e.name], text

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -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"}
&nbsp;
.small-4.columns

View File

@@ -1,14 +1,15 @@
.row.summary
.small-1.columns
%img{"bo-src" => "product.master.images[0].small_url"}
%product-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"
%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"}

View File

@@ -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"}
&nbsp;
.small-4.columns

View File

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

View File

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

View File

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

View File

@@ -1,11 +0,0 @@
describe 'Navigation service', ->
Navigation = null
beforeEach ->
module 'Darkswarm'
inject ($injector)->
Navigation = $injector.get("Navigation")
it "caches the path provided", ->
Navigation.navigate "/foo"
expect(Navigation.path).toEqual "/foo"

View File

@@ -7,6 +7,7 @@ describe "Hubs service", ->
active: false
orders_close_at: new Date()
type: "hub"
visible: true
}
]

View File

@@ -0,0 +1,28 @@
describe 'Navigation service', ->
Navigation = null
window =
location:
href: null
pathname: null
beforeEach ->
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"

View File

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