diff --git a/Gemfile.lock b/Gemfile.lock index 264e4f9..52c7e9c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -93,6 +93,7 @@ GEM rack (~> 1.0) tilt (~> 1.1, != 1.3.0) sqlite3 (1.3.4) + sqlite3 (1.3.4-x86-mingw32) thor (0.14.6) tilt (1.3.3) treetop (1.4.10) @@ -107,6 +108,7 @@ GEM PLATFORMS ruby + x86-mingw32 DEPENDENCIES coffee-rails (~> 3.1.1) diff --git a/app/assets/images/Carlos.PNG b/app/assets/images/Carlos.PNG new file mode 100644 index 0000000..0c0f615 Binary files /dev/null and b/app/assets/images/Carlos.PNG differ diff --git a/app/assets/images/Thumbs.db b/app/assets/images/Thumbs.db new file mode 100644 index 0000000..c6cc877 Binary files /dev/null and b/app/assets/images/Thumbs.db differ diff --git a/app/assets/images/elena.png b/app/assets/images/elena.png new file mode 100644 index 0000000..884d98f Binary files /dev/null and b/app/assets/images/elena.png differ diff --git a/app/assets/javascripts/trips.js.coffee b/app/assets/javascripts/trips.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/trips.js.coffee @@ -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/ diff --git a/app/assets/stylesheets/planet.css b/app/assets/stylesheets/planet.css index 28c4fcc..199e942 100644 --- a/app/assets/stylesheets/planet.css +++ b/app/assets/stylesheets/planet.css @@ -65,6 +65,48 @@ } + +#trip_list table { + border-collapse: collapse; +} + +#trip_list table tr td { + padding: 5px; + vertical-align: top; +} + +#trip_list .list_name { + width: 40%; + margin: 0; + color: #244; + font-weight: bold; + font-size: larger; + text-align: center; +} + +#trip_list .list_order { + width: 10%; + margin: 0; + color: #244; + font-size: larger; + text-align: center; +} + +#trip_list .list_actions { + font-size: x-small; + text-align: right; + padding-left: 1em; +} + +#trip_list .list_line_even { + background: #a8b8f8; +} + +#trip_list .list_line_odd { + background: #88b0f8; +} + + /* START:mainlayout */ /* Styles for main page */ @@ -78,6 +120,12 @@ text-align: center; } +#banner a { color: #669999; } +a:visited { color: #66CCCC; } +a:hover { color: #0033CC; +background-color:#D8D8D8; } + + #banner img { float: left; padding-left: 10px; diff --git a/app/assets/stylesheets/trips.css.scss b/app/assets/stylesheets/trips.css.scss new file mode 100644 index 0000000..f1f72ad --- /dev/null +++ b/app/assets/stylesheets/trips.css.scss @@ -0,0 +1,3 @@ +// 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/ diff --git a/app/controllers/planet_controller.rb b/app/controllers/planet_controller.rb index 97d6b5a..dca5fba 100644 --- a/app/controllers/planet_controller.rb +++ b/app/controllers/planet_controller.rb @@ -1,12 +1,5 @@ class PlanetController < ApplicationController - def index - end - - def contact - end - -# GET /planet/ejemplo - def ejemplo + def author end end diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 9db5a12..c792f6e 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -2,16 +2,16 @@ class SitesController < ApplicationController # GET /sites # GET /sites.json def index - if params[:type_id].nil? or params[:type_id].empty? @sites = Site.all else @sites = Type.find(params[:type_id]).sites end + @trip = Trip.new respond_to do |format| format.html # index.html.erb - format.json { render json: @sites } + format.json { render :json=> @sites } end end @@ -22,7 +22,7 @@ def show respond_to do |format| format.html # show.html.erb - format.json { render json: @site } + format.json { render :json=> @site } end end @@ -33,7 +33,7 @@ def new respond_to do |format| format.html # new.html.erb - format.json { render json: @site } + format.json { render :json=> @site } end end @@ -49,11 +49,11 @@ def create 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 } + 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 } + format.html { render :action=> "new" } + format.json { render :json=> @site.errors, :status=> :unprocessable_entity } end end end @@ -65,11 +65,11 @@ def update respond_to do |format| if @site.update_attributes(params[:site]) - format.html { redirect_to @site, notice: 'Site was successfully updated.' } + 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 } + format.html { render :action=> "edit" } + format.json { render :json=> @site.errors, :status=> :unprocessable_entity } end end end diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb new file mode 100644 index 0000000..1e8ca19 --- /dev/null +++ b/app/controllers/trips_controller.rb @@ -0,0 +1,120 @@ +class TripsController < ApplicationController + # GET /trips + # GET /trips.json + def index + @trips = Trip.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @trips } + end + end + + # GET /trips/1 + # GET /trips/1.json + def show + @trip = Trip.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @trip } + end + end + + # GET /trips/new + # GET /trips/new.json + def new + @trip = Trip.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @trip } + end + end + + # GET /trips/1/edit + def edit + @trip = Trip.find(params[:id]) + end + + # POST /trips + # POST /trips.json + def create + @trip = Trip.new(params[:trip]) + + if !Trip.find(:last, :order => 'trip_id').nil? + @trip.trip_id = Trip.find(:last, :order => 'trip_id').trip_id + 1 + end + + respond_to do |format| + if @trip.save + format.html { redirect_to @trip, notice: 'Trip was successfully created.' } + format.json { render json: @trip, status: :created, location: @trip } + else + format.html { render action: "new" } + format.json { render json: @trip.errors, status: :unprocessable_entity } + end + end + + end + + # PUT /trips/1 + # PUT /trips/1.json + def update + @trip = Trip.find(params[:id]) + # tid1 identificador de posicion viejo + tid1 = @trip.trip_id + + respond_to do |format| + if @trip.update_attributes(params[:trip]) + + @trips = Trip.find(:all, :order => 'trip_id') + + @trips.each do |trip| + # Si la posicion nueva esta por encima de la vieja, baja los que estuvieran entre ellas + if @trip.trip_id < tid1 + if (trip.trip_id < tid1) && (trip.trip_id >= @trip.trip_id) && (trip.site_id != @trip.site_id) + trip.trip_id = trip.trip_id + 1 + trip.save + end + end + # Si la posicion nueva esta por debajo de la vieja, sube los que estuvieran entre ellas + if @trip.trip_id > tid1 + if (trip.trip_id > tid1) && (trip.trip_id <= @trip.trip_id) && (trip.site_id != @trip.site_id) + trip.trip_id = trip.trip_id - 1 + trip.save + end + end + end + + format.html { redirect_to @trip, notice: 'Trip was successfully created.' } + format.json { head :ok } + else + format.html { render action: "edit" } + format.json { render json: @trip.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /trips/1 + # DELETE /trips/1.json + def destroy + @trip = Trip.find(params[:id]) + # tid es la posicion borrada + tid = @trip.trip_id + @trip.destroy + @trips = Trip.find(:all, :order => 'trip_id') + + @trips.each do |trip| + if trip.trip_id > tid + trip.trip_id = trip.trip_id - 1 + trip.save + end + end + + respond_to do |format| + format.html { redirect_to trips_url } + format.json { head :ok } + end + end +end diff --git a/app/helpers/trips_helper.rb b/app/helpers/trips_helper.rb new file mode 100644 index 0000000..04f333d --- /dev/null +++ b/app/helpers/trips_helper.rb @@ -0,0 +1,2 @@ +module TripsHelper +end diff --git a/app/models/site.rb b/app/models/site.rb index dde788c..f934634 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -1,3 +1,5 @@ class Site < ActiveRecord::Base belongs_to :type + belongs_to :trip + validates_presence_of :name, :message => "must be provided" end diff --git a/app/models/trip.rb b/app/models/trip.rb new file mode 100644 index 0000000..5d07e8a --- /dev/null +++ b/app/models/trip.rb @@ -0,0 +1,3 @@ +class Trip < ActiveRecord::Base + has_many :sites +end diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c1b3a26..2274d4b 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,26 +1,46 @@ + Planet <%= stylesheet_link_tag "application" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> + + +
<%= link_to "Home", planet_index_path %>
<%= link_to "Tipos", types_path %>
- <%= link_to "Sitios", sites_path %>
- <%= link_to "Contact", planet_contact_path %> + <%= link_to "Sitios", sites_path %>
+ <%= link_to "Viajes", trips_path %>
+ <%= link_to "Contacto", planet_contact_path %>
+ <%= link_to "Autor", planet_author_path %>
+ <%= link_to "Ejemplo", planet_ejemplo_path %> +
-
- <%= yield %> +
+ <%= yield %> +
+
+ + -
+ \ No newline at end of file diff --git a/app/views/planet/author.html.erb b/app/views/planet/author.html.erb new file mode 100644 index 0000000..81fc5eb --- /dev/null +++ b/app/views/planet/author.html.erb @@ -0,0 +1,13 @@ +

