10079: ajax to display child component details; not working yet.
authorradhika <radhika@curoverse.com>
Tue, 18 Oct 2016 04:24:13 +0000 (00:24 -0400)
committerradhika <radhika@curoverse.com>
Tue, 25 Oct 2016 22:25:40 +0000 (18:25 -0400)
apps/workbench/app/assets/javascripts/work_unit_component.js [new file with mode: 0644]
apps/workbench/app/controllers/work_units_controller.rb
apps/workbench/app/models/proxy_work_unit.rb
apps/workbench/app/models/work_unit.rb
apps/workbench/app/views/work_units/_show_child.html.erb
apps/workbench/app/views/work_units/_show_component.html.erb
apps/workbench/config/routes.rb
apps/workbench/test/integration/jobs_test.rb

diff --git a/apps/workbench/app/assets/javascripts/work_unit_component.js b/apps/workbench/app/assets/javascripts/work_unit_component.js
new file mode 100644 (file)
index 0000000..6c8374b
--- /dev/null
@@ -0,0 +1,17 @@
+$(document).
+    on('click', '.component-detail-panel', function(event) {
+      var href = $($(event.target).attr('href'));
+      if ($(href).attr("class").split(' ').indexOf("in") == -1) {
+        return;   // collapsed; nothing more to do
+      }
+
+      var content_div = href.find('.work-unit-component-detail-body');
+      var content_url = href.attr('content-url');
+      var action_data = href.attr('action-data');
+      $.ajax(content_url, {dataType: 'html', type: 'POST', data: {action_data: action_data}}).
+          done(function(data, status, jqxhr) {
+              content_div.html(data);
+          }).fail(function(jqxhr, status, error) {
+              content_div.html(error);
+          });
+      });
index 6ed25dd334a77b083197c6ad8e39815aa8ea3eba..c0845ee7902fcfe042d5f5a8e5c14e992e5c98a8 100644 (file)
@@ -111,4 +111,29 @@ class WorkUnitsController < ApplicationController
       render_error status: 422
     end
   end
+
+  def show_child_component
+    data = JSON.load(params[:action_data])
+
+    current_obj = data['current_obj']
+    current_obj_type = data['current_obj_type']
+    if current_obj['uuid']
+      resource_class = resource_class_for_uuid current_obj['uuid']
+      obj = object_for_dataclass(resource_class, current_obj['uuid'])
+      current_obj = obj if obj
+    end
+    if current_obj_type == JobWorkUnit.to_s
+      wu = JobWorkUnit.new(current_obj, params['name'])
+    elsif current_obj_type == PipelineInstanceWorkUnit.to_s
+      wu = PipelineInstanceWorkUnit.new(current_obj, params['name'])
+    elsif current_obj_type == ContainerWorkUnit.to_s
+      wu = ContainerWorkUnit.new(current_obj, params['name'])
+    end
+
+    @object ||= arvados_api_client.unpack_api_response data['main_obj'], data['main_obj_kind']
+
+    respond_to do |f|
+      f.html { render(partial: "show_component", locals: {wu: wu}) }
+    end
+  end
 end
index 44905be061d9808d58b34950d9fa0d36edac1bb2..b5349ec595df9163902333b4a893a0a56a784466 100644 (file)
@@ -15,6 +15,10 @@ class ProxyWorkUnit < WorkUnit
     @lbl
   end
 
+  def proxied
+    @proxied
+  end
+
   def uuid
     get(:uuid)
   end
@@ -322,7 +326,7 @@ class ProxyWorkUnit < WorkUnit
     if obj.respond_to? key
       obj.send(key)
     elsif obj.is_a?(Hash)
-      obj[key]
+      obj[key] || obj[key.to_s]
     end
   end
 end
index 0c384bb209d905f0e8d3efa164c79383b0088059..727180ecfa8ab23d02b38a2ffe7f7665606e6c8f 100644 (file)
@@ -5,6 +5,10 @@ class WorkUnit
     # returns the label that was assigned when creating the work unit
   end
 
+  def proxied
+    # returns the proxied object of this work unit
+  end
+
   def uuid
     # returns the arvados UUID of the underlying object
   end
index 0e918be9d9bb01ef6c6c3fd4babcefa17f97bcef..3451923eadd8a34310b949e3d7e5e7ee59e061a3 100644 (file)
@@ -3,7 +3,7 @@
       <div class="row">
         <div class="col-md-3" style="word-break:break-all;">
           <h4 class="panel-title">
-            <a data-toggle="collapse" href="#collapse<%= i %>">
+            <a class="component-detail-panel" data-toggle="collapse" href="#collapse<%= i %>">
               <%= current_obj.label %> <span class="caret"></span>
             </a>
           </h4>
       </div>
   </div>
 
-  <div id="collapse<%= i %>" class="panel-collapse collapse <%= if expanded then 'in' end %>">
-    <div class="panel-body">
-      <%= render partial: 'work_units/show_component', locals: {wu: current_obj} %>
+  <% name = if current_obj.respond_to?('name') then current_obj.name else '' end %>
+  <% kind = if !@object.is_a?(Hash) then ('arvados#' + @object.class.to_s.camelcase(:lower)) else '' end %>
+  <% content_url = url_for(controller: :work_units, action: :show_child_component, name: name) %>
+  <div id="collapse<%=i%>" class="work-unit-component-detail panel-collapse collapse <%= if expanded then 'in' end %>" content-url="<%=content_url%>" action-data="<%={current_obj_type: current_obj.class.to_s, current_obj: current_obj.proxied, main_obj: @object, main_obj_kind: kind}.to_json%>">
+    <div class="panel-body work-unit-component-detail-body">
     </div>
   </div>
 </div>
index 4c0f66095a88251932b6e22febddd64275886256..8f0c2d71eafa351082c5f7756162b928bef496ba 100644 (file)
@@ -41,9 +41,7 @@
   <%= render(partial: "pipeline_instances/show_components_json",
              locals: {error_name: "Unreadable components", backtrace: nil, wu: wu}) %>
 <% else %>
-  <% @descendent_count = 0 if !@descendent_count %>
   <% wu.children.each do |c| %>
-    <% @descendent_count += 1 %>
-    <%= render(partial: 'work_units/show_child', locals: {current_obj: c, i: @descendent_count, expanded: false}) %>
+    <%= render(partial: 'work_units/show_child', locals: {current_obj: c, i: (c.uuid || rand(2**128).to_s(36)), expanded: false}) %>
   <% end %>
 <% end %>
index 7f7854864190318171750cb498a0dc7d941156c9..9bcebbd2749825da1e288805007d1ef5e336bdff 100644 (file)
@@ -16,6 +16,7 @@ ArvadosWorkbench::Application.routes.draw do
   get "all_processes" => 'work_units#index', :as => :all_processes
   get "choose_work_unit_templates" => 'work_unit_templates#choose', :as => :choose_work_unit_templates
   resources :work_units
+  post "show_child_component" => 'work_units#show_child_component'
   resources :nodes
   resources :humans
   resources :traits
index e39d6f4dbf66576df928df93b7cf43030240d3f2..7708ffdc0a42e11e63e7a5f8145e7c2396ef4742 100644 (file)
@@ -154,7 +154,7 @@ class JobsTest < ActionDispatch::IntegrationTest
 
       if readable
         click_link('component1')
-        within('#collapse1') do
+        within('.panel-collapse') do
           assert(has_text? component1['uuid'])
           assert(has_text? component1['script_version'])
           assert(has_text? 'script_parameters')