Auto-merged master into transifex on deployment.

This commit is contained in:
Maikel
2016-07-12 17:44:55 +10:00
committed by GitHub
14 changed files with 189 additions and 109 deletions

View File

@@ -24,7 +24,7 @@ angular.module("admin.indexUtils").directive "objForUpdate", (switchClass, pendi
scope.savedValue = value
scope.success = ->
switchClass( element, "update-success", ["update-pending", "update-error"], 3000 )
switchClass( element, "update-success", ["update-pending", "update-error"], 5000 )
scope.pending = ->
switchClass( element, "update-pending", ["update-error", "update-success"], false )

View File

@@ -1,3 +1,7 @@
Darkswarm.controller "GroupsCtrl", ($scope, Groups) ->
Darkswarm.controller "GroupsCtrl", ($scope, Groups, Search) ->
$scope.Groups = Groups
$scope.order = 'position'
$scope.query = Search.search()
$scope.$watch "query", (query)->
Search.search query

View File

@@ -0,0 +1,21 @@
Darkswarm.directive 'mapOsmTiles', ($timeout) ->
restrict: 'E'
require: '^googleMap'
scope: {}
link: (scope, elem, attrs, ctrl) ->
$timeout =>
map = ctrl.getMap()
map.mapTypes.set 'OSM', new google.maps.ImageMapType
getTileUrl: (coord, zoom) ->
# "Wrap" x (logitude) at 180th meridian properly
# NB: Don't touch coord.x because coord param is by reference, and changing its x property breaks something in Google's lib
tilesPerGlobe = 1 << zoom
x = coord.x % tilesPerGlobe
if x < 0
x = tilesPerGlobe + x
# Wrap y (latitude) in a like manner if you want to enable vertical infinite scroll
'http://tile.openstreetmap.org/' + zoom + '/' + x + '/' + coord.y + '.png'
tileSize: new google.maps.Size(256, 256)
name: 'OpenStreetMap'
maxZoom: 18

View File

@@ -1,46 +1,54 @@
Darkswarm.directive 'mapSearch', ($timeout)->
Darkswarm.directive 'mapSearch', ($timeout, Search) ->
# Install a basic search field in a map
restrict: 'E'
require: '^googleMap'
require: ['^googleMap', 'ngModel']
replace: true
template: '<input id="pac-input" placeholder="' + t('location_placeholder') + '"></input>'
link: (scope, elem, attrs, ctrl)->
template: '<input id="pac-input" ng-model="query" placeholder="' + t('location_placeholder') + '"></input>'
scope: {}
controller: ($scope) ->
$scope.query = Search.search()
$scope.$watch 'query', (query) ->
Search.search query
link: (scope, elem, attrs, ctrls) ->
[ctrl, model] = ctrls
scope.input = document.getElementById("pac-input")
$timeout =>
map = ctrl.getMap()
# Use OSM tiles server
map.mapTypes.set 'OSM', new (google.maps.ImageMapType)(
getTileUrl: (coord, zoom) ->
# "Wrap" x (logitude) at 180th meridian properly
# NB: Don't touch coord.x because coord param is by reference, and changing its x property breakes something in Google's lib
tilesPerGlobe = 1 << zoom
x = coord.x % tilesPerGlobe
if x < 0
x = tilesPerGlobe + x
# Wrap y (latitude) in a like manner if you want to enable vertical infinite scroll
'http://tile.openstreetmap.org/' + zoom + '/' + x + '/' + coord.y + '.png'
tileSize: new (google.maps.Size)(256, 256)
name: 'OpenStreetMap'
maxZoom: 18)
searchBox = scope.createSearchBox map
scope.bindSearchResponse map, searchBox
scope.biasResults map, searchBox
scope.performUrlSearch map
input = (document.getElementById("pac-input"))
map.controls[google.maps.ControlPosition.TOP_LEFT].push input
searchBox = new google.maps.places.SearchBox((input))
scope.createSearchBox = (map) ->
map.controls[google.maps.ControlPosition.TOP_LEFT].push scope.input
return new google.maps.places.SearchBox(scope.input)
google.maps.event.addListener searchBox, "places_changed", ->
places = searchBox.getPlaces()
return if places.length is 0
# For each place, get the icon, place name, and location.
markers = []
bounds = new google.maps.LatLngBounds()
for place in places
#map.setCenter place.geometry.location
map.fitBounds place.geometry.viewport
#map.fitBounds bounds
scope.bindSearchResponse = (map, searchBox) ->
google.maps.event.addListener searchBox, "places_changed", =>
scope.showSearchResult map, searchBox
# Bias the SearchBox results towards places that are within the bounds of the
# current map's viewport.
scope.showSearchResult = (map, searchBox) ->
places = searchBox.getPlaces()
for place in places when place.geometry.viewport?
map.fitBounds place.geometry.viewport
scope.$apply ->
model.$setViewValue elem.val()
# When the map loads, and we have a search from ?query, perform that search
scope.performUrlSearch = (map) ->
google.maps.event.addListenerOnce map, "idle", =>
google.maps.event.trigger(scope.input, 'focus');
google.maps.event.trigger(scope.input, 'keydown', {keyCode: 13});
# Bias the SearchBox results towards places that are within the bounds of the
# current map's viewport.
scope.biasResults = (map, searchBox) ->
google.maps.event.addListener map, "bounds_changed", ->
bounds = map.getBounds()
searchBox.setBounds bounds

View File

@@ -40,6 +40,7 @@
.map-container
%map{"ng-if" => "(isActive(\'/map\') && (mapShowed = true)) || mapShowed"}
%google-map{options: "map.additional_options", center: "map.center", zoom: "map.zoom", styles: "map.styles", draggable: "true"}
%map-osm-tiles
%map-search
%markers{models: "mapMarkers", fit: "true",
coords: "'self'", icon: "'icon'", click: "'reveal'"}

View File

@@ -6,6 +6,7 @@
.map-container{"fill-vertical" => true}
%map{"ng-controller" => "MapCtrl"}
%google-map{options: "map.additional_options", center: "map.center", zoom: "map.zoom", styles: "map.styles", draggable: "true"}
%map-osm-tiles
%map-search
%markers{models: "OfnMap.enterprises", fit: "true",
coords: "'self'", icon: "'icon'", click: "'reveal'"}

View File

@@ -64,6 +64,7 @@ en:
free: "free"
plus_tax: "plus GST"
total_monthly_bill_incl_tax: "Total Monthly Bill (Incl. Tax)"
business_model_configuration: "Business model configuration"
say_no: "No"
say_yes: "Yes"

View File

@@ -216,6 +216,7 @@ module OpenFoodNetwork
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| "" },
proc { |line_items| line_items.all? { |li| li.order.paid? } ? "Yes" : "No" },
proc { |line_items| line_items.first.order.shipping_method.andand.name },
proc { |line_items| rsa.call(line_items) ? 'Y' : 'N' },

