Skip to content

Commit 798e78d

Browse files
author
Christopher Talib
authored
Merge pull request #283 from tosdr/versions-formatting-ux
Versions formatting ux
2 parents 86f8549 + a920675 commit 798e78d

File tree

11 files changed

+166
-139
lines changed

11 files changed

+166
-139
lines changed

app/assets/stylesheets/components/_index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
@import "sort_button";
1111
@import "tabs";
1212
@import "service_title";
13+
@import "versions";
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#panel-style {
2+
background: white;
3+
4+
&:hover {
5+
transform: translateY(-5px);
6+
}
7+
}

app/assets/stylesheets/pages/_point.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
padding: 15px;
3939
}
4040

41+
.p30 {
42+
padding: 30px;
43+
}
44+
4145
.pl15 {
4246
padding-left: 15px;
4347
}
@@ -88,4 +92,12 @@
8892
padding: 15px;
8993
}
9094

95+
.fl {
96+
float: left;
97+
}
98+
99+
.fr {
100+
float: right;
101+
}
102+
91103

app/controllers/points_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def show
4242
@point
4343
puts @point.id
4444
@comments = Comment.where(point_id: @point.id)
45+
@versions = @point.versions
46+
@reaons = @point.reasons
4547
end
4648

4749
def update

app/helpers/application_helper.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
11
module ApplicationHelper
2+
3+
def format_time(time)
4+
time.strftime("%d/%m/%y - %H:%M")
5+
end
6+
7+
def format_figures(figure, first = true)
8+
if first
9+
figure.nil? ? "No changes recorded" : figure.first
10+
else
11+
figure.nil? ? "No changes recorded" : figure.second
12+
end
13+
end
214
end

app/models/point.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ def self.search_points_by_topic(query)
2121
Point.joins(:topic).where("topics.title ILIKE ?", "%#{query}%")
2222
end
2323

24+
# VOTE CONTROLLER ! TODO
25+
# def has_voted(point)
26+
# Vote.where(point_id: point.id, user_id: current_user.id)
27+
# end
28+
2429
def rating_for_table
2530
pointbox = if self.rating.between?(7, 10)
2631
"point-good"

