paper_trail_history 0.1.3 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b3e54f1afaacc531556a2a10d0bfde605e5e8e9bc02c4571d11d5fd1349cd00
4
- data.tar.gz: e0f5777f1c40623e7ffa1cedff478b3b850c47e1418a1c52c4658b071c1a59a0
3
+ metadata.gz: e8f45c5efd0324c99a10d738d2c8db6e6f06b809ded91d04ae2ea1b5a7d6a30a
4
+ data.tar.gz: 3e4280f2afc76462071723e6bf61e2bc28339e7159e69f2223a3b08cde8b36aa
5
5
  SHA512:
6
- metadata.gz: 82be7c5bab02749ab38277d18a9b2d7062100eaed096e80a2d495c6f820f066faf0afe69742ff8022387998af446960bdd815b360d0676453cf4cd734b082ffc
7
- data.tar.gz: b6870227f27cac3e3cfe18c61d5e3386453b2874f2840843119e20fa2a1c945f48b5ae980e77546b8261997eb91d18321ace95b2b8d83bee82481268feb59ac9
6
+ metadata.gz: 1013e6d19a201f4d8c16c6ddcbf7592d7342b3f67a8b3f24f6819f0a7f5f8861b7bda50d1f91dd0830886f898bdd358e4b35e78dc39a070e2b29a608faa713e6
7
+ data.tar.gz: e4c97d3b9b7795d5d427352b21b42bdf67f8143e526486a4a7fcf5d4b649cbdb0b0fab64852a02465b3f0feee314aca4fd08da5a867464fefb428b71ba4a7a1c
@@ -14,19 +14,20 @@ module PaperTrailHistory
14
14
  result = VersionService.restore_version(@version.id)
15
15
 
16
16
  if result[:success]
17
- redirect_back fallback_location: version_path(@version),
18
- notice: result[:message]
17
+ redirect_back_or_to(version_path(@version, model_name: @version.item_type), notice: result[:message])
19
18
  else
20
- redirect_back fallback_location: version_path(@version),
21
- alert: t('paper_trail_history.errors.restore_failed', error: result[:error])
19
+ redirect_back_or_to(version_path(@version, model_name: @version.item_type),
20
+ alert: t('paper_trail_history.errors.restore_failed', error: result[:error]))
22
21
  end
23
22
  end
24
23
 
25
24
  private
26
25
 
27
26
  def find_version
28
- @version = PaperTrail::Version.find(params[:id])
29
- rescue ActiveRecord::RecordNotFound
27
+ @version = VersionService.find_version(params[:id], params[:model_name])
28
+
29
+ return if @version
30
+
30
31
  redirect_to root_path, alert: t('paper_trail_history.errors.version_not_found')
31
32
  end
32
33
  end
@@ -3,5 +3,16 @@
3
3
  module PaperTrailHistory
4
4
  # Helper module providing utility methods for PaperTrailHistory views
5
5
  module ApplicationHelper
6
+ # Generate version path with model_name context when available
7
+ def version_link_path(version, options = {})
8
+ model_name = options[:model_name] || version.item_type
9
+ version_path(version.id, model_name: model_name)
10
+ end
11
+
12
+ # Generate restore version path with model_name context
13
+ def restore_version_link_path(version, options = {})
14
+ model_name = options[:model_name] || version.item_type
15
+ restore_version_path(version.id, model_name: model_name)
16
+ end
6
17
  end
7
18
  end
@@ -19,6 +19,19 @@ module PaperTrailHistory
19
19
  apply_record_filters(versions, params).order(created_at: :desc)
20
20
  end
21
21
 
22
+ def self.find_version(version_id, model_name = nil)
23
+ if model_name.present?
24
+ # Direct query when model_name is known (fast)
25
+ trackable_model = TrackableModel.find(model_name)
26
+ return nil unless trackable_model
27
+
28
+ trackable_model.version_class.unscoped.find_by(id: version_id)
29
+ else
30
+ # Fall back to searching across all tables (backwards compatible)
31
+ find_version_across_tables(version_id)
32
+ end
33
+ end
34
+
22
35
  def self.restore_version(version_id)
23
36
  version = find_version_across_tables(version_id)
24
37
  return validate_version_for_restore(version) unless version_restorable?(version)
@@ -8,9 +8,88 @@
8
8
 
9
9
  <%= yield :head %>
10
10
 
11
- <%= stylesheet_link_tag "paper_trail_history/application", media: "all" %>
12
11
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
13
12
  <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
