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