Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entrega7 #52

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
37 changes: 37 additions & 0 deletions app/views/sites/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@
</div>
<% end %>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

if (navigator.geolocation) { //Check if browser supports W3C Geolocation API

navigator.geolocation.getCurrentPosition (successFunction, errorFunction);

} else { alert('Geolocation is not supported in this browser.'); }

function successFunction(position) {

var lat = position.coords.latitude;
var long = position.coords.longitude;
// alert('Your latitude is :'+lat+' and longitude is '+long);
$("#site_lat").val(lat)
$("#site_long").val(long)
$("#site_zoom").val("15")
}

function errorFunction(position) { alert('Error!'); }


</script>


<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
Expand All @@ -27,6 +52,18 @@
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
<div class="field">
<%= f.label :lat %><br />
<%= f.text_area :lat , :rows => 1 %>
</div>
<div class="field">
<%= f.label :long %><br />
<%= f.text_area :long , :rows => 1 %>
</div>
<div class="field">
<%= f.label :zoom %><br />
<%= f.text_area :zoom , :rows => 1 %>
</div>
<div class="actions">
<%= f.submit %>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/sites/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<dt><%= link_to site.name, site %></dt>
<dd><%= truncate(strip_tags(site.description),
:length => 80) %></dd>
<p><b>Incluido en <i> <%= site.visits.count %> </i> visitas</b> </p>
</dl>
</td>

Expand All @@ -31,4 +32,4 @@

<br />

<%= link_to 'New site', new_site_path %>
<%= link_to 'New site', new_site_path %>
Expand Down
34 changes: 34 additions & 0 deletions app/views/sites/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,19 +1,53 @@
<style type="text/css">
#map_canvas { float:right; width:500px; height:400px; }
</style>

<div id="site">

<h1><%= @site.type.name if @site.type %></h1>

<%= image_tag(@site.image.url, :class => 'site_image') %>

<div id="map_canvas"></div>

<h3><%= @site.name %></h3>

<p><%=sanitize @site.description %></p>

<p><b>Autor:</b> <%= @site.user.name if @site.user %></p>

<p><b>Incluido en <i> <%= @site.visits.count %> </i> visitas</b> </p>
</div>

<div class="visitas">
<b>Visitas:</b> <%= @site.visitas %>
</div>

<script src="http://maps.google.com/maps/api/js?sensor=false"></script>

<script type="text/javascript">

var mylat = <%= @site.lat %>;
var mylong = <%= @site.long %>;

var latlng = new google.maps.LatLng(mylat, mylong);

var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

var marker = new google.maps.Marker({

position: latlng,
map: map,
title: "<%= @site.name %>"
});

</script>

<p />
<% if @site.user == current_user %> <%= link_to 'Edit', edit_site_path(@site) %> |<% end %><%= link_to 'Back', sites_path %>
Expand Down
42 changes: 42 additions & 0 deletions app/views/trips/_trip.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<style type="text/css">
#map_canvas { float:right; width:400px; height:300px; }
</style>

<div id="visit">
<div id="map_canvas"></div>
<table>
<% trip.visits.order(:hour).each do |visit| %>
<tr class="<%= cycle('list_line_odd', 'list_line_even') %>">
Expand All @@ -25,5 +30,42 @@
</tr>
<% end %>
</table>

</div>

<script src="http://maps.google.com/maps/api/js?sensor=false"></script>

<script type="text/javascript">

var mylat = 40;
var mylong = -3;

var latlng = new google.maps.LatLng(mylat, mylong);

var myOptions = {
zoom: 1,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

<% trip.visits.order(:hour).each do |visit| %>

<% next unless visit.site.lat %>
var mylat = <%= visit.site.lat %>;
var mylong = <%= visit.site.long %>;

var latlng = new google.maps.LatLng( mylat , mylong );

var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "<%= visit.site.name %>"
});

<% end %>


</script>

17 changes: 17 additions & 0 deletions db/migrate/20120421132559_localizacion_sitios.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class LocalizacionSitios < ActiveRecord::Migration
def up
change_table :sites do |t|
t.column :lat, :integer
t.column :long, :integer
t.column :zoom, :integer
end
end

def down
change_table :sites do |t|
t.column :lat, :integer
t.column :long, :integer
t.column :zoom, :integer
end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20120421170806_sitios_lat_float.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class SitiosLatFloat < ActiveRecord::Migration
def up
change_column :sites, :lat, :float
change_column :sites, :long, :float
change_column :sites, :zoom, :float
end

def down
end
end
13 changes: 12 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
#
# It's strongly recommended to check this file into your version control system.

ActiveRecord::Schema.define(:version => 20120411160519) do
ActiveRecord::Schema.define(:version => 20120421170806) do

create_table "comments", :force => true do |t|
t.string "comment"
t.integer "user_id"
t.integer "site_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end

create_table "sites", :force => true do |t|
t.string "name"
Expand All @@ -26,6 +34,9 @@
t.string "image_file_size"
t.datetime "image_updated_at"
t.integer "visitas", :default => 0
t.float "lat"
t.float "long"
t.float "zoom"
end

create_table "trips", :force => true do |t|
Expand Down