Fix dashboard auto-refresh, and show last line of log_buffer (if any)
[arvados.git] / apps / workbench / app / views / users / _tables.html.erb
1 <% if current_user.andand.is_active %>
2   <div>
3     <strong>Recent jobs</strong>
4     <%= link_to '(refresh)', request.fullpath, class: 'refresh', remote: true, method: 'get' %>
5     <%= link_to raw("Show all jobs &rarr;"), jobs_path, class: 'pull-right' %>
6     <% if not current_user.andand.is_active or @my_jobs.empty? %>
7       <p>(None)</p>
8     <% else %>
9       <table class="table table-bordered table-condensed table-fixedlayout">
10         <colgroup>
11           <col width="20%" />
12           <col width="20%" />
13           <col width="20%" />
14           <col width="13%" />
15           <col width="27%" />
16         </colgroup>
17
18         <tr>
19           <th>Script</th>
20           <th>Output</th>
21           <th>Log</th>
22           <th>Age</th>
23           <th>Status</th>
24         </tr>
25
26         <% @my_jobs[0..6].each do |j| %>
27           <tr>
28             <td>
29               <small>
30                 <%= link_to j.script[0..31], job_path(j.uuid) %>
31               </small>
32             </td>
33
34             <td>
35               <small>
36                 <% if j.success %>
37
38                   <a href="<%= collection_path(j.output) %>">
39                     <% Collection.limit(1).where(uuid: j.output).each do |c| %>
40                          <% c.files.each do |file| %>
41                       <%= file[0] == '.' ? file[1] : "#{file[0]}/#{file[1]}" %>
42                     <% end %>
43                 <% end %>
44                 </a>
45
46         <% end %>
47         </small>
48 </td>
49
50 <td>
51   <small>
52     <% if j.log %>
53       <% Collection.limit(1).where(uuid: j.log).each do |c| %>
54         <% c.files.each do |file| %>
55           <a href="<%= collection_path(j.log) %>/<%= file[1] %>?disposition=inline&size=<%= file[2] %>">Log</a>
56         <% end %>
57       <% end %>
58     <% elsif j.respond_to? :log_buffer and j.log_buffer %>
59       <% buf = j.log_buffer.strip.split("\n").last %>
60       <span title="<%= buf %>"><%= buf %></span>
61     <% end %>
62   </small>
63 </td>
64
65 <td>
66   <small>
67     <%= raw(distance_of_time_in_words(j.created_at, Time.now).sub('about
68 ','~').sub(' ','&nbsp;')) if j.created_at %>
69   </small>
70 </td>
71
72 <td>
73   <% if j.success %>
74     <span class="label label-success">finished</span>
75   <% elsif j.success == false %>
76     <span class="label label-danger">failed</span>
77   <% elsif j.finished_at %>
78     <span class="label">finished?</span>
79   <% elsif j.started_at %>
80     <span class="label label-success">running</span>
81   <% else %>
82     <span class="label">queued</span>
83   <% end %>
84   <% percent_total_tasks = 100 / (j.tasks_summary[:running] + j.tasks_summary[:done] + j.tasks_summary[:todo]) rescue 0 %>
85   <div class="inline-progress-container pull-right">
86     <div class="progress">
87       <span class="progress-bar progress-bar-success" style="width: <%= j.tasks_summary[:done] * percent_total_tasks rescue 0 %>%;">
88       </span>
89       <span class="progress-bar" style="width: <%= j.tasks_summary[:running] * percent_total_tasks rescue 0 %>%;">
90       </span>
91       <% if j.success == false %>
92       <span class="progress-bar progress-bar-danger" style="width: <%= tasks_summary[:failed] * percent_total_tasks rescue 0 %>%;">
93       </span>
94       <% end %>
95     </div>
96   </div>
97 </td>
98
99 </tr>
100 <% end %>
101 </table>
102 <% end %>
103 </div>
104
105 <div>
106   <strong>Recent pipeline instances</strong>
107   <%= link_to '(refresh)', request.fullpath, class: 'refresh', remote: true, method: 'get' %>
108   <%= link_to raw("Show all pipeline instances &rarr;"), pipeline_instances_path, class: 'pull-right' %>
109   <% if not current_user.andand.is_active or @my_pipelines.empty? %>
110     <p>(None)</p>
111   <% else %>
112     <table class="table table-bordered table-condensed table-fixedlayout">
113       <colgroup>
114         <col width="30%" />
115         <col width="30%" />
116         <col width="13%" />
117         <col width="27%" />
118       </colgroup>
119
120       <tr>
121         <th>Instance</th>
122         <th>Template</th>
123         <th>Age</th>
124         <th>Status</th>
125       </tr>
126
127       <% @my_pipelines[0..6].each do |p| %>
128         <tr>
129           <td>
130             <small>
131               <%= link_to_if_arvados_object p.uuid, friendly_name: true %>
132             </small>
133           </td>
134
135           <td>
136             <small>
137               <%= link_to_if_arvados_object p.pipeline_template_uuid, friendly_name: true %>
138             </small>
139           </td>
140
141           <td>
142             <small>
143               <%= raw(distance_of_time_in_words(p.created_at, Time.now).sub('about
144 ','~').sub(' ','&nbsp;')) if p.created_at %>
145             </small>
146           </td>
147
148           <td>
149             <% if p.success %>
150               <span class="label label-success">finished</span>
151             <% elsif p.success == false %>
152               <span class="label label-danger">failed</span>
153             <% elsif p.active and p.modified_at < 30.minutes.ago %>
154               <span class="label label-info">stopped</span>
155             <% elsif p.active %>
156               <span class="label label-info">running</span>
157             <% else %>
158               <span class="label">queued</span>
159             <% end %>
160
161             <% summary = pipeline_summary p %>
162             <div class="inline-progress-container pull-right">
163               <div class="progress">
164                 <span class="progress-bar progress-bar-success" style="width: <%= summary[:percent_done] %>%;">
165                 </span>
166                 <% if p.success == false %>
167                 <span class="progress-bar progress-bar-danger" style="width: <%= 100.0 - summary[:percent_done] %>%;">
168                 </span>
169                 <% else %>
170                 <span class="progress-bar" style="width: <%= summary[:percent_running] %>%;">
171                 </span>
172                 <span class="progress-bar progress-bar-info" style="width: <%= summary[:percent_queued] %>%;">
173                 </span>
174                 <span class="progress-bar progress-bar-danger" style="width: <%= summary[:percent_failed] %>%;">
175                 </span>
176                 <% end %>
177               </div>
178             </div>
179           </td>
180
181         </tr>
182       <% end %>
183     </table>
184   <% end %>
185 </div>
186
187 <div>
188   <strong>Recent collections</strong>
189   <%= link_to '(refresh)', request.fullpath, class: 'refresh', remote: true, method: 'get' %>
190   <%= link_to raw("Show all collections &rarr;"), collections_path, class: 'pull-right' %>
191   <div class="pull-right" style="padding-right: 1em; width: 30%;">
192     <%= form_tag collections_path,
193           method: 'get',
194           class: 'form-search small-form-margin' do %>
195     <div class="input-group input-group-sm">
196       <%= text_field_tag :search, params[:search], class: 'form-control', placeholder: 'Search' %>
197       <span class="input-group-btn">
198         <%= button_tag(class: 'btn btn-info') do %>
199         <span class="glyphicon glyphicon-search"></span>
200         <% end %>
201       </span>
202     </div>  
203     <% end %>
204   </div>
205   <% if not current_user.andand.is_active or @my_collections.empty? %>
206     <p>(None)</p>
207   <% else %>
208     <table class="table table-bordered table-condensed table-fixedlayout">
209       <colgroup>
210         <col width="46%" />
211         <col width="27%" />
212         <col width="27%" />
213       </colgroup>
214
215       <tr>
216         <th>Contents</th>
217         <th>Tags</th>
218         <th>Age</th>
219       </tr>
220
221       <% @my_collections[0..6].each do |c| %>
222         <tr>
223           <td>
224             <small>
225               <a href="<%= collection_path(c.uuid) %>">
226                 <% c.files.each do |file| %>
227                   <%= file[0] == '.' ? file[1] : "#{file[0]}/#{file[1]}" %>
228                 <% end %>
229               </a>
230             </small>
231           </td>
232           <td>
233             <% if @my_tag_links[c.uuid] %>
234             <small>
235               <%= @my_tag_links[c.uuid].collect(&:name).join(", ") %>
236             </small>
237             <% end %>
238           </td>
239           <td>
240             <small>
241               <%= raw(distance_of_time_in_words(c.created_at, Time.now).sub('about
242 ','~').sub(' ','&nbsp;')) if c.created_at %>
243             </small>
244           </td>
245         </tr>
246       <% end %>
247     </table>
248   <% end %>
249 </div>
250
251 <% else %>
252   <%= image_tag "dax.png", style: "max-width=40%" %>
253 <% end %>
254
255 <% content_for :js do %>
256 setInterval(function(){$('a.refresh:eq(0)').click()}, 60000);
257 <% end %>