administrate-field-paper_trail 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +10 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +69 -0
- data/Rakefile +22 -0
- data/administrate-field-paper_trail.gemspec +22 -0
- data/app/views/fields/paper_trail/_show.html.erb +42 -0
- data/lib/administrate/field/paper_trail.rb +27 -0
- data/spec/lib/administrate/field/paper_trail_spec.rb +14 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 69f939123a47a422bb338a97dcaaf061514c19a25ffcda1922c6b4e5b991736b
|
4
|
+
data.tar.gz: 1efc7453358914b6b6220b7dd2c990c8850aa4cb4e5be0b0d74d4e999e5c72bc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66c858c8b27f43c4a5c126924ae2da54e8f18836ec79d0b8c2244287fe3fc2cbe37b7379b55ae2fd0ee439dfa876455f27e7eaf2165eed0bf50ddf1d45bf84d1
|
7
|
+
data.tar.gz: c70a7df3406500cd94f1cd324a9fe541aefc78e9e013d3fb34ba3da1d71f7c2bc3c9f264f391a2c9a40d9d1d1df130ff1b7ee80c5bd508d459b21ed1abc0f536
|
@@ -0,0 +1,16 @@
|
|
1
|
+
---
|
2
|
+
name: CI
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- name: Set up Ruby
|
12
|
+
uses: ruby/setup-ruby@v1
|
13
|
+
- name: Install dependencies
|
14
|
+
run: bundle install
|
15
|
+
- name: Run tests
|
16
|
+
run: bundle exec rspec
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.2.0
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Irvan Fauziansyah
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# AdministrateFieldPaperTrail
|
2
|
+
|
3
|
+
![Gem](https://img.shields.io/gem/v/administrate-field-paper_trail.svg)
|
4
|
+
![CI](https://github.com/IrvanFza/administrate-field-paper_trail/workflows/CI/badge.svg)
|
5
|
+
|
6
|
+
An [Administrate](https://github.com/thoughtbot/administrate/) plugin to show record change histories from [PaperTrail](https://github.com/paper-trail-gem/paper_trail).
|
7
|
+
|
8
|
+
## Requirements
|
9
|
+
|
10
|
+
- Ruby on Rails version >= 5.0
|
11
|
+
- Administrate version >= 0.2.2
|
12
|
+
- PaperTrail version >= 2.7.2
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Make sure you already setup [PaperTrail](https://github.com/paper-trail-gem/paper_trail#1b-installation) properly in your project.
|
17
|
+
Add `administrate-field-paper_trail` to your Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'administrate-field-paper_trail'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
```
|
25
|
+
$ bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
Add to your `UserDashboard`:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
ATTRIBUTE_TYPES = {
|
34
|
+
changeset: Field::PaperTrail.with_options(excluded_attributes: %w[created_at updated_at]),
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
The `excluded_attributes` option takes an array of string of the attributes you want to exclude from the result.
|
39
|
+
|
40
|
+
Then show the data either in your show page like so:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
SHOW_PAGE_ATTRIBUTES = %i[
|
44
|
+
changeset
|
45
|
+
]
|
46
|
+
```
|
47
|
+
|
48
|
+
Currently, only support to show changes in the show page. Contribution will be appreciated.
|
49
|
+
|
50
|
+
## To Do
|
51
|
+
|
52
|
+
- [x] Show record changes information in the show page
|
53
|
+
- [ ] Show count of changes of each records in the index page
|
54
|
+
- [ ] Add i18n support for the result message
|
55
|
+
- [ ] Add i18n support for date/time value
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Contribution are welcome (codes, suggestions, and bugs)
|
60
|
+
2. Please test your code: `bundle exec rspec`
|
61
|
+
3. Please document your code
|
62
|
+
4. Bug reports and pull requests are welcome on GitHub at https://github.com/IrvanFza/administrate-field-paper_trail
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
[MIT License](https://github.com/IrvanFza/administrate-field-paper_trail/blob/master/LICENSE.md)
|
67
|
+
|
68
|
+
---
|
69
|
+
Based on the [Administrate::Field::Image](https://github.com/thoughtbot/administrate-field-image) template
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "bundler/setup"
|
5
|
+
rescue LoadError
|
6
|
+
puts "You must `gem install bundler` and `bundle install` to run rake tasks"
|
7
|
+
end
|
8
|
+
|
9
|
+
require "bundler/gem_tasks"
|
10
|
+
|
11
|
+
##
|
12
|
+
# Configure the test suite.
|
13
|
+
##
|
14
|
+
require "rspec/core"
|
15
|
+
require "rspec/core/rake_task"
|
16
|
+
|
17
|
+
RSpec::Core::RakeTask.new
|
18
|
+
|
19
|
+
##
|
20
|
+
# By default, just run the tests.
|
21
|
+
##
|
22
|
+
task default: :spec
|
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "administrate-field-paper_trail"
|
5
|
+
gem.version = "0.1.0"
|
6
|
+
gem.authors = ["Irvan Fauziansyah"]
|
7
|
+
gem.email = ["ervhan@gmail.com"]
|
8
|
+
gem.homepage = "https://github.com/IrvanFza/administrate-field-paper_trail"
|
9
|
+
gem.summary = "Administrate field for PaperTrail"
|
10
|
+
gem.description = "Administrate's plugin to show PaperTrail versions via new field type"
|
11
|
+
gem.license = "MIT"
|
12
|
+
|
13
|
+
gem.require_paths = ["lib"]
|
14
|
+
gem.files = `git ls-files`.split("\n")
|
15
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
|
17
|
+
gem.add_dependency "administrate", ">= 0.2.2"
|
18
|
+
gem.add_dependency "paper_trail", ">= 2.7.2"
|
19
|
+
gem.add_dependency "rails", ">= 5.0"
|
20
|
+
|
21
|
+
gem.add_development_dependency "rspec", "~> 3.4"
|
22
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<%#
|
2
|
+
# PaperTrail Show Partial
|
3
|
+
|
4
|
+
This partial renders a paper_trail attribute,
|
5
|
+
to be displayed on a resource's show page.
|
6
|
+
|
7
|
+
By default, the attribute is rendered as a table tag.
|
8
|
+
|
9
|
+
## Local variables:
|
10
|
+
|
11
|
+
- `field`:
|
12
|
+
An instance of [Administrate::Field::Image][1].
|
13
|
+
A wrapper around the image url pulled from the database.
|
14
|
+
|
15
|
+
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Field/Image
|
16
|
+
%>
|
17
|
+
|
18
|
+
<% versions = field.resource.versions %>
|
19
|
+
<% if versions.present? %>
|
20
|
+
<table aria-describedby="Record Changes">
|
21
|
+
<thead>
|
22
|
+
<tr>
|
23
|
+
<th width="10%">Action</th>
|
24
|
+
<th width="10%">Updated By</th>
|
25
|
+
<th width="10%">Updated At</th>
|
26
|
+
<th>Changes</th>
|
27
|
+
</tr>
|
28
|
+
</thead>
|
29
|
+
<tbody>
|
30
|
+
<% versions.each do |version| %>
|
31
|
+
<tr>
|
32
|
+
<td width="10%"><%= version.event %></td>
|
33
|
+
<td width="10%"><%= version.whodunnit %></td>
|
34
|
+
<td width="10%"><%= version.created_at %></td>
|
35
|
+
<td><%= field.humanize_changeset(version.changeset) %></td>
|
36
|
+
</tr>
|
37
|
+
<% end %>
|
38
|
+
<tbody>
|
39
|
+
</table>
|
40
|
+
<% else %>
|
41
|
+
-
|
42
|
+
<% end %>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "administrate/field/base"
|
2
|
+
require "rails"
|
3
|
+
|
4
|
+
module Administrate
|
5
|
+
module Field
|
6
|
+
class PaperTrail < Administrate::Field::Base
|
7
|
+
class Engine < ::Rails::Engine
|
8
|
+
end
|
9
|
+
|
10
|
+
def excluded_attributes
|
11
|
+
options.fetch(:excluded_attributes, %w[id created_at updated_at])
|
12
|
+
end
|
13
|
+
|
14
|
+
def humanize_changeset(changeset)
|
15
|
+
result = ''
|
16
|
+
changeset.each do |attribute, values|
|
17
|
+
next if excluded_attributes.include?(attribute)
|
18
|
+
|
19
|
+
old_value, new_value = values
|
20
|
+
result += "#{attribute.gsub('_', ' ').capitalize} changed from '#{old_value}' to '#{new_value}'. "
|
21
|
+
end
|
22
|
+
|
23
|
+
result
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "administrate/field/paper_trail"
|
2
|
+
|
3
|
+
describe Administrate::Field::PaperTrail do
|
4
|
+
describe "#to_partial_path" do
|
5
|
+
it "returns a partial based on the page being rendered" do
|
6
|
+
page = :show
|
7
|
+
field = Administrate::Field::PaperTrail.new(:image, "/a.jpg", page)
|
8
|
+
|
9
|
+
path = field.to_partial_path
|
10
|
+
|
11
|
+
expect(path).to eq("/fields/paper_trail/#{page}")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: administrate-field-paper_trail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Irvan Fauziansyah
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-01-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: administrate
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: paper_trail
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.7.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.7.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.4'
|
69
|
+
description: Administrate's plugin to show PaperTrail versions via new field type
|
70
|
+
email:
|
71
|
+
- ervhan@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".github/workflows/main.yml"
|
77
|
+
- ".gitignore"
|
78
|
+
- ".ruby-version"
|
79
|
+
- CHANGELOG.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- administrate-field-paper_trail.gemspec
|
85
|
+
- app/views/fields/paper_trail/_show.html.erb
|
86
|
+
- lib/administrate/field/paper_trail.rb
|
87
|
+
- spec/lib/administrate/field/paper_trail_spec.rb
|
88
|
+
homepage: https://github.com/IrvanFza/administrate-field-paper_trail
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubygems_version: 3.4.3
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Administrate field for PaperTrail
|
111
|
+
test_files:
|
112
|
+
- spec/lib/administrate/field/paper_trail_spec.rb
|