Merge branch '2042-new-collection-from-selected-files'
authorPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 10 Mar 2014 21:08:46 +0000 (17:08 -0400)
committerPeter Amstutz <peter.amstutz@curoverse.com>
Mon, 10 Mar 2014 21:08:46 +0000 (17:08 -0400)
14 files changed:
apps/workbench/app/assets/javascripts/editable.js
apps/workbench/app/assets/javascripts/selection.js
apps/workbench/app/assets/stylesheets/application.css.scss
apps/workbench/app/controllers/actions_controller.rb [new file with mode: 0644]
apps/workbench/app/controllers/collections_controller.rb
apps/workbench/app/controllers/jobs_controller.rb
apps/workbench/app/controllers/pipeline_instances_controller.rb
apps/workbench/app/helpers/collections_helper.rb
apps/workbench/app/helpers/provenance_helper.rb
apps/workbench/app/models/collection.rb
apps/workbench/app/views/collections/_show_files.html.erb
apps/workbench/app/views/layouts/application.html.erb
apps/workbench/config/routes.rb
sdk/python/bin/arv-normalize

index adb49d7c15b6628d56729821e618ef534f1b18ba..e37b9444c1615bfd10ce760fa3934f0ab7e76c0d 100644 (file)
@@ -1,6 +1,14 @@
 $.fn.editable.defaults.ajaxOptions = {type: 'put', dataType: 'json'};
 $.fn.editable.defaults.send = 'always';
+
+// Default for editing is popup.  I experimented with inline which is a little
+// nicer in that it shows up right under the mouse instead of nearby.  However,
+// the inline box is taller than the regular content, which causes the page
+// layout to shift unless we make the table rows tall, which leaves a lot of
+// wasted space when not editing.  Also inline can get cut off if the page is
+// too narrow, when the popup box will just move to do the right thing.
 //$.fn.editable.defaults.mode = 'inline';
