Skip to content

Commit 5dcece1

Browse files
committed
update files structure
1 parent 4951643 commit 5dcece1

File tree

9 files changed

+151
-133
lines changed

9 files changed

+151
-133
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
activeadmin_latlng (0.3.1)
4+
activeadmin_latlng (1.0.0)
55
activeadmin
66

77
GEM

lib/activeadmin/views/activeadmin_form.rb

Lines changed: 1 addition & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -19,135 +19,5 @@ def latlng **args
1919
end
2020
end
2121
end
22-
23-
class LatlngProxy < FormtasticProxy
24-
def build(_, *args, &_block)
25-
@lang, @id_lat, @id_lng, @height, @loading_map, @api_key = *args
26-
end
27-
end
28-
29-
class GoogleMapProxy < LatlngProxy
30-
def key
31-
@api_key ? "&key=#{@api_key}" : ""
32-
end
33-
34-
def loading_map_code
35-
@loading_map ? "<script src=\"https://maps.googleapis.com/maps/api/js?language=#{@lang}#{key}&callback=googleMapObject.init\" async defer></script>" : ''
36-
end
37-
38-
def to_s
39-
"<li>" \
40-
"#{loading_map_code}" \
41-
"<div id=\"google_map\" style=\"height: #{@height}px\"></div>" \
42-
"<script>
43-
var googleMapObject = {
44-
coords: null,
45-
map: null,
46-
marker: null,
47-
48-
getCoordinates: function() {
49-
return {
50-
lat: parseFloat($(\"##{@id_lat}\").val()) || 55.7522200,
51-
lng: parseFloat($(\"##{@id_lng}\").val()) || 37.6155600,
52-
};
53-
},
54-
55-
saveCoordinates: function() {
56-
$(\"##{@id_lat}\").val( googleMapObject.coords.lat.toFixed(10) );
57-
$(\"##{@id_lng}\").val( googleMapObject.coords.lng.toFixed(10) );
58-
},
59-
60-
init: function() {
61-
googleMapObject.coords = googleMapObject.getCoordinates();
62-
googleMapObject.saveCoordinates();
63-
64-
googleMapObject.map = new google.maps.Map(document.getElementById('google_map'), {
65-
center: googleMapObject.coords,
66-
zoom: 12
67-
});
68-
69-
var latLngCoord = new google.maps.LatLng(googleMapObject.coords.lat, googleMapObject.coords.lng);
70-
googleMapObject.marker = new google.maps.Marker({
71-
position: latLngCoord,
72-
map: googleMapObject.map,
73-
draggable: true
74-
});
75-
googleMapObject.map.addListener('click', function(e) {
76-
googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
77-
googleMapObject.saveCoordinates();
78-
googleMapObject.marker.setPosition(googleMapObject.coords);
79-
});
80-
googleMapObject.marker.addListener('drag', function(e) {
81-
googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
82-
googleMapObject.saveCoordinates();
83-
});
84-
}
85-
}
86-
</script>" \
87-
"</li>"
88-
end
89-
end
90-
91-
class YandexMapProxy < LatlngProxy
92-
def key
93-
@api_key ? "&apikey=#{@api_key}" : ""
94-
end
95-
96-
def loading_map_code
97-
@loading_map ? "<script src=\"https://api-maps.yandex.ru/2.1/?lang=#{@lang}#{key}&load=Map,Placemark\" type=\"text/javascript\"></script>" : ''
98-
end
99-
100-
def to_s
101-
"<li>" \
102-
"#{loading_map_code}" \
103-
"<div id=\"yandex_map\" style=\"height: #{@height}px\"></div>" \
104-
"<script type=\"text/javascript\">
105-
var yandexMapObject = {
106-
coords: null,
107-
map: null,
108-
placemark: null,
109-
110-
getCoordinates: function() {
111-
return [
112-
parseFloat($(\"##{@id_lat}\").val()) || 55.7522200,
113-
parseFloat($(\"##{@id_lng}\").val()) || 37.6155600,
114-
];
115-
},
116-
117-
saveCoordinates: function() {
118-
$(\"##{@id_lat}\").val( yandexMapObject.coords[0].toFixed(10) );
119-
$(\"##{@id_lng}\").val( yandexMapObject.coords[1].toFixed(10) );
120-
},
121-
122-
init: function() {
123-
yandexMapObject.coords = yandexMapObject.getCoordinates();
124-
yandexMapObject.saveCoordinates();
125-
126-
yandexMapObject.map = new ymaps.Map(\"yandex_map\", {
127-
center: yandexMapObject.coords,
128-
zoom: 12
129-
});
130-
131-
yandexMapObject.placemark = new ymaps.Placemark( yandexMapObject.coords, {}, { preset: \"twirl#redIcon\", draggable: true } );
132-
yandexMapObject.map.geoObjects.add(yandexMapObject.placemark);
133-
134-
yandexMapObject.placemark.events.add(\"dragend\", function (e) {
135-
yandexMapObject.coords = this.geometry.getCoordinates();
136-
yandexMapObject.saveCoordinates();
137-
}, yandexMapObject.placemark);
138-
139-
yandexMapObject.map.events.add(\"click\", function (e) {
140-
yandexMapObject.coords = e.get(\"coords\");
141-
yandexMapObject.saveCoordinates();
142-
yandexMapObject.placemark.geometry.setCoordinates(yandexMapObject.coords);
143-
});
144-
}
145-
}
146-
147-
ymaps.ready(yandexMapObject.init);
148-
</script>" \
149-
"</li>"
150-
end
151-
end
15222
end
153-
end
23+
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module ActiveAdmin
2+
module Views
3+
class GoogleMapProxy < LatlngProxy
4+
def key
5+
@api_key ? "&key=#{@api_key}" : ""
6+
end
7+
8+
def loading_map_code
9+
@loading_map ? "<script src=\"https://maps.googleapis.com/maps/api/js?language=#{@lang}#{key}&callback=googleMapObject.init\" async defer></script>" : ''
10+
end
11+
12+
def to_s
13+
File.open(File.expand_path('../templates/google.html', __FILE__)).read % [loading_map_code, @height, @id_lat, @id_lng]
14+
end
15+
end
16+
end
17+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module ActiveAdmin
2+
module Views
3+
class LatlngProxy < FormtasticProxy
4+
def build(_, *args, &_block)
5+
@lang, @id_lat, @id_lng, @height, @loading_map, @api_key = *args
6+
end
7+
end
8+
end
9+
end
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<li>
2+
%s
3+
<div id="google_map" style="height: %spx"></div>
4+
<script>
5+
var googleMapObject = {
6+
idLat: '%s',
7+
idLng: '%s',
8+
coords: null,
9+
map: null,
10+
marker: null,
11+
12+
getCoordinates: function() {
13+
return {
14+
lat: parseFloat($("#" + googleMapObject.idLat).val()) || 55.7522200,
15+
lng: parseFloat($("#" + googleMapObject.idLng).val()) || 37.6155600,
16+
};
17+
},
18+
19+
saveCoordinates: function() {
20+
$("#" + googleMapObject.idLat).val( googleMapObject.coords.lat.toFixed(10) );
21+
$("#" + googleMapObject.idLng).val( googleMapObject.coords.lng.toFixed(10) );
22+
},
23+
24+
init: function() {
25+
googleMapObject.coords = googleMapObject.getCoordinates();
26+
googleMapObject.saveCoordinates();
27+
28+
googleMapObject.map = new google.maps.Map(document.getElementById('google_map'), {
29+
center: googleMapObject.coords,
30+
zoom: 12
31+
});
32+
33+
var latLngCoord = new google.maps.LatLng(googleMapObject.coords.lat, googleMapObject.coords.lng);
34+
googleMapObject.marker = new google.maps.Marker({
35+
position: latLngCoord,
36+
map: googleMapObject.map,
37+
draggable: true
38+
});
39+
googleMapObject.map.addListener('click', function(e) {
40+
googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
41+
googleMapObject.saveCoordinates();
42+
googleMapObject.marker.setPosition(googleMapObject.coords);
43+
});
44+
googleMapObject.marker.addListener('drag', function(e) {
45+
googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
46+
googleMapObject.saveCoordinates();
47+
});
48+
}
49+
}
50+
</script>
51+
</li>
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<li>
2+
%s
3+
<div id="yandex_map" style="height: %spx"></div>
4+
<script>
5+
var yandexMapObject = {
6+
idLat: '%s',
7+
idLng: '%s',
8+
coords: null,
9+
map: null,
10+
placemark: null,
11+
12+
getCoordinates: function() {
13+
return [
14+
parseFloat($("#" + yandexMapObject.idLat).val()) || 55.7522200,
15+
parseFloat($("#" + yandexMapObject.idLng).val()) || 37.6155600,
16+
];
17+
},
18+
19+
saveCoordinates: function() {
20+
$("#" + yandexMapObject.idLat).val( yandexMapObject.coords[0].toFixed(10) );
21+
$("#" + yandexMapObject.idLng).val( yandexMapObject.coords[1].toFixed(10) );
22+
},
23+
24+
init: function() {
25+
yandexMapObject.coords = yandexMapObject.getCoordinates();
26+
yandexMapObject.saveCoordinates();
27+
28+
yandexMapObject.map = new ymaps.Map("yandex_map", {
29+
center: yandexMapObject.coords,
30+
zoom: 12
31+
});
32+
33+
yandexMapObject.placemark = new ymaps.Placemark( yandexMapObject.coords, {}, { preset: "twirl#redIcon", draggable: true } );
34+
yandexMapObject.map.geoObjects.add(yandexMapObject.placemark);
35+
36+
yandexMapObject.placemark.events.add("dragend", function (e) {
37+
yandexMapObject.coords = this.geometry.getCoordinates();
38+
yandexMapObject.saveCoordinates();
39+
}, yandexMapObject.placemark);
40+
41+
yandexMapObject.map.events.add("click", function (e) {
42+
yandexMapObject.coords = e.get("coords");
43+
yandexMapObject.saveCoordinates();
44+
yandexMapObject.placemark.geometry.setCoordinates(yandexMapObject.coords);
45+
});
46+
}
47+
}
48+
49+
ymaps.ready(yandexMapObject.init);
50+
</script>
51+
</li>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module ActiveAdmin
2+
module Views
3+
class YandexMapProxy < LatlngProxy
4+
def key
5+
@api_key ? "&apikey=#{@api_key}" : ""
6+
end
7+
8+
def loading_map_code
9+
@loading_map ? "<script src=\"https://api-maps.yandex.ru/2.1/?lang=#{@lang}#{key}&load=Map,Placemark\" type=\"text/javascript\"></script>" : ''
10+
end
11+
12+
def to_s
13+
File.open(File.expand_path('../templates/yandex.html', __FILE__)).read % [loading_map_code, @height, @id_lat, @id_lng]
14+
end
15+
end
16+
end
17+
end

lib/activeadmin_latlng.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
require 'activeadmin'
2+
require 'activeadmin/views/latlng_proxy'
3+
require 'activeadmin/views/google_map_proxy'
4+
require 'activeadmin/views/yandex_map_proxy'
25
require 'activeadmin/views/activeadmin_form'
36

47
module ActiveadminLatlng

lib/activeadmin_latlng/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ActiveadminLatlng
2-
VERSION = "0.3.1"
2+
VERSION = "1.0.0"
33
end

0 commit comments

Comments
 (0)