Skip to content

Commit

Permalink
Multiple trips on home page Fixes #6
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily Hoskin committed Aug 16, 2014
1 parent a205bb3 commit e98d533
Show file tree
Hide file tree
Showing 13 changed files with 8,848 additions and 107 deletions.
44 changes: 7 additions & 37 deletions app/assets/javascripts/home.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,3 @@
var COUNT = 5;

function show_images(){
var image = 0;
$( "#user-images .col-md-2" ).each(function(){
if(image < COUNT){
$( this ).show()
} else {
$( this ).hide()
}

image++;
})
}

var move_right = function(){
$firstUser = $( "#user-images .col-md-2" ).first().detach();
$( "#user-images" ).append($firstUser);
show_images();
}

var move_left = function(){
$lastUser = $( "#user-images .col-md-2" ).last().detach();
$( "#user-images" ).prepend($lastUser);
show_images();
}

var change_image = function(newImage, element){
return function(){
$( element ).attr("src", newImage)
}
}

var id_like_to_go_clicked = function(){
var place_id = this.id.match(/[0-9]+/);
var place_name = $( this ).parent().parent().children( "h3" ).text();
Expand All @@ -43,10 +10,13 @@ var id_like_to_go_clicked = function(){
});
}

$( document ).ready(function(){
$( "<img id='arrow-left' src='/arrow-left.png' />" ).addClass('col-md-1').click(move_left).mouseenter(change_image("/arrow-left-rollover.png", "#arrow-left")).mouseout(change_image("/arrow-left.png", "#arrow-left")).prependTo( "#users" );
$( "<img id='arrow-right' src='/arrow-right.png' />" ).addClass('col-md-1').click(move_right).mouseenter(change_image("/arrow-right-rollover.png", "#arrow-right")).mouseout(change_image("/arrow-right.png", "#arrow-right")).appendTo( "#users" );
show_images();


$( document ).ready(function(){
$( ".id-like-to-go-button" ).click(id_like_to_go_clicked)

});

$(window).load(function(){
//equal_height_featured_trips();
});
37 changes: 11 additions & 26 deletions app/assets/stylesheets/home.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,18 @@

#banner{
width:100%;
overflow:hidden;
background-image:url('/Bournemouth_pier.jpg');
background-repeat:no-repeat;
background-size: cover;
background-position: center top;
}

#featured-trip{
.featured-trip{
background-color:#eee8d0;
width:40%;
margin-left:auto;
margin-right:auto;
padding-left:50px;
padding-right:50px;
margin-top:20px;
margin-bottom:20px;
position:relative;
margin-left:10px;
margin-right:10px;
padding-left:10px;
padding-right:10px;
}

#banner h3 {
Expand Down Expand Up @@ -65,19 +60,11 @@
float:left;
}


#arrow-left {
float:left;
margin-top:40px;
}

#arrow-right {
float:right;
margin-top:40px;
.user-images {
margin-left:20px;
margin-right:20px;
}

#user-images {
}

.name {
text-align:center;
Expand All @@ -102,23 +89,21 @@
float:left;
}

#find-out-more {
.find-out-more {
float:right;
margin-top:20px;
}

#cost-box {
width:100%;
}

#users {
margin-bottom:15px;
}

#cost-box {
.cost-box {
padding-top:20px;
padding-bottom:20px;
padding-left:10px;
width:100%;
}

#infomation-box {
Expand Down
1 change: 1 addition & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class HomeController < ApplicationController
def index
@trips = Trip.all.limit(3)
@trip = Trip.first
@users = @trip.users
@comments = @trip.comments.order(priorty: :desc, created_at: :desc).limit(5)
Expand Down
4 changes: 4 additions & 0 deletions app/models/trip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ class Trip < ActiveRecord::Base
has_many :trip_images
has_many :users, through: :tickets
validates :page_name, uniqueness: { case_sensitive: false }

def date_to_string
self.date.mday.ordinalize + " " + self.date.strftime("%B")
end
end
86 changes: 48 additions & 38 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,50 +4,60 @@
</div>

<div id='banner'>
<div id='featured-trip'>
<div id='intro-text'>
<h3>Bournmouth Weekend Coach Trip</h3>
<h4>Price includes 4 star hotel and coach travel</h4>
</div>
<div id='featured-trips' class='row'>
<% for trip in @trips %>
<div class='trip col-md-4'>
<div class='featured-trip'>
<div id='intro-text'>
<h3><%= trip.name %></h3>
<h4><%= trip.tagline %></h4>
</div>

