rails_admin_map_field 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ Rails Admin Map Field
2
+ =====================
3
+
4
+ rails_admin_map_field is a gem that works with sferik's **rails_admin** (https://github.com/keitoaino/rails_admin) to provide an easy to use Google Maps interface for displaying and setting geographic co-ordinates in a model.
5
+
6
+ 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.
7
+
8
+ Usage
9
+ =====
10
+
11
+ rails_admin_map_field expects that the model will have two attributes, one for latitude and one for longitude of the point represented. To enable rails_admin_map_field, add the following to your `Gemfile`:
12
+
13
+ ```ruby
14
+ gem 'rails_admin_map_field', git: 'git://github.com/keitoaino/rails_admin_map_field.git'
15
+ ```
16
+
17
+ Then, add in your `config/initializers/rails_admin.rb` initializer:
18
+
19
+ ```ruby
20
+ RailsAdmin.config do |config|
21
+ config.model User do
22
+ edit do
23
+ field :latitude, :map
24
+ end
25
+ end
26
+ end
27
+ ```
28
+
29
+ **Note**: The field which is set as a map-type field must be the latitude field, not the longitude. By default, rails_admin_map_field will guess that the longitude field is called "longitude".
30
+
31
+ Configuration
32
+ =============
33
+
34
+ For different configurations, rails_admin_map_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.
38
+ - `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.
39
+ - `default_longitude` - the longitude used if the longitude field is blank. Defaults to -0.126, the longitude of London, UK.
40
+
41
+ A more complicated configuration example:
42
+
43
+ ```ruby
44
+ RailsAdmin.config do |config|
45
+ config.model Point do
46
+ edit do
47
+ field :lat, :map do
48
+ longitude_field :lon
49
+ google_api_key "a1b2c3d4e5f6deadbeef"
50
+ default_latitude -34.0 # Sydney, Australia
51
+ default_longitude 151.0
52
+ end
53
+ end
54
+ end
55
+ end
56
+ ```
57
+
58
+ LICENSE
59
+ =======
60
+ rails_admin_map_field is licensed under the MIT license.
61
+
62
+ Copyright (C) 2011 by Jason Langenauer
63
+
64
+ Permission is hereby granted, free of charge, to any person obtaining a copy
65
+ of this software and associated documentation files (the "Software"), to deal
66
+ in the Software without restriction, including without limitation the rights
67
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
68
+ copies of the Software, and to permit persons to whom the Software is
69
+ furnished to do so, subject to the following conditions:
70
+
71
+ The above copyright notice and this permission notice shall be included in
72
+ all copies or substantial portions of the Software.
73
+
74
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
75
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
76
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
77
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
78
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
79
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
80
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ address = document.getElementById window.address
2
+ lat = document.getElementById window.lat
3
+ lng = document.getElementById window.lng
4
+
5
+ geocoder = new google.maps.Geocoder()
6
+ marker = null
7
+
8
+ mapOptions = {
9
+ zoom: 8,
10
+ mapTypeId: google.maps.MapTypeId.ROADMAP
11
+ }
12
+
13
+ map_element = document.getElementById 'map'
14
+ map = new google.maps.Map map_element, mapOptions
15
+
16
+ google.maps.event.addListener map, 'click', (event) ->
17
+ updateLocation event.latLng
18
+
19
+ updateLocation = (location, center) ->
20
+ if marker
21
+ marker.setPosition location
22
+ else
23
+ marker = new google.maps.Marker
24
+ position: location,
25
+ map: map
26
+
27
+ lat.value = location.lat()
28
+ lng.value = location.lng()
29
+
30
+ if center
31
+ map.setCenter location
32
+
33
+ setInterval ->
34
+ google.maps.event.trigger map, 'resize'
35
+ , 100
36
+
37
+ address.addEventListener 'keyup', ->
38
+ geocoder.geocode {address: this.value}, (results, status) ->
39
+ if status == google.maps.GeocoderStatus.OK
40
+ updateLocation results[0].geometry.location, true
41
+
42
+
43
+ updateLocation new google.maps.LatLng(lat.value, lng.value), true
@@ -0,0 +1,3 @@
1
+ #map
2
+ width: 500px
3
+ height: 300px
@@ -0,0 +1,13 @@
1
+ = form.send :text_field, field.address_field, id: field.address_dom_name
2
+ #map
3
+ = form.send :hidden, field.lat_field, id: field.lat_dom_name
4
+ = form.send :hidden, field.lng_field, id: field.lng_dom_name
5
+
6
+ javascript:
7
+ window.address = "#{field.address_dom_name}";
8
+ window.lat = "#{field.lat_dom_name}";
9
+ window.lng = "#{field.lng_dom_name}";
10
+
11
+ = javascript_include_tag 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false'
12
+ = javascript_include_tag 'map'
13
+ = stylesheet_link_tag 'map'
data/gem.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: UTF-8
2
+
3
+ Gem::Specification.new do |s|
4
+ s.add_development_dependency('devise', '>= 1.1')
5
+ s.add_development_dependency('rspec-rails', '>= 2.4')
6
+ s.add_development_dependency('yard', '>= 0.6')
7
+ s.add_development_dependency('sqlite3')
8
+ s.add_development_dependency('gmaps4rails')
9
+
10
+ # If you add a runtime dependency, please maintain alphabetical order
11
+ s.add_runtime_dependency('rails', '>= 3.0.0')
12
+
13
+ # TODO: uncomment next line when rails_admin gem will be released
14
+ # s.add_runtime_dependency('rails_admin', '> 0.0.1')
15
+
16
+
17
+ s.name = "rails_admin_map_field"
18
+ s.version = "0.0.1"
19
+ s.platform = Gem::Platform::RUBY
20
+ s.authors = ["Keito Aino"]
21
+ s.email = ["keitoaino@gmail.com"]
22
+ s.homepage = "http://github.com/keitoaino/"
23
+ s.summary = "Adds a map field using the Google Maps API to rails_admin"
24
+ s.description = "A map field for RailsAdmin that can be used to manipulate a latitude/longitude field pair"
25
+ s.rubyforge_project = s.name
26
+
27
+ s.required_rubygems_version = ">= 1.3.6"
28
+
29
+ s.files = `git ls-files`.split("\n")
30
+ s.require_path = 'lib'
31
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails'
2
+ require 'rails_admin_map_field'
3
+
4
+ module RailsAdminMapField
5
+ class Engine < Rails::Engine
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ module RailsAdmin::Config::Fields::Types
2
+ class Map < RailsAdmin::Config::Fields::Base
3
+ RailsAdmin::Config::Fields::Types::register(:map, self)
4
+
5
+ def allowed_methods
6
+ [@name, address_field, lat_field, lng_field]
7
+ end
8
+
9
+ register_instance_option :address_field do
10
+ :address
11
+ end
12
+
13
+ register_instance_option :lat_field do
14
+ :lat
15
+ end
16
+
17
+ register_instance_option :lng_field do
18
+ :lng
19
+ end
20
+
21
+
22
+ register_instance_option(:partial) do
23
+ :form_map
24
+ end
25
+
26
+ register_instance_option(:google_api_key) do
27
+ nil
28
+ end
29
+
30
+ def address_dom_name
31
+ @dom_name ||= "#{bindings[:form].object_name}_#{address_field}"
32
+ end
33
+
34
+ def lat_dom_name
35
+ @lat_dom_name ||= "#{bindings[:form].object_name}_#{lat_field}"
36
+ end
37
+
38
+ def lng_dom_name
39
+ @lng_dom_name ||= "#{bindings[:form].object_name}_#{lng_field}"
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails_admin'
2
+ require 'rails_admin_map_field/rails_admin/config/fields/types/map'
3
+ load 'rails_admin_map_field/engine.rb'
4
+
5
+ # load 'rails_admin_map_field/factory.rb'
6
+
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_admin_map_field
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Keito Aino
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: devise
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '1.1'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '2.4'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '2.4'
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0.6'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0.6'
62
+ - !ruby/object:Gem::Dependency
63
+ name: sqlite3
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: gmaps4rails
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rails
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 3.0.0
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 3.0.0
110
+ description: A map field for RailsAdmin that can be used to manipulate a latitude/longitude
111
+ field pair
112
+ email:
113
+ - keitoaino@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - README.md
119
+ - app/assets/javascript/map.coffee
120
+ - app/assets/stylesheets/map.css.sass
121
+ - app/views/rails_admin/main/_form_map.html.slim
122
+ - gem.gemspec
123
+ - lib/rails_admin_map_field.rb
124
+ - lib/rails_admin_map_field/engine.rb
125
+ - lib/rails_admin_map_field/rails_admin/config/fields/types/map.rb
126
+ homepage: http://github.com/keitoaino/
127
+ licenses: []
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ! '>='
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ! '>='
142
+ - !ruby/object:Gem::Version
143
+ version: 1.3.6
144
+ requirements: []
145
+ rubyforge_project: rails_admin_map_field
146
+ rubygems_version: 1.8.25
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: Adds a map field using the Google Maps API to rails_admin
150
+ test_files: []