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

Jorge Somavilla #10

Open
wants to merge 2 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
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ group :test do
# Pretty printed test output
gem 'turn', '0.8.2', :require => false
end

gem 'therubyracer'
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ GEM
railties (~> 3.0)
thor (~> 0.14)
json (1.6.1)
libv8 (3.3.10.4)
mail (2.3.0)
i18n (>= 0.4.0)
mime-types (~> 1.16)
Expand Down Expand Up @@ -94,6 +95,8 @@ GEM
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.4)
therubyracer (0.9.9)
libv8 (~> 3.3.10)
thor (0.14.6)
tilt (1.3.3)
treetop (1.4.10)
Expand All @@ -116,5 +119,6 @@ DEPENDENCIES
rails (= 3.1.3)
sass-rails (~> 3.1.5)
sqlite3
therubyracer
turn (= 0.8.2)
uglifier (>= 1.0.3)
2 changes: 2 additions & 0 deletions app/assets/javascripts/jquery.cleditor.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*= require cleditor

2 changes: 2 additions & 0 deletions app/assets/stylesheets/jquery.cleditor.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//= require cleditor

1 change: 1 addition & 0 deletions app/assets/stylesheets/trips.css.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Place all the styles related to the trips controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
#mapa{width:400px;height:400px;margin-top:25px;float:right;padding-top:4ex}
15 changes: 14 additions & 1 deletion app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#MODIFICACIONES:
# * index: creo hash con sitio-numero_repeticiones para la vista index_html.erb de sites
# * show: defino num para la vista show.html.erb de sites

class SitesController < ApplicationController
# GET /sites
# GET /sites.json
Expand All @@ -8,7 +12,13 @@ def index
else
@sites = Type.find(params[:type_id]).sites
end


#creo hash con sitio-numero_repeticiones para la vista index_html.erb de sites
@num = {}
@sites.each do |s|
@num[s.id] = Selected.where(site_id: s.id).count()
end

respond_to do |format|
format.html # index.html.erb
format.json { render json: @sites }
Expand All @@ -20,6 +30,9 @@ def index
def show
@site = Site.find(params[:id])

# defino num para la vista show.html.erb de sites
@num = Selected.where(site_id: @site.id).count()

respond_to do |format|
format.html # show.html.erb
format.json { render json: @site }
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/trips_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# MODIFICACIÓN
# * Defino @selecteds para vista show de trips

class TripsController < ApplicationController
# GET /trips
# GET /trips.json
Expand All @@ -15,7 +18,7 @@ def index
def show
@trip = Trip.find(params[:id])
@selected = Selected.new
@selecteds = Selected.where(trip_id: params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @trip }
Expand Down
2 changes: 1 addition & 1 deletion app/models/site.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class Site < ActiveRecord::Base
belongs_to :type
has_many :selected
has_many :selected, :dependent => :destroy
end
2 changes: 1 addition & 1 deletion app/models/trip.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
class Trip < ActiveRecord::Base
has_many :selecteds
has_many :selecteds, :dependent => :destroy
end
42 changes: 40 additions & 2 deletions app/views/sites/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
<!--
MODIFICACIONES:
* Añado script google maps
* Añado script que obtiene coordenadas del sitio
* primero busca que estén ya definidas
* si no intenta solicitarlas al navegador
* Añado etiquetas (lat2, long2) al texto de las cajas de latitud y longitud, para poder modificarlo
-->


<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
function success(position) {
var lat = document.querySelector('#lat2');
var lon = document.querySelector('#long2');
if ( ! lon.value && !lat.value){
lat.value = position.coords.latitude;
lon.value = position.coords.longitude;
}
}
function error(msg) {
var s = document.querySelector('#status');
s.innerHTML = typeof msg == 'string' ? msg : "failed";
s.className = 'fail';
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
error('not supported');
}
</script>







