Skip to content

Commit 11a1b7e

Browse files
committed
Merge pull request #2 from tpais/master
act entrega 7
2 parents b99503f + 1ab3edb commit 11a1b7e

File tree

11 files changed

+149
-5
lines changed

11 files changed

+149
-5
lines changed

app/controllers/comments_controller.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ class CommentsController < ApplicationController
33
# authenticate_user! ejecuta acción solo si sesión existe
44
before_filter :authenticate_user!
55

6+
67
def create
78
@site = Site.find(params[:site_id])
89
@comment = @site.comments.create(params[:comment])
910
@comment.user_id = current_user.id
10-
@comment.site_id = @site.id
1111

1212
respond_to do |format|
1313
if @comment.save
@@ -50,4 +50,7 @@ def edit
5050
@site = Site.find(params[:site_id])
5151
@comment = @site.comments.find(params[:id])
5252
end
53+
def index
54+
@user = User.find(params[:user_id])
55+
end
5356
end

app/views/comments/_comment.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<p>
2+
23
<b><%= comment.user.name %>:</b>
34
<%= comment.comment %>
45
</p>

app/views/comments/_edit.html.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<%= form_for([@site, @comment]) do |f| %>
2+
<div class="field">
3+
<%= f.text_area :comment %>
4+
</div>
5+
<div class="actions">
6+
<%= f.submit %>
7+
</div>
8+
<% end %>

app/views/comments/edit.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
<<<<<<< HEAD
2+
=======
13
<h1>Editing site</h1>
24

5+
>>>>>>> b99503f08cc204480f05572e31c865d1d1601d6f
36
<%= form_for([@site, @comment]) do |f| %>
47
<div class="field">
58
<%= f.text_area :comment %>

app/views/sites/_form.html.erb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
2+
<script type="text/javascript">
3+
var lat
4+
var long
5+
6+
window.onload=function() {
7+
if (navigator.geolocation) { //Check if browser supports W3C Geolocation API
8+
navigator.geolocation.getCurrentPosition (successFunction, errorFunction);
9+
} else { alert('Geolocation is not supported in this browser.'); }
10+
}
11+
function successFunction(position) {
12+
lat = position.coords.latitude;
13+
long = position.coords.longitude;
14+
$("#site_latitud").val(lat);
15+
$("#site_longitud").val(long);
16+
$("#site_zoom").val(15);
17+
}
18+
19+
function errorFunction(position) { alert('Calculo automatico de coordenadas con errores'); }
20+
21+
22+
</script>
23+
124
<%= form_for(@site) do |f| %>
225
<% if @site.errors.any? %>
326
<div id="error_explanation">
@@ -23,11 +46,25 @@
2346
<%= f.label :type_id %><br />
2447
<%= f.collection_select(:type_id, Type.find(:all, :order => :name), :id, :name) %>
2548
</div>
49+
<div class="field">
50+
<%= f.label :latitud %><br />
51+
<%= f.text_field :latitud %>
52+
</div>
53+
<div class="field">
54+
<%= f.label :longitud %><br />
55+
<%= f.text_field :longitud %>
56+
</div>
57+
<div class="field">
58+
<%= f.label :zoom %><br />
59+
<%= f.text_field :zoom %>
60+
</div>
2661
<div class="field">
2762
<%= f.label :image %><br />
2863
<%= f.file_field :image %>
2964
</div>
3065
<div class="actions">
3166
<%= f.submit %>
3267
</div>
68+
3369
<% end %>
70+

app/views/sites/_sitelist.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<dt><%= link_to site.name, site %></dt>
1616
<dd><%= truncate(strip_tags(site.description),
1717
:length => 80) %>
18+
</dd>
19+
<dd>
20+
<b>Viajes:</b> <%=site.visits.length%>
1821
</dd>
1922
<dd>
2023
<% if site.comments != [] %>

