diff --git a/.gitignore b/.gitignore index 28a4c21..0103038 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ # ignore al .DS_store files of MAC OSX .DS_Store +#ignore paperclip installation files +public/system +.project \ No newline at end of file diff --git a/Gemfile b/Gemfile index 7764763..8362f86 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,13 @@ gem 'rails', '3.2.2' gem 'sqlite3' +gem 'paperclip' + +gem 'devise' + +gem 'jquery-rails' + +gem 'cleditor_rails' # Gems used only for assets and not required # in production environments by default. diff --git a/Gemfile.lock b/Gemfile.lock index 81a3ba7..00d598c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -29,7 +29,10 @@ GEM i18n (~> 0.6) multi_json (~> 1.0) arel (3.0.2) + bcrypt-ruby (3.0.1) builder (3.0.0) + cleditor_rails (0.0.3) + cocaine (0.2.1) coffee-rails (3.2.2) coffee-script (>= 2.2.0) railties (~> 3.2.0) @@ -37,6 +40,11 @@ GEM coffee-script-source execjs coffee-script-source (1.2.0) + devise (2.0.4) + bcrypt-ruby (~> 3.0) + orm_adapter (~> 0.0.3) + railties (~> 3.1) + warden (~> 1.1.1) erubis (2.7.0) execjs (1.3.0) multi_json (~> 1.0) @@ -53,6 +61,12 @@ GEM treetop (~> 1.4.8) mime-types (1.17.2) multi_json (1.1.0) + orm_adapter (0.0.7) + paperclip (2.4.5) + activerecord (>= 2.3.0) + activesupport (>= 2.3.2) + cocaine (>= 0.0.2) + mime-types polyglot (0.3.3) rack (1.4.1) rack-cache (1.2) @@ -98,13 +112,18 @@ GEM uglifier (1.2.3) execjs (>= 0.3.0) multi_json (>= 1.0.2) + warden (1.1.1) + rack (>= 1.0) PLATFORMS ruby DEPENDENCIES + cleditor_rails coffee-rails (~> 3.2.1) + devise jquery-rails + paperclip rails (= 3.2.2) sass-rails (~> 3.2.3) sqlite3 diff --git a/app/assets/images/fotocarnet.jpg b/app/assets/images/fotocarnet.jpg new file mode 100644 index 0000000..7424162 Binary files /dev/null and b/app/assets/images/fotocarnet.jpg differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 9097d83..84d87a2 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,5 +11,6 @@ // GO AFTER THE REQUIRES BELOW. // //= require jquery +//= require cleditor //= require jquery_ujs //= require_tree . diff --git a/app/assets/javascripts/comentarios.js.coffee b/app/assets/javascripts/comentarios.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/comentarios.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/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/javascripts/visits.js.coffee b/app/assets/javascripts/visits.js.coffee new file mode 100644 index 0000000..7615679 --- /dev/null +++ b/app/assets/javascripts/visits.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/application.css b/app/assets/stylesheets/application.css index 3b5cc66..50d53e3 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -9,5 +9,6 @@ * compiled file, but it's generally better to create a new file per style scope. * *= require_self + *= require cleditor *= require_tree . */ diff --git a/app/assets/stylesheets/comentarios.css.scss b/app/assets/stylesheets/comentarios.css.scss new file mode 100644 index 0000000..494c101 --- /dev/null +++ b/app/assets/stylesheets/comentarios.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the comentarios controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/planet.css b/app/assets/stylesheets/planet.css index 28c4fcc..71561d8 100644 --- a/app/assets/stylesheets/planet.css +++ b/app/assets/stylesheets/planet.css @@ -9,6 +9,56 @@ font: bold smaller sans-serif; } +#comentarios a {font-weight:bold; + color:black; + font: 105% sans-serif; + } +#links a { color : #555;} + + +#search { + + position: relative; + width: 310px; + top: 5px; + left: 5px; + + + + +} + +#search .notice { + + color : red; + +} + +#links { + +text-align:center; +margin-top: 10px; +margin-bottom: 10px; +word-spacing:25pt; + +} +#map_canvas { + height: 300pt; + width: 300pt; + } + + + +#cv {font:sans-serif;} + +#personal-data {font:sans-serif;} + +#personal-data img { + padding-bottom:60px; + padding-right:30px; + float:left; +} + #planet h1 { font: 150% sans-serif; @@ -71,6 +121,7 @@ #banner { background: #668; padding-top: 10px; + padding-bottom: 10px; border-bottom: 2px solid; font: small-caps 40px/40px "Times New Roman", serif; @@ -83,6 +134,19 @@ padding-left: 10px; } +#banner .user { + margin-top: 50px; + margin-right:20px; + float: right; + color: #bfb; + font-size: small; + +} + +#banner .user a { + color:#555; +} + #columns { background: #446; } diff --git a/app/assets/stylesheets/trips.css.scss b/app/assets/stylesheets/trips.css.scss new file mode 100644 index 0000000..473cbc3 --- /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/assets/stylesheets/visits.css.scss b/app/assets/stylesheets/visits.css.scss new file mode 100644 index 0000000..99b00b9 --- /dev/null +++ b/app/assets/stylesheets/visits.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the visits 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/comentarios_controller.rb b/app/controllers/comentarios_controller.rb new file mode 100644 index 0000000..63b96ce --- /dev/null +++ b/app/controllers/comentarios_controller.rb @@ -0,0 +1,99 @@ +class ComentariosController < ApplicationController + # GET /comentarios + # GET /comentarios.json + before_filter :authenticate_user!, :except => [:index,:show] + def index + + + + + @comentarios = Site.find(params[:site_id]).comentarios # path: /types/id/sites + + + + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @sites } + + end + end + + # GET /comentarios/1 + # GET /comentarios/1.json + def show + @comentario = Comentario.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @comentario } + end + end + + # GET /comentarios/new + # GET /comentarios/new.json + def new + + @comentario = current_user.comentarios.build + + + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @comentario } + end + end + + # GET /comentarios/1/edit + def edit + @comentario = current_user.comentarios.find(params[:id]) + + end + + # POST /comentarios + # POST /comentarios.json + def create + + @comentario = current_user.comentarios.build(params[:comentario])#creamos un comentario con lo que nos pasa el formulario + @comentario.site_id = params[:site_id] + + respond_to do |format| + if @comentario.save + format.html { redirect_to site_comentarios_url, notice: 'Comentario was successfully created.' } + format.json { render json: site_comentarios_url, status: :created, location: site_comentarios_url } + else + format.html { render action: "new" } + format.json { render json: @comentario.errors, status: :unprocessable_entity } + end + end + end + + # PUT /comentarios/1 + # PUT /comentarios/1.json + def update + @comentario = current_user.comentarios.find(params[:id]) #cogemos el comentario a actualizar + + + respond_to do |format| + if @comentario.update_attributes(params[:comentario])#intentamos actualizar el comentario con el pasado por el formulario + format.html { redirect_to site_comentarios_path(@comentario.site) , notice: 'Comentario was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @comentario.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /comentarios/1 + # DELETE /comentarios/1.json + def destroy + @comentario = current_user.comentarios.find(params[:id]) + @comentario.destroy + + respond_to do |format| + format.html { redirect_to site_comentarios_path(@comentario.site) } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/planet_controller.rb b/app/controllers/planet_controller.rb index be7ac0a..7f0dde4 100644 --- a/app/controllers/planet_controller.rb +++ b/app/controllers/planet_controller.rb @@ -1,11 +1,31 @@ class PlanetController < ApplicationController + # GET /planet/index + def index end +def search + busqueda = params[:busqueda] + if busqueda.length < 3 + flash[:notice] = "Debe introducir al menos 3 caracteres" + redirect_to planet_index_path + end + @sites= Site.where("name like ? or description like ?" , "%" + params[:busqueda] + "%" , "%" + params[:busqueda] + "%") + @trips= Trip.where("name like ? or description like ?" , "%" + params[:busqueda] + "%" , "%" + params[:busqueda] + "%") + end +# GET /planet/contact + def contact end +# GET /planet/ejemplo + def ejemplo end + + # GET /planet/author + + def author + end end diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index f3ae9ad..4ec57e7 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -1,4 +1,11 @@ class SitesController < ApplicationController + +after_filter :count_visit, :only => :show + +def count_visit + @site.increment!(:visitas) +end + before_filter :authenticate_user!, :except => [:index,:show] # GET /sites # GET /sites.json def index @@ -27,7 +34,7 @@ def show # GET /sites/new # GET /sites/new.json def new - @site = Site.new + @site = current_user.sites.build #crea sitio vacio asociado a current user respond_to do |format| format.html # new.html.erb @@ -37,13 +44,13 @@ def new # GET /sites/1/edit def edit - @site = Site.find(params[:id]) + @site = current_user.sites.find(params[:id]) end # POST /sites # POST /sites.json def create - @site = Site.new(params[:site]) + @site = current_user.sites.build(params[:site]) respond_to do |format| if @site.save @@ -59,7 +66,7 @@ def create # PUT /sites/1 # PUT /sites/1.json def update - @site = Site.find(params[:id]) + @site = current_user.sites.find(params[:id]) respond_to do |format| if @site.update_attributes(params[:site]) @@ -75,7 +82,7 @@ def update # DELETE /sites/1 # DELETE /sites/1.json def destroy - @site = Site.find(params[:id]) + @site = current_user.sites.find(params[:id]) @site.destroy respond_to do |format| diff --git a/app/controllers/trips_controller.rb b/app/controllers/trips_controller.rb new file mode 100644 index 0000000..56cc227 --- /dev/null +++ b/app/controllers/trips_controller.rb @@ -0,0 +1,86 @@ +class TripsController < ApplicationController + + before_filter :authenticate_user!, :except => [:index, :show] + # 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]) + @visit= @trip.visits.build + + 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 = current_user.trips.build #crea viaje vacio + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @trip } + end + end + + # GET /trips/1/edit + def edit + @trip = current_user.trips.find(params[:id]) + end + + # POST /trips + # POST /trips.json + def create + @trip = current_user.trips.build(params[:trip]) + + 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 = current_user.trips.find(params[:id]) + + respond_to do |format| + if @trip.update_attributes(params[:trip]) + format.html { redirect_to @trip, notice: 'Trip was successfully updated.' } + format.json { head :no_content } + 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 = current_user.trips.find(params[:id]) + @trip.destroy + + respond_to do |format| + format.html { redirect_to trips_url } + format.json { head :no_content } + end + end +end diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb index da826f4..68bc419 100644 --- a/app/controllers/types_controller.rb +++ b/app/controllers/types_controller.rb @@ -53,6 +53,8 @@ def create end end + + # PUT /types/1 # PUT /types/1.json def update @@ -80,4 +82,13 @@ def destroy format.json { head :no_content } end end + + def ordered_index + @types = Type.find(:all, :order => :name) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @type } + end + end end diff --git a/app/controllers/visits_controller.rb b/app/controllers/visits_controller.rb new file mode 100644 index 0000000..e10dbcf --- /dev/null +++ b/app/controllers/visits_controller.rb @@ -0,0 +1,87 @@ +class VisitsController < ApplicationController + # GET /visits + # GET /visits.json + def index + @visits = Visit.all + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @visits } + end + end + + # GET /visits/1 + # GET /visits/1.json + def show + @visit = Visit.find(params[:id]) + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @visit } + end + end + + # GET /visits/new + # GET /visits/new.json + def new + @visit = Visit.new + + respond_to do |format| + format.html # new.html.erb + format.json { render json: @visit } + end + end + + # GET /visits/1/edit + def edit + @visit = Visit.find(params[:id]) + end + + # POST /visits + # POST /visits.json + def create + @visit = Visit.new(params[:visit]) + + respond_to do |format| + if @visit.save + + format.html { redirect_to @visit.trip, notice: 'Visit was successfully created.' } + format.js + format.json { render json: @visit, status: :created, location: @visit } + else + format.html { render action: "new" } + format.json { render json: @visit.errors, status: :unprocessable_entity } + end + end + end + + # PUT /visits/1 + # PUT /visits/1.json + def update + @visit = Visit.find(params[:id]) + + respond_to do |format| + if @visit.update_attributes(params[:visit]) + + format.html { redirect_to @visit.trip, notice: 'Visit was successfully updated.' } + format.json { head :no_content } + else + format.html { render action: "edit" } + format.json { render json: @visit.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /visits/1 + # DELETE /visits/1.json + def destroy + @visit = Visit.find(params[:id]) + @visit.destroy + + respond_to do |format| + + format.html { redirect_to @visit.trip } + format.json { head :no_content } + end + end +end diff --git a/app/helpers/comentarios_helper.rb b/app/helpers/comentarios_helper.rb new file mode 100644 index 0000000..a8f928b --- /dev/null +++ b/app/helpers/comentarios_helper.rb @@ -0,0 +1,2 @@ +module ComentariosHelper +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/helpers/visits_helper.rb b/app/helpers/visits_helper.rb new file mode 100644 index 0000000..8ce5f83 --- /dev/null +++ b/app/helpers/visits_helper.rb @@ -0,0 +1,2 @@ +module VisitsHelper +end diff --git a/app/models/comentario.rb b/app/models/comentario.rb new file mode 100644 index 0000000..fe49b14 --- /dev/null +++ b/app/models/comentario.rb @@ -0,0 +1,8 @@ +class Comentario < ActiveRecord::Base + belongs_to :site + belongs_to :user + + validates :site_id,:user_id, :presence => true #El comentario debe tener un contenido y pertenecer a un sitio y usuario + validates :coment, :presence => true, + :length => { :maximum => 240 } +end diff --git a/app/models/site.rb b/app/models/site.rb index 3eb288d..c0f1300 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -1,3 +1,14 @@ class Site < ActiveRecord::Base belongs_to :type + belongs_to :user + has_many :comentarios + has_many :visits + has_many :trips, :through => :visits + has_attached_file :image + + # Debe estar protegido para evitar accesos indeseados + attr_protected :user_id + + # Se añaden estas definiciones + validates :name, :type_id, :presence => true # campo obligatorio end diff --git a/app/models/trip.rb b/app/models/trip.rb new file mode 100644 index 0000000..a175941 --- /dev/null +++ b/app/models/trip.rb @@ -0,0 +1,7 @@ +class Trip < ActiveRecord::Base + belongs_to :user + has_many :visits + has_many :sites, :through => :visits + + attr_protected :user_id #Por Seguridad +end diff --git a/app/models/type.rb b/app/models/type.rb index 7c3d2ac..2284d1f 100644 --- a/app/models/type.rb +++ b/app/models/type.rb @@ -1,3 +1,8 @@ class Type < ActiveRecord::Base has_many :sites + + + # Se añade esta definición de recurso + validates :name, :description, :presence => true # campo obligatorio + validates :name, :uniqueness => true # Campo único (no repetido) end diff --git a/app/models/user.rb b/app/models/user.rb new file mode 100644 index 0000000..f4fa6f7 --- /dev/null +++ b/app/models/user.rb @@ -0,0 +1,14 @@ +class User < ActiveRecord::Base + has_many :sites + has_many :comentarios + has_many :trips + # Include default devise modules. Others available are: + # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable + + validates_presence_of :name + + # Setup accessible (or protected) attributes for your model + attr_accessible :name, :email, :password, :password_confirmation, :remember_me +end diff --git a/app/models/visit.rb b/app/models/visit.rb new file mode 100644 index 0000000..ca23b73 --- /dev/null +++ b/app/models/visit.rb @@ -0,0 +1,4 @@ +class Visit < ActiveRecord::Base + belongs_to :trip + belongs_to :site +end diff --git a/app/views/comentarios/_form.html.erb b/app/views/comentarios/_form.html.erb new file mode 100644 index 0000000..d4c98a1 --- /dev/null +++ b/app/views/comentarios/_form.html.erb @@ -0,0 +1,27 @@ +<%= form_for([:site, @comentario]) do |f| %> + <% if @comentario.errors.any? %> +
+
|
+
+
+
+
+
+ <% if comentario.user == current_user %>
+ + <%= link_to 'Eliminar', [comentario.site, comentario], + :confirm => 'Are you sure?', + :method => :delete %> + + <%= link_to 'Editar', edit_site_comentario_path(comentario.site,comentario) %> + + + + + + <% end %> + |
+
<%= notice %>
+ ++ Coment: + <%= @comentario.coment %> +
+ ++ User: + <%= @comentario.user_id %> +
+ ++ Site: + <%= @comentario.site_id %> +
+ + +<%= link_to 'Edit', edit_comentario_path(@comentario) %> | +<%= link_to 'Back', comentarios_path %> diff --git a/app/views/devise/_links.erb b/app/views/devise/_links.erb new file mode 100644 index 0000000..eab783a --- /dev/null +++ b/app/views/devise/_links.erb @@ -0,0 +1,25 @@ +<%- if controller_name != 'sessions' %> + <%= link_to "Sign in", new_session_path(resource_name) %>Welcome <%= @resource.email %>!
+ +You can confirm your account email through the link below:
+ +<%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %>
diff --git a/app/views/devise/mailer/reset_password_instructions.html.erb b/app/views/devise/mailer/reset_password_instructions.html.erb new file mode 100644 index 0000000..ae9e888 --- /dev/null +++ b/app/views/devise/mailer/reset_password_instructions.html.erb @@ -0,0 +1,8 @@ +Hello <%= @resource.email %>!
+ +Someone has requested a link to change your password, and you can do this through the link below.
+ +<%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) %>
+ +If you didn't request this, please ignore this email.
+Your password won't change until you access the link above and create a new one.
diff --git a/app/views/devise/mailer/unlock_instructions.html.erb b/app/views/devise/mailer/unlock_instructions.html.erb new file mode 100644 index 0000000..2263c21 --- /dev/null +++ b/app/views/devise/mailer/unlock_instructions.html.erb @@ -0,0 +1,7 @@ +Hello <%= @resource.email %>!
+ +Your account has been locked due to an excessive amount of unsuccessful sign in attempts.
+ +Click the link below to unlock your account:
+ +<%= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) %>
diff --git a/app/views/devise/passwords/edit.html.erb b/app/views/devise/passwords/edit.html.erb new file mode 100644 index 0000000..5f7bcf8 --- /dev/null +++ b/app/views/devise/passwords/edit.html.erb @@ -0,0 +1,16 @@ +Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :confirm => "Are you sure?", :method => :delete %>.
+ +<%= link_to "Back", :back %> diff --git a/app/views/devise/registrations/new.html.erb b/app/views/devise/registrations/new.html.erb new file mode 100644 index 0000000..06911fd --- /dev/null +++ b/app/views/devise/registrations/new.html.erb @@ -0,0 +1,21 @@ +La localización exacta es longitud: ' + + mylong + ' y latitud: ' + mylat + '
'; + + var latlng = new google.maps.LatLng(mylat, mylong); + + } else { + + var thediv = document.getElementById('locationinfo'); + thediv.innerHTML = 'La localización exacta es longitud: ' + + longitud[0] + ' y latitud: ' + latitud[0] + '
'; + +var latlng = new google.maps.LatLng(latitud[0], longitud[0]); + + + } + + var myOptions = { + zoom: zom, + center: latlng, + mapTypeId: google.maps.MapTypeId.ROADMAP + }; + + var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); + +//Add marker +if(latitud.length != null) { +for(var i=0; i