Skip to content

Commit e2ef602

Browse files
committed
Added early support to view BACs
Items list shown for all BACs, colored by success/failure. Only RubyRunner has a special view for the moment.
1 parent 02e8bd5 commit e2ef602

File tree

4 files changed

+144
-1
lines changed

4 files changed

+144
-1
lines changed

BrainPortal/app/controllers/background_activities_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ def show #:nodoc:
4242
@bac = BackgroundActivity.all
4343
@bac = @bac.where(:user_id => current_user.id) if ! current_user.has_role?(:admin_user)
4444
@bac = @bac.find(bac_id)
45-
render :json => @bac.for_api
45+
46+
respond_to do |format|
47+
format.html if current_user.has_role?(AdminUser) # show.html.erb
48+
format.json { render :json => @bac.for_api }
49+
format.any { head :unauthorized }
50+
end
4651
end
4752

4853
# Admin only, HTML only
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
<fieldset>
4+
<legend>Ruby Code</legend>
5+
6+
<% sections = %w( prepare_dynamic_items before_first_item process after_last_item ) %>
7+
8+
<% sections.each do |methodname| %>
9+
<h5><%= methodname %>()</h5>
10+
<pre class="script_preview"><code><%= @bac.options[methodname] %></code></pre>
11+
<p>
12+
<% end %>
13+
</fieldset>
14+

BrainPortal/app/views/background_activities/_background_activity_table.html.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,14 @@
228228
<% end %>
229229
<% end %>
230230

231+
<%
232+
if current_user.has_role? :admin_user
233+
t.column("Show", :show) do |bac|
234+
link_to("Show", background_activity_path(bac), :class => 'action_link')
235+
end
236+
end
237+
%>
238+
231239
<% end %>
232240

233241
<% end %>
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
2+
<%-
3+
#
4+
# CBRAIN Project
5+
#
6+
# Copyright (C) 2008-2025
7+
# The Royal Institution for the Advancement of Learning
8+
# McGill University
9+
#
10+
# This program is free software: you can redistribute it and/or modify
11+
# it under the terms of the GNU General Public License as published by
12+
# the Free Software Foundation, either version 3 of the License, or
13+
# (at your option) any later version.
14+
#
15+
# This program is distributed in the hope that it will be useful,
16+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
# GNU General Public License for more details.
19+
#
20+
# You should have received a copy of the GNU General Public License
21+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
#
23+
-%>
24+
25+
<% title @bac.pretty_name %>
26+
27+
<%= show_table(@bac, :as => :background_activity, :header => "Background Activity") do |t| %>
28+
29+
<% t.cell("Type") do %>
30+
<%= @bac.class.to_s.demodulize %>
31+
<% end %>
32+
33+
<% t.cell("Status") do %>
34+
<%= @bac.status %>
35+
<% end %>
36+
37+
<% t.cell("User") do %>
38+
<%= link_to_user_if_accessible(@bac.user) %>
39+
<% end %>
40+
41+
<% t.cell("Execution Server") do %>
42+
<%= link_to_bourreau_if_accessible(@bac.remote_resource) %>
43+
<% end %>
44+
45+
<% t.cell("Total Number Of Items") do %>
46+
<%= if @bac.is_configured_for_dynamic_items?
47+
"(Dynamic items list)"
48+
elsif @bac.items.size == 0
49+
"(None ?)"
50+
else
51+
@bac.items.size
52+
end
53+
%>
54+
<% end %>
55+
56+
<% t.cell("Number Of Successes") do %>
57+
<%= if @bac.is_configured_for_dynamic_items?
58+
"-"
59+
elsif @bac.num_successes == 0
60+
"0 (None)"
61+
elsif @bac.items.size == @bac.num_successes
62+
"#{@bac.num_successes} (All of them)"
63+
else
64+
@bac.num_successes
65+
end
66+
%>
67+
<% end %>
68+
69+
<% t.cell("Number Of Items Processed") do %>
70+
<%= if @bac.is_configured_for_dynamic_items?
71+
"-"
72+
elsif @bac.current_item == 0
73+
"0 (None yet!)"
74+
elsif @bac.items.size == @bac.current_item
75+
"#{@bac.current_item} (All of them)"
76+
else
77+
@bac.current_item
78+
end
79+
%>
80+
<% end %>
81+
82+
<% t.cell("Number Of Failures") do %>
83+
<%= if @bac.is_configured_for_dynamic_items?
84+
"-"
85+
elsif @bac.num_failures == 0
86+
"0 (None)"
87+
elsif @bac.items.size == @bac.num_failures
88+
"#{@bac.num_failures} (All of them)"
89+
else
90+
@bac.num_failures
91+
end
92+
%>
93+
<% end %>
94+
95+
<% end %>
96+
97+
<% if (!@bac.is_configured_for_dynamic_items? && @bac.items.size > 0) %>
98+
99+
<fieldset>
100+
<legend>Items</legend>
101+
<% bad_hash = @bac.failed_items.index_by(&:itself) %>
102+
<% num_processed = @bac.current_item %>
103+
<%= array_to_table(@bac.items.each_with_index.to_a, :table_class => 'xsimple', :cols => 10) do |(item,i),r,c| %>
104+
<%= i %> :
105+
<%= if i > num_processed
106+
item.to_s
107+
else
108+
red_if(bad_hash[item],item,nil, :color1 => 'green', :color2 => 'red')
109+
end
110+
%>
111+
<% end %>
112+
</fieldset>
113+
114+
<% end %>
115+
116+
<%= (render :partial => "background_activities/#{@bac.class.to_s.demodulize}") rescue nil %>

0 commit comments

Comments
 (0)