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

Entrega 3.1 - añadido autores : Víctor Hugo Bazán Milla - Enrique Pardo Vázquez-Bruno #14

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Binary file added app/assets/images/Avatar-1-ld.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/Machu-Picchu.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/Playa_Jardin_Tenerife_2005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/ciudad-real.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/epardo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/logo3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/montaña.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/javascripts/sites.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
3 changes: 3 additions & 0 deletions app/assets/javascripts/viajes.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
108 changes: 108 additions & 0 deletions app/assets/stylesheets/planet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#banner {
background: #668;
padding-top: 10px;
padding-bottom: 10px;
border-bottom: 2px solid;
font: small-caps 40px/40px
"Times New Roman", serif;
color: #bfb;
text-align: center;
}


#banner img {
float: left;
padding-left: 10px;
}
#columns {
background: #446;
}
#main {
margin-left: 9em;
padding-top: 4ex;
padding-left: 2em;
background: white;
}
#side {
float: left;
padding-top: 1em;
padding-left: 1em;
padding-bottom: 1em;
width: 8em;
background: #446;
}
#side a {
color: #bfb;
font-size: small;
}
#columns a{
color: #bfb;
font-size: small;
}
#columns #main a{
color: #222266;
font-size: small;
}
#planet #notice {
color: #000;
border: 2px solid red;
padding: 1em;
margin-bottom: 2em;
background-color: #f0f0f0;
font: bold smaller sans-serif;
}
#planet h1 {
font: 150% sans-serif;
color: #226;
border-bottom: 3px dotted #77d;
}
/* Styles for index, sites and types */
#site_list table {
border-collapse: collapse;
}
#site_list table tr td {
padding: 5px;
vertical-align: top;
}
#site_list .list_image {
width: 60px;
height: 70px;
}

#site_list .list_description {
width: 60%;
}
#site_list .list_description dl {
margin: 0;
}
#site_list .list_description dt {
color: #244;
font-weight: bold;
font-size: larger;
}
#site_list .list_description dd {
margin: 0;
}
#site_list .list_actions {
font-size: x-small;
text-align: right;
padding-left: 1em;
}
#site_list .list_line_even {
background: #a8b8f8;
}
#site_list .list_line_odd {
background: #88b0f8;
}
div#columns div#main div#site_list table tbody tr.list_line_odd td.list_description dl dt a{
color: #BBFFBB;
font-size: small;
}
div#columns div#main div#site a {
float:right;
font-size:medium;
padding-right:2em;

}


3 changes: 3 additions & 0 deletions app/assets/stylesheets/sites.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Sites controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/viajes.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the Viajes controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
7 changes: 7 additions & 0 deletions app/controllers/planet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ def contact
def ejemplo
end

#GET /planet/author
def author
end

#GET /planet/viajes
def viaje
end
end
96 changes: 96 additions & 0 deletions app/controllers/sites_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
class SitesController < ApplicationController
# GET /sites
# GET /sites.json

def index
@num_orden_sig = Viaje.all.count+1
# Se incluye @site = Site.all dentro de esta sentencia if-else-end
# -> si la condición es falsa el path es: /types/id/sites
if params[:type_id].nil? or params[:type_id].empty?
@sites = Site.all

else
@sites = Type.find(params[:type_id]).sites
@type = Type.find(params[:type_id]).name
end


respond_to do |format|
format.html # index.html.erb
format.json { render json: @sites }
end
end

# GET /sites/1
# GET /sites/1.json

def show
@site = Site.find(params[:id])


respond_to do |format|
format.html # show.html.erb
format.json { render json: @site }
end
end

# GET /sites/new
# GET /sites/new.json
def new
@site = Site.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @site }
end
end

# GET /sites/1/edit
def edit
@site = Site.find(params[:id])
end

# POST /sites
# POST /sites.json
def create
@site = Site.new(params[:site])

respond_to do |format|
if @site.save
format.html { redirect_to @site, notice: 'Site was successfully created.' }
format.json { render json: @site, status: :created, location: @site }
else
format.html { render action: "new" }
format.json { render json: @site.errors, status: :unprocessable_entity }
end
end
end

