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