Skip to content

Commit

Permalink
update files structure
Browse files Browse the repository at this point in the history
  • Loading branch information
forsaken1 committed Sep 27, 2017
1 parent 4951643 commit 5dcece1
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 133 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
activeadmin_latlng (0.3.1)
activeadmin_latlng (1.0.0)
activeadmin

GEM
Expand Down
132 changes: 1 addition & 131 deletions lib/activeadmin/views/activeadmin_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,135 +19,5 @@ def latlng **args
end
end
end

class LatlngProxy < FormtasticProxy
def build(_, *args, &_block)
@lang, @id_lat, @id_lng, @height, @loading_map, @api_key = *args
end
end

class GoogleMapProxy < LatlngProxy
def key
@api_key ? "&key=#{@api_key}" : ""
end

def loading_map_code
@loading_map ? "<script src=\"https://maps.googleapis.com/maps/api/js?language=#{@lang}#{key}&callback=googleMapObject.init\" async defer></script>" : ''
end

def to_s
"<li>" \
"#{loading_map_code}" \
"<div id=\"google_map\" style=\"height: #{@height}px\"></div>" \
"<script>
var googleMapObject = {
coords: null,
map: null,
marker: null,
getCoordinates: function() {
return {
lat: parseFloat($(\"##{@id_lat}\").val()) || 55.7522200,
lng: parseFloat($(\"##{@id_lng}\").val()) || 37.6155600,
};
},
saveCoordinates: function() {
$(\"##{@id_lat}\").val( googleMapObject.coords.lat.toFixed(10) );
$(\"##{@id_lng}\").val( googleMapObject.coords.lng.toFixed(10) );
},
init: function() {
googleMapObject.coords = googleMapObject.getCoordinates();
googleMapObject.saveCoordinates();
googleMapObject.map = new google.maps.Map(document.getElementById('google_map'), {
center: googleMapObject.coords,
zoom: 12
});
var latLngCoord = new google.maps.LatLng(googleMapObject.coords.lat, googleMapObject.coords.lng);
googleMapObject.marker = new google.maps.Marker({
position: latLngCoord,
map: googleMapObject.map,
draggable: true
});
googleMapObject.map.addListener('click', function(e) {
googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
googleMapObject.saveCoordinates();
googleMapObject.marker.setPosition(googleMapObject.coords);
});
googleMapObject.marker.addListener('drag', function(e) {
googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
googleMapObject.saveCoordinates();
});
}
}
</script>" \
"</li>"
end
end

class YandexMapProxy < LatlngProxy
def key
@api_key ? "&apikey=#{@api_key}" : ""
end

def loading_map_code
@loading_map ? "<script src=\"https://api-maps.yandex.ru/2.1/?lang=#{@lang}#{key}&load=Map,Placemark\" type=\"text/javascript\"></script>" : ''
end

def to_s
"<li>" \
"#{loading_map_code}" \
"<div id=\"yandex_map\" style=\"height: #{@height}px\"></div>" \
"<script type=\"text/javascript\">
var yandexMapObject = {
coords: null,
map: null,
placemark: null,
getCoordinates: function() {
return [
parseFloat($(\"##{@id_lat}\").val()) || 55.7522200,
parseFloat($(\"##{@id_lng}\").val()) || 37.6155600,
];
},
saveCoordinates: function() {
$(\"##{@id_lat}\").val( yandexMapObject.coords[0].toFixed(10) );
$(\"##{@id_lng}\").val( yandexMapObject.coords[1].toFixed(10) );
},
init: function() {
yandexMapObject.coords = yandexMapObject.getCoordinates();
yandexMapObject.saveCoordinates();
yandexMapObject.map = new ymaps.Map(\"yandex_map\", {
center: yandexMapObject.coords,
zoom: 12
});
yandexMapObject.placemark = new ymaps.Placemark( yandexMapObject.coords, {}, { preset: \"twirl#redIcon\", draggable: true } );
yandexMapObject.map.geoObjects.add(yandexMapObject.placemark);
yandexMapObject.placemark.events.add(\"dragend\", function (e) {
yandexMapObject.coords = this.geometry.getCoordinates();
yandexMapObject.saveCoordinates();
}, yandexMapObject.placemark);
yandexMapObject.map.events.add(\"click\", function (e) {
yandexMapObject.coords = e.get(\"coords\");
yandexMapObject.saveCoordinates();
yandexMapObject.placemark.geometry.setCoordinates(yandexMapObject.coords);
});
}
}
ymaps.ready(yandexMapObject.init);
</script>" \
"</li>"
end
end
end
end
end
17 changes: 17 additions & 0 deletions lib/activeadmin/views/google_map_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module ActiveAdmin
module Views
class GoogleMapProxy < LatlngProxy
def key
@api_key ? "&key=#{@api_key}" : ""
end

def loading_map_code
@loading_map ? "<script src=\"https://maps.googleapis.com/maps/api/js?language=#{@lang}#{key}&callback=googleMapObject.init\" async defer></script>" : ''
end

def to_s
File.open(File.expand_path('../templates/google.html', __FILE__)).read % [loading_map_code, @height, @id_lat, @id_lng]
end
end
end
end
9 changes: 9 additions & 0 deletions lib/activeadmin/views/latlng_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module ActiveAdmin
module Views
class LatlngProxy < FormtasticProxy
def build(_, *args, &_block)
@lang, @id_lat, @id_lng, @height, @loading_map, @api_key = *args
end
end
end
end
51 changes: 51 additions & 0 deletions lib/activeadmin/views/templates/google.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<li>
%s
<div id="google_map" style="height: %spx"></div>
<script>
var googleMapObject = {
idLat: '%s',
idLng: '%s',
coords: null,
map: null,
marker: null,

getCoordinates: function() {
return {
lat: parseFloat($("#" + googleMapObject.idLat).val()) || 55.7522200,
lng: parseFloat($("#" + googleMapObject.idLng).val()) || 37.6155600,
};
},

saveCoordinates: function() {
$("#" + googleMapObject.idLat).val( googleMapObject.coords.lat.toFixed(10) );
$("#" + googleMapObject.idLng).val( googleMapObject.coords.lng.toFixed(10) );
},

init: function() {
googleMapObject.coords = googleMapObject.getCoordinates();
googleMapObject.saveCoordinates();

googleMapObject.map = new google.maps.Map(document.getElementById('google_map'), {
center: googleMapObject.coords,
zoom: 12
});

var latLngCoord = new google.maps.LatLng(googleMapObject.coords.lat, googleMapObject.coords.lng);
googleMapObject.marker = new google.maps.Marker({
position: latLngCoord,
map: googleMapObject.map,
draggable: true
});
googleMapObject.map.addListener('click', function(e) {
googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
googleMapObject.saveCoordinates();
googleMapObject.marker.setPosition(googleMapObject.coords);
});
googleMapObject.marker.addListener('drag', function(e) {
googleMapObject.coords = { lat: e.latLng.lat(), lng: e.latLng.lng() };
googleMapObject.saveCoordinates();
});
}
}
</script>
</li>
51 changes: 51 additions & 0 deletions lib/activeadmin/views/templates/yandex.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<li>
%s
<div id="yandex_map" style="height: %spx"></div>
<script>
var yandexMapObject = {
idLat: '%s',
idLng: '%s',
coords: null,
map: null,
placemark: null,

getCoordinates: function() {
return [
parseFloat($("#" + yandexMapObject.idLat).val()) || 55.7522200,
parseFloat($("#" + yandexMapObject.idLng).val()) || 37.6155600,
];
},

saveCoordinates: function() {
$("#" + yandexMapObject.idLat).val( yandexMapObject.coords[0].toFixed(10) );
$("#" + yandexMapObject.idLng).val( yandexMapObject.coords[1].toFixed(10) );
},

init: function() {
yandexMapObject.coords = yandexMapObject.getCoordinates();
yandexMapObject.saveCoordinates();

yandexMapObject.map = new ymaps.Map("yandex_map", {
center: yandexMapObject.coords,
zoom: 12
});

yandexMapObject.placemark = new ymaps.Placemark( yandexMapObject.coords, {}, { preset: "twirl#redIcon", draggable: true } );
yandexMapObject.map.geoObjects.add(yandexMapObject.placemark);

yandexMapObject.placemark.events.add("dragend", function (e) {
yandexMapObject.coords = this.geometry.getCoordinates();
yandexMapObject.saveCoordinates();
}, yandexMapObject.placemark);

yandexMapObject.map.events.add("click", function (e) {
yandexMapObject.coords = e.get("coords");
yandexMapObject.saveCoordinates();
yandexMapObject.placemark.geometry.setCoordinates(yandexMapObject.coords);
});
}
}

ymaps.ready(yandexMapObject.init);
</script>
</li>
17 changes: 17 additions & 0 deletions lib/activeadmin/views/yandex_map_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module ActiveAdmin
module Views
class YandexMapProxy < LatlngProxy
def key
@api_key ? "&apikey=#{@api_key}" : ""
end

def loading_map_code
@loading_map ? "<script src=\"https://api-maps.yandex.ru/2.1/?lang=#{@lang}#{key}&load=Map,Placemark\" type=\"text/javascript\"></script>" : ''
end

def to_s
File.open(File.expand_path('../templates/yandex.html', __FILE__)).read % [loading_map_code, @height, @id_lat, @id_lng]
end
end
end
end
3 changes: 3 additions & 0 deletions lib/activeadmin_latlng.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
require 'activeadmin'
require 'activeadmin/views/latlng_proxy'
require 'activeadmin/views/google_map_proxy'
require 'activeadmin/views/yandex_map_proxy'
require 'activeadmin/views/activeadmin_form'

module ActiveadminLatlng
Expand Down
2 changes: 1 addition & 1 deletion lib/activeadmin_latlng/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ActiveadminLatlng
VERSION = "0.3.1"
VERSION = "1.0.0"
end

0 comments on commit 5dcece1

Please sign in to comment.