Skip to content

Commit

Permalink
Merge pull request #253 from tosdr/sprint/implementing-paper-trail
Browse files Browse the repository at this point in the history
[WIP] Paper Trail and data history
  • Loading branch information
Christopher Talib authored Feb 24, 2018
2 parents 20cd5ee + 16abd64 commit 695f3f6
Show file tree
Hide file tree
Showing 22 changed files with 532 additions and 299 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gem 'postmark-rails'
gem 'devise'
gem 'figaro'
gem 'jbuilder', '~> 2.0'
gem 'pg'
gem 'pg', '~> 0.21'
gem 'puma'
gem 'rails', '5.1.4'
gem 'redis'
Expand All @@ -24,6 +24,7 @@ gem 'simple_form'
gem 'uglifier'
gem 'formtastic'
gem 'pundit'
gem 'paper_trail'

group :development, :test do
gem 'pry-byebug'
Expand Down
40 changes: 23 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/activeadmin/activeadmin.git
revision: 9af04e7516fc8b34bb126990a1b1a05b57f3b0c7
revision: cfa8a34ed039de9aafb84b1cd3cc195939906218
specs:
activeadmin (2.0.0.alpha)
arbre (>= 1.1.1)
Expand All @@ -17,12 +17,12 @@ GIT

GIT
remote: git://github.com/activeadmin/inherited_resources.git
revision: 46493ce10fc7d9f0bcd753f5d298c67ca83cf9b0
revision: 8603b3054683fa798134d76c12a32d9e287b307e
specs:
inherited_resources (1.7.2)
actionpack (>= 4.2, < 5.2)
inherited_resources (1.8.0)
actionpack (>= 4.2, <= 5.2)
has_scope (~> 0.6)
railties (>= 4.2, < 5.2)
railties (>= 4.2, <= 5.2)
responders

GEM
Expand Down Expand Up @@ -70,7 +70,7 @@ GEM
arbre (1.1.1)
activesupport (>= 3.0.0)
arel (8.0.0)
autoprefixer-rails (7.1.6)
autoprefixer-rails (7.2.5)
execjs
babel-source (5.8.35)
babel-transpiler (0.7.0)
Expand All @@ -86,7 +86,7 @@ GEM
coderay (1.1.2)
concurrent-ruby (1.0.5)
crass (1.0.3)
devise (4.3.0)
devise (4.4.0)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0, < 5.2)
Expand Down Expand Up @@ -131,7 +131,7 @@ GEM
kaminari-core (1.1.1)
launchy (2.4.3)
addressable (~> 2.3)
letter_opener (1.4.1)
letter_opener (1.6.0)
launchy (~> 2.2)
listen (3.0.8)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand All @@ -144,14 +144,17 @@ GEM
method_source (0.9.0)
mini_mime (1.0.0)
mini_portile2 (2.3.0)
minitest (5.10.3)
multi_json (1.12.2)
nio4r (2.1.0)
minitest (5.11.1)
multi_json (1.13.1)
nio4r (2.2.0)
nokogiri (1.8.1)
mini_portile2 (~> 2.3.0)
orm_adapter (0.5.0)
paper_trail (8.1.2)
activerecord (>= 4.2, < 5.2)
request_store (~> 1.1)
pg (0.21.0)
polyamorous (1.3.1)
polyamorous (1.3.2)
activerecord (>= 3.0)
postmark (1.10.0)
json
Expand All @@ -162,7 +165,7 @@ GEM
pry (0.11.3)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
pry-byebug (3.5.0)
pry-byebug (3.5.1)
byebug (~> 9.1)
pry (~> 0.10)
pry-rails (0.3.6)
Expand Down Expand Up @@ -208,10 +211,12 @@ GEM
rb-inotify (0.9.10)
ffi (>= 0.5.0, < 2)
redis (4.0.1)
request_store (1.4.0)
rack (>= 1.4)
responders (2.4.0)
actionpack (>= 4.2.0, < 5.3)
railties (>= 4.2.0, < 5.3)
sass (3.5.3)
sass (3.5.5)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
Expand Down Expand Up @@ -246,7 +251,7 @@ GEM
tilt (2.0.8)
tzinfo (1.2.4)
thread_safe (~> 0.1)
uglifier (3.2.0)
uglifier (4.1.3)
execjs (>= 0.3.0, < 3)
warden (1.2.7)
rack (>= 1.0)
Expand Down Expand Up @@ -275,7 +280,8 @@ DEPENDENCIES
jquery-rails
letter_opener
listen (~> 3.0.5)
pg
paper_trail
pg (~> 0.21)
postmark-rails
pry-byebug
pry-rails
Expand All @@ -294,4 +300,4 @@ RUBY VERSION
ruby 2.3.5p376