Elena Moreno Alonso

+<%= image_tag('elena.png') %> +

Madrid

+

elenaypunto@gmail.com

+

Estudiante de ingeniería de Telecomunicaciones

+ + +

Carlos González merino

+<%= image_tag('Carlos.PNG') %> + +

Madrid

+

carlosgonza88@gmail.com

+

Estudiante de ingeniería de Telecomunicaciones

diff --git a/app/views/sites/index.html.erb b/app/views/sites/index.html.erb index f1034b8..89f091a 100644 --- a/app/views/sites/index.html.erb +++ b/app/views/sites/index.html.erb @@ -6,7 +6,9 @@ - <%= link_to image_tag(site.image_url, :class => 'list_image'), site %> + <% if site.image_url != "" %> + <%= link_to image_tag(site.image_url, :class => 'list_image'), site %> + <% end %> @@ -23,6 +25,11 @@ <%= link_to 'Destroy', site, :confirm => 'Are you sure?', :method => :delete %> + <%= form_for(@trip, remote: true) do |f| %> + <% f.number_field :trip_id, :value => 1, :hidden => true %> + <% f.number_field :site_id, :value => site.id, :hidden => true %> + <%= f.submit "Add site" %> + <% end %> <% end %> diff --git a/app/views/sites/show.html.erb b/app/views/sites/show.html.erb index 244b974..8813405 100644 --- a/app/views/sites/show.html.erb +++ b/app/views/sites/show.html.erb @@ -1,6 +1,6 @@
-

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

