Skip to content

Commit 68adefa

Browse files
author
Evan Radkoff
committed
Fix point versions (broken deserialization issue). Change UI to not hide the details under a dropdown, and only show what has changed.
1 parent ab1cb50 commit 68adefa

3 files changed

Lines changed: 71 additions & 40 deletions

File tree

app/helpers/application_helper.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,9 @@ def hide_tags(snippet)
9494
).html_safe
9595
end
9696

97-
def format_figures(figure, first: true)
98-
if first
99-
figure.nil? ? 'No changes recorded' : figure.first
100-
else
101-
figure.nil? ? 'No changes recorded' : figure.second
102-
end
97+
def format_version_change(figure, first: true)
98+
return 'No changes recorded' if figure.nil?
99+
100+
first ? figure.first : figure.last
103101
end
104102
end

app/views/points/_table_versions.html.erb

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,55 +2,66 @@
22
<% counter = 1 %>
33
<% @versions.each_with_index do |version, index| %>
44
<% counter += 1 %>
5-
<% event = version.event == "create" ? "Analysis created" : "Analysis updated" %>
5+
<% is_create = version.event == "create" %>
6+
<% event = is_create ? "Analysis created" : "Analysis updated" %>
67
<% title = version.changeset["title"] %>
78
<% analysis = version.changeset["analysis"] %>
89
<% status = version.changeset["status"] %>
10+
911
<% version.changeset['change_reason'].nil? ? reason = "No reason provided for previous changes" : reason = version.changeset["change_reason"].second %>
1012
<div class="panel panel-default" id="panel<%=counter%>">
1113
<div class="panel-heading" id="panel-style">
1214
<div class="row">
13-
<div class="col-sm-4">
15+
<div class="col-sm-6">
1416
<h5>
1517
<b>Version <%= @versions.length - index %>:</b> <%= version.changeset["updated_at"].nil? ? @point.updated_at : version.changeset["updated_at"].second.time %> by <%= username version.whodunnit %> <%= rank_badge version.item.respond_to?(:user) ? version.item.user : version.whodunnit %>
1618
</h5>
1719
</div>
18-
<div class="col-sm-4">
19-
<h5>
20-
<a data-toggle="collapse" data-target="#collapse<%=counter%>"
21-
href="#collapse<%=counter%>" class="collapsed">
22-
<%= event %>
23-
</a>
24-
</h5>
25-
</div>
26-
<div class="col-sm-4 text-right">
27-
<a data-toggle="collapse" data-target="#collapse<%=counter%>"
28-
href="#collapse<%=counter%>" class="collapsed">
29-
<span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span>
30-
</a>
20+
<div class="col-sm-6">
21+
<h5><%= event %></h5>
3122
</div>
23+
</div>
3224
</div>
33-
</div>
34-
<div id="collapse<%=counter%>" class="panel-collapse collapse">
35-
<div class="panel-body">
36-
<div class="row">
37-
<div class="col-sm-6">
38-
<p><b>Previous Title:</b> <%= format_figures(title) %></p>
39-
<p><b>Updated Title:</b> <%= format_figures(title, first: false) %></p>
40-
</div>
41-
<div class="col-sm-6">
42-
<p><b>Previous Analysis:</b> <%= format_figures(analysis) %></p>
43-
<p><b>Updated Analysis:</b> <%= format_figures(analysis, first: false) %></p>
44-
</div>
45-
<div class="col-sm-6">
46-
<p><b>Previous Status:</b> <%= status_badge format_figures(status) %></p>
47-
<p><b>Updated Status:</b> <%= status_badge format_figures(status, first: false) %></p>
48-
</div>
49-
</div>
25+
<div class="panel-body">
26+
<div class="row">
27+
<% if is_create %>
28+
<% if title %>
29+
<div class="col-sm-6">
30+
<p><b>Title:</b> <%= title&.last %></p>
31+
</div>
32+
<% end %>
33+
<% if analysis %>
34+
<div class="col-sm-6">
35+
<p><b>Analysis:</b> <%= analysis&.last %></p>
36+
</div>
37+
<% end %>
38+
<% if status %>
39+
<div class="col-sm-6">
40+
<p><b>Status:</b> <%= status_badge status&.last %></p>
41+
</div>
42+
<% end %>
43+
<% else %>
44+
<% if title %>
45+
<div class="col-sm-6">
46+
<p><b>Previous Title:</b> <%= format_version_change(title) %></p>
47+
<p><b>Updated Title:</b> <%= format_version_change(title, first: false) %></p>
48+
</div>
49+
<% end %>
50+
<% if analysis %>
51+
<div class="col-sm-6">
52+
<p><b>Previous Analysis:</b> <%= format_version_change(analysis) %></p>
53+
<p><b>Updated Analysis:</b> <%= format_version_change(analysis, first: false) %></p>
54+
</div>
55+
<% end %>
56+
<% if status %>
57+
<div class="col-sm-6">
58+
<p><b>Previous Status:</b> <%= status_badge format_version_change(status) %></p>
59+
<p><b>Updated Status:</b> <%= status_badge format_version_change(status, first: false) %></p>
60+
</div>
61+
<% end %>
62+
<% end %>
5063
</div>
5164
</div>
5265
</div>
5366
<% end %>
5467
</div>
55-
</div>
56-

config/initializers/paper_trail.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,25 @@
33
# Association Tracking for PaperTrail has been extracted to a separate gem. To use it, please add `paper_trail-association_tracking` to your Gemfile. If you don't use it (most people don't, that's the default) and you set `track_associations = false` somewhere (probably a rails initializer) you can remove that line now.
44

55
# PaperTrail.config.track_associations = false
6+
7+
# Psych 4 disabled unsafe YAML loading by default, which broke deserialization of existing `object_changes`
8+
# rows in the `versions` table containing ActiveSupport time objects. Permit the classes we store.
9+
module PaperTrail
10+
module Serializers
11+
module YAML
12+
PERMITTED_YAML_CLASSES = [
13+
ActiveSupport::TimeWithZone,
14+
ActiveSupport::TimeZone,
15+
Time,
16+
Date,
17+
DateTime,
18+
Symbol,
19+
BigDecimal
20+
].freeze
21+
22+
def self.load(string)
23+
::YAML.safe_load(string, permitted_classes: PERMITTED_YAML_CLASSES, aliases: true)
24+
end
25+
end
26+
end
27+
end

0 commit comments

Comments
 (0)