10645: display collection link with disposition. preload mount and command collections.
authorradhika <radhika@curoverse.com>
Thu, 11 May 2017 12:54:59 +0000 (08:54 -0400)
committerradhika <radhika@curoverse.com>
Thu, 11 May 2017 12:54:59 +0000 (08:54 -0400)
apps/workbench/app/views/application/_show_text_with_locators.html.erb
apps/workbench/app/views/work_units/_component_detail.html.erb
apps/workbench/test/controllers/container_requests_controller_test.rb

index f25bd2b4c91fadd92eafbbb2cea0d68203c362f3..4525c44914aec67830bc37edc49aa4b477ad0778 100644 (file)
@@ -5,12 +5,27 @@
     <% text_data.each_line do |l| %>
       <% text_part = l %>
       <% match = keep_locator_in_json l %>
-      <% if match %>
-        <% text_part = match[1] %>
-        <% rindex = match[2].rindex('"'); match2 = match[2][0..rindex-1] %>
-        <% pdh_readable = object_readable(match2) %>
-        <% quote_char = '"' %>
-      <% end %>
-      <span style="white-space: pre-wrap; margin: none;"><%= text_part %><% if match %><% if pdh_readable then %><%= link_to_arvados_object_if_readable(match[3], match[3], friendly_name: true) %><%= link_to_arvados_object_if_readable(match2, match2, link_text: match[4]) %><% else %><%= match2%><% end %><%=quote_char+match[5]%><br/><% end %></span>
+
+      <%
+        if match
+          text_part = match[1]
+          rindex = match[2].rindex('"'); match2 = match[2][0..rindex-1]
+          quote_char = '"'
+
+          pdh_readable = object_readable(match2)
+          file_link = ''
+          if pdh_readable and match[4].size > 0
+            link_params = {controller: 'collections', action: 'show_file', uuid: match[3], file: match[4][1..-1]}
+            preview_allowed = preview_allowed_for(match[4])
+            if preview_allowed
+              file_link = link_to(raw(match[4]), link_params.merge(disposition: 'inline'))
+            else
+              file_link = link_to(raw(match[4]), link_params.merge(disposition: 'attachment'))
+            end
+          end
+        end
+      %>
+
+      <span style="white-space: pre-wrap; margin: none;"><%= text_part %><% if match %><% if pdh_readable then %><%= link_to_arvados_object_if_readable(match[3], match[3], friendly_name: true) %><%= file_link%><% else %><%= match2%><% end %><%=quote_char+match[5]%><br/><% end %></span>
     <% end %>
   </div>
index 82cd42bc619ef934b27125da9c21d9b12fefce99..55abc75ea622fb22d11ebbba8dd1e3edf18ed6b5 100644 (file)
@@ -3,9 +3,28 @@
   collections_pdhs = collections.select {|x| !CollectionsHelper.match(x).nil?}.uniq.compact
   collections_uuids = collections - collections_pdhs
   preload_collections_for_objects collections_uuids if collections_uuids.any?
-  preload_for_pdhs collections_pdhs if collections_pdhs.any?
+  preload_links_for_objects collections_uuids if collections_uuids.any?
 
   preload_objects_for_dataclass(Repository, [current_obj.repository], :name) if current_obj.repository
+
+  # if container_X, preload mounted collections
+  if @object.is_a? Container or @object.is_a? ContainerRequest
+    # get any collections in mounts
+    mounts = current_obj.send(:mounts) if current_obj.respond_to?(:mounts)
+    input_obj = mounts.andand[:"/var/lib/cwl/cwl.input.json"].andand[:content]
+    if input_obj
+      input_obj.to_s.scan(/([0-9a-f]{32}\+\d+)/).each {|cs| collections_pdhs += cs}
+    end
+
+    command = current_obj.send(:command) if current_obj.respond_to?(:command)
+    if command
+      command.to_s.scan(/([0-9a-f]{32}\+\d+)/).each {|cs| collections_pdhs += cs}
+    end
+  end
+
+  collections_pdhs.compact.uniq
+  preload_for_pdhs collections_pdhs if collections_pdhs.any?
+  preload_links_for_objects collections_pdhs if collections_pdhs.any?
 %>
 
       <div class="container">
index c9e9d2f4eafdc9d74b5a67a3d86bfb130083023c..554aaf6d041324445e1017bdf7e17df94c5b7e0a 100644 (file)
@@ -116,8 +116,8 @@ class ContainerRequestsControllerTest < ActionController::TestCase
     assert_response :success
 
     assert_match /hello/, @response.body
-    assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45%2Ffoo" # mount input1
-    assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45%2Fbar" # mount input2
+    assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/foo" # mount input1
+    assert_includes @response.body, "href=\"\/collections/fa7aeb5140e2848d39b416daeef4ffc5+45/bar" # mount input2
     assert_includes @response.body, "href=\"\/collections/1fd08fc162a5c6413070a8bd0bffc818+150" # mount workflow
     assert_includes @response.body, "href=\"#Log\""
     assert_includes @response.body, "href=\"#Provenance\""