app/views/layouts/application.html.erb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@
3636
<%= yield %>
3737
</div>
3838
<%= render "shared/footer" %>
39-
39+
<%= javascript_include_tag 'application' %>
4040
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
4141
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
4242
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
4343
</body>
44-
4544
</body>
4645
</html>
Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,56 @@
1-
<div class="article-holder status-changes">
2-
3-
<!-- <table class="table">
4-
<thead class="thead thead-dark">
5-
<th scope="col">STATUS UPDATES</th>
6-
<th scope="col">REASON</th>
7-
<th scope="col">WHEN</th>
8-
</thead>
9-
<tbody>
10-
<% @point.reasons.each do |reason| %>
11-
<tr>
12-
<th scope="row"><%= reason.status %></th>
13-
<td><%= reason.content %></td>
14-
<td><%= time_ago_in_words reason.created_at %> ago</td>
15-
</tr>
16-
</tbody>
17-
<% end %>
18-
</table> -->
19-
20-
<table class="table">
21-
<thead class="thead thead-dark">
22-
<th scope="col">ANALYSIS UPDATES</th>
23-
<th scope="col">TEXT CHANGES</th>
24-
<th scope="col">WHEN</th>
25-
<!-- <th scope="col">WHO</th> -->
26-
</thead>
27-
<tbody>
28-
<% @point.versions.each do |v| %>
29-
<tr>
30-
<th scope="row"><%= v.event %></th>
31-
<td>
32-
<% if v.changeset["analysis"] %>
33-
Analysis change: <%= v.changeset["analysis"] %>
34-
<% elsif v.changeset["status"] %>
35-
Status change: <%= v.changeset["status"] %>
36-
<% else %>
37-
No changes recorded
38-
<% end %>
39-
</td>
40-
<td><%= v.changeset["updated_at"] %></td>
41-
<!-- make a better view for username <td><%= v.whodunnit %></td> -->
42-
</tr>
43-
<% end %>
44-
</tbody>
45-
</table>
1+
<div class="panel-group" id="accordion">
2+
<% counter = 1 %>
3+
<% @versions.each do |version| %>
4+
<% event = version.event == "create" ? "Analysis created" : "Analysis updated" %>
5+
<% analysis = version.changeset["analysis"] %>
6+
<% status = version.changeset["status"] %>
7+
<% version.changeset['reason'].nil? ? reason = "No reason provided for previous changes" : reason = version.changeset["reason"].second %>
8+
<% counter += 1 %>
9+
<div class="panel panel-default" id="panel<%=counter%>">
10+
<div class="panel-heading" id="panel-style">
11+
<div class="row">
12+
<div class="col-sm-4">
13+
<h5>
14+
<b>Version <%= counter - 1 %>:</b> <%= format_time(version.changeset["updated_at"].second.time) %>
15+
</h5>
16+
</div>
17+
<div class="col-sm-4">
18+
<h5>
19+
<a data-toggle="collapse" data-target="#collapse<%=counter%>"
20+
href="#collapse<%=counter%>" class="collapsed">
21+
<%= event %>
22+
</a>
23+
</h5>
24+
</div>
25+
<div class="col-sm-4 text-right">
26+
<a data-toggle="collapse" data-target="#collapse<%=counter%>"
27+
href="#collapse<%=counter%>" class="collapsed">
28+
<span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span>
29+
</a>
30+
</div>
31+
</div>
32+
</div>
33+
<div id="collapse<%=counter%>" class="panel-collapse collapse">
34+
<div class="panel-body">
35+
<div class="row">
36+
<div class="col-sm-12 mb15">
37+
<p><b>Reason for changes:</b> <%= reason %></p>
38+
</div>
39+
</div>
40+
<div class="row">
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> <%= format_figures(status) %></p>
47+
<p><b>Updated Status:</b> <%= format_figures(status, first = false) %></p>
48+
</div>
49+
</div>
50+
</div>
51+
</div>
52+
</div>
53+
<% end %>
4654
</div>
55+
</div>
56+

app/views/points/show.html.erb

Lines changed: 63 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,78 @@
1-
<div class="point-holder">
2-
3-
<div class="article-holder">
4-
<div class="article-point-header">
5-
<ul class="point-info">
6-
<li class="point-items">
7-
<div class="pl50">
8-
<span class="bolder">Service:</span> <%= @point.service.name %>
9-
</div>
10-
<div class="pl50">
11-
<span class="bolder">Status:</span> <%= @point.status %>
12-
</div>
13-
<div class="pl50">
14-
<span class="bolder">Rating:</span> <%= @point.rating %>
15-
</div>
16-
<div class="pl50">
17-
<span class="bolder">Changes:</span> <%= @point.versions.size %>
18-
</div>
19-
</li>
20-
</ul>
21-
</div>
1+
<div class="row">
2+
<div class="col-sm-6">
3+
<h4 class="lighter fl"><%= @point.title %></h4>
224
</div>
23-
24-
<div class="article-holder">
25-
26-
<div class="article-point-header">
27-
<h3 class="lighter"><%= @point.title %></h3>
28-
</div>
29-
30-
<div class="article-point-text-holder p15">
31-
<div class="article-point-text pad-left pad-right">
32-
<span class="bolder">Analysis:</span> <%= @point.analysis %>
33-
</div>
5+
<div class="col-sm-6">
6+
<% if current_user %>
7+
<% if current_user.curator %>
8+
<div class="dropdown btn-group fr">
9+
<a class="btn btn-primary dropdown-toggle" data-toggle="dropdown" href="#">
10+
Update Point
11+
<span class="caret"></span>
12+
</a>
13+
<ul class="dropdown-menu">
14+
<li><%= link_to 'Edit Content', edit_point_path(@point) %></li>
15+
<li><%= link_to 'Update Status', new_point_reason_path(@point) %></li>
16+
<li>
17+
<% if @point.status == "approved" %>
18+
<% if !@point.is_featured? %>
19+
<%= link_to 'Feature', featured_point_path(@point), method: :put%>
20+
<% else %>
21+
<%= link_to 'Un-Feature', featured_point_path(@point), method: :put %>
22+
<% end %>
23+
<% end %>
24+
</li>
25+
<li>
26+
<%= link_to 'Delete Point', @point, method: :delete %>
27+
</li>
28+
</ul>
3429
</div>
35-
30+
<% end %>
31+
<% end %>
3632
</div>
33+
</div>
3734