View File

@@ -42,6 +42,7 @@ feature 'Business Model Configuration' do
click_button "Update"
expect(page).to have_content "Business model configuration has been successfully updated!"
expect(Spree::Config.account_invoices_monthly_fixed).to eq 10
expect(Spree::Config.account_invoices_monthly_rate).to eq 0.05
expect(Spree::Config.account_invoices_monthly_cap).to eq 30

View File

@@ -60,7 +60,7 @@ feature 'Customers' do
create(:order, customer: customer1)
expect{
within "tr#c_#{customer1.id}" do
find("a.delete-customer").click
find("a.delete-customer").trigger('click')
end
expect(page).to have_selector "#info-dialog .text", text: "Delete failed: customer has associated orders"
click_button "OK"
@@ -115,7 +115,7 @@ feature 'Customers' do
expect(customer1.tag_list).to eq []
end
it "prevents duplicate codes from being saved" do
it "prevents duplicate codes from being saved", retry: 3 do
select2_select managed_distributor1.name, from: "shop_id"
within "tr#c_#{customer1.id}" do

View File

@@ -12,8 +12,8 @@ feature 'Groups', js: true do
page.should have_content group.name
end
it "renders enterprise modals for groups" do
visit groups_path
page.should have_content group.name
it "searches by URL" do
visit groups_path(anchor: "/?query=xyzzy")
expect(page).to have_content "No groups found"
end
end

View File

@@ -27,45 +27,54 @@ feature %q{
producer1.set_producer_property 'Local', 'Victoria'
producer2.set_producer_property 'Fair Trade', 'FT123'
visit producers_path
end
it "filters by taxon" do
toggle_filters
toggle_filter 'Vegetables'
page.should_not have_content producer1.name
page.should have_content producer2.name
toggle_filter 'Vegetables'
toggle_filter 'Fruit'
page.should have_content producer1.name
page.should_not have_content producer2.name
it "searches by URL" do
visit producers_path(anchor: "/?query=xyzzy")
expect(page).to have_content "Sorry, no results found for xyzzy"
end
it "shows all producers with expandable details" do
page.should have_content producer1.name
expand_active_table_node producer1.name
context "on the producers page" do
before do
visit producers_path
end
# -- Taxons
page.should have_content 'Fruit'
it "filters by taxon" do
toggle_filters
# -- Properties
page.should have_content 'Organic' # Product property
page.should have_content 'Local' # Producer property
end
toggle_filter 'Vegetables'
it "doesn't show invisible producers" do
page.should_not have_content invisible_producer.name
end
page.should_not have_content producer1.name
page.should have_content producer2.name
it "links to places to buy produce" do
expand_active_table_node producer1.name
page.should have_link shop.name
toggle_filter 'Vegetables'
toggle_filter 'Fruit'
page.should have_content producer1.name
page.should_not have_content producer2.name
end
it "shows all producers with expandable details" do
page.should have_content producer1.name
expand_active_table_node producer1.name
# -- Taxons
page.should have_content 'Fruit'
# -- Properties
page.should have_content 'Organic' # Product property
page.should have_content 'Local' # Producer property
end
it "doesn't show invisible producers" do
page.should_not have_content invisible_producer.name
end
it "links to places to buy produce" do
expand_active_table_node producer1.name
page.should have_link shop.name
end
end

View File

@@ -14,56 +14,70 @@ feature 'Shops', js: true do
before do
producer.set_producer_property 'Organic', 'NASAA 12345'
visit shops_path
end
it "shows hubs" do
page.should have_content distributor.name
expand_active_table_node distributor.name
page.should have_content "OUR PRODUCERS"
it "searches by URL" do
visit shops_path(anchor: "/?query=xyzzy")
expect(page).to have_content "Sorry, no results found for xyzzy"
end
it "does not show invisible hubs" do
page.should_not have_content invisible_distributor.name
end
it "should not show hubs that are not in an order cycle" do
create(:simple_product, distributors: [d1, d2])
visit shops_path
page.should have_no_selector 'hub.inactive'
page.should have_no_selector 'hub', text: d2.name
end
context "on the shops path" do
before do
visit shops_path
end
it "should show closed shops after clicking the button" do
create(:simple_product, distributors: [d1, d2])
visit shops_path
click_link_and_ensure("Show closed shops", -> { page.has_selector? 'hub.inactive' })
page.should have_selector 'hub.inactive', text: d2.name
end
it "should link to the hub page" do
follow_active_table_node distributor.name
expect(page).to have_current_path enterprise_shop_path(distributor)
end
describe "hub producer modal" do
let!(:product) { create(:simple_product, supplier: producer, taxons: [taxon]) }
let!(:taxon) { create(:taxon, name: 'Fruit') }
let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) }
it "should show hub producer modals" do
it "shows hubs" do
page.should have_content distributor.name
expand_active_table_node distributor.name
expect(page).to have_content producer.name
open_enterprise_modal producer
modal_should_be_open_for producer
page.should have_content "OUR PRODUCERS"
end
within ".reveal-modal" do
expect(page).to have_content 'Fruit' # Taxon
expect(page).to have_content 'Organic' # Producer property
it "does not show invisible hubs" do
page.should_not have_content invisible_distributor.name
end
it "should not show hubs that are not in an order cycle" do
create(:simple_product, distributors: [d1, d2])
visit shops_path
page.should have_no_selector 'hub.inactive'
page.should have_no_selector 'hub', text: d2.name
end
it "should show closed shops after clicking the button" do
create(:simple_product, distributors: [d1, d2])
visit shops_path
click_link_and_ensure("Show closed shops", -> { page.has_selector? 'hub.inactive' })
page.should have_selector 'hub.inactive', text: d2.name
end
it "should link to the hub page" do
follow_active_table_node distributor.name
expect(page).to have_current_path enterprise_shop_path(distributor)
end
describe "hub producer modal" do
let!(:product) { create(:simple_product, supplier: producer, taxons: [taxon]) }
let!(:taxon) { create(:taxon, name: 'Fruit') }
let!(:order_cycle) { create(:simple_order_cycle, distributors: [distributor], coordinator: create(:distributor_enterprise), variants: [product.variants.first]) }
it "should show hub producer modals" do
expand_active_table_node distributor.name
expect(page).to have_content producer.name
open_enterprise_modal producer
modal_should_be_open_for producer
within ".reveal-modal" do
expect(page).to have_content 'Fruit' # Taxon
expect(page).to have_content 'Organic' # Producer property
end
end
end
end
private
def click_link_and_ensure(link_text, check)
# Buttons appear to be unresponsive for a while, so keep clicking them until content appears
using_wait_time 0.5 do

View File

@@ -93,5 +93,24 @@ module OpenFoodNetwork
end
end
end
describe "columns are aligned" do
let(:d1) { create(:distributor_enterprise) }
let(:oc1) { create(:simple_order_cycle) }
let(:o1) { create(:order, completed_at: 1.day.ago, order_cycle: oc1, distributor: d1) }
let(:li1) { build(:line_item) }
let(:user) { create(:admin_user)}
before { o1.line_items << li1 }
it 'has aligned columsn' do
report_types = ["", "order_cycle_supplier_totals", "order_cycle_supplier_totals_by_distributor", "order_cycle_distributor_totals_by_supplier", "order_cycle_customer_totals"]
report_types.each do |report_type|
report = OrdersAndFulfillmentsReport.new user, report_type: report_type
report.header.size.should == report.columns.size
end
end
end
end
end