human readable data size
authorTom Clegg <tom@clinicalfuture.com>
Tue, 5 Feb 2013 13:47:58 +0000 (08:47 -0500)
committerTom Clegg <tom@clinicalfuture.com>
Tue, 5 Feb 2013 13:47:58 +0000 (08:47 -0500)
app/assets/stylesheets/application.css
app/helpers/application_helper.rb
app/views/collections/show.html.erb

index ca1f1ea6efd13faebc8bf542053de007d903d19d..0c7cba97b608b98f002b2f2bb51d9d510d316e94 100644 (file)
@@ -27,3 +27,6 @@ table.topalign>thead>tr>td {
     font-size: .8em;
     color: #888;
 }
+table .data-size, .table .data-size {
+    text-align: right;
+}
index d4cc4ec92dc37929fcde6929824b049aab66a960..2bd65bb75d37005762210a70e70e8c9b0b18995c 100644 (file)
@@ -2,4 +2,19 @@ module ApplicationHelper
   def current_user
     controller.current_user
   end
+  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]
+    end
+    cooked = raw + cooked
+    if cooked.length >= 9
+      '<b>' + cooked[0..-9] + '</b>' + cooked[-8..-1]
+    else
+      cooked
+    end
+  end
 end
index 5394541b8f5da25bc3948d4ba79cd1117f09dc87..60443775e322d87479d3d86814e71836f4419339 100644 (file)
@@ -76,7 +76,7 @@
        <tr class="contain-align-left">
          <th>
            collection
-         </th><th>
+         </th><th class="data-size">
            data size
          </th><th>
            protected?
@@ -92,8 +92,8 @@
        <tr class="collection">
          <td>
            <span class="btn"><tt class="deemphasize"><%= sourcedata[:uuid] %></tt></span>
-         </td><td>
-           <%= sourcedata[:collection].data_size if sourcedata[:collection] and sourcedata[:collection].data_size %>
+         </td><td class="data-size">
+           <%= raw(human_readable_bytes_html(18972784837 || sourcedata[:collection].data_size)) if sourcedata[:collection] and sourcedata[:collection].data_size %>
          </td><td>
            <% if sourcedata[:protected] %>
            <span class="btn btn-success">yes</span>