Merge remote-tracking branch 'origin/master' into 4031-fix-graph-connections
[arvados.git] / apps / workbench / app / controllers / jobs_controller.rb
index b3204bf64e8d52cd3aa9d31315e0129225ef339d..536518277f1ca86da6256af0887a5be9ee7bc560 100644 (file)
@@ -3,17 +3,25 @@ class JobsController < ApplicationController
   def generate_provenance(jobs)
     return if params['tab_pane'] != "Provenance"
 
-    nodes = []
+    nodes = {}
     collections = []
+    hashes = []
     jobs.each do |j|
-      nodes << j
-      collections << j[:output]
-      collections.concat(ProvenanceHelper::find_collections(j[:script_parameters]))
-      nodes << {:uuid => j[:script_version]}
+      nodes[j[:uuid]] = j
+      hashes << j[:output]
+      ProvenanceHelper::find_collections(j[:script_parameters]) do |hash, uuid|
+        collections << uuid if uuid
+        hashes << hash if hash
+      end
+      nodes[j[:script_version]] = {:uuid => j[:script_version]}
     end
 
     Collection.where(uuid: collections).each do |c|
-      nodes << c
+      nodes[c[:portable_data_hash]] = c
+    end
+
+    Collection.where(portable_data_hash: hashes).each do |c|
+      nodes[c[:portable_data_hash]] = c
     end
 
     @svg = ProvenanceHelper::create_provenance_graph nodes, "provenance_svg", {
@@ -36,7 +44,11 @@ class JobsController < ApplicationController
 
   def cancel
     @object.cancel
-    redirect_to @object
+    if params[:return_to]
+      redirect_to params[:return_to]
+    else
+      redirect_to @object
+    end
   end
 
   def show