38-
<% if @point.reasons.any? || @point.versions.any? %>
39-
<%= render 'table_reasons' %>
40-
<% end %>
41-
42-
<div class="m15 mw6">
43-
<ul class="point-info">
44-
<li class="point-items">
35+
<br>
4536

46-
<% unless current_user.nil? %>
37+
<div class="row">
38+
<div class="col-sm-3">
39+
<span class="bolder">Service:</span> <%= @point.service.name %>
40+
</div>
41+
<div class="col-sm-3">
42+
<span class="bolder">Status:</span> <%= @point.status %>
43+
</div>
44+
<div class="col-sm-3">
45+
<span class="bolder">Rating:</span> <%= @point.rating %>
46+
</div>
47+
<div class="col-sm-3">
48+
<span class="bolder">Changes:</span> <%= @point.versions.size %>
49+
</div>
50+
</div>
4751

48-
<% if current_user.curator? %>
52+
<br>
53+
<br>
4954

50-
<div class="pl15">
51-
<%= link_to 'Update Status', new_point_reason_path(@point), class: 'btn btn-primary' %>
52-
</div>
53-
<div class="pl15">
54-
<%= link_to 'Edit Point', edit_point_path(@point), class: 'btn btn-primary' %>
55-
</div>
56-
<div class="pl15">
57-
<% if @point.status == "approved" %>
58-
<% if !@point.is_featured? %>
59-
<%= link_to 'Feature', featured_point_path(@point), method: :put, class: 'btn btn-primary' %>
60-
<% else %>
61-
<%= link_to 'Un-Feature', featured_point_path(@point), method: :put, class: 'btn btn-warning' %>
62-
<% end %>
63-
<% end %>
64-
</div>
65-
<div class="pl15">
66-
<%= link_to 'Delete', @point, method: :delete, class: 'btn btn-danger' %>
67-
</div>
55+
<div class="row">
56+
<div class="col-sm-10 col-sm-offset-1 p30 bgw">
57+
<%= @point.analysis %>
58+
</div>
59+
</div>
6860

69-
<% elsif current_user.id == @point.user_id %>
61+
<br>
62+
<br>
7063

71-
<div class="pl15">
72-
<%= link_to 'All points', points_path, class: 'btn btn-primary' %>
73-
</div>
74-
<div class="pl15">
75-
<%= link_to 'Edit', edit_point_path(@point), class: 'btn btn-primary' %>
76-
</div>
77-
<div class="pl15">
78-
<%= link_to 'Back', :back, class: 'btn btn-primary' %>
79-
</div>
64+
<% if @point.versions.any? %>
8065

81-
<% else %>
66+
<div class="row">
67+
<div class="col-sm-12">
68+
<span class="bolder">We track editorial changes to analyses and updates to a point's status and display the previous versions here as part of an effort to promote transparency regarding our curation process.</span>
69+
</div>
8270

83-
<div class="pl15">
84-
<%= link_to 'All points', points_path, class: 'btn btn-primary' %>
85-
</div>
86-
<div class="pl15">
87-
<%= link_to 'Back', :back, class: 'btn btn-primary' %>
88-
</div>
89-
<% end %>
71+
</div>
9072

91-
<% else %>
92-
<div class="pl15">
93-
<%= link_to 'Back', :back, class:'btn btn-primary' %>
94-
</div>
73+
<br>
9574

96-
<% end %>
97-
</li>
98-
</ul>
99-
</div>
75+
<%= render 'table_reasons' %>
10076

101-
</div>
77+
<% end %>
10278

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddChangeReasonToPoints < ActiveRecord::Migration[5.1]
2+
def change
3+
add_column :points, :change_reason, :text
4+
end
5+
end

0 commit comments

Comments
 (0)