Moved "size" column to last and added SI order of magnitude suffixes instead of showi...
authorPeter Amstutz <peter.amstutz@curoverse.com>
Tue, 14 Jan 2014 14:17:12 +0000 (09:17 -0500)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Tue, 14 Jan 2014 14:17:12 +0000 (09:17 -0500)
apps/workbench/app/helpers/application_helper.rb
apps/workbench/app/views/collections/show.html.erb

index c67b314cb82e72edbe4b338337bbe63fdd5b741e..37601090f2c7693e04733a4e01164f0b4572ec02 100644 (file)
@@ -13,13 +13,34 @@ module ApplicationHelper
 
   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={})
index 057ced89fd164104f71a329aba5bd300819431d9..0c5795d509d79747b59a87559d6c400e5fc78448 100644 (file)
     <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>