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