Skip to content

Commit e155405

Browse files
committed
Write out StrongPresenter
This gem was originally written by Ronald (one of the original authors of this repo) but now looks to be abandoned and definitely doesn't support Rails >= 5.0. We only had one major usage, which I just replaced by generating the table manually, which IMO is more readable anyway.
1 parent 507b89b commit e155405

11 files changed

Lines changed: 72 additions & 124 deletions

File tree

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ gem "whenever", require: false # for cron jobs
2525
gem "tilt"
2626
gem "simple-navigation", "3.11.0"
2727
gem "simple_form", "3.2.1"
28-
gem "strong_presenter", "~> 0.2.2"
2928
gem "render_anywhere"
3029
gem "pygments.rb", "~> 2.0"
3130
gem "ranked-model", "< 0.4.3" # pinned because 0.4.3-0.4.4 are broken (see https://github.com/brendon/ranked-model/issues/139; we also need the fix in https://github.com/brendon/ranked-model/pull/152); we can't update to 0.4.5 yet because it requires activerecord >= 4.2

Gemfile.lock

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ GEM
5151
minitest (~> 5.1)
5252
thread_safe (~> 0.3, >= 0.3.4)
5353
tzinfo (~> 1.1)
54-
addressable (2.8.1)
55-
public_suffix (>= 2.0.2, < 6.0)
54+
addressable (2.8.7)
55+
public_suffix (>= 2.0.2, < 7.0)
5656
afm (0.2.2)
5757
arel (6.0.4)
5858
ast (2.4.3)
@@ -71,15 +71,15 @@ GEM
7171
debug_inspector (>= 0.0.1)
7272
builder (3.2.4)
7373
byebug (9.1.0)
74-
capybara (2.17.0)
74+
capybara (3.9.0)
7575
addressable
7676
mini_mime (>= 0.1.3)
77-
nokogiri (>= 1.3.3)
78-
rack (>= 1.0.0)
79-
rack-test (>= 0.5.4)
80-
xpath (>= 2.0, < 4.0)
81-
capybara-email (2.5.0)
82-
capybara (~> 2.4)
77+
nokogiri (~> 1.8)
78+
rack (>= 1.6.0)
79+
rack-test (>= 0.6.3)
80+
xpath (~> 3.1)
81+
capybara-email (3.0.2)
82+
capybara (>= 2.4, < 4.0)
8383
mail
8484
carrierwave (1.3.2)
8585
activemodel (>= 4.0.0)
@@ -275,7 +275,6 @@ GEM
275275
regexp_parser (2.10.0)
276276
render_anywhere (0.0.12)
277277
rails (>= 3.0.7)
278-
request_store (1.0.8)
279278
responders (2.4.1)
280279
actionpack (>= 4.2.0, < 6.0)
281280
railties (>= 4.2.0, < 6.0)
@@ -366,14 +365,6 @@ GEM
366365
rubocop (= 1.12.1)
367366
rubocop-performance (= 1.10.1)
368367
statsd-ruby (1.5.0)
369-
strong_attributes (0.0.2)
370-
activesupport (>= 3.0)
371-
strong_presenter (0.2.2)
372-
actionpack (>= 3.0)
373-
activemodel (>= 3.0)
374-
activesupport (>= 3.0)
375-
request_store (~> 1.0.3)
376-
strong_attributes (~> 0.0.2)
377368
superfish-rails (1.6.0.1)
378369
test_after_commit (1.2.2)
379370
activerecord (>= 3.2, < 5.0)
@@ -406,8 +397,8 @@ GEM
406397
world-flags (0.6.5)
407398
hashie (>= 1.2)
408399
i18n (>= 0.6)
409-
xpath (2.1.0)
410-
nokogiri (~> 1.3)
400+
xpath (3.2.0)
401+
nokogiri (~> 1.8)
411402
yui-compressor (0.12.0)
412403

413404
PLATFORMS
@@ -463,7 +454,6 @@ DEPENDENCIES
463454
sinatra
464455
spring
465456
standard
466-
strong_presenter (~> 0.2.2)
467457
superfish-rails (~> 1.6.0)
468458
test_after_commit (~> 1.2)
469459
tilt

app/controllers/problems_controller.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ def submit_params
1414
params.require(:submission).permit(*submit_attributes).merge(user_id: current_user.id, problem_id: params[:id])
1515
end
1616

17-
def visible_attributes
18-
visible_attributes = [:linked_name, :input, :output, :memory_limit, :time_limit, :linked_owner, :progress_bar]
19-
visible_attributes << :edit_link if policy(@problem).update?
20-
visible_attributes << :destroy_link if policy(@problem).destroy?
21-
visible_attributes << :test_status if policy(@problem).inspect?
22-
visible_attributes
23-
end
24-
2517
def index
2618
raise Pundit::NotAuthorizedError if current_user.nil?
2719
case params[:filter].to_s
@@ -34,8 +26,6 @@ def index
3426
end
3527
@problems = @problems.order(id: :desc)
3628
authorize @problem, :update?
37-
38-
@problems_presenter = ProblemPresenter::Collection.new(@problems).permit!(*visible_attributes)
3929
end
4030

4131
def show

