Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,909 changes: 7,909 additions & 0 deletions .idea/dataSources.ids

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions .idea/huggles.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

578 changes: 415 additions & 163 deletions .idea/workspace.xml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ gem 'sdoc', '~> 0.4.0', group: :doc

gem 'devise', '~> 3.5.1'
gem 'bootstrap-sass', '~> 3.3.5.1'
gem 'activerecord-postgis-adapter', '~> 3.0.0'

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
Expand Down
8 changes: 8 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ GEM
activemodel (= 4.2.1)
activesupport (= 4.2.1)
arel (~> 6.0)
activerecord-postgis-adapter (3.0.0)
activerecord (~> 4.2)
rgeo-activerecord (~> 4.0)
activesupport (4.2.1)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
Expand Down Expand Up @@ -121,6 +124,10 @@ GEM
rdoc (4.2.0)
responders (2.1.0)
railties (>= 4.2.0, < 5)
rgeo (0.3.20)
rgeo-activerecord (4.0.0)
activerecord (~> 4.2)
rgeo (~> 0.3)
sass (3.4.16)
sass-rails (5.0.3)
railties (>= 4.0.0, < 5.0)
Expand Down Expand Up @@ -160,6 +167,7 @@ PLATFORMS
ruby

DEPENDENCIES
activerecord-postgis-adapter (~> 3.0.0)
bootstrap-sass (~> 3.3.5.1)
byebug
coffee-rails (~> 4.1.0)
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require_tree .
//= require_tree
91 changes: 58 additions & 33 deletions app/assets/javascripts/map/geocode.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,77 @@
var map;
var huggles = huggles || {}
huggles.after_google = huggles.after_google || []
var huggles = huggles || {};
huggles.after_google = huggles.after_google || [];

function showPins(coords) {
$(coords).each(function(i, coord) {
var pos = new google.maps.LatLng(coord[1],
coord[0]);

var marker = new google.maps.Marker({
map: map,
position: pos
});

})
}


function initialize() {
function showOtherPins(lat, lon) {
$.ajax('/sync', {
datatype: 'script',
method: 'POST',
data: {
sync: {
lat: lat,
lon: lon}
}
})
}

var mapOptions = {
zoom: 17
};
map = new google.maps.Map(document.getElementById('map-container'),
mapOptions);

// Try HTML5 geolocation
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var pos = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);

var marker = new google.maps.Marker({
map: map,
position: pos,
});
function updateMap() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var lat = position.coords.latitude + Math.random() * 0.005;
var lon = position.coords.longitude + Math.random() * 0.005;

map.setCenter(pos);
var pos = new google.maps.LatLng(lat,
lon);

google.maps.event.addListener(marker, 'click', function(event) {
var marker = new google.maps.Marker({
map: map,

var lat = marker.getPosition().lat();
var lng = marker.getPosition().lng();

$('#lat').val(lat);
$('#lng').val(lng);
});
});

map.setCenter(pos);

}, function() {
handleNoGeolocation(true);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation(false);
marker.setPosition(pos);


showOtherPins(lat, lon)

}, function () {
handleNoGeolocation(true);
});
} else {
// Browser doesn't support Geolocation
handleNoGeolocation(false);
}
}


updateMap();

setInterval(updateMap, 3000000);

}

function handleNoGeolocation(errorFlag) {
Expand All @@ -56,12 +89,4 @@ function handleNoGeolocation(errorFlag) {

var infowindow = new google.maps.InfoWindow(options);
map.setCenter(options.position);
}

huggles.after_google.push(
initialize
//function() {
// google.maps.event.addDomListener(window, 'load', initialize);
//
//}
)
}
12 changes: 2 additions & 10 deletions app/assets/javascripts/map/gmap.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
var huggles = huggles || {}