<div id='infomation-box'>
<h4 class='info'><span class='float-left'>Departing</span> <span class='float-right'><%= trip.departing %></span></h4>
<h4 class='info'><span class='float-left'>Date</span> <span class='float-right'><%= trip.date_to_string %></span></h4>
<div style='clear:both'></div>
</div>
<div style='clear:both'></div>
<%= render "shared/social_box", trip: trip %>
<div class='cost-box'>
<div id='trip-cost'>
<h3>Cost £70</h3>
<p>Invite others to get a discount</p>
<h4>All attendents must be 18+</h4>
</div>
<div class='find-out-more'>
<a href='/trip/<%= trip.page_name%>' class="btn btn-primary btn-lg">Find out more</a>
</div>
<div style='clear:both'></div>
</div>
<div style='clear:both'></div>
</div>

<div id='infomation-box'>
<h4 class='info'><span class='float-left'>Departing</span> <span class='float-right'>Birmingham</span></h4>
<h4 class='info'><span class='float-left'>Date</span> <span class='float-right'>23rd August</span></h4>
<div style='clear:both'></div>
</div>
<div style='clear:both'></div>
<%= render "shared/social_box" %>
<div id='cost-box'>
<div id='trip-cost'>
<h3>Cost £70</h3>
<p>Invite others to get a discount</p>
<h4>All attendents must be 18+</h4>
</div>
<div id='find-out-more'>
<a href='/trip/BournmouthWeekendCoachTrip'class="btn btn-primary btn-lg">Find out more</a>
</div>
<div style='clear:both'></div>
</div>

<% end %>
</div>

</div>

<div id='where-should-we-go-next'>
<h2 id='where-should-we-go-title-text'>Where should we go next?</h2>
<% for place in @places %>
<div class='place'>
<h3 class='place-name'><%= place.name%></h3>
<div class='row'>
<% for image in place.images %>
<div class='col-md-4'>
<img class='place-image' src='<%= image.url%>' />
<h2 id='where-should-we-go-title-text'>Where should we go next?</h2>
<% for place in @places %>
<div class='place'>
<h3 class='place-name'><%= place.name%></h3>
<div class='row'>
<% for image in place.images %>
<div class='col-md-4'>
<img class='place-image' src='<%= image.url%>' />
</div>
<% end %>
</div>
<div class='id-like-to-go'>
<h4><%= place.count%> People want to go </h4>
<button type="button" class='id-like-to-go-button btn btn-primary' id='button<%= place.id %>'>I'd like to go</button>
</div>
</div>
<% end %>
</div>
<div class='id-like-to-go'>
<h4><%= place.count%> People want to go </h4>
<button type="button" class='id-like-to-go-button btn btn-primary' id='button<%= place.id %>'>I'd like to go</button>
</div>
</div>
<% end %>
<div style='clear:both'></div>
<div style='clear:both'></div>
</div>
11 changes: 7 additions & 4 deletions app/views/shared/_social_box.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
<% users = trip.users %>
<% comments = trip.comments %>
<div id='social-box'>
<p id='attending'><%= @users.count %> <%= @users.count == 1 ? "person is" : "people are" %> going</p>
<p id='attending'><%= users.count %> <%= users.count == 1 ? "person is" : "people are" %> going</p>
<div class='row' id='users'>
<div id='user-images'>
<% for user in @users %>
<div class='user-images'>
<% for user in users.limit(6) %>
<div class='user-image col-md-2'>
<p class='name'><%= user.name %></p>
<img src='<%= user.profile_picture %>' />
</div>
<% end %>
<div style='clear:both'></div>
</div>
</div>
<div id='recent-comment'>
<% for comment in @comments %>
<% for comment in comments %>
<p><span class='comment-name'><%= comment.user.name %></span> <span class='comment-says'>says</span><span class='comment-content'> "<%= comment.comment %>" </span></p>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/trip/trip_page.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>
<div class='col-md-4'>
<div id='booking-info'>
<h2><%= @trip.date.mday.ordinalize + " " + @trip.date.strftime("%B") %></h2>
<h2><%= @trip.date_to_string %></h2>
<%= @trip.booking_info.html_safe %>

<div id='booking-pane'>
Expand Down
Binary file modified db/development.sqlite3
Binary file not shown.
5 changes: 5 additions & 0 deletions db/migrate/20140816052347_add_tag_line_to_trip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTagLineToTrip < ActiveRecord::Migration
def change
add_column :trips, :tagline, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20140816052811_add_departing_to_trip.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDepartingToTrip < ActiveRecord::Migration
def change
add_column :trips, :departing, :string
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140816005255) do
ActiveRecord::Schema.define(version: 20140816052811) do

create_table "comments", force: true do |t|
t.integer "user_id"
Expand Down Expand Up @@ -62,6 +62,8 @@
t.string "highlight_text"
t.date "date"
t.string "booking_info"
t.string "tagline"
t.string "departing"
end

add_index "trips", ["page_name"], name: "index_trips_on_page_name", unique: true
Expand Down
Loading

0 comments on commit e98d533

Please sign in to comment.