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