loggable_activity 0.2.1 → 0.5.0

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.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +29 -42
  3. data/.vscode/commands.json +2 -2
  4. data/.vscode/terminals.json +8 -8
  5. data/CHEAT_SHEET.md +31 -0
  6. data/MIT-LICENSE +21 -0
  7. data/README.md +31 -45
  8. data/Rakefile +6 -4
  9. data/app/assets/config/loggable_activity_manifest.js +4 -0
  10. data/app/assets/javascripts/loggable_activity/application.js +2 -0
  11. data/app/assets/stylesheets/loggable_activity/application.scss +20 -0
  12. data/app/controllers/concerns/.keep +0 -0
  13. data/app/controllers/loggable_activity/activities_controller.rb +12 -0
  14. data/app/controllers/loggable_activity/application_controller.rb +6 -0
  15. data/app/helpers/loggable_activity/activities_helper.rb +17 -0
  16. data/app/helpers/loggable_activity/application_helper.rb +6 -0
  17. data/app/jobs/loggable_activity/application_job.rb +6 -0
  18. data/app/mailers/loggable_activity/application_mailer.rb +8 -0
  19. data/app/models/loggable_activity/application_record.rb +7 -0
  20. data/app/views/kaminari/kaminari-turbo-bootstrap/_first_page.html.erb +14 -0
  21. data/app/views/kaminari/kaminari-turbo-bootstrap/_gap.html.erb +8 -0
  22. data/app/views/kaminari/kaminari-turbo-bootstrap/_last_page.html.erb +13 -0
  23. data/app/views/kaminari/kaminari-turbo-bootstrap/_next_page.html.erb +13 -0
  24. data/app/views/kaminari/kaminari-turbo-bootstrap/_page.html.erb +14 -0
  25. data/app/views/kaminari/kaminari-turbo-bootstrap/_paginator.html.erb +27 -0
  26. data/app/views/kaminari/kaminari-turbo-bootstrap/_prev_page.html.erb +14 -0
  27. data/app/views/layouts/loggable_activity/application.html.erb +19 -0
  28. data/app/views/loggable_activity/activities/_activities.html.erb +56 -0
  29. data/app/views/loggable_activity/activities/index.html.erb +7 -0
  30. data/app/views/loggable_activity/activities/show.html.erb +2 -0
  31. data/config/initializers/kaminari_config.rb +14 -0
  32. data/config/routes.rb +7 -0
  33. data/{lib/generators/loggable_activity/templates/create_loggable_activities.rb → db/migrate/20240702092648_create_loggable_activity_tables.rb} +18 -10
  34. data/git-org/HEAD +1 -0
  35. data/git-org/config +7 -0
  36. data/git-org/description +1 -0
  37. data/git-org/hooks/applypatch-msg.sample +15 -0
  38. data/git-org/hooks/commit-msg.sample +24 -0
  39. data/git-org/hooks/fsmonitor-watchman.sample +174 -0
  40. data/git-org/hooks/post-update.sample +8 -0
  41. data/git-org/hooks/pre-applypatch.sample +14 -0
  42. data/git-org/hooks/pre-commit.sample +49 -0
  43. data/git-org/hooks/pre-merge-commit.sample +13 -0
  44. data/git-org/hooks/pre-push.sample +53 -0
  45. data/git-org/hooks/pre-rebase.sample +169 -0
  46. data/git-org/hooks/pre-receive.sample +24 -0
  47. data/git-org/hooks/prepare-commit-msg.sample +42 -0
  48. data/git-org/hooks/push-to-checkout.sample +78 -0
  49. data/git-org/hooks/update.sample +128 -0
  50. data/git-org/info/exclude +6 -0
  51. data/lib/loggable_activity/activity.rb +3 -3
  52. data/lib/{schemas → loggable_activity}/config_schema.json +3 -3
  53. data/lib/loggable_activity/configuration.rb +51 -75
  54. data/lib/loggable_activity/data_owner.rb +0 -1
  55. data/lib/loggable_activity/encryption.rb +16 -7
  56. data/lib/loggable_activity/encryption_key.rb +4 -7
  57. data/lib/loggable_activity/engine.rb +27 -0
  58. data/lib/loggable_activity/error.rb +0 -10
  59. data/lib/loggable_activity/hooks.rb +10 -5
  60. data/lib/loggable_activity/payload.rb +8 -11
  61. data/lib/loggable_activity/sanitizer.rb +6 -2
  62. data/lib/loggable_activity/services/base_payloads_builder.rb +14 -5
  63. data/lib/loggable_activity/services/destroy_payloads_builder.rb +2 -1
  64. data/lib/loggable_activity/services/payloads_builder.rb +9 -2
  65. data/lib/loggable_activity/services/update_payloads_builder.rb +30 -2
  66. data/lib/loggable_activity/version.rb +1 -1
  67. data/lib/loggable_activity.rb +51 -14
  68. data/lib/tasks/loggable_activity_tasks.rake +6 -0
  69. metadata +129 -117
  70. data/.document +0 -1
  71. data/.nojekyll +0 -1
  72. data/.rspec +0 -3
  73. data/CONSIDERTIONS.md +0 -129
  74. data/GETTING-STARTED.md +0 -119
  75. data/LICENSE.txt +0 -21
  76. data/PAYLOAD_EXAMPLE.md +0 -63
  77. data/ROADMAP.md +0 -23
  78. data/docs/LoggableActivity/Activity.html +0 -555
  79. data/docs/LoggableActivity/Configuration.html +0 -330
  80. data/docs/LoggableActivity/ConfigurationError.html +0 -148
  81. data/docs/LoggableActivity/DataOwner.html +0 -138
  82. data/docs/LoggableActivity/Encryption.html +0 -234
  83. data/docs/LoggableActivity/EncryptionError.html +0 -145
  84. data/docs/LoggableActivity/EncryptionKey.html +0 -351
  85. data/docs/LoggableActivity/Error.html +0 -145
  86. data/docs/LoggableActivity/Hooks.html +0 -759
  87. data/docs/LoggableActivity/Payload.html +0 -432
  88. data/docs/LoggableActivity/Services/BasePayloadsBuilder.html +0 -442
  89. data/docs/LoggableActivity/Services/DestroyPayloadsBuilder.html +0 -395
  90. data/docs/LoggableActivity/Services/PayloadsBuilder.html +0 -342
  91. data/docs/LoggableActivity/Services/UpdatePayloadsBuilder.html +0 -490
  92. data/docs/LoggableActivity/Services.html +0 -93
  93. data/docs/LoggableActivity.html +0 -102
  94. data/docs/created.rid +0 -14
  95. data/docs/css/fonts.css +0 -167
  96. data/docs/css/rdoc.css +0 -687
  97. data/docs/fonts/Lato-Light.ttf +0 -0
  98. data/docs/fonts/Lato-LightItalic.ttf +0 -0
  99. data/docs/fonts/Lato-Regular.ttf +0 -0
  100. data/docs/fonts/Lato-RegularItalic.ttf +0 -0
  101. data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
  102. data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
  103. data/docs/images/add.png +0 -0
  104. data/docs/images/arrow_up.png +0 -0
  105. data/docs/images/brick.png +0 -0
  106. data/docs/images/brick_link.png +0 -0
  107. data/docs/images/bug.png +0 -0
  108. data/docs/images/bullet_black.png +0 -0
  109. data/docs/images/bullet_toggle_minus.png +0 -0
  110. data/docs/images/bullet_toggle_plus.png +0 -0
  111. data/docs/images/date.png +0 -0
  112. data/docs/images/delete.png +0 -0
  113. data/docs/images/find.png +0 -0
  114. data/docs/images/loadingAnimation.gif +0 -0
  115. data/docs/images/macFFBgHack.png +0 -0
  116. data/docs/images/package.png +0 -0
  117. data/docs/images/page_green.png +0 -0
  118. data/docs/images/page_white_text.png +0 -0
  119. data/docs/images/page_white_width.png +0 -0
  120. data/docs/images/plugin.png +0 -0
  121. data/docs/images/ruby.png +0 -0
  122. data/docs/images/tag_blue.png +0 -0
  123. data/docs/images/tag_green.png +0 -0
  124. data/docs/images/transparent.png +0 -0
  125. data/docs/images/wrench.png +0 -0
  126. data/docs/images/wrench_orange.png +0 -0
  127. data/docs/images/zoom.png +0 -0
  128. data/docs/index.html +0 -99
  129. data/docs/js/darkfish.js +0 -97
  130. data/docs/js/navigation.js +0 -105
  131. data/docs/js/navigation.js.gz +0 -0
  132. data/docs/js/search.js +0 -110
  133. data/docs/js/search_index.js +0 -1
  134. data/docs/js/search_index.js.gz +0 -0
  135. data/docs/js/searcher.js +0 -229
  136. data/docs/js/searcher.js.gz +0 -0
  137. data/docs/table_of_contents.html +0 -617
  138. data/help/loggable_activity_help.txt +0 -19
  139. data/lib/generators/.DS_Store +0 -0
  140. data/lib/generators/loggable_activity/.DS_Store +0 -0
  141. data/lib/generators/loggable_activity/install_generator.rb +0 -109
  142. data/lib/generators/loggable_activity/templates/.DS_Store +0 -0
  143. data/lib/generators/loggable_activity/templates/binary_ids/create_loggable_activities.rb +0 -30
  144. data/lib/generators/loggable_activity/templates/config/locales/loggable_activity.en.yml +0 -36
  145. data/lib/generators/loggable_activity/templates/config/loggable_activity.yaml +0 -29
  146. data/lib/generators/loggable_activity/templates/loggable_activity.en.yaml +0 -36
  147. data/pkg/loggable_activity-0.1.35.gem +0 -0
  148. data/sig/loggable_activity.rbs +0 -4
  149. /data/{.rspec_status → app/assets/images/loggable_activity/.keep} +0 -0
  150. /data/lib/{generators/loggable_activity/templates → loggable_activity/concerns}/current_user.rb +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c639f2566d6a3dd820a7657b9b8bb398e5a861347ae1bc7d7474724c6c344b4c