app/helpers/problems_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,18 @@ def markdown_parse(str, relative_root: request.path + "/")
4040
end
4141
content.to_s.html_safe
4242
end
43+
44+
def test_status(problem)
45+
colour = case problem.test_status
46+
when -1 then "#FF0000"
47+
when -2 then "#FF8000"
48+
when 0 then "#808080"
49+
when 1 then "#FFFF00"
50+
when 2 then "#80FF00"
51+
when 3 then "#00C000"
52+
else; "#808080"
53+
end
54+
55+
content_tag :div, " ", style: "border-radius: 50%; width: 15px; height: 15px; background-color: #{colour}; display: inline-block"
56+
end
4357
end

app/presenters/application_presenter.rb

Lines changed: 0 additions & 19 deletions
This file was deleted.

app/presenters/problem_presenter.rb

Lines changed: 0 additions & 48 deletions
This file was deleted.

app/views/importers/problem_series/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
</td>
7373
<td>
7474
<% if !imported_problem.nil? %>
75-
<%= ProblemPresenter.new(imported_problem).test_status %>
75+
<%= test_status(imported_problem) %>
7676
<%= link_to imported_problem.try(:name), problem_path(problem[:problem_id]) %>
7777
(<%= imported_problem.problem_set_associations.detect{|psa| psa.problem_set_id == issue[:problem_set_id].to_i}.try(:weighting) %>)
7878
<%= imported_problem.memory_limit || '?' %> MB, <%= imported_problem.time_limit || '?' %> s

app/views/problem_sets/_item.html.erb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@
2727
<tbody>
2828
<% problems.each do |problem| %>
2929
<tr>
30-
<td width="100%">&nbsp;&nbsp;&nbsp;<%= ProblemPresenter.new(problem).test_status + "&nbsp;".html_safe if policy(problem).inspect? %><%= link_to problem.name, problem %></td>
30+
<td width="100%">&nbsp;&nbsp;&nbsp;
31+
32+
<% if policy(problem).inspect? %>
33+
<%= test_status(problem) %>
34+
&nbsp;
35+
<% end %>
36+
37+
<%= link_to problem.name, problem %>
38+
</td>
39+
3140
<td>
3241
<%= weighted ? progress_bar(problem.weighted_score, problem.weighting) : progress_bar(problem.weighted_score) %>
3342
</td>

app/views/problems/index.html.erb

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,49 @@
11
<% content_for :title, "Problems" %>
22
<% toolbox_push :new, new_problem_path if policy(Problem).create? %>
33

4-
<% columns = {:test_status => "",
5-
:linked_name => "Name",
6-
:input => "Input",
7-
:output => "Output",
8-
:memory_limit => "Memory Limt",
9-
:time_limit => "Time Limit",
10-
:linked_owner => "Owner",
11-
:progress_bar => "Progress",
12-
:edit_link => "",
13-
:destroy_link => ""} %>
144
<table class="main_table">
155
<thead>
166
<tr>
17-
<% @problems_presenter.select_permitted(*columns.keys).each do |key| %>
18-
<th><%= columns[key] %></th>
19-
<% end %>
7+
<% if policy(Problem.new).inspect? %><th></th><% end %>
8+
<th>Name</th>
9+
<th>Input</th>
10+
<th>Output</th>
11+
<th>Memory limit</th>
12+
<th>Time limit</th>
13+
<th>Owner</th>
14+
<th>Progress</th>
15+
<% if policy(Problem.new).update? %><th></th><% end %>
16+
<% if policy(Problem.new).destroy? %><th></th><% end %>
2017
</tr>
2118
</thead>
19+
2220
<tbody>
23-
<% @problems_presenter.each do |problem_presenter| %>
24-
<tr>
25-
<% problem_presenter.presents(*columns.keys).each do |value| %>
26-
<%= content_tag :td, value %>
21+
<% @problems.each do |problem| %>
22+
<tr>
23+
<% if policy(problem).inspect? %>
24+
<td><%= test_status(problem) %></td>
25+
<% end %>
26+
27+
<td><%= link_to(problem.name, problem) %></td>
28+
<td><%= problem.input || "stdin" %></td>
29+
<td><%= problem.output || "stdout" %></td>
30+
<td><%= problem.memory_limit %> MB</td>
31+
<td><%= problem.time_limit %> s</td>
32+
<td><%= link_to(problem.owner.username, problem.owner) if problem.owner.present? %></td>
33+
<td><%= progress_bar(problem.score) if problem.score %></td>
34+
35+
<% if policy(problem).update? %>
36+
<td><%= link_to("Edit", problem_path(problem)) %></td>
37+
<% end %>
38+
39+
<% if policy(problem).destroy? %>
40+
<td>
41+
<%= link_to("Destroy", problem_path(problem), method: :delete, data: { confirm: "Are you sure?" }) %>
42+
</td>
43+
<% end %>
44+
</tr>
2745
<% end %>
28-
</tr>
29-
<% end %>
3046
</tbody>
3147
</table>
3248

3349
<br />
34-

spec/features/problem_browsing_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
headers = find(".main_table > thead > tr").all("th").map(&:text)
1313
rows = find(".main_table > tbody").all("tr").map { |r| r.all("td").map(&:text) }
14-
expect(headers).to eq(["", "Name", "Input", "Output", "Memory Limt", "Time Limit", "Owner", "Progress", "", ""])
14+
expect(headers).to eq(["", "Name", "Input", "Output", "Memory limit", "Time limit", "Owner", "Progress", "", ""])
1515
expect(rows.length).to eq(Problem.count)
1616

1717
expect(rows[0]).to eq(["", problem.name, problem.input, problem.output, "1 MB", "1.0 s", "System", "", "Edit", "Destroy"])

0 commit comments

Comments
 (0)