def human_readable_bytes_html(n)
return h(n) unless n.is_a? Fixnum
- raw = n.to_s
- cooked = ''
- while raw.length > 3
- cooked = ',' + raw[-3..-1] + cooked
- raw = raw[0..-4]
+
+ orders = {
+ 1 => "bytes",
+ 1024 => "KiB",
+ (1024*1024) => "MiB",
+ (1024*1024*1024) => "GiB",
+ (1024*1024*1024*1024) => "TiB"
+ }
+
+ orders.each do |k, v|
+ sig = (n.to_f/k)
+ if sig >=1 and sig < 1024
+ if v == 'bytes'
+ return "%i #{v}" % sig
+ else
+ return "%0.1f #{v}" % sig
+ end
+ end
end
- cooked = raw + cooked
+
+ return h(n)
+ #raw = n.to_s
+ #cooked = ''
+ #while raw.length > 3
+ # cooked = ',' + raw[-3..-1] + cooked
+ # raw = raw[0..-4]
+ #end
+ #cooked = raw + cooked
end
def resource_class_for_uuid(attrvalue, opts={})
<table class="table table-bordered" style="table-layout: fixed">
<thead>
<tr>
- <th style="width: 10em; text-align:right">size</th>
- <th>
- path
- </th>
- <th>
- file
- </th>
- <th style="width:2em">
- </th>
+ <th>path</th>
+ <th>file</th>
+ <th style="width:1.5em">d/l</th>
+ <th style="width: 7em; text-align:right">size</th>
</tr>
</thead><tbody>
<% if @object then @object.files.sort_by{|f|f[1]}.each do |file| %>
<% file_path = "#{file[0]}/#{file[1]}" %>
<tr>
- <td style="text-align:right">
- <%= raw(human_readable_bytes_html(file[2])) %>
- </td>
<td>
<%= file[0] %>
</td>
+
<td>
<%= link_to file[1], {controller: 'collections', action: 'show_file', uuid: @object.uuid, file: file_path, size: file[2], disposition: 'inline'}, {title: 'View in browser'} %>
</td>
+
<td>
<div style="display:inline-block">
<%= link_to raw('<i class="icon-download"></i>'), {controller: 'collections', action: 'show_file', uuid: @object.uuid, file: file_path, size: file[2], disposition: 'attachment'}, {class: 'label label-info', title: 'Download'} %>
</div>
</td>
+
+ <td style="text-align:right">
+ <%= raw(human_readable_bytes_html(file[2])) %>
+ </td>
+
</tr>
<% end; end %>
</tbody>