rails_admin_place_field 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f43dc0c284e2982ee9d6a4ad25f28f543af39d9
|
4
|
+
data.tar.gz: 19b3dc88b7bf3473cf9178af8012f89b245b4ed6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 352c1570bbf58f106b6b5d72125e57e3612df581f3b696758e101ac7899f7d3f29f5a2a3f1ffb4c4045bc4b1df8e67561be6d7548bb34e4109f2515ae4f285a0
|
7
|
+
data.tar.gz: 0e00a819ac8395d726f672cbf2faf67db92d12bf639b8686b33caf299168e1f144a18a3ed9dbd3e0b5de32555b6f006eefdd3a19c260fc9e8fe19b509c0db53d
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Rails Admin Place Field
|
2
|
+
|
3
|
+
rails_admin_place_field is a gem that works with [rails_admin](https://github.com/sferik/rails_admin) to provide an easy to use Google Maps interface for displaying and setting geographic co-ordinates in a model and then performing lookups for associations to a nearby Google Place or Foursquare Venue
|
4
|
+
|
5
|
+
Where a latitude and longitude is set on the model, it is indicated by a marker shown on a Google map centered at the marker. The administrator can change the value of these fields by clicking on the desired new location on the map.
|
6
|
+
|
7
|
+
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
rails_admin_place_field expects that the model will have two attributes, one for latitude and one for longitude of the point represented. To enable rails_admin_place_field, add the following to your `Gemfile`:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem "rails_admin_place_field", :git => "git://github.com/thinkclay/rails_admin_place_field.git"
|
14
|
+
```
|
15
|
+
|
16
|
+
Then, add in your `config/initializers/rails_admin.rb` initializer:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
RailsAdmin.config do |config|
|
20
|
+
config.model Place do
|
21
|
+
edit do
|
22
|
+
field :latitude, :place
|
23
|
+
field :longitude, :hidden
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
**Note**: The field which is set as a :place field must be the latitude field, not the longitude.
|
30
|
+
|
31
|
+
|
32
|
+
## Configuration
|
33
|
+
|
34
|
+
For different configurations, rails_admin_place_field can be configured with the following:
|
35
|
+
|
36
|
+
- `longitude_field` - the name of the longitude field that forms the the co-ordinate with the latitude field specified. Defaults to "longitude"
|
37
|
+
- `google_api_key` - if you use a Google Maps API Key, it can be specified here, otherwise the maps will do limited lookups without a key
|
38
|
+
- `foursquare_api_key` - this api will be disabled until a valid key is provided
|
39
|
+
- `places_api_key` - this api will be disabled until a valid key is provided
|
40
|
+
- `default_latitude` - the latitude to center the map shown on if the latitude field is blank. Defaults to 51.5, the latitude of London, UK.
|
41
|
+
- `default_longitude` - the longitude used if the longitude field is blank. Defaults to -0.126, the longitude of London, UK.
|
42
|
+
|
43
|
+
A more complicated configuration example:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
RailsAdmin.config do |config|
|
47
|
+
config.model Place do
|
48
|
+
edit do
|
49
|
+
field :latitude, :place do
|
50
|
+
longitude_field :longitude
|
51
|
+
google_api_key "a1b2c3d4e5f6deadbeef"
|
52
|
+
places_api_key "a1b2c3d4e5f6deadbeef"
|
53
|
+
foursquare_api_key "a1b2c3d4e5f6deadbeef"
|
54
|
+
default_latitude -34.0
|
55
|
+
default_longitude 151.0
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
-------
|
63
|
+
rails_admin_place_field is licensed under the MIT license.
|
64
|
+
|
65
|
+
Kudos and credit to [beyondthestory](https://github.com/beyondthestory/rails_admin_map_field) for his map_field which gave me the starting point to learn how to make this field
|
@@ -0,0 +1,88 @@
|
|
1
|
+
= javascript_include_tag ("//maps.googleapis.com/maps/api/js?key=#{field.google_api_key}&sensor=false&callback=init_map_field")
|
2
|
+
|
3
|
+
= javascript_tag do
|
4
|
+
:plain
|
5
|
+
function init_map_field()
|
6
|
+
{
|
7
|
+
jQuery(function() {
|
8
|
+
var marker = null;
|
9
|
+
var latlng = new google.maps.LatLng(
|
10
|
+
#{form.object.send(field.name) || field.default_latitude},
|
11
|
+
#{form.object.send(field.longitude_field) || field.default_longitude}
|
12
|
+
);
|
13
|
+
|
14
|
+
var myOptions = {
|
15
|
+
zoom: #{field.default_zoom_level},
|
16
|
+
center: latlng,
|
17
|
+
mapTypeId: google.maps.MapTypeId.ROADMAP
|
18
|
+
};
|
19
|
+
|
20
|
+
var map = new google.maps.Map(document.getElementById("#{field.dom_name}"), myOptions);
|
21
|
+
|
22
|
+
- if form.object.send(field.name) && form.object.send(field.longitude_field)
|
23
|
+
:plain
|
24
|
+
marker = new google.maps.Marker({
|
25
|
+
position: new google.maps.LatLng(#{form.object.send(field.name)},#{form.object.send(field.longitude_field)}),
|
26
|
+
map: map
|
27
|
+
});
|
28
|
+
|
29
|
+
:plain
|
30
|
+
google.maps.event.addListener(map, 'click', function(e) {
|
31
|
+
map_update(e.latLng);
|
32
|
+
foursquare_search(e.latLng.lat() + ',' + e.latLng.lng());
|
33
|
+
});
|
34
|
+
|
35
|
+
function map_update(location)
|
36
|
+
{
|
37
|
+
if (marker)
|
38
|
+
{
|
39
|
+
marker.setPosition(location);
|
40
|
+
}
|
41
|
+
else
|
42
|
+
{
|
43
|
+
marker = new google.maps.Marker({
|
44
|
+
position: location,
|
45
|
+
map: map
|
46
|
+
});
|
47
|
+
}
|
48
|
+
|
49
|
+
map.setCenter(location);
|
50
|
+
jQuery("##{field.latitude_dom_name}").val(location.lat());
|
51
|
+
jQuery("##{field.longitude_dom_name}").val(location.lng());
|
52
|
+
}
|
53
|
+
|
54
|
+
function foursquare_search(location)
|
55
|
+
{
|
56
|
+
var foursquare_url = 'https://api.foursquare.com/v2/venues/search?ll='+ location + '&intent=checkin'
|
57
|
+
+ '&client_id=' + "#{field.foursquare_api_key}"
|
58
|
+
+ '&client_secret=' + "#{field.foursquare_api_secret}"
|
59
|
+
+ '&v=' + "#{Time.new.strftime("%Y%m%d")}";
|
60
|
+
|
61
|
+
$.get(
|
62
|
+
foursquare_url,
|
63
|
+
function(response) {
|
64
|
+
if ( response && response.meta.code == 200 )
|
65
|
+
{
|
66
|
+
response.response.venues.forEach(function(venue) {
|
67
|
+
jQuery('#foursquare_venue').append('<option value="'+venue.id+'">'+venue.name+'</option>').change(function() {
|
68
|
+
jQuery("##{field.foursquare_dom_name}").val($(this).val());
|
69
|
+
});
|
70
|
+
});
|
71
|
+
}
|
72
|
+
else
|
73
|
+
{
|
74
|
+
alert('foursquare venue lookup failed');
|
75
|
+
}
|
76
|
+
});
|
77
|
+
}
|
78
|
+
|
79
|
+
})};
|
80
|
+
|
81
|
+
|
82
|
+
%div.ramf-map-container{:id => field.dom_name, :style => "width:300px;height:200px"}
|
83
|
+
%select#foursquare_venue
|
84
|
+
%option
|
85
|
+
|
86
|
+
= form.send :hidden_field, field.foursquare_field, :id => field.foursquare_dom_name
|
87
|
+
= form.send :hidden_field, field.name, :id => field.latitude_dom_name
|
88
|
+
= form.send :hidden_field, field.longitude_field, :id => field.longitude_dom_name
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module RailsAdmin::Config::Fields::Types
|
2
|
+
class Place < RailsAdmin::Config::Fields::Base
|
3
|
+
|
4
|
+
RailsAdmin::Config::Fields::Types::register(:place, self)
|
5
|
+
|
6
|
+
def allowed_methods
|
7
|
+
[@name, longitude_field, foursquare_field]
|
8
|
+
end
|
9
|
+
|
10
|
+
# THe name of the corresponding longitude field to match the latitude field
|
11
|
+
# in this object.
|
12
|
+
register_instance_option(:longitude_field) do
|
13
|
+
:longitude
|
14
|
+
end
|
15
|
+
|
16
|
+
register_instance_option(:foursquare_field) do
|
17
|
+
:foursquare
|
18
|
+
end
|
19
|
+
|
20
|
+
register_instance_option(:partial) do
|
21
|
+
:place_select
|
22
|
+
end
|
23
|
+
|
24
|
+
register_instance_option(:google_api_key) do
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
register_instance_option(:places_api_key) do
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
register_instance_option(:foursquare_api_key) do
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
register_instance_option(:foursquare_api_secret) do
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
# Latitude value to display in the map if the latitude attribute is nil
|
41
|
+
# (Otherwise the location defaults to (0,0) which is in the Gulf of Guinea
|
42
|
+
register_instance_option(:default_latitude) do
|
43
|
+
51.5 # Latitude of London, United Kingdom
|
44
|
+
end
|
45
|
+
|
46
|
+
# Longitude value to display if the longitude attribute is nil
|
47
|
+
register_instance_option(:default_longitude) do
|
48
|
+
-0.126 # Longitude of London, United Kingdom
|
49
|
+
end
|
50
|
+
|
51
|
+
# Default zoom level of the map
|
52
|
+
register_instance_option(:default_zoom_level) do
|
53
|
+
8
|
54
|
+
end
|
55
|
+
|
56
|
+
def dom_name
|
57
|
+
@dom_name ||= "#{bindings[:form].object_name}_#{@name}_#{longitude_field}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def latitude_dom_name
|
61
|
+
@lat_dom_name ||= "#{bindings[:form].object_name}_#{@name}"
|
62
|
+
end
|
63
|
+
|
64
|
+
def longitude_dom_name
|
65
|
+
@lon_dom_name ||= "#{bindings[:form].object_name}_#{longitude_field}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def foursquare_dom_name
|
69
|
+
@foursquare_dom_name ||= "#{bindings[:form].object_name}_#{foursquare_field}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails_admin_place_field
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Clay McIlrath
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.4'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails_admin
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>'
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>'
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.1
|
55
|
+
description: A place field for RailsAdmin that can be used to retrieve a google place
|
56
|
+
or foursquare venue
|
57
|
+
email:
|
58
|
+
- clay.mcilrath@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- lib/rails_admin_place_field/engine.rb
|
64
|
+
- lib/rails_admin_place_field/rails_admin/config/fields/types/place.rb
|
65
|
+
- lib/rails_admin_place_field.rb
|
66
|
+
- app/views/rails_admin/main/_place_select.html.haml
|
67
|
+
- README.md
|
68
|
+
homepage: http://github.com/thinkclay/
|
69
|
+
licenses: []
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 1.3.6
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project: rails_admin_place_field
|
87
|
+
rubygems_version: 2.0.3
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Adds a place field to rails_admin using the Google Places and Foursquare
|
91
|
+
API's
|
92
|
+
test_files: []
|