13
+
14
+ <style>
15
+ /* Git-style diff formatting */
16
+ .diff-container {
17
+ font-family: 'SFMono-Regular', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
18
+ font-size: 0.9rem;
19
+ }
20
+
21
+ .diff-section {
22
+ border: 1px solid #e1e4e8;
23
+ border-radius: 6px;
24
+ overflow: hidden;
25
+ }
26
+
27
+ .diff-header {
28
+ background-color: #f6f8fa;
29
+ padding: 8px 12px;
30
+ border-bottom: 1px solid #e1e4e8;
31
+ font-weight: 600;
32
+ color: #586069;
33
+ }
34
+
35
+ .diff-content {
36
+ background-color: #fff;
37
+ }
38
+
39
+ .diff-line {
40
+ display: flex;
41
+ align-items: flex-start;
42
+ padding: 2px 0;
43
+ line-height: 1.45;
44
+ position: relative;
45
+ }
46
+
47
+ .diff-line code {
48
+ background: none;
49
+ border: none;
50
+ padding: 4px 8px;
51
+ margin: 0;
52
+ flex: 1;
53
+ font-size: 0.85rem;
54
+ white-space: pre-wrap;
55
+ word-break: break-all;
56
+ }
57
+
58
+ .diff-marker {
59
+ display: inline-block;
60
+ width: 20px;
61
+ text-align: center;
62
+ font-weight: bold;
63
+ flex-shrink: 0;
64
+ font-size: 0.9rem;
65
+ padding: 4px 0;
66
+ user-select: none;
67
+ }
68
+
69
+ .diff-removed {
70
+ background-color: #ffeef0;
71
+ border-left: 3px solid #f85149;
72
+ }
73
+
74
+ .diff-removed .diff-marker {
75
+ color: #f85149;
76
+ background-color: #ffdddf;
77
+ }
78
+
79
+ .diff-added {
80
+ background-color: #e6ffed;
81
+ border-left: 3px solid #2ea043;
82
+ }
83
+
84
+ .diff-added .diff-marker {
85
+ color: #2ea043;
86
+ background-color: #ccf2d4;
87
+ }
88
+
89
+ .diff-line:hover {
90
+ background-color: rgba(0, 0, 0, 0.05);
91
+ }
92
+ </style>
14
93
  </head>
15
94
  <body>
16
95
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
@@ -16,8 +16,8 @@
16
16
  <% versions.each do |decorated_version| %>
17
17
  <tr>
18
18
  <td>
19
- <%= link_to "##{decorated_version.version.id}",
20
- version_path(decorated_version.version.id),
19
+ <%= link_to "##{decorated_version.version.id}",
20
+ version_link_path(decorated_version.version),
21
21
  class: "text-decoration-none" %>
22
22
  </td>
23
23
  <td>
@@ -41,13 +41,13 @@
41
41
  <% end %>
42
42
  <td>
43
43
  <div class="btn-group btn-group-sm">
44
- <%= link_to "View", version_path(decorated_version.version.id), class: "btn btn-outline-primary btn-sm" %>
44
+ <%= link_to "View", version_link_path(decorated_version.version), class: "btn btn-outline-primary btn-sm" %>
45
45
  <% if decorated_version.can_restore? %>
46
- <%= button_to "Restore",
47
- restore_version_path(decorated_version.version.id),
46
+ <%= button_to "Restore",
47
+ restore_version_link_path(decorated_version.version),
48
48
  method: :patch,
