Skip to content

Commit

Permalink
Merge pull request #132 from minnestar/random-session-order
Browse files Browse the repository at this point in the history
Random session order
  • Loading branch information
jcoyne committed Jul 15, 2016
2 parents 19014d1 + b883106 commit a80f99b
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 19 deletions.
14 changes: 13 additions & 1 deletion src/app/assets/stylesheets/shared.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ $white: #fff;
$grey: rgb(209, 217, 220);
$minnebar-purple: #414D87;

@mixin columns($width, $gap) {
column-width: $width;
column-gap: $gap;
-moz-column-width: $width;
-moz-column-gap: $gap;
-webkit-column-width: $width;
-webkit-column-gap: $gap;
}

body {
background-color: #fff;
font-family: 'Helvetica Neue', Verdana, Helvetica, sans-serif;
Expand Down Expand Up @@ -120,13 +129,16 @@ ul.sessionsList {
margin: 0;
padding: 0;
list-style-type: none;
@include columns(24em, 1em);
li.attending {
background: image-url("minnebar.png") no-repeat 0 .1em;
}
li {
margin: 16px 0;
margin: 0.6em 0;
padding-left: 1.8em;
letter-spacing: -0.05em;
display: inline-block; // prevent column break
width: 100%;
a {
&:link, &:visited {
font: 700 1.2em / 1.2em;
Expand Down
3 changes: 2 additions & 1 deletion src/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class PagesController < ApplicationController
def home
@current_event = Event.current_event
@recent_sessions = @current_event ? @current_event.sessions.limit(10).order('created_at desc') : []
@recent_sessions = @current_event ? @current_event.sessions.limit(4).recent : []
@random_sessions = @current_event ? @current_event.sessions.limit(6).random_order : []

@categories = Category.all.order('id')
end
Expand Down
2 changes: 1 addition & 1 deletion src/app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def index
else
@event = Event.current_event
end
@sessions = @event.sessions
@sessions = @event.sessions.order('created_at desc')
respond_with @sessions do |format|
format.json {
render json: SessionsJsonBuilder.new.to_json(@sessions.uniq.flatten)
Expand Down
6 changes: 5 additions & 1 deletion src/app/models/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class Session < ActiveRecord::Base

scope :with_attendence_count, -> { select('*').joins("LEFT OUTER JOIN (SELECT session_id, count(id) AS attendence_count FROM attendances GROUP BY session_id) AS attendence_aggregation ON attendence_aggregation.session_id = sessions.id") }

scope :for_current_event, lambda { where(event_id: Event.current_event.id) }
scope :for_current_event, -> { where(event_id: Event.current_event.id) }

scope :recent, -> { order('created_at desc') }

scope :random_order, -> { order('random()') }

validates_presence_of :description
validates_presence_of :event_id
Expand Down
4 changes: 2 additions & 2 deletions src/app/views/pages/_category_grid.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="column grid_<%= grid %>">
<h3>Sessions about <%= category.name %></h3>
<ul class="sessionsList">
<%= render category.sessions.for_current_event.limit(5) %>
<%= render category.sessions.for_current_event.random_order.limit(5) %>
</ul>
<p><%= link_to 'See more...', category_path(category) %></p>
<p class="more_sessions"><%= link_to 'See more...', category_path(category) %></p>
</div>

15 changes: 12 additions & 3 deletions src/app/views/pages/_sessions.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<h2>Recently Added Sessions</h2>
<%= cache Session.maximum(:updated_at), expires_in: 20.seconds do %>

<h2>A Sampling of Sessions</h2>
<ul class="sessionsList">
<%= render @recent_sessions %>
<%= render @random_sessions %>
</ul>
<p class="more_sessions"><%= link_to 'See all sessions', sessions_path %></p>

<h2>Recently Added</h2>
<ul class="sessionsList">
<%= render @recent_sessions %>
</ul>
<p class="more_sessions"><%= link_to 'See all sessions', sessions_path %></p>

<div class="row">
<%= render 'category_grid', category: @categories.first, grid: 3 %>
<%= render 'category_grid', category: @categories.second, grid: 3 %>
Expand All @@ -21,4 +29,5 @@
<div class="row">
<p><%= add_sessions_button %></p>
</div>


<% end %>
19 changes: 11 additions & 8 deletions src/app/views/sessions/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<% title('All Sessions') %>
<div class="row">
<p><%= add_sessions_button %></p>
<div class="column grid_6" style="margin-left:0px">
<ul class="sessionsList">
<%= render @sessions %>
</ul>
</div>
</div>
(most recently added first)

<% cache [Session.maximum(:updated_at), current_participant] do %>
<div class="row">
<p><%= add_sessions_button %></p>
<div class="column grid_10" style="margin-left:0px">
<ul class="sessionsList">
<%= render @sessions %>
</ul>
</div>
</div>
<% end %>
4 changes: 2 additions & 2 deletions src/spec/features/interest_gathering_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

scenario "As a guest, I want to express my interest", js: true do

click_link "A neat talk"
click_link "A neat talk", match: :first
page.find("#attend").click

fill_in "Name", with: "Dennis Ritchie"
Expand All @@ -28,7 +28,7 @@
scenario "As a signed in user I want to express my interest", js: true do
sign_in_user user

click_link "A neat talk"
click_link "A neat talk", match: :first
page.find("#attend").click

expect(page).to have_content 'Thanks for your interest in this session.'
Expand Down

0 comments on commit a80f99b

Please sign in to comment.