# PUT /sites/1
# PUT /sites/1.json
def update
@site = Site.find(params[:id])

respond_to do |format|
if @site.update_attributes(params[:site])
format.html { redirect_to @site, notice: 'Site was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @site.errors, status: :unprocessable_entity }
end
end
end

# DELETE /sites/1
# DELETE /sites/1.json
def destroy
@site = Site.find(params[:id])
@site.destroy

respond_to do |format|
format.html { redirect_to sites_url }
format.json { head :ok }
end
end
end
111 changes: 111 additions & 0 deletions app/controllers/viajes_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
class ViajesController < ApplicationController
# GET /viajes
# GET /viajes.json
def index
@viajes = Viaje.find(:all, :order =>"orden")
@sitios = Site.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @viajes }
end
end

# GET /viajes/1
# GET /viajes/1.json
def show
@viaje = Viaje.find(params[:id])
@sitio = Site.find(@viaje.site_id)
respond_to do |format|
format.html # show.html.erb
format.json { render json: @viaje }
end
end

# GET /viajes/new
# GET /viajes/new.json
def new
@viaje = Viaje.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @viaje }
end
end

# GET /viajes/1/edit
def edit
@viaje = Viaje.find(params[:id])
end



# POST /viajes
# POST /viajes.json


def create
@orden_sig = (Viaje.all.count+1)
if params[:site_id].nil?
@viaje = Viaje.new(params[:viaje])
else
if params[:orden]==@orden_sig
@viaje = Viaje.new(params[:viaje])
else
params[:orden]= @orden_sig
@viaje = Viaje.new(params[:viaje])
# @viaje = Viaje.new(:site_id =>params[:viaje][:site_id], :orden => (Viaje.all.count+1))
end
end
respond_to do |format|
if @viaje.save
format.html { redirect_to @viaje, notice: 'Viaje was successfully created. Order: '+ @orden_sig.to_s }
format.json { render json: @viaje, status: :created, location: @viaje }
else
format.html { render action: "new" }
format.json { render json: @viaje.errors, status: :unprocessable_entity }
end
end
end

# PUT /viajes/1
# PUT /viajes/1.json
def update
#if params[:site_id]!=nil #si site_id no es nil ...
@orden_new = params[:viaje][:orden]
@orden_old = params[:viaje][:orden_old]
@viaje_old = Viaje.find_by_orden(@orden_new)
@viaje = Viaje.find(params[:id]) #al que modifico pongo orden que me envian y al viaje_old le pongo el orden del actual

respond_to do |format|
if (@viaje.update_attributes(:orden => @orden_new) and @viaje_old.update_attributes(:orden => @orden_old))
# if @viaje.update_attributes(params[:viaje])
format.html { redirect_to @viaje, notice: 'Viaje was successfully updated. Order Changed--> ' + 'new order: '+@orden_new.to_s}
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @viaje.errors, status: :unprocessable_entity }
end
end


end

# DELETE /viajes/1
# DELETE /viajes/1.json
def destroy
@viaje = Viaje.find(params[:id])
@orden = @viaje.orden #al borrar hay que reordenar los sitios del viaje
@resto_sitios = Viaje.where("orden > ?", @orden)
@viaje.destroy

@resto_sitios.each do |viaje|

viaje.update_attributes(:orden => @orden)
@orden = @orden+1
end
respond_to do |format|
format.html { redirect_to viajes_url }
format.json { head :ok }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/sites_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module SitesHelper
end
2 changes: 2 additions & 0 deletions app/helpers/viajes_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ViajesHelper
end
4 changes: 4 additions & 0 deletions app/models/site.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Site < ActiveRecord::Base
belongs_to:type
belongs_to:viaje
end
1 change: 1 addition & 0 deletions app/models/type.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class Type < ActiveRecord::Base
has_many:sites
end
3 changes: 3 additions & 0 deletions app/models/viaje.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Viaje < ActiveRecord::Base
has_many:site
end
Loading