4
- data.tar.gz: 8551b4aab8f630be997b6af7b8372d7efd84221824bbacb25bb6c444f6c83978
3
+ metadata.gz: 62e1b197ae053af29d55c9b183c358a773f43186691c20c8e124ba7786bde586
4
+ data.tar.gz: ae8bd2c8d9a9718c02fc246c2a5a703b6fad9b27823cf357a51020d96b0a5a16
5
5
  SHA512:
6
- metadata.gz: 03422fe2e2d154f894da7a0eab5fac78f1048b6e6d3d4addbf1fa0bd66d9a674913ca666a4a4e743cbaf95ff5edbfb8711641596330b370d5d29d3e0922f4af6
7
- data.tar.gz: '08de4b66e4aba0d210be64f83eb78b51fcb6c351d3340e9f1dfba334194d5c6a705daeefe6f66aae8a7cc8409a94b1ba4ec33d222a957e549b0811629f6ebfcb'
6
+ metadata.gz: 7ed08eae394bc830b08d21f68de6b3f77811fde3b73d4278351bc807ee7c9de3369632bb349f16e45dd518e74297064494b1f810bb1b2c3cf1744d34f898adf9
7
+ data.tar.gz: 91891b25f6826cd70fcacc3bd3365a14b50e319c6d3af6ceecf72cb8340adb1298a79d28a1d08964087011c9e3766e188fe80193a3d293d087611a543817a7f4
data/.rubocop.yml CHANGED
@@ -1,51 +1,38 @@
1
1
  AllCops:
