Merge branch 'master' into 2187-enhance-user-setup
[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 .paging-number {
9 display: inline-block;
10 min-width: 1.2em;
11 }
12 <% end %>
13
14 <% if results.result_offset != nil and results.result_limit != nil and results.items_available != nil %>
15 <div class="index-paging">
16   Displaying <%= results.result_offset+1 %> &ndash; 
17   <%= if results.result_offset + results.result_limit > results.items_available 
18         results.items_available 
19       else 
20         results.result_offset + results.result_limit 
21       end %>
22  out of <%= results.items_available %>
23 </div>
24
25 <% if not (results.result_offset == 0 and results.items_available <= results.result_limit) %>
26   
27 <div class="index-paging">
28
29 <% if results.result_offset > 0 %>
30   <% if results.result_offset > results.result_limit %>
31     <% prev_offset = results.result_offset - results.result_limit %>
32   <% else %>
33     <% prev_offset = 0 %>
34   <% end %>
35 <% else %>
36   <% prev_offset = nil %>
37 <% end %>
38
39 <% this_offset = results.result_offset %>
40
41 <% if (results.result_offset + results.result_limit) < results.items_available %>
42   <% next_offset = results.result_offset + results.result_limit %>
43 <% else %>
44   <% next_offset = nil %>
45 <% end %>
46
47 <span class="pull-left">
48 <% if results.result_offset > 0 %>
49   <%= link_to raw("<span class='glyphicon glyphicon-fast-backward'></span>"), {:id => object, :offset => 0, :limit => results.result_limit}  %>
50 <% else %>
51   <span class='glyphicon glyphicon-fast-backward text-muted'></span>  
52 <% end %>
53
54 <% if prev_offset %>
55   <%= link_to raw("<span class='glyphicon glyphicon-step-backward'></span>"), {:id => object, :offset => prev_offset, :limit => results.result_limit}  %>
56 <% else %>
57 <span class='glyphicon glyphicon-step-backward text-muted'></span>
58 <% end %>
59 </span>
60
61 <% first = this_offset - (10 * results.result_limit) %>
62 <% last = this_offset + (11 * results.result_limit) %>
63
64 <% lastpage_offset = (results.items_available / results.result_limit) * results.result_limit %>
65
66 <% if last > results.items_available %>
67   <% first -= (last - lastpage_offset) %>
68   <% last -= (last - results.items_available) %>
69 <% end %>
70
71 <% if first < 0 %>
72   <% d = -first %>
73   <% first += d %>
74   <% last += d %>
75 <% end %>
76
77 <% last = results.items_available if last > results.items_available %>
78
79 <% i = first %>
80 <% n = first / results.result_limit %>
81
82 <% if first > 0 %>
83 &hellip;
84 <% end %>
85
86 <% while i < last %>
87 <% if i != this_offset %>
88   <%= link_to "#{n+1}", {:id => @object, :offset => i, :limit => results.result_limit}, class: 'paging-number' %>
89 <% else %>
90   <span class="paging-number" style="font-weight: bold;"><%= n+1 %></span>
91 <% end %>
92 <% i += results.result_limit %>
93 <% n += 1 %>
94 <% end %>
95
96 <% if last < results.items_available %>
97 &hellip;
98 <% end %>
99
100 <span class="pull-right">
101 <% if next_offset %>
102   <%= link_to raw("<span class='glyphicon glyphicon-step-forward'></span>"), {:id => @object, :offset => next_offset, :limit => results.result_limit}  %>
103 <% else %>
104 <span class='glyphicon glyphicon-forward text-muted'></span>
105 <% end %>
106
107 <% if (results.items_available - results.result_offset) >= results.result_limit %>
108   <%= link_to raw("<span class='glyphicon glyphicon-fast-forward'></span>"), {:id => @object, :offset => results.items_available - (results.items_available % results.result_limit), 
109         :limit => results.result_limit}  %>
110 <% else %>
111   <span class='glyphicon glyphicon-fast-forward text-muted'></span>  
112 <% end %>
113
114 </span>
115
116 </div>
117
118 <% end %>
119
120 <% end %>