<%= form_for(@site) do |f| %>
<% if @site.errors.any? %>
<div id="error_explanation">
Expand Down Expand Up @@ -25,11 +63,11 @@
</div>
<div class="field">
<%= f.label :latitude %><br />
<%= f.text_field :latitude %>
<%= f.text_field :latitude, id: "lat2" %>
</div>
<div class="field">
<%= f.label :longitude %><br />
<%= f.text_field :longitude %>
<%= f.text_field :longitude, id: "long2" %>
</div>
<div class="field">
<%= f.label :zoom %><br />
Expand Down
16 changes: 13 additions & 3 deletions app/views/sites/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
MODIFICACIÓN:
* Añado linea contador veces añadido
-->

<div id="site_list">
<h1>Listing Sites</h1>

Expand All @@ -14,6 +19,11 @@
<dt><%= link_to site.name, site %></dt>
<dd><%= truncate(strip_tags(site.description),
:length => 80) %></dd>


<br/> Veces añadido: <%= @num[site.id] %>


</dl>
</td>

Expand All @@ -22,13 +32,13 @@
<%= link_to 'Edit', edit_site_path(site) %><br/>
<%= link_to 'Destroy', site,
:confirm => 'Are you sure?',
:method => :delete %>
</td>
:method => :delete %><br/>
</td>
</tr>
<% end %>
</table>
</div>

<br />

<%= link_to 'New site', new_site_path %>
<%= link_to 'New site', new_site_path %>
7 changes: 6 additions & 1 deletion app/views/sites/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<!--
MODIFICACIÓN
* Contador de veces que el sitio ha sido añadido
-->

<div id="site">

<h1><%= @site.type.name if @site.type %></h1>
Expand All @@ -7,7 +12,7 @@
<h3><%= @site.name %></h3>

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

Veces añadido: <%= @num %>
<div class="position">
<span>
<b>Latitude:</b>
Expand Down
53 changes: 53 additions & 0 deletions app/views/trips/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,54 @@
<!--
MODIFICACIONES
* Añado script google maps
* Añado javascript con funcion displayPosition
* Añado div con id=mapa
-->

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

function displayPosition() {
var mylat = 0.0;
var mylong = 0.0;
// Store my position (“y=mylat”, “x=mylong”) in variable “latlng”
var latlng = new google.maps.LatLng(mylat, mylong);
// Define my Google Maps options in variable “myOptions”
var myOptions = {
zoom: 2,
// Define scale
center: latlng,
// Define map center
mapTypeId: google.maps.MapTypeId.SATELLITE // tipo Roadmad, Satellite, Terrain, Hybrid
};
// Load Google Map according to “myOptions” in Canvas identified by “map_canvas”
var map = new google.maps.Map(document.getElementById("mapa"), myOptions);
// Add marker in Google Maps “map” in position defined by “latlng”
<% for s in @selecteds do %>
<% site = Site.find(s.site_id) %>
var title<%= site.id %> = "<%= site.name %>";
var mylat<%= site.id %> = <%= site.latitude %>;
var mylong<%= site.id %> = <%= site.longitude %>;

latlng<%= site.id %> = new google.maps.LatLng(mylat<%= site.id %>, mylong<%= site.id %>);
var image = new google.maps.MarkerImage(
"<%= image_path(site.image_url) %>",
new google.maps.Size(80,70),
new google.maps.Point(0,0),
new google.maps.Point(20,35),
new google.maps.Size(80,70)
);
var marker<%= site.id %> = new google.maps.Marker({
position: latlng<%= site.id %>,
map: map,
title: title<%= site.id %>,
icon: image
});
<% end %>
}
window.onload=displayPosition;
</script>

<% if notice %>
<p id="notice"><%= notice %></p>
<% end %>
Expand All @@ -20,6 +71,8 @@

<div id="site_list">

<div id="mapa" ></div>

<h1>Sitios a visitar</h1>

<%= render(@trip) %>
Expand Down