function loadScript() {
//var script = document.createElement('script');
//script.type = 'text/javascript';
//script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp' +
// '&signed_in=false&callback=initialize';
//document.body.appendChild(script);
//$.getScript('https://maps.googleapis.com/maps/api/js?v=3.exp')
// .done(function() {
$(huggles.after_google).each(function(i, f) {
f()
$(huggles.after_google).each(function(i, f) {
f()
})
//})
}

window.onload = loadScript;
27 changes: 14 additions & 13 deletions app/assets/javascripts/map/marker_location.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
var huggles = huggles || {}
huggles.after_google = huggles.after_google || []

huggles.after_google.push(
function () {
google.maps.event.addListener(map, "rightclick", function(event) {
var lat = event.latLng.lat();
var lng = event.latLng.lng();
// populate yor box/field with lat, lng
alert("Lat=" + lat + "; Lng=" + lng);
})
}
)
//var huggles = huggles || {};
//huggles.after_google = huggles.after_google || [];
//
//huggles.after_google.push(
// function () {
//
// google.maps.event.addListener(map, 'click', function(event) {
// var lat = event.latLng.lat();
// var lng = event.latLng.lng();
// // populate yor box/field with lat, lng
// alert("Lat=" + lat + "; Lng=" + lng);
// })
// }
//);
13 changes: 13 additions & 0 deletions app/assets/stylesheets/_google_maps.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#map-container {
height: 400px;
border-radius: 16px 16px;
border-color: #fff;
border-style: solid;
box-shadow: 2px 2px 10px #B1B1B1;
margin-top: 25px;
border-width: 7px;
}
#map-canvas {
height: 384px;
width: 100%;
}
3 changes: 2 additions & 1 deletion app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@import "bootstrap-sprockets";
@import "bootstrap";
@import "bootstrap";
@import "google_maps";
1 change: 1 addition & 0 deletions app/controllers/profile_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ProfileController < ApplicationController

def new

end

def index
Expand Down
24 changes: 24 additions & 0 deletions app/controllers/sync_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class SyncController < ApplicationController
def sync
location = current_user.set_location sync_params if user_signed_in?
lat = sync_params[:lat]
lon = sync_params[:lon]

locs = Location.where "ST_DWithin(lonlat, 'POINT(? ?)', 500.0)", lon.to_f, lat.to_f
locs = locs.where "updated_at >= now() - INTERVAL '3 minutes'"
locs = locs.where "user_id <> ?", current_user.id
logger.debug " LOCS: #{locs.to_a.inspect}"
points = locs.map{|x| [x.lonlat.x, x.lonlat.y]}
render js: "showPins(#{points})"
end

def refresh_points

end

private

def sync_params
params.require(:sync).permit :lat, :lon
end
end
3 changes: 3 additions & 0 deletions app/models/location.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Location < ActiveRecord::Base
belongs_to :user
end
10 changes: 10 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
class User < ActiveRecord::Base
has_one :location
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

def set_location sync_params
location = self.location || Location.new
location.user = self
location.lonlat = "POINT(#{sync_params['lon'].to_f} #{sync_params['lat'].to_f})"
location.save

location
end
end
2 changes: 0 additions & 2 deletions app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@
<%= f.submit "Log in" %>
</div>
<% end %>

<%= render "devise/shared/links" %>
5 changes: 4 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
<html>
<head>
<title>Huggles</title>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=false&callback=initialize" ></script>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>

<%= render "shared/navbar" %>

<%= yield %>

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=false&callback=initialize" ></script>

</body>
</html>
8 changes: 8 additions & 0 deletions app/views/profile/_index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1>Profile</h1>

<h1>Potential Huggles</h1>

<div id="map-container">
<div id="map-canvas">
</div>
</div>
14 changes: 1 addition & 13 deletions app/views/profile/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
<h1>Profile</h1>

<h1>Potential Huggles</h1>

<form action="">
<input type="hidden" name="lat" id="lat"/>
<input type="hidden" name="lng" id="lng"/>
</form>

<div id="map-container">
<div id="map-canvas">
</div>
</div>
<%= render 'index' %>
Loading