* Added support for offset and limit query parameters (?limit=x&offset=y) to workbenc...
[arvados.git] / apps / workbench / app / views / application / _paging.html.erb
1 <% content_for :css do %>
2 .index-paging {
3 text-align: center;
4 padding-left: 1em;
5 padding-right: 1em;
6 background-color: whitesmoke;
7 }
8 <% end %>
9
10 <% if results.result_offset != nil and results.result_limit != nil and results.items_available != nil %>
11 <div class="index-paging">
12
13 <% if results.result_offset > 0 %>
14   <% if results.result_offset > results.result_limit %>
15     <% prev_offset = results.result_offset - results.result_limit %>
16   <% else %>
17     <% prev_offset = 0 %>
18   <% end %>
19 <% else %>
20   <% prev_offset = nil %>
21 <% end %>
22
23 <% this_offset = results.result_offset %>
24 <% this_page = results.result_offset / results.result_limit %>
25
26 <% if (results.result_offset + results.result_limit) < results.items_available %>
27   <% next_offset = results.result_offset + results.result_limit %>
28 <% else %>
29   <% next_offset = nil %>
30 <% end %>
31
32 <span class="pull-left">
33 <% if results.result_offset > 0 %>
34   <%= link_to raw("<span class='glyphicon glyphicon-fast-backward'></span>"), {:id => object, :offset => 0, :limit => results.result_limit}  %>
35 <% else %>
36   <span class='glyphicon glyphicon-fast-backward text-muted'></span>  
37 <% end %>
38
39 <% if prev_offset %>
40   <%= link_to raw("<span class='glyphicon glyphicon-step-backward'></span>"), {:id => object, :offset => prev_offset, :limit => results.result_limit}  %>
41 <% else %>
42 <span class='glyphicon glyphicon-step-backward text-muted'></span>
43 <% end %>
44 </span>
45
46 <% n = this_page - 10 %>
47 <% if n >= 0 %>
48   <% last = this_page + 10 %>
49   &hellip;
50 <% else %>
51   <% n = 0 %>
52   <% last = 20 %>
53 <% end %>
54
55 <% i = n * results.result_limit %>
56 <% while i < results.items_available and n < last %>
57 <% if n != this_page %>
58   <%= link_to "#{n+1}", {:id => @object, :offset => i, :limit => results.result_limit} %>
59 <% else %>
60   <%= n+1 %>
61 <% end %>
62 <% i += results.result_limit %>
63 <% n += 1 %>
64 <% end %>
65
66 <% if i < results.items_available %>
67 &hellip;
68 <% end %>
69
70 <span class="pull-right">
71 <% if next_offset %>
72   <%= link_to raw("<span class='glyphicon glyphicon-step-forward'></span>"), {:id => @object, :offset => next_offset, :limit => results.result_limit}  %>
73 <% else %>
74 <span class='glyphicon glyphicon-forward text-muted'></span>
75 <% end %>
76
77 <% if (results.items_available - results.result_offset) >= results.result_limit %>
78   <%= link_to raw("<span class='glyphicon glyphicon-fast-forward'></span>"), {:id => @object, :offset => results.items_available - (results.items_available % results.result_limit), 
79         :limit => results.result_limit}  %>
80 <% else %>
81   <span class='glyphicon glyphicon-fast-forward text-muted'></span>  
82 <% end %>
83
84 </span>
85
86 </div>
87 <% end %>