app/views/sites/show.html.erb

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
<style type="text/css">
2+
html { height: 100% }
3+
body { height: 100%; margin: 0; padding: 0 }
4+
#map_canvas { height: 100% }
5+
</style>
6+
<script src="http://maps.google.com/maps/api/js?sensor=false">
7+
// Carga librería de Google Maps. Doc: http://code.google.com/apis/maps/documentation/javascript/
8+
</script>
9+
<script type="text/javascript">
10+
var map;
11+
var marker;
12+
window.onload=function() {
13+
var latitude = <%= @site.latitud %>
14+
var longitude = <%= @site.longitud %>
15+
var zoom = <%= @site.zoom %>
16+
17+
var latlng = new google.maps.LatLng(latitude,longitude);
18+
var myOptions = {
19+
zoom: zoom,
20+
center: latlng,
21+
mapTypeId: google.maps.MapTypeId.HYBRID
22+
}
23+
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
24+
marker = new google.maps.Marker({
25+
position: latlng,
26+
map: map
27+
});
28+
}
29+
</script>
30+
131
<div id="site">
232

333
<h1><%= @site.type.name if @site.type %></h1>
@@ -8,8 +38,11 @@
838

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

41+
<div id="map_canvas" <%if @site.latitud!=nil && @site.latitud!=nil %> style="width: 920px; height: 480px;"><%end%></div>
42+
1143
<p><b>Autor:</b>
1244
<%= @site.user.name if @site.user %></p>
45+
<p><b>Veces incluido en un viaje:</b> <%=@site.visits.length%></p>
1346

1447
</div>
1548

@@ -23,8 +56,8 @@
2356
<% end %>
2457
<%= link_to 'Back', sites_path %>
2558

26-
<h2>Comments</h2>
59+
<h2>Commentarios</h2>
2760
<%= render @site.comments %>
2861

29-
<h2>Add a comment:</h2>
62+
<h2>Añadir comentario:</h2>
3063
<%= render "comments/form" %>

app/views/trips/_trip.html.erb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
<style type="text/css">
2+
html { height: 100% }
3+
body { height: 100%; margin: 0; padding: 0 }
4+
#map_canvas { height: 100% }
5+
</style>
6+
<script src="http://maps.google.com/maps/api/js?sensor=false">
7+
// Carga librería de Google Maps. Doc: http://code.google.com/apis/maps/documentation/javascript/
8+
</script>
9+
<script type="text/javascript">
10+
11+
window.onload=function() {
12+
var myOptions = {
13+
center: new google.maps.LatLng(0,0 ),
14+
zoom: 1,
15+
mapTypeId: google.maps.MapTypeId.HYBRID
16+
};
17+
var map = new google.maps.Map(document.getElementById("map_canvas"),
18+
myOptions);
19+
20+
21+
<% @trip.sites.each do |site| %>
22+
var latitude = <%= site.latitud %>
23+
var longitude = <%= site.longitud %>
24+
var zoom = 12
25+
var latlng = new google.maps.LatLng(latitude,longitude);
26+
var myOptions = {
27+
zoom: zoom,
28+
center: latlng,
29+
mapTypeId: google.maps.MapTypeId.HYBRID
30+
}
31+
32+
map.setOptions(myOptions);
33+
34+
var icon = new google.maps.MarkerImage ("<%= asset_path(site.image) %>", new google.maps.Size(100,75), new google.maps.Point(0,0), new google.maps.Point(0,30));
35+
var marker = new google.maps.Marker({
36+
position: latlng,
37+
map: map,
38+
icon: icon
39+
});
40+
<% end %>
41+
}
42+
</script>
43+
<div id="map_canvas" style="width: 900px; height: 480px;"></div>
144
<div id="visit">
245
<table>
346
<% trip.visits.order(:hour).each do |visit| %>

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
resources :sites, :only => [ :index ] # Restringe a acción “index”
1717

1818
end
19-
19+
2020
get "planet/index"
2121

2222
get "planet/contact"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Geoloc < ActiveRecord::Migration
2+
def up
3+
add_column :sites, :latitud, :float
4+
add_column :sites, :longitud, :float
5+
add_column :sites, :zoom, :integer
6+
end
7+
8+
def down
9+
end
10+
end

0 commit comments

Comments
 (0)