2
- TargetRubyVersion: '3.2.0'
3
- NewCops: enable
4
- Exclude:
5
- # - 'vendor/**/*'
6
-
7
- Style/OpenStructUse:
8
- Enabled: false
9
-
10
- Style/Documentation:
11
- Enabled: false
12
-
13
- Gemspec/DevelopmentDependencies:
14
- Enabled: false
15
-
2
+ Exclude:
3
+ - 'db/migrate/20240702092648_create_loggable_activity_tables.rb'
16
4
  Layout/LineLength:
17
- Enabled: false
18
-
5
+ Exclude:
6
+ - 'lib/loggable_activity/services/payloads_builder.rb'
7
+ - 'lib/loggable_activity/hooks.rb'
8
+ - 'lib/loggable_activity/activity.rb'
9
+ Metrics/AbcSize:
10
+ Exclude:
11
+ - 'lib/loggable_activity/encryption.rb'
19
12
  Metrics/BlockLength:
20
- Enabled: false
21
-
22
- Metrics/MethodLength:
23
- Enabled: false
24
-
25
- Metrics/CyclomaticComplexity:
26
- Enabled: false
27
-
28
- Style/IfUnlessModifier:
29
- Enabled: false
30
-
31
- Metrics/PerceivedComplexity:
32
- Enabled: false
33
-
13
+ Exclude:
14
+ - 'test/dummy/config/environments/development.rb'
15
+ - 'loggable_activity.gemspec'
16
+ - 'test/dummy/db/schema.rb'
34
17
  Metrics/ClassLength:
