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