Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Paginating job history

  • Loading branch information...
commit 5a63359561b045c806c1be770ba8d3d43e2b68c8 1 parent 0c5e851
@joelmoss joelmoss authored
View
1  Gemfile
@@ -21,6 +21,7 @@ gem 'grit'
gem 'girl_friday'
gem 'dotiw'
gem 'inherited_resources'
+gem 'kaminari'
gem 'simple_form', :git => 'https://github.com/plataformatec/simple_form.git'
group :development, :test do
View
5 Gemfile.lock
@@ -119,6 +119,10 @@ GEM
railties (~> 3.0)
thor (~> 0.14)
json (1.6.3)
+ kaminari (0.13.0)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ railties (>= 3.0.0)
less (2.0.8)
commonjs (~> 0.2.0)
therubyracer (~> 0.9.9)
@@ -256,6 +260,7 @@ DEPENDENCIES
guard-rspec
inherited_resources
jquery-rails
+ kaminari
marked
mysql2
omniauth-github
View
10 app/views/kaminari/_gap.html.erb
@@ -0,0 +1,10 @@
+<%# Non-link tag that stands for skipped pages...
+ - available local variables
+ current_page: a page object for the currently displayed page
+ num_pages: total number of pages
+ per_page: number of items to fetch per page
+ remote: data-remote
+-%>
+<li class="disabled">
+ <%= link_to '...', '#' %>
+</li>
View
12 app/views/kaminari/_next_page.html.erb
@@ -0,0 +1,12 @@
+<!--
+ # Link to the "Next" page
+ # available local variables
+ # url: url to the next page
+ # current_page: a page object for the currently displayed page
+ # num_pages: total number of pages
+ # per_page: number of items to fetch per page
+ # remote: data-remote
+-->
+<li class="next <%= current_page.last? ? ' disabled' : '' %>">
+ <%= link_to raw(t 'views.pagination.next'), (current_page.last? ? '#' : url), :rel => 'next', :remote => remote %>
+</li>
View
13 app/views/kaminari/_page.html.erb
@@ -0,0 +1,13 @@
+<!--
+ # Link showing page number
+ # available local variables
+ # page: a page object for "this" page
+ # url: url to this page
+ # current_page: a page object for the currently displayed page
+ # num_pages: total number of pages
+ # per_page: number of items to fetch per page
+ # remote: data-remote
+-->
+<li class="page<%= ' active' if page.current? %>">
+ <%= link_to page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
+</li>
View
24 app/views/kaminari/_paginator.html.erb
@@ -0,0 +1,24 @@
+<!--
+ # The container tag
+ # available local variables
+ # current_page: a page object for the currently displayed page
+ # num_pages: total number of pages
+ # per_page: number of items to fetch per page
+ # remote: data-remote
+ # paginator: the paginator that renders the pagination tags inside
+-->
+<%= paginator.render do %>
+ <div class="pagination">
+ <ul>
+ <%= prev_page_tag %>
+ <%- each_page do |page| %>
+ <% if page.left_outer? || page.right_outer? || page.inside_window? -%>
+ <%= page_tag page %>
+ <% elsif !page.was_truncated? -%>
+ <%= gap_tag %>
+ <% end -%>
+ <%- end -%>
+ <%= next_page_tag %>
+ </ul>
+ </div>
+<%- end -%>
View
12 app/views/kaminari/_prev_page.html.erb
@@ -0,0 +1,12 @@
+<!--
+ # Link to the "Previous" page
+ # available local variables
+ # url: url to the previous page
+ # current_page: a page object for the currently displayed page
+ # num_pages: total number of pages
+ # per_page: number of items to fetch per page
+ # remote: data-remote
+-->
+<li class="prev <%= current_page.first? ? ' disabled' : '' %>">
+ <%= link_to raw(t 'views.pagination.previous'), (current_page.first? ? '#' : url), :rel => 'prev', :remote => remote %>
+</li>
View
4 app/views/projects/show/_history.html.erb
@@ -18,7 +18,7 @@
</thead>
<tbody>
- <%- resource.jobs.each do |job| -%>
+ <%- resource.jobs.page(params[:page]).each do |job| -%>
<tr>
<td class="small">
<strong><%= time_ago_in_words job.created_at %> ago</strong>
@@ -36,6 +36,8 @@
</tbody>
</table>
+
+ <%= paginate resource.jobs.page(params[:page]) %>
<%- end -%>
Please sign in to comment.
Something went wrong with that request. Please try again.