+

Site: <%= @site.type.name if @site.type %>

<%= image_tag(@site.image_url, :class => 'site_image') %> diff --git a/app/views/trips/_form.html.erb b/app/views/trips/_form.html.erb new file mode 100644 index 0000000..d41335b --- /dev/null +++ b/app/views/trips/_form.html.erb @@ -0,0 +1,34 @@ +<%= form_for(@trip) do |f| %> + <% if @trip.errors.any? %> +
+

<%= pluralize(@trip.errors.count, "error") %> prohibited this trip from being saved:

+ + +
+ <% end %> + +
+ Trip name:
+ <%= t = Site.find_by_id(@trip.site_id).name %> + +
+
+ <% f.label :site_id %>
+ <% f.number_field :site_id %> +
+ +
+ New position: + <% f.label :trip_id %>
+ <%= f.collection_select(:trip_id, Trip.find(:all, :order => :trip_id), :trip_id, :trip_id) %>
+

+ +
+ <%= f.submit %> +
+ +<% end %> diff --git a/app/views/trips/edit.html.erb b/app/views/trips/edit.html.erb new file mode 100644 index 0000000..71287a4 --- /dev/null +++ b/app/views/trips/edit.html.erb @@ -0,0 +1,6 @@ +

Editing trip

+ +<%= render 'form' %> + +<%= link_to 'Show', @trip %> | +<%= link_to 'Back', trips_path %> diff --git a/app/views/trips/index.html.erb b/app/views/trips/index.html.erb new file mode 100644 index 0000000..92e6884 --- /dev/null +++ b/app/views/trips/index.html.erb @@ -0,0 +1,31 @@ +
+

Listing selected sites

+ + + + + + + + + + + +<% @trips = Trip.find(:all, :order => :trip_id) %> + +<% @trips.each do |trip| %> + + + + +<% end %> +
OrderSelected site
+ <%= trip.trip_id %> + + <%= t = Site.find_by_id(trip.site_id).name %> + + <%= link_to 'Show', site_path(trip.site_id) %>
+ <%= link_to 'Edit', edit_trip_path(trip) %>
+ <%= link_to 'Destroy', trip, confirm: 'Are you sure?', method: :delete %>
+
+
\ No newline at end of file diff --git a/app/views/trips/show.html.erb b/app/views/trips/show.html.erb new file mode 100644 index 0000000..a3954d0 --- /dev/null +++ b/app/views/trips/show.html.erb @@ -0,0 +1,15 @@ +

<%= notice %>

+ +

+ Trip name: + <%= @trip.site_id %> +

+ +

+ Trip: + <%= @trip.id %> +

+ + +<%= link_to 'Edit', edit_trip_path(@trip) %> | +<%= link_to 'Back', trips_path %> diff --git a/config/initializers/session_store.rb b/config/initializers/session_store.rb index 697d0c8..b43a624 100644 --- a/config/initializers/session_store.rb +++ b/config/initializers/session_store.rb @@ -1,6 +1,6 @@ # Be sure to restart your server when you modify this file. -Planet::Application.config.session_store :cookie_store, key: '_planet_session' +Planet::Application.config.session_store :cookie_store, :key=> '_planet_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information diff --git a/config/initializers/wrap_parameters.rb b/config/initializers/wrap_parameters.rb index 999df20..8b5b128 100644 --- a/config/initializers/wrap_parameters.rb +++ b/config/initializers/wrap_parameters.rb @@ -5,7 +5,7 @@ # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do - wrap_parameters format: [:json] + wrap_parameters format=[:json] end # Disable root element in JSON by default. diff --git a/config/routes.rb b/config/routes.rb index 4572a56..e621836 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,9 @@ Planet::Application.routes.draw do + resources :trips + + get "planet/author" + resources :sites resources :types diff --git a/config/wrap_parameters.rb b/config/wrap_parameters.rb new file mode 100644 index 0000000..b871673 --- /dev/null +++ b/config/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. +# +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format= [:json] +end + +# Disable root element in JSON by default. +ActiveSupport.on_load(:active_record) do + self.include_root_in_json = false +end diff --git a/db/migrate/20111216152020_create_trips.rb b/db/migrate/20111216152020_create_trips.rb new file mode 100644 index 0000000..2a77ffd --- /dev/null +++ b/db/migrate/20111216152020_create_trips.rb @@ -0,0 +1,12 @@ +class CreateTrips < ActiveRecord::Migration + def change + create_table :trips do |t| + + t.integer :trip_id + t.integer :site_id + + t.timestamps + end + + end +end diff --git a/db/schema.rb b/db/schema.rb index 3717026..f283a91 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1,4 +1,3 @@ -# encoding: UTF-8 # This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. @@ -11,7 +10,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20111127165324) do +ActiveRecord::Schema.define(:version => 20111216152020) do create_table "sites", :force => true do |t| t.string "name" @@ -25,6 +24,13 @@ t.datetime "updated_at" end + create_table "trips", :force => true do |t| + t.integer "trip_id" + t.integer "site_id" + t.datetime "created_at" + t.datetime "updated_at" + end + create_table "types", :force => true do |t| t.string "name" t.text "description" diff --git a/test/fixtures/trips.yml b/test/fixtures/trips.yml new file mode 100644 index 0000000..8feb428 --- /dev/null +++ b/test/fixtures/trips.yml @@ -0,0 +1,9 @@ +# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html + +one: + trip_name: MyString + trip_id: 1 + +two: + trip_name: MyString + trip_id: 1 diff --git a/test/functional/planet_controller_test.rb b/test/functional/planet_controller_test.rb index 88229e0..c614714 100644 --- a/test/functional/planet_controller_test.rb +++ b/test/functional/planet_controller_test.rb @@ -1,13 +1,8 @@ require 'test_helper' class PlanetControllerTest < ActionController::TestCase - test "should get index" do - get :index - assert_response :success - end - - test "should get contact" do - get :contact + test "should get author" do + get :author assert_response :success end diff --git a/test/functional/trips_controller_test.rb b/test/functional/trips_controller_test.rb new file mode 100644 index 0000000..d7b24ba --- /dev/null +++ b/test/functional/trips_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class TripsControllerTest < ActionController::TestCase + setup do + @trip = trips(:one) + end + + test "should get index" do + get :index + assert_response :success + assert_not_nil assigns(:trips) + end + + test "should get new" do + get :new + assert_response :success + end + + test "should create trip" do + assert_difference('Trip.count') do + post :create, trip: @trip.attributes + end + + assert_redirected_to trip_path(assigns(:trip)) + end + + test "should show trip" do + get :show, id: @trip.to_param + assert_response :success + end + + test "should get edit" do + get :edit, id: @trip.to_param + assert_response :success + end + + test "should update trip" do + put :update, id: @trip.to_param, trip: @trip.attributes + assert_redirected_to trip_path(assigns(:trip)) + end + + test "should destroy trip" do + assert_difference('Trip.count', -1) do + delete :destroy, id: @trip.to_param + end + + assert_redirected_to trips_path + end +end diff --git a/test/unit/helpers/trips_helper_test.rb b/test/unit/helpers/trips_helper_test.rb new file mode 100644 index 0000000..dcfddff --- /dev/null +++ b/test/unit/helpers/trips_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class TripsHelperTest < ActionView::TestCase +end diff --git a/test/unit/trip_test.rb b/test/unit/trip_test.rb new file mode 100644 index 0000000..1ed8ca6 --- /dev/null +++ b/test/unit/trip_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class TripTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end