+
 $.fn.editable.defaults.params = function (params) {
     var a = {};
     var key = params.pk.key;
@@ -14,4 +22,4 @@ $.fn.editable.defaults.validate = function (value) {
     if (value == "***invalid***") {
         return "Invalid selection";
     }
-}
\ No newline at end of file
+}
index 24dc9bd91f81f40f7beee9a263a398dd05e2c220..9213b70a712754ebbb4911519b873334ea474c33 100644 (file)
@@ -40,7 +40,6 @@ jQuery(function($){
     };
 
     var remove_selection_click = function(e) {
-        //remove_selection($(this).attr('name'));
         remove_selection($(this).val());
     };
 
@@ -52,20 +51,22 @@ jQuery(function($){
     var update_count = function(e) {
         var lst = get_selection_list();
         $("#persistent-selection-count").text(lst.length);
-
         if (lst.length > 0) {
-            $('#persistent-selection-list').html('<li><a href="#" class="btn pull-right" id="clear_selections_button">Clear selections</a></li>'
-                                                 +'<li class="notification"><table style="width: 100%"></table></li>');
+            $('#selection-form-content').html(
+                '<li><a href="#" id="clear_selections_button">Clear selections</a></li>'
+                    + '<li><input type="submit" name="combine_selected_files_into_collection" '
+                    + ' id="combine_selected_files_into_collection" '
+                    + ' value="Combine selected collections and files into a new collection" /></li>'
+                    + '<li class="notification"><table style="width: 100%"></table></li>');
+
             for (var i = 0; i < lst.length; i++) {
-                $('#persistent-selection-list > li > table').append("<tr>"
+                $('#selection-form-content > li > table').append("<tr>"
                                                        + "<td>"
-                                                       + "<form>"
-                                                       + "<input class='remove-selection' type='checkbox' value='" + lst[i].uuid + "' checked='true'></input>"
-                                                       + "</form>"
+                                                       + "<input class='remove-selection' name='selection[]' type='checkbox' value='" + lst[i].uuid + "' checked='true' data-stoppropagation='true' />"
                                                        + "</td>"
 
                                                        + "<td>"
-                                                       + "<span style='padding-left: 1em'><a href=\"" + lst[i].href + "\">" + lst[i].name + "</a></span>"
+                                                       + "<div style='padding-left: 1em'><a href=\"" + lst[i].href + "\">" + lst[i].name + "</a></div>"
                                                        + "</td>"
 
                                                        + "<td style=\"vertical-align: top\">"
@@ -75,7 +76,7 @@ jQuery(function($){
                                                        + "</tr>");
             }
         } else {
-            $('#persistent-selection-list').html("<li class='notification empty'>No selections.</li>");
+            $('#selection-form-content').html("<li class='notification empty'>No selections.</li>");
         }
 
         var checkboxes = $('.persistent-selection:checkbox');
@@ -111,6 +112,10 @@ jQuery(function($){
 
 
     $(window).on('load storage', update_count);
+
+    $('#selection-form-content').on("click", function(e) {
+        e.stopPropagation();
+    });
 });
 
 add_form_selection_sources = null;
index f9173898e31757379358c734ad88594070fb8fe9..455e4c0a9fa6cb13553cd121b5c64f427c8fbc90 100644 (file)
@@ -185,10 +185,3 @@ table.table-fixed-header-row tbody {
     overflow-y: auto;
 }
 
-#persistent-selection-list {
-    width: 500px;
-}
-
-#persistent-selection-list li table tr {
-  border-top: 1px solid rgb(221, 221, 221);
-}
diff --git a/apps/workbench/app/controllers/actions_controller.rb b/apps/workbench/app/controllers/actions_controller.rb
new file mode 100644 (file)
index 0000000..74e5831
--- /dev/null
@@ -0,0 +1,99 @@
+class ActionsController < ApplicationController
+
+  skip_before_filter :find_object_by_uuid, only: :post
+
+  def combine_selected_files_into_collection
+    lst = []
+    files = []
+    params["selection"].each do |s|
+      m = CollectionsHelper.match(s)
+      if m and m[1] and m[2]
+        lst.append(m[1] + m[2])
+        files.append(m)
+      end
+    end
+
+    collections = Collection.where(uuid: lst)
+
+    chash = {}
+    collections.each do |c|
+      c.reload()
+      chash[c.uuid] = c
+    end
+
+    combined = ""
+    files.each do |m|
+      mt = chash[m[1]+m[2]].manifest_text
+      if m[4]
+        IO.popen(['arv-normalize', '--extract', m[4][1..-1]], 'w+b') do |io|
+          io.write mt
+          io.close_write
+          while buf = io.read(2**20)
+            combined += buf
+          end
+        end
+      else
+        combined += chash[m[1]+m[2]].manifest_text
+      end
+    end
+
+    normalized = ''
+    IO.popen(['arv-normalize'], 'w+b') do |io|
+      io.write combined
+      io.close_write
+      while buf = io.read(2**20)
+        normalized += buf
+      end
+    end
+
+    require 'digest/md5'
+
+    d = Digest::MD5.new()
+    d << normalized
+    newuuid = "#{d.hexdigest}+#{normalized.length}"
+
+    env = Hash[ENV].
+      merge({
+              'ARVADOS_API_HOST' =>
+              $arvados_api_client.arvados_v1_base.
+              sub(/\/arvados\/v1/, '').
+              sub(/^https?:\/\//, ''),
+              'ARVADOS_API_TOKEN' => Thread.current[:arvados_api_token],
+              'ARVADOS_API_HOST_INSECURE' =>
+              Rails.configuration.arvados_insecure_https ? 'true' : 'false'
+            })
+
+    IO.popen([env, 'arv-put', '--raw'], 'w+b') do |io|
+      io.write normalized
+      io.close_write
+      while buf = io.read(2**20)
+
+      end
+    end
+
+    newc = Collection.new({:uuid => newuuid, :manifest_text => normalized})
+    newc.save!
+
+    chash.each do |k,v|
+      l = Link.new({
+                     tail_kind: "arvados#collection",
+                     tail_uuid: k,
+                     head_kind: "arvados#collection", 
+                     head_uuid: newuuid,
+                     link_class: "provenance",
+                     name: "provided"
+                   })
+      l.save!
+    end
+
+    redirect_to controller: 'collections', action: :show, id: newc.uuid
+  end
+
+  def post
+    if params["combine_selected_files_into_collection"]
+      combine_selected_files_into_collection
+    else
+      redirect_to :back
+    end
+  end
+end
index b6997b97595d59c1f3f905995628e34da381e224..737583a31e68c6d6ab64b40ba298bafe0832dd41 100644 (file)
@@ -102,8 +102,16 @@ class CollectionsController < ApplicationController
     end
     
     Collection.where(uuid: @object.uuid).each do |u|
-      @prov_svg = ProvenanceHelper::create_provenance_graph u.provenance, "provenance_svg", {:direction => :top_down, :combine_jobs => :script_only} rescue nil
-      @used_by_svg = ProvenanceHelper::create_provenance_graph u.used_by, "used_by_svg", {:direction => :top_down, :combine_jobs => :script_only, :pdata_only => true} rescue nil
+      puts request
+      @prov_svg = ProvenanceHelper::create_provenance_graph(u.provenance, "provenance_svg", 
+                                                            {:request => request,
+                                                              :direction => :top_down, 
+                                                              :combine_jobs => :script_only}) rescue nil
+      @used_by_svg = ProvenanceHelper::create_provenance_graph(u.used_by, "used_by_svg", 
+                                                               {:request => request,
+                                                                 :direction => :top_down, 
+                                                                 :combine_jobs => :script_only, 
+                                                                 :pdata_only => true}) rescue nil
     end
   end
 
index d302bffad5359751b213a63afecf4c8dfa39faa9..4705bb5204ed47ec9429901cb701b8ef69c3f984 100644 (file)
@@ -14,7 +14,10 @@ class JobsController < ApplicationController
       nodes << c
     end
 
-    @svg = ProvenanceHelper::create_provenance_graph nodes, "provenance_svg", {:all_script_parameters => true, :script_version_nodes => true}
+    @svg = ProvenanceHelper::create_provenance_graph nodes, "provenance_svg", {
+      :request => request,
+      :all_script_parameters => true, 
+      :script_version_nodes => true}
   end
 
   def index
index e477102985121529455164116a92b0baccef9735..c2a398c9b2b36b2f96505ee13cd8e558ce6c3a5f 100644 (file)
@@ -88,6 +88,7 @@ class PipelineInstancesController < ApplicationController
     provenance, pips = graph(@pipelines)
 
     @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
+      :request => request,
       :all_script_parameters => true, 
       :combine_jobs => :script_and_version,
       :script_version_nodes => true,
@@ -159,6 +160,7 @@ class PipelineInstancesController < ApplicationController
     @pipelines = @objects
 
     @prov_svg = ProvenanceHelper::create_provenance_graph provenance, "provenance_svg", {
+      :request => request,
       :all_script_parameters => true, 
       :combine_jobs => :script_and_version,
       :script_version_nodes => true,
index df0ba22eac92f411ed58a268ccfd5b6a4cb2af8d..7b548dfb84b4ae25a2bbe2e57ffa265d29118277 100644 (file)
@@ -6,6 +6,6 @@ module CollectionsHelper
   end
 
   def self.match(uuid)
-    /^([a-f0-9]{32}(\+[0-9]+)?)(\+.*)?$/.match(uuid.to_s)
+    /^([a-f0-9]{32})(\+[0-9]+)?(\+.*?)?(\/.*)?$/.match(uuid.to_s)
   end
 end
index 8278d37f3ec022525bdfc42b0f2103bdf080e078..c0b2fd36f814d0be75c01343f7b071cdf62fff2e 100644 (file)
@@ -7,13 +7,15 @@ module ProvenanceHelper
       @visited = {}
       @jobs = {}
     end
-
+    
     def self.collection_uuid(uuid)
       m = CollectionsHelper.match(uuid)
       if m
-        #if m[2]
-        return m[1]
-        #else
+        if m[2]
+          return m[1]+m[2]
+        else
+          return m[1]
+        end
         #  Collection.where(uuid: ['contains', m[1]]).each do |u|
         #    puts "fixup #{uuid} to #{u.uuid}"
         #    return u.uuid
@@ -30,11 +32,16 @@ module ProvenanceHelper
     end
 
     def describe_node(uuid)
+      uuid = uuid.to_sym
       bgcolor = determine_fillcolor @opts[:pips][uuid] if @opts[:pips]
 
       rsc = ArvadosBase::resource_class_for_uuid uuid.to_s
       if rsc
-        href = "/#{rsc.to_s.underscore.pluralize rsc}/#{uuid}"
+        href = Rails.application.routes.url_helpers.url_for ({:controller => rsc.to_s.tableize, 
+                                                               :action => :show, 
+                                                               :id => uuid.to_s, 
+                                                               :host => @opts[:request].host, 
+                                                               :port => @opts[:request].port})
       
         #"\"#{uuid}\" [label=\"#{rsc}\\n#{uuid}\",href=\"#{href}\"];\n"
         if rsc == Collection
@@ -44,11 +51,12 @@ module ProvenanceHelper
             #puts "empty!"
             return "\"#{uuid}\" [label=\"(empty collection)\"];\n"
           end
+          puts "#{uuid.class} #{@pdata[uuid]}"
           if @pdata[uuid] 
             #puts @pdata[uuid]
             if @pdata[uuid][:name]
               return "\"#{uuid}\" [label=\"#{@pdata[uuid][:name]}\",href=\"#{href}\",shape=oval,#{bgcolor}];\n"
-            else
+            else              
               files = nil
               if @pdata[uuid].respond_to? :files
                 files = @pdata[uuid].files
@@ -67,6 +75,7 @@ module ProvenanceHelper
                 if i < files.length
                   label += "\\n&vellip;"
                 end
+                #puts "#{uuid} #{label} #{files}"
                 return "\"#{uuid}\" [label=\"#{label}\",href=\"#{href}\",shape=oval,#{bgcolor}];\n"
               end
             end  
@@ -99,7 +108,7 @@ module ProvenanceHelper
         gr = "\"#{head}\" -> \"#{tail}\""
       end
       if extra.length > 0
-        gr += "["
+        gr += " ["
         extra.each do |k, v|
           gr += "#{k}=\"#{v}\","
         end
@@ -209,6 +218,8 @@ module ProvenanceHelper
               gr += edge(job_uuid(job), job[:script_version], {:label => "script_version"})
             end
           end
+        elsif rsc == Link
+          # do nothing
         else
           gr += describe_node(uuid)
         end
@@ -216,8 +227,14 @@ module ProvenanceHelper
 
       @pdata.each do |k, link|
         if link[:head_uuid] == uuid.to_s and link[:link_class] == "provenance"
+          href = Rails.application.routes.url_helpers.url_for ({:controller => Link.to_s.tableize, 
+                                                                 :action => :show, 
+                                                                 :id => link[:uuid], 
+                                                                 :host => @opts[:request].host, 
+                                                                 :port => @opts[:request].port})
+
           gr += describe_node(link[:tail_uuid])
-          gr += edge(link[:head_uuid], link[:tail_uuid], {:label => link[:name], :href => "/links/#{link[:uuid]}"}) 
+          gr += edge(link[:head_uuid], link[:tail_uuid], {:label => link[:name], :href => href}) 
           gr += generate_provenance_edges(link[:tail_uuid])
         end
       end
@@ -230,7 +247,12 @@ module ProvenanceHelper
     def describe_jobs
       gr = ""
       @jobs.each do |k, v|
-        gr += "\"#{k}\" [href=\"/jobs?"
+        href = Rails.application.routes.url_helpers.url_for ({:controller => Job.to_s.tableize, 
+                                                               :action => :index, 
+                                                               :host => @opts[:request].host, 
+                                                               :port => @opts[:request].port})
+
+        gr += "\"#{k}\" [href=\"#{href}?"
         
         n = 0
         v.each do |u|
@@ -241,11 +263,11 @@ module ProvenanceHelper
         gr += "\",label=\""
         
         if @opts[:combine_jobs] == :script_only
-          gr += uuid = "#{v[0][:script]}"
+          gr += "#{v[0][:script]}"
         elsif @opts[:combine_jobs] == :script_and_version
-          gr += uuid = "#{v[0][:script]}"
+          gr += "#{v[0][:script]}" # Just show the name but the nodes will be distinct
         else
-          gr += uuid = "#{v[0][:script]}\\n#{v[0][:finished_at]}"
+          gr += "#{v[0][:script]}\\n#{v[0][:finished_at]}"
         end
         gr += "\",#{determine_fillcolor n}];\n"
       end
@@ -289,8 +311,8 @@ edge [fontsize=10];
     gr += "}"
     svg = ""
 
-    #puts gr
-
+    puts gr
+    
     require 'open3'
 
     Open3.popen2("dot", "-Tsvg") do |stdin, stdout, wait_thr|
index e22a5f72f4a3a062c0fc9b5cc7fa8bb287ba7fe8..6bc55bde3d21199fda4c31fa3143800d9b03c026 100644 (file)
@@ -1,4 +1,5 @@
 class Collection < ArvadosBase
+
   def total_bytes
     if files
       tot = 0
@@ -25,22 +26,4 @@ class Collection < ArvadosBase
     $arvados_api_client.api "collections/#{self.uuid}/", "used_by"
   end
 
-  # def selection_label
-  #   name = ''
-  #   i = 0 
-  #   if self.files.length > 3
-  #     m = 3
-  #   else
-  #     m = self.files.length 
-  #   end
-  #   while i < m
-  #     name += "#{self.files[i][1]}"
-  #     i += 1
-  #     name += ", " if i < m
-  #   end
-  #   if i < self.files.length
-  #     name += "&ellip;"
-  #   end
-  #   name
-  # end
 end
index 705ded388a28ba1837c07f84ef9c4324451dfe9e..956958eddb9fe0785946eb7a36bd0f866e00996e 100644 (file)
     </tr>
   </thead><tbody>
     <% if @object then @object.files.sort_by{|f|[f[0],f[1]]}.each do |file| %>
-    <% file_path = "#{file[0]}/#{file[1]}" %>
-    <tr>
-      <td>
-        <% fp2 = file_path[2..-1] if file_path[0..1] == './' %>
-        <% fp2 ||= file_path %>
-<%= check_box_tag 'uuids[]', @object.uuid+file_path, false, {
-  :class => 'persistent-selection', 
-  :friendly_type => "File",
-  :friendly_name => "#{@object.uuid}/#{fp2}",
-  :href => "#{url_for controller: 'collections', action: 'show', id: @object.uuid }/#{file_path}" 
-      } %>
-      </td>
-      <td>
-        <%= file[0] %>
-      </td>
+      <% f0 = file[0] %>
+      <% f0 = '' if f0 == '.' %>
+      <% f0 = f0[2..-1] if f0[0..1] == './' %>
+      <% f0 += '/' if not f0.empty? %>
+      <% file_path = "#{f0}#{file[1]}" %>
+      <tr>
+        <td>
+          <%= check_box_tag 'uuids[]', @object.uuid+'/'+file_path, false, {
+                :class => 'persistent-selection', 
+                :friendly_type => "File",
+                :friendly_name => "#{@object.uuid}/#{file_path}",
+                :href => "#{url_for controller: 'collections', action: 'show', id: @object.uuid }/#{file_path}" 
+              } %>
+        </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>
+          <%= 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 style="text-align:right">
-        <%= raw(human_readable_bytes_html(file[2])) %>
-      </td>
+        <td style="text-align:right">
+          <%= raw(human_readable_bytes_html(file[2])) %>
+        </td>
 
-      <td>
-        <div style="display:inline-block">
-          <%= link_to raw('<i class="glyphicon glyphicon-download-alt"></i>'), {controller: 'collections', action: 'show_file', uuid: @object.uuid, file: file_path, size: file[2], disposition: 'attachment'}, {class: 'btn btn-info btn-sm', title: 'Download'} %>
-        </div>
-      </td>
-    </tr>
+        <td>
+          <div style="display:inline-block">
+            <%= link_to raw('<i class="glyphicon glyphicon-download-alt"></i>'), {controller: 'collections', action: 'show_file', uuid: @object.uuid, file: file_path, size: file[2], disposition: 'attachment'}, {class: 'btn btn-info btn-sm', title: 'Download'} %>
+          </div>
+        </td>
+      </tr>
     <% end; end %>
   </tbody>
 </table>
index 68f0e109bd3a125a5087f808c93e701812785464..abef47136fd21dd90ae67cf246b51431344ef7b8 100644 (file)
             <span class="badge" id="persistent-selection-count"></span>
             <span class="caret"></span>
           </a>
-          <ul class="dropdown-menu" role="menu" id="persistent-selection-list">
+            <ul class="dropdown-menu" role="menu" id="persistent-selection-list">
+              <%= form_tag '/actions' do %>
+              <div id="selection-form-content"></div>
+              <% end %>
           </ul>
         </li>
 
index 527d6efef5e4a0ed9e058b361fbd3e567a9f88bd..617679eb33b69a48b47ad1a323a8060a8e5dde96 100644 (file)
@@ -34,6 +34,9 @@ ArvadosWorkbench::Application.routes.draw do
   match '/collections/graph' => 'collections#graph'
   resources :collections
   get '/collections/:uuid/*file' => 'collections#show_file', :format => false
+
+  post 'actions' => 'actions#post'
+
   root :to => 'users#welcome'
 
   # Send unroutable requests to an arbitrary controller
index b1a6ca7b42970f100b4badba45f6755aeb4094d8..755b56507289bbf1d5601ed3e9f238523a0dae1e 100755 (executable)
@@ -13,6 +13,8 @@ logger = logging.getLogger(os.path.basename(sys.argv[0]))
 parser = argparse.ArgumentParser(
     description='Read manifest on standard input and put normalized manifest on standard output.')
 
+parser.add_argument('--extract', type=str, help="The file to extract from the input manifest")
+
 args = parser.parse_args()
 
 import arvados
@@ -21,4 +23,17 @@ r = sys.stdin.read()
     
 cr = arvados.CollectionReader(r)
 
-print cr.manifest_text()
+if args.extract:
+    i = args.extract.rfind('/')
+    if i == -1:
+        stream = '.'
+        fn = args.extract
+    else:
+        stream = args.extract[:i]
+        fn = args.extract[(i+1):]
+    for s in cr.all_streams():
+        if s.name() == stream:
+            if fn in s.files():
+                sys.stdout.write(s.files()[fn].as_manifest())
+else:
+    sys.stdout.write(cr.manifest_text())