administrate-field-address_lat_lng 1.0.0

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
+ SHA256:
3
+ metadata.gz: de82683d7b68f2a17d83c7655c12d0b55e1a9e90c2e22af8f71fcb54dcbb3b2d
4
+ data.tar.gz: eaf3fb24d8441391ecd32ba88645ff5637d588881d4904bcf8a4267851082b18
5
+ SHA512:
6
+ metadata.gz: d22f8e1648e0d118c89aa44cb93d5d759e32d4b7f32f69e652b5877b379669ac9c64888d7dcefc0b80eb482780345565fdb0ac09ad2959db926f6e2ba649618f
7
+ data.tar.gz: 337417f28b70c86bd1adc0262fea3508f638def73e228d83624bcf9a9df93ae6364419239cf83db531907b91c78da804825c74c0a997ed063f8bd740e069b49f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.4.1
4
+ - 2.3.4
5
+ - 2.2.7
6
+ before_install: gem install bundler -v 1.15.0
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at rich@fishpercolator.co.uk. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in administrate-field-select.gemspec
4
+ gemspec
5
+
6
+ # Specify greater versions than in the gemspec for travis's benefit
7
+ gem 'rails', '>= 5.0'
8
+ gem 'administrate', '>= 0.7'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Rich Daley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Administrate::Field::AddressLatLng
2
+
3
+ Adds fields for displaying/editing latitude/longitude fields on a map to ThoughtBot's [Administrate](https://github.com/thoughtbot/administrate)
4
+
5
+ [![Gem Version](https://img.shields.io/gem/v/administrate-field-address_lat_lng.svg?style=flat)](https://rubygems.org/gems/administrate-field-address_lat_lng)
6
+ [![Build Status](https://img.shields.io/travis/fishpercolator/administrate-field-address_lat_lng/master.svg?style=flat)](https://travis-ci.org/fishpercolator/administrate-field-address_lat_lng)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'administrate-field-address_lat_lng'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ## Usage
21
+
22
+ In your dashboard's `ATRRIBUTE_TYPES`, use the type `Field::AddressLatLng` with options:
23
+
24
+ ```ruby
25
+ ATTRIBUTE_TYPES = {
26
+ lat: Field::AddressLatLng,
27
+ lng: Field::AddressLatLng,
28
+ }
29
+ ```
30
+
31
+ On show pages, you will now see a map directly below the `lng` field, which shows the location on a map. On edit pages, you can click this map to change the values of `lat` and `lng` in the form.
32
+
33
+ **Important**: Your `lat` and `lng` fields must appear in the right order (`lat` first) in `SHOW_PAGE_ATTRIBUTES` and `FORM_ATTRIBUTES`. This is because each field generates a piece of the final javascript so they must be evaluated in the correct order.
34
+
35
+ If your fields are not called `lat` and `lng`, you must specify options to make it clear which is which, e.g.:
36
+
37
+ ```ruby
38
+ ATTRIBUTE_TYPES = {
39
+ latitude: Field::AddressLatLng.with_options({lat: true}),
40
+ longitude: Field::AddressLatLng.with_options({lng: true}),
41
+ }
42
+ ```
43
+
44
+ Additional options that are available:
45
+
46
+ * `initial`: Set to an array like `[53.8003,-1.5519]`. Will cause the center of the map to be this point if the lat/lng have not yet been set (e.g. for new records). Defaults to Leeds, UK (because that's where the author is from).
47
+ * `zoom`: Set the default zoom level for maps drawn (defaults to 11).
48
+ * `search`: `true` (default) or `false`. Enable location search. Requires `google_api_key` option too.
49
+ * `google_api_key`: A [key for the Google Maps JavaScript API](https://developers.google.com/maps/documentation/javascript/get-api-key). Required for location search to work.
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/fishpercolator/administrate-field-address_lat_lng. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "administrate-field-address_lat_lng"
7
+ spec.version = "1.0.0"
8
+ spec.authors = ["Rassas Achref"]
9
+ spec.email = ["rassasachref@gmail.com"]
10
+
11
+ spec.summary = %q{Administrate field for address/latitude/longitude}
12
+ spec.description = %q{Adds an Administrate::Field::AddressLatLng for viewing & editing Address/latitude/longitude fields on a map}
13
+ spec.homepage = "https://github.com/rassas/administrate-field-address_lat_lng"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'administrate', '>= 0.3', '<= 0.16'
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.11"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "pry", "~> 0.10.3"
26
+ spec.add_development_dependency "erubis", "~> 2.7"
27
+ end
@@ -0,0 +1,8 @@
1
+ .map-container {
2
+ clear: both;
3
+ width: 100%;
4
+ }
5
+ #addresslatlngmap {
6
+ width: 100%;
7
+ height: 400px;
8
+ }
@@ -0,0 +1,12 @@
1
+ <% if field.which == :address %>
2
+ <div class="field-unit__label">
3
+ <%= f.label field.attribute %>
4
+ </div>
5
+ <div class="field-unit__field">
6
+ <%= f.text_field field.attribute, class: "addresslatlng-#{field.which}" %>
7
+ </div>
8
+ <% else %>
9
+ <%= f.hidden_field field.attribute, class: "addresslatlng-#{field.which}" %>
10
+ <% end %>
11
+ <%= render 'fields/address_lat_lng/var', field: field if field.which != :address %>
12
+ <%= render 'fields/address_lat_lng/map', edit: true, field: field if field.lng? %>
@@ -0,0 +1 @@
1
+ <%= field.to_s %>
@@ -0,0 +1,101 @@
1
+ <div class="map-container">
2
+ <div id="addresslatlngmap"></div>
3
+ </div>
4
+ <% content_for :javascript do %>
5
+ <%= content_tag(:script, '', src: "https://maps.googleapis.com/maps/api/js?key=#{field.google_api_key}&libraries=places") %>
6
+ <script type="text/javascript">
7
+ // Get the centre lat/lng from the field or the initial default if the field
8
+ // hasn't been set yet
9
+ if (lng === undefined) {
10
+ var initLatLng = new google.maps.LatLng(<%= field.initial.to_json %>[0], <%= field.initial.to_json %>[1]);
11
+ } else {
12
+ var initLatLng = new google.maps.LatLng(lat, lng)
13
+ }
14
+
15
+ // Attach a google map to the div above
16
+ var map = new google.maps.Map(
17
+ document.querySelector("#addresslatlngmap"),
18
+ {
19
+ center: initLatLng,
20
+ zoom: <%= field.zoom %>
21
+ }
22
+ );
23
+
24
+ var createMarker = function(latlng) {
25
+ marker = new google.maps.Marker({
26
+ position: latlng,
27
+ map: map
28
+ });
29
+ };
30
+
31
+ var setMarker = function (latlng) {
32
+ if (marker === undefined) {
33
+ createMarker(latlng);
34
+ } else {
35
+ marker.setMap(null);
36
+ createMarker(latlng);
37
+ }
38
+ $('.addresslatlng-lat').val(latlng.lat);
39
+ $('.addresslatlng-lng').val(latlng.lng);
40
+ <% if field.search? %>
41
+ setAddressFromLatLng(latlng, ".addresslatlng-address");
42
+ <% end %>
43
+ };
44
+
45
+ var setAddressFromLatLng = function (latlng, inputAddressSelector) {
46
+ var geocoder = new google.maps.Geocoder();
47
+ geocoder.geocode({
48
+ 'location': latlng
49
+ }, function (results, status) {
50
+ if (status === google.maps.GeocoderStatus.OK) {
51
+ if (results[1]) {
52
+ address = results[0].formatted_address;
53
+ $(inputAddressSelector).val(address)
54
+ }
55
+ }
56
+ });
57
+ }
58
+
59
+ // Add a marker if the field has been set already
60
+ var marker;
61
+ if (lng !== undefined) {
62
+ createMarker(initLatLng);
63
+ }
64
+ <% if edit %>
65
+ // In edit mode, move the marker and update the fields when a user clicks
66
+ // inside the map
67
+ map.addListener('click', function (event) {
68
+ setMarker(event.latLng);
69
+ });
70
+ <% end %>
71
+
72
+ <% if field.search? %>
73
+ let autocomplete = new google.maps.places.Autocomplete(
74
+ /** @type {!HTMLInputElement} */
75
+ (document.querySelector(
76
+ ".addresslatlng-address"
77
+ )), {
78
+ types: ["geocode"]
79
+ }
80
+ );
81
+
82
+ autocomplete.addListener('place_changed', function (e) {
83
+ var place = autocomplete.getPlace();
84
+ if (!place.geometry) {
85
+ // User entered the name of a Place that was not suggested and
86
+ // pressed the Enter key, or the Place Details request failed.
87
+ window.alert("No details available for input: '" + place.name + "'");
88
+ return;
89
+ }
90
+
91
+ if (place.geometry.viewport) {
92
+ map.fitBounds(place.geometry.viewport);
93
+ } else {
94
+ map.setCenter(place.geometry.location);
95
+ map.setZoom(17); // Why 17? Because it looks good.
96
+ }
97
+ setMarker(place.geometry.location);
98
+ })
99
+ <% end %>
100
+ </script>
101
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <%= field.to_s %>
2
+ <%= render 'fields/address_lat_lng/var', field: field %>
3
+ <%= render 'fields/address_lat_lng/map', edit: false, field: field if field.lng? %>
@@ -0,0 +1,5 @@
1
+ <% content_for :javascript do %>
2
+ <script type="text/javascript">
3
+ var <%= field.which %> = <%= field.data || 'undefined' %>;
4
+ </script>
5
+ <% end %>
@@ -0,0 +1,63 @@
1
+ require 'administrate/field/base'
2
+ require 'rails'
3
+
4
+ module Administrate
5
+ module Field
6
+ class AddressLatLng < Base
7
+ class Engine < ::Rails::Engine
8
+ initializer 'administrate-field-address_lat_lng.add_assets' do |app|
9
+ if app.config.respond_to? :assets
10
+ app.config.assets.precompile << %w(address_lat_lng.css)
11
+ end
12
+
13
+ if defined?(Administrate::Engine)
14
+ Administrate::Engine.add_stylesheet 'address_lat_lng.css'
15
+ end
16
+ end
17
+ end
18
+
19
+ # True if the :lat option has been provided, or field is called :lat
20
+ def lat?
21
+ options.fetch(:lat, attribute == :lat)
22
+ end
23
+
24
+ # True if the :lng option has been provided, or field is called :lng
25
+ def lng?
26
+ options.fetch(:lng, attribute == :lng)
27
+ end
28
+
29
+ def address?
30
+ options.fetch(:address, attribute == :address)
31
+ end
32
+
33
+ # Return wether or not search should be enabled (defaults to true)
34
+ def search?
35
+ options.fetch(:search, true) && google_api_key.present?
36
+ end
37
+
38
+ # Get Google API Key. How to obtain one: https://developers.google.com/maps/documentation/javascript/get-api-key
39
+ def google_api_key
40
+ options.fetch(:google_api_key, nil)
41
+ end
42
+
43
+ # Returns :lat or :lng depending on which type this is
44
+ def which
45
+ lat? ? :lat : lng? ? :lng : :address
46
+ end
47
+
48
+ # Returns the initial co-ordinates of blank maps (defaults to Leeds, UK)
49
+ def initial
50
+ options.fetch(:initial, [53.8003,-1.5519])
51
+ end
52
+
53
+ # Returns the initial zoom level for maps (defaults to 11)
54
+ def zoom
55
+ options.fetch(:zoom, 11)
56
+ end
57
+
58
+ def to_s
59
+ data
60
+ end
61
+ end
62
+ end
63
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: administrate-field-address_lat_lng
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rassas Achref
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: administrate
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ - - "<="
21
+ - !ruby/object:Gem::Version
22
+ version: '0.16'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.3'
30
+ - - "<="
31
+ - !ruby/object:Gem::Version
32
+ version: '0.16'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.11'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.11'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: pry
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.10.3
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.10.3
89
+ - !ruby/object:Gem::Dependency
90
+ name: erubis
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '2.7'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '2.7'
103
+ description: Adds an Administrate::Field::AddressLatLng for viewing & editing Address/latitude/longitude
104
+ fields on a map
105
+ email:
106
+ - rassasachref@gmail.com
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - ".gitignore"
112
+ - ".rspec"
113
+ - ".travis.yml"
114
+ - CODE_OF_CONDUCT.md
115
+ - Gemfile
116
+ - LICENSE.txt
117
+ - README.md
118
+ - Rakefile
119
+ - administrate-field-address_lat_lng.gemspec
120
+ - app/assets/stylesheets/address_lat_lng.css
121
+ - app/views/fields/address_lat_lng/_form.html.erb
122
+ - app/views/fields/address_lat_lng/_index.html.erb
123
+ - app/views/fields/address_lat_lng/_map.html.erb
124
+ - app/views/fields/address_lat_lng/_show.html.erb
125
+ - app/views/fields/address_lat_lng/_var.html.erb
126
+ - lib/administrate/field/address_lat_lng.rb
127
+ homepage: https://github.com/rassas/administrate-field-address_lat_lng
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubygems_version: 3.1.4
147
+ signing_key:
148
+ specification_version: 4
149
+ summary: Administrate field for address/latitude/longitude
150
+ test_files: []