Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika@curoverse.com>
[arvados.git] / apps / workbench / app / views / projects / _show_dashboard.html.erb
index 806ed8a7735edb898725ea9744168176d1f02a7c..3be8e374a2977b16ca76b53f3e7de645c4751ea9 100644 (file)
@@ -1,20 +1,90 @@
+<%# Copyright (C) The Arvados Authors. All rights reserved.
+
+SPDX-License-Identifier: AGPL-3.0 %>
+
+<%
+  recent_procs = recent_processes(12)
+
+  # preload container_uuids of any container requests
+  recent_crs = recent_procs.map {|p| p if p.is_a?(ContainerRequest)}.compact.uniq
+  recent_cr_containers = recent_crs.map {|cr| cr.container_uuid}.compact.uniq
+  preload_objects_for_dataclass(Container, recent_cr_containers) if recent_cr_containers.andand.any?
+
+  # fetch children of all the active crs in one call, if there are any
+  active_crs = recent_crs.each {|cr| cr if (cr.priority > 0 and cr.state != 'Final' and cr.container_uuid)}
+  active_cr_uuids = active_crs.map(&:uuid)
+  active_cr_containers = active_crs.map {|cr| cr.container_uuid}.compact.uniq
+  cr_children = {}
+  if active_cr_containers.any?
+    active_cr_containers.each { |c| cr_children[c] = []}
+    cols = ContainerRequest.columns.map(&:name) - %w(id updated_at mounts)
+    reqs = ContainerRequest.select(cols).where(requesting_container_uuid: active_cr_containers).results
+    reqs.each {|cr| cr_children[cr.requesting_container_uuid] << cr} if reqs
+  end
+
+  wus = {}
+  outputs = []
+  recent_procs.each do |p|
+    if p.uuid.in?(active_cr_uuids)
+      wu = p.work_unit(nil, child_objects=cr_children[p.container_uuid])
+    else
+      wu = p.work_unit
+    end
+
+    wus[p] = wu
+    outputs << wu.outputs
+  end
+  outputs = outputs.flatten.uniq
+
+  collection_pdhs = outputs.select {|x| !(m = CollectionsHelper.match(x)).nil?}.uniq.compact
+  collection_uuids = outputs - collection_pdhs
+
+  if Rails.configuration.show_recent_collections_on_dashboard
+    recent_cs = recent_collections(8)
+    collection_uuids = collection_uuids + recent_cs[:collections].collect {|c| c.uuid}
+    collection_uuids.flatten.uniq
+  end
+
+  preload_collections_for_objects collection_uuids if collection_uuids.any?
+  preload_for_pdhs collection_pdhs if collection_pdhs.any?
+  preload_links_for_objects(collection_pdhs + collection_uuids)
+%>
+
+<%
+  recent_procs_panel_width = 6
+  if !PipelineInstance.api_exists?(:index)
+    recent_procs_title = 'Recent processes'
+    run_proc_title = 'Choose a workflow to run:'
+    show_node_status = false
+    # Recent processes panel should take the entire width when is the only one
+    # being rendered.
+    if !Rails.configuration.show_recent_collections_on_dashboard
+      recent_procs_panel_width = 12
+    end
+  else
+    recent_procs_title = 'Recent pipelines and processes'
+    run_proc_title = 'Choose a pipeline or workflow to run:'
+    show_node_status = true
+  end
+%>
+
   <div class="row">
-    <div class="col-md-6">
+    <div class="col-md-<%= recent_procs_panel_width %>">
       <div class="panel panel-default" style="min-height: 10.5em">
         <div class="panel-heading">
-          <span class="panel-title">Recent pipelines and processes</span>
+          <span class="panel-title"><%=recent_procs_title%></span>
           <% if current_user.andand.is_active %>
             <span class="pull-right recent-processes-actions">
               <span>
                 <%= link_to(
                 choose_work_unit_templates_path(
-                  title: 'Choose a pipeline or workflow to run:',
+                  title: run_proc_title,
                   action_name: 'Next: choose inputs <i class="fa fa-fw fa-arrow-circle-right"></i>',
                   action_href: work_units_path,
                   action_method: 'post',
                   action_data: {'selection_param' => 'work_unit[template_uuid]', 'work_unit[owner_uuid]' => current_user.uuid, 'success' => 'redirect-to-created-object'}.to_json),
                 { class: "btn btn-primary btn-xs", remote: true }) do %>
-                  <i class="fa fa-fw fa-gear"></i> Run a pipeline...
+                  <i class="fa fa-fw fa-gear"></i> Run a process...
                 <% end %>
               </span>
               <span>
           <% end %>
         </div>
 
-        <% _recent_processes = recent_processes(12) %>
         <div class="panel-body recent-processes">
-          <% if _recent_processes.empty? %>
+          <% if recent_procs.empty? %>
             No recent pipelines or processes.
           <% else %>
-          <% _recent_processes.each do |p| %>
-            <% wu = p.work_unit %>
+          <% wus.each do |p, wu| %>
             <% if wu.is_finished? %>
             <div class="dashboard-panel-info-row row-<%=wu.uuid%>">
               <div class="row">
     </div>
 
     <div class="col-md-6">
+      <% if show_node_status %>
       <% nodes = Node.filter([["last_ping_at", ">", Time.now - 3600]]).results %>
       <div class="panel panel-default" style="min-height: 10.5em">
         <div class="panel-heading"><span class="panel-title">Compute node status</span>
           </div>
         </div>
       </div>
+      <% end %>
+      <% if Rails.configuration.show_recent_collections_on_dashboard %>
       <div class="panel panel-default">
         <div class="panel-heading"><span class="panel-title">Recent collections</span>
           <span class="pull-right">
           </span>
         </div>
         <div class="panel-body">
-          <% r = recent_collections(8) %>
-          <% r[:collections].each do |p| %>
+          <% recent_cs[:collections].each do |p| %>
             <div class="dashboard-panel-info-row">
               <div>
-                <i class="fa fa-fw fa-folder-o"></i><%= link_to_if_arvados_object r[:owners][p[:owner_uuid]], friendly_name: true %>/
+                <% if recent_cs[:owners][p[:owner_uuid]].is_a?(Group) %>
+                <i class="fa fa-fw fa-folder-o"></i><%= link_to_if_arvados_object recent_cs[:owners][p[:owner_uuid]], friendly_name: true %>/
+                <% end %>
                 <span class="pull-right"><%= render_localized_date(p[:modified_at], "noseconds") %></span>
               </div>
               <div class="text-overflow-ellipsis" style="margin-left: 1em; width: 100%"><%= link_to_if_arvados_object p, {friendly_name: true, no_tags: true} %>
           <% end %>
         </div>
       </div>
+      <% end %>
     </div>
   </div>