49
- data: {
50
- confirm: "Are you sure you want to restore this version?"
49
+ data: {
50
+ confirm: "Are you sure you want to restore this version?"
51
51
  },
52
52
  class: "btn btn-outline-warning btn-sm" %>
53
53
  <% end %>
@@ -10,11 +10,11 @@
10
10
  <h1>Version Details</h1>
11
11
  <div>
12
12
  <% if @decorated_version.can_restore? %>
13
- <%= button_to "Restore This Version",
14
- restore_version_path(@version),
13
+ <%= button_to "Restore This Version",
14
+ restore_version_link_path(@version),
15
15
  method: :patch,
16
- data: {
17
- confirm: "Are you sure you want to restore this version? This will overwrite the current data."
16
+ data: {
17
+ confirm: "Are you sure you want to restore this version? This will overwrite the current data."
18
18
  },
19
19
  class: "btn btn-warning" %>
20
20
  <% end %>
@@ -68,11 +68,11 @@
68
68
  This will restore the record to the state it was in at this version.
69
69
  <strong>This action cannot be undone</strong>, but will create a new version entry.
70
70
  </p>
71
- <%= button_to "Restore This Version",
72
- restore_version_path(@version),
71
+ <%= button_to "Restore This Version",
72
+ restore_version_link_path(@version),
73
73
  method: :patch,
74
- data: {
75
- confirm: "Are you sure you want to restore this version? This will overwrite the current data and cannot be undone."
74
+ data: {
75
+ confirm: "Are you sure you want to restore this version? This will overwrite the current data and cannot be undone."
76
76
  },
77
77
  class: "btn btn-warning" %>
78
78
  </div>
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PaperTrailHistory
4
- VERSION = '0.1.3'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paper_trail_history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Deutscher
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: paper_trail
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '7.2'
32
+ version: '8.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '7.2'
39
+ version: '8.0'
40
40
  description: |
41
41
  PaperTrailHistory is a mountable Rails engine that provides a comprehensive web interface for viewing, searching,
42
42
  and managing audit trail versions created by the PaperTrail gem. Features include listing trackable models,
@@ -50,7 +50,6 @@ files:
50
50
  - MIT-LICENSE
51
51
  - README.md
52
52
  - Rakefile
53
- - app/assets/stylesheets/paper_trail_history/application.css
54
53
  - app/controllers/paper_trail_history/application_controller.rb
55
54
  - app/controllers/paper_trail_history/models_controller.rb
56
55
  - app/controllers/paper_trail_history/records_controller.rb
@@ -93,14 +92,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
93
92
  requirements:
94
93
  - - ">="
95
94
  - !ruby/object:Gem::Version
96
- version: 3.1.0
95
+ version: 3.3.0
97
96
  required_rubygems_version: !ruby/object:Gem::Requirement
98
97
  requirements:
99
98
  - - ">="
100
99
  - !ruby/object:Gem::Version
101
100
  version: '0'
102
101
  requirements: []
103
- rubygems_version: 3.6.6
102
+ rubygems_version: 3.6.9
104
103
  specification_version: 4
105
104
  summary: A Rails engine providing a web interface for managing PaperTrail versions.
106
105
  test_files: []
@@ -1,93 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
- * files in this directory. Styles in this file should be added after the last require_* statement.
11
- * It is generally better to create a new file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
16
-
17
- /* Git-style diff formatting */
18
- .diff-container {
19
- font-family: 'SFMono-Regular', 'Monaco', 'Inconsolata', 'Roboto Mono', monospace;
20
- font-size: 0.9rem;
21
- }
22
-
23
- .diff-section {
24
- border: 1px solid #e1e4e8;
25
- border-radius: 6px;
26
- overflow: hidden;
27
- }
28
-
29
- .diff-header {
30
- background-color: #f6f8fa;
31
- padding: 8px 12px;
32
- border-bottom: 1px solid #e1e4e8;
33
- font-weight: 600;
34
- color: #586069;
35
- }
36
-
37
- .diff-content {
38
- background-color: #fff;
39
- }
40
-
41
- .diff-line {
42
- display: flex;
43
- align-items: flex-start;
44
- padding: 2px 0;
45
- line-height: 1.45;
46
- position: relative;
47
- }
48
-
49
- .diff-line code {
50
- background: none;
51
- border: none;
52
- padding: 4px 8px;
53
- margin: 0;
54
- flex: 1;
55
- font-size: 0.85rem;
56
- white-space: pre-wrap;
57
- word-break: break-all;
58
- }
59
-
60
- .diff-marker {
61
- display: inline-block;
62
- width: 20px;
63
- text-align: center;
64
- font-weight: bold;
65
- flex-shrink: 0;
66
- font-size: 0.9rem;
67
- padding: 4px 0;
68
- user-select: none;
69
- }
70
-
71
- .diff-removed {
72
- background-color: #ffeef0;
73
- border-left: 3px solid #f85149;
74
- }
75
-
76
- .diff-removed .diff-marker {
77
- color: #f85149;
78
- background-color: #ffdddf;
79
- }
80
-
81
- .diff-added {
82
- background-color: #e6ffed;
83
- border-left: 3px solid #2ea043;
84
- }
85
-
86
- .diff-added .diff-marker {
87
- color: #2ea043;
88
- background-color: #ccf2d4;
89
- }
90
-
91
- .diff-line:hover {
92
- background-color: rgba(0, 0, 0, 0.05);
93
- }