-
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into uk/trial-length
Conflicts: config/locales/en.yml
- Loading branch information
Showing
32 changed files
with
320 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 5 additions & 1 deletion
6
app/assets/javascripts/darkswarm/controllers/groups_controller.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
12 changes: 9 additions & 3 deletions
12
app/assets/javascripts/darkswarm/directives/enterprise_modal.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
Darkswarm.directive "enterpriseModal", ($modal)-> | ||
Darkswarm.directive "enterpriseModal", ($modal, Enterprises, EnterpriseResource) -> | ||
restrict: 'E' | ||
replace: true | ||
template: "<a ng-transclude></a>" | ||
transclude: true | ||
link: (scope, elem, attrs, ctrl)-> | ||
elem.on "click", (ev)=> | ||
link: (scope, elem, attrs, ctrl) -> | ||
elem.on "click", (ev) => | ||
ev.stopPropagation() | ||
params = | ||
id: scope.enterprise.id | ||
EnterpriseResource.relatives params, (data) => | ||
Enterprises.addEnterprises data | ||
scope.enterprise = Enterprises.enterprises_by_id[scope.enterprise.id] | ||
Enterprises.dereferenceEnterprise scope.enterprise | ||
scope.modalInstance = $modal.open(controller: ctrl, templateUrl: 'enterprise_modal.html', scope: scope) |
21 changes: 21 additions & 0 deletions
21
app/assets/javascripts/darkswarm/directives/map_osm_tiles.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
82 changes: 45 additions & 37 deletions
82
app/assets/javascripts/darkswarm/directives/map_search.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
input = (document.getElementById("pac-input")) | ||
map.controls[google.maps.ControlPosition.TOP_LEFT].push input | ||
searchBox = new google.maps.places.SearchBox((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 | ||
|
||
# Bias the SearchBox results towards places that are within the bounds of the | ||
# current map's viewport. | ||
searchBox = scope.createSearchBox map | ||
scope.bindSearchResponse map, searchBox | ||
scope.biasResults map, searchBox | ||
scope.performUrlSearch map | ||
|
||
scope.createSearchBox = (map) -> | ||
map.controls[google.maps.ControlPosition.TOP_LEFT].push scope.input | ||
return new google.maps.places.SearchBox(scope.input) | ||
|
||
scope.bindSearchResponse = (map, searchBox) -> | ||
google.maps.event.addListener searchBox, "places_changed", => | ||
scope.showSearchResult map, searchBox | ||
|
||
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 | ||
|
6 changes: 3 additions & 3 deletions
6
app/assets/javascripts/darkswarm/filters/filter_products.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Darkswarm.filter 'products', (Matcher)-> | ||
(products, text)-> | ||
Darkswarm.filter 'products', (Matcher) -> | ||
(products, text) -> | ||
products ||= [] | ||
text ?= "" | ||
products.filter (product)=> | ||
products.filter (product) => | ||
propertiesToMatch = [product.name, product.supplier.name, product.primary_taxon.name] | ||
Matcher.match propertiesToMatch, text |
19 changes: 15 additions & 4 deletions
19
app/assets/javascripts/darkswarm/services/dereferencer.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
Darkswarm.factory 'Dereferencer', -> | ||
new class Dereferencer | ||
dereference: (array, data)-> | ||
if array | ||
for object, i in array | ||
array[i] = data[object.id] | ||
dereference: (array, data) -> | ||
@dereference_from(array, array, data) | ||
|
||
dereference_from: (source, target, data) -> | ||
unreferenced = [] | ||
if source && target | ||
for object, i in source | ||
# skip empty entries in sparse array | ||
continue unless source.hasOwnProperty(i) | ||
key = object?.id | ||
if data.hasOwnProperty(key) | ||
target[i] = data[key] | ||
else | ||
unreferenced[i] = object | ||
unreferenced |
8 changes: 8 additions & 0 deletions
8
app/assets/javascripts/darkswarm/services/enterprise_resource.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Darkswarm.factory 'EnterpriseResource', ($resource) -> | ||
$resource('/enterprise/:id.json', {}, { | ||
'relatives': | ||
method: 'GET' | ||
url: '/enterprises/:id/relatives.json' | ||
isArray: true | ||
cache: true | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.