BUNDLED WITH
1.16.0
1.16.1
1 change: 1 addition & 0 deletions app/assets/stylesheets/components/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
@import "footer";
@import "button";
@import "sort_button";
@import "tabs";
@import "service_title";
18 changes: 18 additions & 0 deletions app/assets/stylesheets/components/_tabs.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.tabs-bar-container {
display: flex;
justify-content: center;
padding: 0px;
margin: 0px;

}

.tabs-bar {
padding: 10px;
margin: 5px;
}

.tabs-bar.active {
background-color: transparent;
color: black;
}

15 changes: 4 additions & 11 deletions app/assets/stylesheets/pages/_point.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
padding-left: 15px;
}

.pl50 {
padding-left: 50px;
}

.m15 {
margin-top: 15px;
margin-bottom: 15px;
Expand All @@ -67,18 +71,7 @@
align-items: center;
}

.point-status {
padding-left: 50px;
}


.point-rating {
padding-left: 50px;
}

.status-changes {
max-height: 200px;
overflow: scroll;
}

.lighter {
Expand Down
1 change: 1 addition & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
before_action :set_paper_trail_whodunnit
def configure_permitted_parameters
# For additional in app/views/devise/registrations/edit.html.erb
devise_parameter_sanitizer.permit(:account_update, keys: [:username])
Expand Down
36 changes: 18 additions & 18 deletions app/models/point.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
class Point < ApplicationRecord
belongs_to :user, optional: true
belongs_to :service
has_many :reasons, dependent: :destroy
belongs_to :topic
has_paper_trail
belongs_to :user, optional: true
belongs_to :service
has_many :reasons, dependent: :destroy
belongs_to :topic

validates :title, presence: true
validates :title, length: { in: 5..140 }
validates :source, presence: true
validates :status, inclusion: { in: ["approved", "pending", "declined", "disputed", "draft"], allow_nil: false }
validates :analysis, presence: true
validates :rating, presence: true
validates :rating, numericality: true
validates :title, presence: true
validates :title, length: { in: 5..140 }
validates :source, presence: true
validates :status, inclusion: { in: ["approved", "pending", "declined", "disputed", "draft"], allow_nil: false }
validates :analysis, presence: true
validates :rating, presence: true
validates :rating, numericality: true

def self.search_points_by_multiple(query)
Point.joins(:service).where("services.name ILIKE ? or points.status ILIKE ?", "%#{query}%", "%#{query}%")
end
def self.search_points_by_multiple(query)
Point.joins(:service).where("services.name ILIKE ? or points.status ILIKE ?", "%#{query}%", "%#{query}%")
end

def self.search_points_by_topic(query)
Point.joins(:topic).where("topics.title ILIKE ?", "%#{query}%")
end
def self.search_points_by_topic(query)
Point.joins(:topic).where("topics.title ILIKE ?", "%#{query}%")
end
# VOTE CONTROLLER ! TODO
# def has_voted(point)
# Vote.where(point_id: point.id, user_id: current_user.id)
# end

end
8 changes: 8 additions & 0 deletions app/models/service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Service < ApplicationRecord
has_paper_trail
has_many :points

validates :name, presence: true
Expand All @@ -19,19 +20,26 @@ def service_ratings
unless avg.nan?
case avg.round
when 9..10
self.update_attributes(grade:"A")
"A"
when 7..8
self.update_attributes(grade:"B")
"B"
when 5..6
self.update_attributes(grade:"C")
"C"
when 3..4
self.update_attributes(grade:"D")
"D"
when 0..2
self.update_attributes(grade:"F")
"F"
else
self.update_attributes(grade:"N/A")
"N/A"
end
else
self.update_attributes(grade:"N/A")
"N/A"
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/topic.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Topic < ApplicationRecord
has_paper_trail
has_many :points

validates :title, presence: true, uniqueness: true
Expand All @@ -12,5 +13,4 @@ def self.search_by_topic_title(query)
def self.search_by_topic_service(query)
Topic.joins(:point).where("points.name ILIKE ?", "%#{query}%")
end

end
38 changes: 20 additions & 18 deletions app/views/points/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,32 @@ document.getElementById('points-table-container').innerHTML = output;
<% end %>
</div>
<div class="card-inline-item card-inline-options">
<% if current_user %>
<% if current_user.curator? %>

<% if current_user.curator? %>
<%= link_to(point_path(p), :class => 'btn') do %>
<i class="fa fa-eye" aria-hidden="true"></i>
<% end %>
<%= link_to(edit_point_path(p), :class => 'btn') do %>
<i class="fa fa-pencil" aria-hidden="true"></i>
<% end %>

<%= link_to(point_path(p), :class => 'btn') do %>
<i class="fa fa-eye" aria-hidden="true"></i>
<% end %>
<%= link_to(edit_point_path(p), :class => 'btn') do %>
<i class="fa fa-pencil" aria-hidden="true"></i>
<% end %>
<% elsif current_user.id == p.user_id %>

<% elsif current_user.id == p.user_id %>
<%= link_to(point_path(p), :class => 'btn') do %>
<i class="fa fa-eye" aria-hidden="true"></i>
<% end %>
<%= link_to(edit_point_path(p), :class => 'btn') do %>
<i class="fa fa-pencil" aria-hidden="true"></i>
<% end %>

<%= link_to(point_path(p), :class => 'btn') do %>
<i class="fa fa-eye" aria-hidden="true"></i>
<% end %>
<%= link_to(edit_point_path(p), :class => 'btn') do %>
<i class="fa fa-pencil" aria-hidden="true"></i>
<% end %>
<% end %>

<% else %>
<% else %>

<%= link_to(point_path(p), :class => 'btn') do %>
<i class="fa fa-eye" aria-hidden="true"></i>
<% end %>
<%= link_to(point_path(p), :class => 'btn') do %>
<i class="fa fa-eye" aria-hidden="true"></i>
<% end %>

<% end %>

Expand Down
46 changes: 46 additions & 0 deletions app/views/points/_table_reasons.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div class="article-holder status-changes">

<!-- <table class="table">
<thead class="thead thead-dark">
<th scope="col">STATUS UPDATES</th>
<th scope="col">REASON</th>
<th scope="col">WHEN</th>
</thead>
<tbody>
<% @point.reasons.each do |reason| %>
<tr>
<th scope="row"><%= reason.status %></th>
<td><%= reason.content %></td>
<td><%= time_ago_in_words reason.created_at %> ago</td>
</tr>
</tbody>
<% end %>
</table> -->

<table class="table">
<thead class="thead thead-dark">
<th scope="col">ANALYSIS UPDATES</th>
<th scope="col">TEXT CHANGES</th>
<th scope="col">WHEN</th>
<!-- <th scope="col">WHO</th> -->
</thead>
<tbody>
<% @point.versions.each do |v| %>
<tr>
<th scope="row"><%= v.event %></th>
<td>
<% if v.changeset["analysis"] %>
Analysis change: <%= v.changeset["analysis"] %>
<% elsif v.changeset["status"] %>
Status change: <%= v.changeset["status"] %>
<% else %>
No changes recorded
<% end %>
</td>
<td><%= v.changeset["updated_at"] %></td>
<!-- make a better view for username <td><%= v.whodunnit %></td> -->
</tr>
<% end %>
</tbody>
</table>
</div>
6 changes: 0 additions & 6 deletions app/views/points/create.js.erb

This file was deleted.

Loading

0 comments on commit 695f3f6

Please sign in to comment.