35
18
  Exclude:
36
- - lib/loggable_activity/services/update_payloads_builder.rb
37
-
38
- Metrics/ParameterLists:
19
+ - 'lib/loggable_activity/services/update_payloads_builder.rb'
20
+ Metrics/MethodLength:
39
21
  Exclude:
40
- - lib/loggable_activity/services/base_payloads_builder.rb
41
-
22
+ - 'lib/loggable_activity/services/update_payloads_builder.rb'
23
+ - 'lib/loggable_activity/services/destroy_payloads_builder.rb'
24
+ - 'lib/loggable_activity/services/base_payloads_builder.rb'
25
+ - 'lib/loggable_activity/hooks.rb'
26
+ - 'lib/loggable_activity/encryption.rb'
27
+ - 'lib/loggable_activity/activity.rb'
28
+ - 'lib/loggable_activity/services/payloads_builder.rb'
29
+ - 'lib/loggable_activity/hooks.rb'
42
30
  Metrics/ModuleLength:
43
31
  Exclude:
44
- - lib/loggable_activity/hooks.rb
45
-
46
- Metrics/AbcSize:
32
+ - 'lib/loggable_activity/hooks.rb'
33
+ Style/Documentation:
47
34
  Exclude:
48
- - lib/loggable_activity/encryption.rb
49
- # - lib/loggable_activity/update_payloads_builderx.rb
50
- - lib/generators/loggable_activity/templates/binary_ids/create_loggable_activities.rb
51
- - lib/generators/loggable_activity/templates/create_loggable_activities.rb
35
+ - 'test/**/*'
36
+ - 'app/models/loggable_activity/application_record.rb'
37
+ - 'app/mailers/loggable_activity/application_mailer.rb'
38
+ - 'app/helpers/loggable_activity/application_helper.rb'
@@ -9,7 +9,7 @@
9
9
  "alignment": "right",
10
10
  "priority": 300,
11
11
  "tooltip": "Run test for current line",
12
- "filterFileRegex": ".*_spec\\.rb"
12
+ "filterFileRegex": ".*_test\\.rb"
13
13
  },
14
14
  {
15
15
  "command": "terminals.runTerminalByName",
@@ -20,7 +20,7 @@
20
20
  "alignment": "right",
21
21
  "priority": 290,
22
22
  "tooltip": "Run test for current file",
23
- "filterFileRegex": ".*_spec\\.rb"
23
+ "filterFileRegex": ".*_test\\.rb"
24
24
  }
25
25
  ]
26
26
  }
@@ -8,10 +8,10 @@
8
8
  "onlySingle": true,
9
9
  "icon": "run",
10
10
  "commands": [
11
- "dir=[file] && test_path=${${(s:/spec/:)dir}[1]} && file=\"spec/\"${${(s:/spec/:)dir}[2]}",
12
- "echo \"$dir\\n$test_path\\n$file:[lineNumber]\"",
13
- "cd $test_path",
14
- "rspec $file:[lineNumber]"
11
+ "dir=$(dirname [file]) && test_file=$(basename [file])",
12
+ "echo \"$dir\\n$test_file:[lineNumber]\"",
13
+ "cd $dir",
14
+ "rails test $dir/$test_file:[lineNumber]"
15
15
  ]
16
16
  },
17
17
  {
@@ -21,10 +21,10 @@
21
21
  "onlySingle": true,
22
22
  "icon": "run-all",
23
23
  "commands": [
24
- "dir=[file] && test_path=${${(s:/spec/:)dir}[1]} && file=\"spec/\"${${(s:/spec/:)dir}[2]}",
25
- "echo \"$dir\\n$test_path\\n$file\"",
26
- "cd $test_path",
27
- "rspec $file"
24
+ "dir=$(dirname [file]) && test_file=$(basename [file])",
25
+ "echo \"$dir\\n$test_file\"",
26
+ "cd $dir",
27
+ "rails test $dir/$test_file"
28
28
  ]
29
29
  }
30
30
  ]
