Commit 46ac0d8b authored by Tyler Lemburg's avatar Tyler Lemburg
Browse files

Add pagination to reservations view in space home

parent a6408d81
......@@ -6,19 +6,29 @@ get '/:service_space_url_name/?' do
require_login
load_service_space
page = params[:page].to_i
page = 1 if page.nil? || page <= 0
reservations = Reservation.joins(:resource).includes(:event).
where(:resources => {:service_space_id => @space.id}).
where(:user_id => @user.id).
where('end_time >= ?', Time.now).
order(:start_time).all
where('end_time >= ?', Time.now.midnight).
order(:start_time).limit(5).offset((page-1)*5)
total_pages = (Reservation.joins(:resource).includes(:event).
where(:resources => {:service_space_id => @space.id}).
where(:user_id => @user.id).
where('end_time >= ?', Time.now.midnight).count + 4) / 5
events = Event.includes(:event_type).joins(:event_signups).
where(:event_signups => {:user_id => @user.id}, :service_space_id => @space.id).
where('end_time >= ?', Time.now).
where('end_time >= ?', Time.now.midnight).
order(:start_time).all
erb :space_home, :layout => :fixed, :locals => {
:reservations => reservations,
:events => events
:events => events,
:total_pages => total_pages,
:page => page
}
end
\ No newline at end of file
......@@ -40,6 +40,39 @@ You have no upcoming reservations. You can view upcoming trainings to get certif
<% end %>
</tbody>
</table>
<% if total_pages > 1 %>
<script>
WDN.loadCSS(WDN.getTemplateFilePath('css/modules/pagination.css'));
</script>
<div style="text-align: center;">
<div style="display: inline-block;">
<ul class="wdn_pagination" data-tab="pending" style="padding-left: 0;">
<% if page != 1 %>
<li class="arrow prev"><a href="?page=<%= page-1 %>" title="Go to the previous page">← prev</a></li>
<% end %>
<% before_ellipsis_shown = false; after_ellipsis_shown = false %>
<% (1..total_pages).each do |i| %>
<% if i == page %>
<li class="selected"><span><%= i %></span></li>
<% elsif (i <= 3 || i >= total_pages - 2 || i == page - 1 ||
i == page - 2 || i == page + 1 || $i == page + 2) %>
<li><a href="?page=<%= i %>" title="Go to page <%= i %>"><%= i %></a></li>
<% elsif (i < page && !before_ellipsis_shown) %>
<li><span class="ellipsis">...</span></li>
<% before_ellipsis_shown = true %>
<% elsif (i > page && !after_ellipsis_shown) %>
<li><span class="ellipsis">...</span></li>
<% after_ellipsis_shown = true %>
<% end %>
<% end %>
<% if page != total_pages %>
<li class="arrow next"><a href="?page=<%= page+1 %>" title="Go to the next page">next →</a></li>
<% end %>
</ul>
</div>
</div>
<% end %>
<% end %>
<h4>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment