Rip out a bunch of very very slow workbench code that doesn't seem to
[arvados.git] / apps / workbench / app / views / projects / _show_dashboard.html.erb
1 <%# Copyright (C) The Arvados Authors. All rights reserved.
2
3 SPDX-License-Identifier: AGPL-3.0 %>
4
5 <%
6   recent_procs = recent_processes(12)
7
8   # preload container_uuids of any container requests
9   recent_crs = recent_procs.map {|p| p if p.is_a?(ContainerRequest)}.compact.uniq
10   recent_cr_containers = recent_crs.map {|cr| cr.container_uuid}.compact.uniq
11   preload_objects_for_dataclass(Container, recent_cr_containers) if recent_cr_containers.andand.any?
12
13   # fetch children of all the active crs in one call, if there are any
14   active_crs = recent_crs.each {|cr| cr if (cr.priority.andand > 0 and cr.state != 'Final' and cr.container_uuid)}
15   active_cr_uuids = active_crs.map(&:uuid)
16   active_cr_containers = active_crs.map {|cr| cr.container_uuid}.compact.uniq
17   cr_children = {}
18   if active_cr_containers.any?
19     active_cr_containers.each { |c| cr_children[c] = []}
20     cols = ContainerRequest.columns.map(&:name) - %w(id updated_at mounts)
21   end
22
23   wus = {}
24   outputs = []
25   recent_procs.each do |p|
26     if p.uuid.in?(active_cr_uuids)
27       wu = p.work_unit(nil, child_objects=cr_children[p.container_uuid])
28     else
29       wu = p.work_unit
30     end
31
32     wus[p] = wu
33     outputs << wu.outputs
34   end
35   outputs = outputs.flatten.uniq
36
37   collection_pdhs = outputs.select {|x| !(m = CollectionsHelper.match(x)).nil?}.uniq.compact
38   collection_uuids = outputs - collection_pdhs
39
40   if Rails.configuration.show_recent_collections_on_dashboard
41     recent_cs = recent_collections(8)
42     collection_uuids = collection_uuids + recent_cs[:collections].collect {|c| c.uuid}
43     collection_uuids.flatten.uniq
44   end
45
46   preload_collections_for_objects collection_uuids if collection_uuids.any?
47   preload_for_pdhs collection_pdhs if collection_pdhs.any?
48   preload_links_for_objects(collection_pdhs + collection_uuids)
49 %>
50
51 <%
52   recent_procs_panel_width = 6
53   if !PipelineInstance.api_exists?(:index)
54     recent_procs_title = 'Recent processes'
55     run_proc_title = 'Choose a workflow to run:'
56     show_node_status = false
57     # Recent processes panel should take the entire width when is the only one
58     # being rendered.
59     if !Rails.configuration.show_recent_collections_on_dashboard
60       recent_procs_panel_width = 12
61     end
62   else
63     recent_procs_title = 'Recent pipelines and processes'
64     run_proc_title = 'Choose a pipeline or workflow to run:'
65     show_node_status = true
66   end
67 %>
68
69   <div class="row">
70     <div class="col-md-<%= recent_procs_panel_width %>">
71       <div class="panel panel-default" style="min-height: 10.5em">
72         <div class="panel-heading">
73           <span class="panel-title"><%=recent_procs_title%></span>
74           <% if current_user.andand.is_active %>
75             <span class="pull-right recent-processes-actions">
76               <span>
77                 <%= link_to(
78                 choose_work_unit_templates_path(
79                   title: run_proc_title,
80                   action_name: 'Next: choose inputs <i class="fa fa-fw fa-arrow-circle-right"></i>',
81                   action_href: work_units_path,
82                   action_method: 'post',
83                   action_data: {'selection_param' => 'work_unit[template_uuid]', 'work_unit[owner_uuid]' => current_user.uuid, 'success' => 'redirect-to-created-object'}.to_json),
84                 { class: "btn btn-primary btn-xs", remote: true }) do %>
85                   <i class="fa fa-fw fa-gear"></i> Run a process...
86                 <% end %>
87               </span>
88               <span>
89                   <%= link_to all_processes_path, class: 'btn btn-default btn-xs' do %>
90                     All processes <i class="fa fa-fw fa-arrow-circle-right"></i>
91                   <% end %>
92               </span>
93             </span>
94           <% end %>
95         </div>
96
97         <div class="panel-body recent-processes">
98           <% if recent_procs.empty? %>
99             No recent pipelines or processes.
100           <% else %>
101           <% wus.each do |p, wu| %>
102             <% if wu.is_finished? %>
103             <div class="dashboard-panel-info-row row-<%=wu.uuid%>">
104               <div class="row">
105                 <div class="col-md-6 text-overflow-ellipsis">
106                   <%= link_to_if_arvados_object p, {friendly_name: true} %>
107                 </div>
108                 <div class="col-md-2">
109                   <span class="label label-<%=wu.state_bootstrap_class%>"><%=wu.state_label%></span>
110                 </div>
111                 <div class="col-md-4">
112                   <%= render_localized_date(wu.finished_at || wu.modified_at, "noseconds") %>
113                 </div>
114               </div>
115               <div class="row">
116                 <div class="col-md-12">
117                   <% if wu.started_at and wu.finished_at %>
118                     <% wu_time = wu.finished_at - wu.started_at %>
119                     Active for <%= render_runtime(wu_time, false) %>
120                   <% end %>
121
122                   <%= render partial: 'work_units/show_output', locals: {wu: wu, align: 'pull-right', include_icon: true} %>
123                 </div>
124               </div>
125
126             </div>
127             <% else %>
128             <div class="dashboard-panel-info-row row-<%=wu.uuid%>">
129               <div class="row">
130                 <div class="col-md-6">
131                   <%= link_to_if_arvados_object p, {friendly_name: true} %>
132                 </div>
133                 <% if wu.is_running? %>
134                 <div class="col-md-6">
135                   <div class="progress" style="margin-bottom: 0px">
136                     <% wu.progress %>
137                   </div>
138                 </div>
139                 <% else %>
140                 <div class="col-md-2">
141                   <span class="label label-<%=wu.state_bootstrap_class%>"><%=wu.state_label%></span>
142                 </div>
143                 <% end %>
144               </div>
145
146               <div class="clearfix">
147                 Started at <%= render_localized_date(wu.started_at || wu.created_at, "noseconds") %>.
148                 <% wu_time = Time.now - (wu.started_at || wu.created_at) %>
149                 Active for <%= render_runtime(wu_time, false) %>.
150
151                 <div class="pull-right">
152                 </div>
153               </div>
154             </div>
155             <% end %>
156           <% end %>
157           <% end %>
158         </div>
159       </div>
160     </div>
161
162     <div class="col-md-6">
163       <% if show_node_status %>
164       <% nodes = Node.filter([["last_ping_at", ">", Time.now - 3600]]).results %>
165       <div class="panel panel-default" style="min-height: 10.5em">
166         <div class="panel-heading"><span class="panel-title">Compute node status</span>
167           <span class="pull-right compute-node-actions">
168             <% if current_user.andand.is_admin %>
169               <span>
170                 <%= link_to nodes_path, class: 'btn btn-default btn-xs' do %>
171                   All nodes <i class="fa fa-fw fa-arrow-circle-right"></i>
172                 <% end %>
173               </span>
174             <% end %>
175           </span>
176         </div>
177         <div class="panel-body compute-node-summary-pane">
178           <div>
179             <%= render partial: 'compute_node_summary', locals: {nodes: nodes} %>
180             <% active_nodes = [] %>
181             <% nodes.sort_by { |n| n.hostname || "" }.each do |n| %>
182               <% if n.crunch_worker_state.in? ["busy", "idle"] %>
183                 <% active_nodes << n %>
184               <% end %>
185             <% end %>
186             <% if active_nodes.any? %>
187               <div style="text-align: center">
188                 <a data-toggle="collapse" href="#compute_node_status">Details <span class="caret"></span></a>
189               </div>
190             <% end %>
191           </div>
192           <div id="compute_node_status" class="collapse">
193             <%= render partial: 'compute_node_status', locals: {nodes: active_nodes} %>
194           </div>
195         </div>
196       </div>
197       <% end %>
198       <% if Rails.configuration.show_recent_collections_on_dashboard %>
199       <div class="panel panel-default">
200         <div class="panel-heading"><span class="panel-title">Recent collections</span>
201           <span class="pull-right">
202             <%= link_to collections_path, class: 'btn btn-default btn-xs' do %>
203               All collections <i class="fa fa-fw fa-arrow-circle-right"></i>
204             <% end %>
205           </span>
206         </div>
207         <div class="panel-body">
208           <% recent_cs[:collections].each do |p| %>
209             <div class="dashboard-panel-info-row">
210               <div>
211                 <% if recent_cs[:owners][p[:owner_uuid]].is_a?(Group) %>
212                 <i class="fa fa-fw fa-folder-o"></i><%= link_to_if_arvados_object recent_cs[:owners][p[:owner_uuid]], friendly_name: true %>/
213                 <% end %>
214                 <span class="pull-right"><%= render_localized_date(p[:modified_at], "noseconds") %></span>
215               </div>
216               <div class="text-overflow-ellipsis" style="margin-left: 1em; width: 100%"><%= link_to_if_arvados_object p, {friendly_name: true, no_tags: true} %>
217               </div>
218             </div>
219           <% end %>
220         </div>
221       </div>
222       <% end %>
223     </div>
224   </div>