data/CHEAT_SHEET.md ADDED
@@ -0,0 +1,31 @@
1
+ ### Build gem on localhost
2
+ ```
3
+ gem build loggable_activity.gemspec
4
+ ```
5
+
6
+ ### Release gem
7
+ - Catch DONT update VERSION, this is done by `gem bump --version x.x.x`
8
+ - Update the CHANGE_LOG.md
9
+
10
+ Make sure `gem install gem-release` is installed
11
+
12
+ ```
13
+ $ gem bump --version 0.3.0
14
+ $ rake release
15
+ $ read terminal output and authorize release
16
+ ```
17
+
18
+ ### Heroku
19
+ ```
20
+ $ heroku pg:backups:capture --app loggableactivity
21
+ $ heroku pg:backups:download --app loggableactivity
22
+ ```
23
+ install on localhost
24
+ ```
25
+ $ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U maxgronlund -d activity_logger_development latest.dump
26
+ ```
27
+
28
+ ## Build documentation
29
+ ```
30
+ $ rdoc -o docs/ --all --main
31
+ ```
data/MIT-LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright Max
2
+ Groenlund
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,45 +1,31 @@
1
- # Loggable Activity 🌟
2
- Secure protect data and log how it is handled
3
- - Keep an activity log of how data in the db are handled.
4
- - Protect and secure the privacy of data stored in Activity Logs
5
- - Prepare for General Data Protection Regulation (GDPR) compliance.
6
- - Handles activities that involves more than one table in the DB.
7
- - Encrypt data stored in the activity log
8
- - Support binary_ids
9
-
10
- ### Important!
11
- This project is under development and not ready for production. There might be breaking changes, so please consult the CHANGELOG.md
12
- ### What it is not
13
- - An error logging system
14
- - A paper trails system with rollback.
15
- - A backup system
16
-
17
- ### Applications
18
- Most organizations needs to keep a log of how users interact with data stored in the DB
19
- - Finance
20
- - Healthcare
21
- - Sales and Support
22
-
23
- *Super simplified example from the healthcare.*
24
- - Each patient has a journal, that is updated on a regular basis.
25
- - Supervisor needs to follow the journal, how was it updated, who read it, did it get deleted.
26
- - Security personnel needs to know how the journal is handled, who did what when.
27
- - Patients has the right to know how their journal is handled and that their data will be removed when required.
28
-
29
- Beside the journal in the db, an activity log is kept so it is possible to track how the journal is used.<br/>
30
- At some point in time the patients data from the DB and the activity log has to be removed according to GDPR.<br/>
31
-
32
- ### Getting started
33
- please read the [GETTING-STARTED.md](https://github.com/maxgronlund/LoggableActivity/blob/main/GETTING-STARTED.md) guide
34
-
35
- ### Contribute
36
- 👉 Join the Slack channel here: [LoggableActivity Slack Workspace](https://join.slack.com/t/loggableactivity/shared_invite/zt-2a3tvgv37-mGwjHJTrBXBH2srXFRRSXQ)
37
- <br/>
38
- 👉 Want to play around with an online version: [Show Demo](https://loggableactivity-efe7b931c886.herokuapp.com/)
39
- <br/>
40
- We value each contribution and believe in the power of community. Looking forward to seeing you there!
41
-
42
-
43
- ### Test
44
- We embrace the philosophy of black-box testing, where we focus on the input and output of the public interface without worrying about internal implementation details.<br/>
45
- This approach aligns with the principle of testing behavior rather than implementation.
1
+ # LoggableActivity
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem "loggable_activity"
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install loggable_activity
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
29
+
30
+ ##
31
+ bin/rails loggable_activity:install:migrations
data/Rakefile CHANGED
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
3
+ require 'bundler/setup'
4
+
5
+ APP_RAKEFILE = File.expand_path('test/dummy/Rakefile', __dir__)
6
+ load 'rails/tasks/engine.rake'
5
7
 
6
- RSpec::Core::RakeTask.new(:spec)
8
+ load 'rails/tasks/statistics.rake'
7
9
 
8
- task default: :spec
10
+ require 'bundler/gem_tasks'
@@ -0,0 +1,4 @@
1
+ //= link_directory ../stylesheets/loggable_activity .css
2
+ //= link application.css
3
+ //= link_directory ../javascripts/loggable_activity .js
4
+ //= link application.js
@@ -0,0 +1,2 @@
1
+ //= require bootstrap
2
+
@@ -0,0 +1,20 @@
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
+ @import "bootstrap/functions";
18
+ @import "bootstrap/variables";
19
+ @import "bootstrap/mixins";
20
+ @import "bootstrap";
File without changes
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggableActivity
4
+ # Controller for activities
5
+ class ActivitiesController < ApplicationController
6
+ def index
7
+ @activities = LoggableActivity::Activity.order(created_at: :desc).page params[:page]
8
+ end
9
+
10
+ def show; end
11
+ end
12
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggableActivity
4
+ class ApplicationController < ActionController::Base
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggableActivity
4
+ # Helper methods for activities
5
+ module ActivitiesHelper
6
+ require 'json'
7
+ def activity_action(activity)
8
+ I18n.t("loggable_activity.#{activity.action}")
9
+ end
10
+
11
+ def format_json_for_display(hash_data)
12
+ JSON.pretty_generate(hash_data)
13
+ rescue JSON::ParserError
14
+ hash_data.to_s
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggableActivity
4
+ module ApplicationHelper
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggableActivity
4
+ class ApplicationJob < ActiveJob::Base
5
+ end
6
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggableActivity
4
+ class ApplicationMailer < ActionMailer::Base
5
+ default from: 'from@example.com'
6
+ layout 'mailer'
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggableActivity
4
+ class ApplicationRecord < ActiveRecord::Base
5
+ self.abstract_class = true
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ <%# Link to the "First" page
2
+ - available local variables
3
+ url: url to the first page
4
+ current_page: a page object for the currently displayed page
5
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <% unless current_page.first? %>
10
+ <li class="page-item">
11
+ <%# <%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :class => 'page-link', :remote => remote %>
12
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, class: 'page-link', data: { turbo: true } %>
13
+ </li>
14
+ <% end %>
@@ -0,0 +1,8 @@
1
+ <%# Non-link tag that stands for skipped pages...
2
+ - available local variables
3
+ current_page: a page object for the currently displayed page
4
+ num_pages: total number of pages
5
+ per_page: number of items to fetch per page
6
+ remote: data-remote
7
+ -%>
8
+ <li class="page-item disabled"><a href="#" onclick="return false;" class="page-link"><%= raw(t 'views.pagination.truncate') %></a></li>
@@ -0,0 +1,13 @@
1
+ <%# Link to the "Last" page
2
+ - available local variables
3
+ url: url to the last page
4
+ current_page: a page object for the currently displayed page
5
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <% unless current_page.last? %>
10
+ <li class="page-item">
11
+ <%= link_to_unless current_page.last?, raw(t('views.pagination.last')), url, class: 'page-link', data: { turbo: true } %>
12
+ </li>
13
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <%# Link to the "Next" page
2
+ - available local variables
3
+ url: url to the next page
4
+ current_page: a page object for the currently displayed page
5
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <% unless current_page.last? %>
10
+ <li class="page-item">
11
+ <%= link_to_unless current_page.last?, raw(t('views.pagination.next')), url, class: 'page-link', rel: 'next', data: { turbo: true }, remote: remote %>
12
+ </li>
13
+ <% end %>
@@ -0,0 +1,14 @@
1
+ <%# Link showing page number
2
+ - available local variables
3
+ page: a page object for "this" page
4
+ url: url to this page
5
+ current_page: a page object for the currently displayed page
6
+ num_pages: total number of pages
7
+ per_page: number of items to fetch per page
8
+ remote: data-remote
9
+ -%>
10
+ <li class="page-item<%= ' active' if page.current? %>">
11
+ <%#= link_to page, url, opts = {:remote => remote, :class => 'page-link', :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
12
+ <%= link_to page, url, class: 'page-link', rel: page.next? ? 'next' : page.prev? ? 'prev' : nil, data: { turbo: true }, remote: remote %>
13
+
14
+ </li>
@@ -0,0 +1,27 @@
1
+ <%# The container tag
2
+ - available local variables
3
+ current_page: a page object for the currently displayed page
4
+ num_pages: total number of pages
5
+ per_page: number of items to fetch per page
6
+ remote: data-remote
7
+ paginator: the paginator that renders the pagination tags inside
8
+ -%>
9
+ <%- pagination_class ||= '' %>
10
+ <%- nav_class ||= '' %>
11
+ <%= paginator.render do -%>
12
+ <nav class="<%= nav_class %>">
13
+ <ul class="pagination <%= pagination_class %>">
14
+ <%= first_page_tag unless current_page.first? %>
15
+ <%= prev_page_tag unless current_page.first? %>
16
+ <% each_page do |page| -%>
17
+ <% if page.left_outer? || page.right_outer? || page.inside_window? -%>
18
+ <%= page_tag page %>
19
+ <% elsif !page.was_truncated? -%>
20
+ <%= gap_tag %>
21
+ <% end -%>
22
+ <% end -%>
23
+ <%= next_page_tag unless current_page.last? %>
24
+ <%= last_page_tag unless current_page.last? %>
25
+ </ul>
26
+ </nav>
27
+ <% end -%>
@@ -0,0 +1,14 @@
1
+ <%# Link to the "Previous" page
2
+ - available local variables
3
+ url: url to the previous page
4
+ current_page: a page object for the currently displayed page
5
+ num_pages: total number of pages
6
+ per_page: number of items to fetch per page
7
+ remote: data-remote
8
+ -%>
9
+ <% unless current_page.first? %>
10
+ <li class="page-item">
11
+ <%#= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote, :class => 'page-link' %>
12
+ <%= link_to_unless current_page.first?, raw(t('views.pagination.previous')), url, rel: 'prev', class: 'page-link', data: { turbo: true }, remote: remote %>
13
+ </li>
14
+ <% end %>
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Loggable activity</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+ <%= stylesheet_link_tag "loggable_activity/application", media: "all" %>
8
+ <%= javascript_include_tag 'loggable_activity/application', defer: true %>
9
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/themes/prism.min.css" rel="stylesheet">
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.24.1/prism.min.js"></script>
11
+
12
+ </head>
13
+ <body>
14
+ <div class="container">
15
+ <%= yield %>
16
+ </div>
17
+
18
+ </body>
19
+ </html>
@@ -0,0 +1,56 @@
1
+ <table class="table table-borderless">
2
+ <thead>
3
+ <tr>
4
+ <th>
5
+ <div class="row">
6
+ <div class="col-3">
7
+ <b class="text-secondary">Action</b>
8
+ </div>
9
+ <div class="col-3">
10
+ <b class="text-secondary">Record</b>
11
+ </div>
12
+ <div class="col-3">
13
+ <b class="text-secondary">Actor</b>
14
+ </div>
15
+ <div class="col-3">
16
+ <b class="text-secondary">Created At</b>
17
+ </div>
18
+ </div>
19
+ </th>
20
+ </tr>
21
+ </thead>
22
+ <tbody>
23
+ <% @activities.each do |activity| %>
24
+ <tr>
25
+ <td>
26
+ <div class="alert alert-info" type="button" data-bs-toggle="collapse" data-bs-target="#activity_<%= activity.id %>" aria-expanded="false" aria-controls="collapseExample">
27
+ <div class="row">
28
+ <div class="col-3">
29
+ <%= activity_action(activity) %>
30
+ </div>
31
+ <div class="col-3">
32
+ <%= t(activity.record_display_name) %>
33
+ </div>
34
+ <div class="col-3">
35
+ <%= t(activity.actor_display_name) %>
36
+ </div>
37
+ <div class="col-3">
38
+ <%= l(activity.created_at, format: :long) %>
39
+ </div>
40
+ </div>
41
+ </div>
42
+ <div class="collapse" id="activity_<%= activity.id %>">
43
+ <pre>
44
+ <code class="language-json">
45
+ <%= format_json_for_display(activity.attrs) %>
46
+ </code>
47
+ </pre>
48
+ </div>
49
+ </td>
50
+ </tr>
51
+ <% end %>
52
+ </tbody>
53
+ </table>
54
+ <script>
55
+ Prism.highlightAll();
56
+ </script>
@@ -0,0 +1,7 @@
1
+ <h1>Activities</h1>
2
+ <%= render partial: "activities", activities: @activities %>
3
+
4
+ <%= paginate @activities, theme: 'kaminari-turbo-bootstrap' %>
5
+
6
+
7
+
@@ -0,0 +1,2 @@
1
+ <h1>Activities#show</h1>
2
+ <p>Find me in app/views/loggable_activity/activities/show.html.erb</p>
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ Kaminari.configure do |config|
4
+ config.default_per_page = 3
5
+ # config.max_per_page = nil
6
+ # config.window = 4
7
+ # config.outer_window = 0
8
+ # config.left = 0
9
+ # config.right = 0
10
+ # config.page_method_name = :page
11
+ # config.param_name = :page
12
+ # config.max_pages = nil
13
+ # config.params_on_first_page = false
14
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ LoggableActivity::Engine.routes.draw do
4
+ resources :activities, only: %i[index show]
5
+
6
+ root to: 'activities#index'
7
+ end