Link to show/download files from collections. refs #1748
authorTom Clegg <tom@curoverse.com>
Thu, 2 Jan 2014 17:41:06 +0000 (09:41 -0800)
committerTom Clegg <tom@curoverse.com>
Thu, 2 Jan 2014 17:41:06 +0000 (09:41 -0800)
apps/workbench/app/controllers/collections_controller.rb
apps/workbench/app/views/collections/show.html.erb

index 3cea60b9d95bbbde9d446e574575971f6baf1320..bf311dd5a971baa1acf10e029dcc70d8bd6023f4 100644 (file)
@@ -48,6 +48,8 @@ class CollectionsController < ApplicationController
     end
     self.response.headers['Content-Type'] =
       Rack::Mime::MIME_TYPES[ext] || 'application/octet-stream'
+    self.response.headers['Content-Length'] = params[:size] if params[:size]
+    self.response.headers['Content-Disposition'] = params[:disposition] if params[:disposition]
     self.response_body = FileStreamer.new opts
   end
 
index 3dc97628c2aed6f15331869a7a72996bbc10dc46..cc8eec352f50941797ebbfb146a62f3f0a79e3a3 100644 (file)
 
 <div class="tab-content">
   <div id="files" class="tab-pane fade in active">
-    <table class="table table-bordered">
+    <table class="table table-bordered" style="table-layout: fixed">
       <thead>
-        <tr><th style="text-align:right">size (bytes)</th><th>filename</th></tr>
+        <tr>
+          <th style="width: 10em; text-align:right">size</th>
+          <th>
+            <div style="width:3.5em; display:inline-block"></div>
+            path
+          </th>
+        </tr>
       </thead><tbody>
-        <% if @object then @object.files.each do |file| %>
+        <% 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] %>/<%= file[1] %>
+            <div style="width:3.5em; 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'} %>
+            <% if file_path.match /\.(txt|pdf|png|jpe?g|gif|tiff?)$/i %>
+            <%= link_to raw('<i class="icon-play"></i>'), {controller: 'collections', action: 'show_file', uuid: @object.uuid, file: file_path, size: file[2], disposition: 'inline'}, {class: 'label label-info', title: 'View in browser'} %>
+            <% end %>
+            </div>
+            <%= file_path %>
           </td>
         </tr>
         <% end; end %>