loggable_activity 0.1.55 → 0.1.56

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e2ab2f4d7ec08a5f53176ae3e3289b8470c5cc39013a1bc48e06c3b596f11ee
4
- data.tar.gz: 3c5037f59fc9e408fd693afbd3208f530b52cb4f3791b91f8dfad603a66e2513
3
+ metadata.gz: 0026d9021dbb8d457f89aae37cefeab76c25307392f7df9bf33576ced785ab2a
4
+ data.tar.gz: 1a7e30aee22dad70a1d5b6cfdbc8fbc5647ed9a84acb8e1793a12342dbd2845f
5
5
  SHA512:
6
- metadata.gz: 017f1f1418adb7acd44ed3af4cd08ccdcc396dc9d61c63b2b584c994b46018923832155a1ae64361a8d75c5414257591ff174e33696c356c844c241063343c14
7
- data.tar.gz: 2da5d2b4981ad8470f6ed75b2710c6e75f36d19dafb99496cc0e49f1e7c2a0f008b94d234780c693e6eb841437ffa6933f7abd133526a6c9eec56b8e75fa1259
6
+ metadata.gz: 4207be61cc5c3fc3c9f6f8a37a6d589b92c0c5067cfc76dc8187ff94a4c8fcf4f8438c0682830bd609ff78883c3ee863985642926ddbece92a2a230c6b96e7a9
7
+ data.tar.gz: c770403638780d4708ef561eea6e3522dc1d16de6ac916d656db608e52ec24d88ba24a8314410f542d31a56d1f192a6869a67a0a486721dffc7d2b01dea8d7a8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+
2
+ ## [0.1.56] - 2024-03-04
3
+ ### Breaking change
4
+ - Generate links in helpers
5
+
1
6
  ## [0.1.54] - 2024-02-24
2
7
  - Support for BinaryID's
3
8
  - Updated README.md
@@ -10,7 +10,9 @@ module LoggableActivity
10
10
  class_option :template, type: :string, default: 'erb'
11
11
 
12
12
  def create_helper
13
- copy_file 'helpers/loggable_activity_helper.rb', 'app/helpers/loggable_activity_helper.rb'
13
+ copy_file 'helpers/activity_helper.rb', 'app/helpers/loggable_activity/activity_helper.rb'
14
+ copy_file 'helpers/routes_helper.rb', 'app/helpers/loggable_activity/routes_helper.rb'
15
+ copy_file 'helpers/router.rb', 'app/helpers/loggable_activity/router.rb'
14
16
  end
15
17
 
16
18
  def create_views
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggableActivity
4
+ module ActivityHelper
5
+ # include ApplicationHelper
6
+ include LoggableActivity::Router
7
+
8
+ def render_activity(activity)
9
+ render partial: template_path(activity), locals: { activity: }
10
+ end
11
+
12
+ # def relation_type(relation_attrs)
13
+ # title = I18n.t("loggable.activity.models.#{relation_attrs[:record_type]}")
14
+ # if path = path_to_payload(relation_attrs[:path])
15
+ # path
16
+ # else
17
+ # title
18
+ # end
19
+ # end
20
+
21
+ private
22
+
23
+ def action_template_path(activity)
24
+ "loggable_activity/templates/#{activity.action.gsub('.', '/')}"
25
+ end
26
+
27
+ def template_path(activity)
28
+ template_path = action_template_path(activity)
29
+ if lookup_context.template_exists?(template_path, [], true)
30
+ template_path
31
+ else
32
+ action = activity.action.split('.').last || 'default'
33
+ "loggable_activity/templates/default/#{action}"
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'action_view'
4
+
5
+ module LoggableActivity
6
+ module Router
7
+ # include ApplicationHelper
8
+ include LoggableActivity::RoutesHelper
9
+
10
+ def primary_activity_text_or_link(activity)
11
+ route = activity.primary_route
12
+ text = text_for_link(route)
13
+ return text if route.nil?
14
+ return text if activity.record.nil?
15
+
16
+ url = url_to_record(route, activity.record)
17
+ return text unless url.present?
18
+
19
+ link_to(text, url)
20
+ end
21
+
22
+ def payload_type_text_or_link(attrs)
23
+ route = attrs[:route]
24
+ return model_translation(attrs) if route.nil?
25
+
26
+ record = find_record(attrs)
27
+ return model_translation(attrs) if record.nil?
28
+
29
+ text = text_for_link(route)
30
+
31
+ url = url_to_record(route, record)
32
+ return text if url.nil?
33
+
34
+ link_to(text, url)
35
+ end
36
+
37
+ private
38
+
39
+ def text_for_link(route)
40
+ I18n.t("loggable.activity.routes.#{route}")
41
+ end
42
+
43
+ def model_translation(attrs)
44
+ I18n.t("loggable.activity.models.#{attrs[:record_type]}")
45
+ end
46
+
47
+ def find_record(attrs)
48
+ record_class = attrs[:record_type].constantize
49
+ record_class.find(attrs[:record_id])
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggableActivity
4
+ module RoutesHelper
5
+ include ApplicationHelper
6
+
7
+ def url_to_record(route, record)
8
+ case route
9
+ when 'show_doctor', 'show_patient', 'show_user', 'show_user_profile'
10
+ demo_user_url(record)
11
+ when 'show_demo_address'
12
+ demo_city_demo_address_url(record.demo_city, record)
13
+ when 'show_demo_city'
14
+ demo_city_url(record)
15
+ when 'show_demo_journal'
16
+ demo_journal_url(record)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -41,7 +41,7 @@ module LoggableActivity
41
41
  record_id: payload.record_id,
42
42
  payload_type: payload.payload_type,
43
43
  attrs: payload.attrs,
44
- path: payload.payload_route
44
+ route: payload.payload_route
45
45
  }
46
46
  end
47
47
  end
@@ -75,7 +75,7 @@ module LoggableActivity
75
75
  updated_relations_attrs:
76
76
  }
77
77
  end
78
-
78
+
79
79
  # Returns the attributes for the primary payload, without the relations.
80
80
  #
81
81
  # Example:
@@ -132,8 +132,8 @@ module LoggableActivity
132
132
  # Returns:
133
133
  # "/path/to/activity"
134
134
  #
135
- def path
136
- primary_payload&.route
135
+ def primary_route
136
+ primary_payload&.payload_route
137
137
  end
138
138
 
139
139
  # Returns the display name for a actor. what method to use if defined in '/config/loggable_activity.yaml'
@@ -176,6 +176,16 @@ module LoggableActivity
176
176
 
177
177
  private
178
178
 
179
+ # Returns the primary payload associated with the activity.
180
+ #
181
+ # Example usage:
182
+ # payload = @activity.primary_payload
183
+ # puts payload.record_type # => 'SOMD_MODEL_NAME'
184
+ #
185
+ def primary_payload
186
+ ordered_payloads.find { |p| p.payload_type == 'primary_payload' }
187
+ end
188
+
179
189
  # Returns the attributes for the update+payload.
180
190
  def update_attrs
181
191
  update_payload_attrs = attrs.find { |p| p[:payload_type] == 'update_payload' }
@@ -185,10 +195,6 @@ module LoggableActivity
185
195
  update_payload_attrs
186
196
  end
187
197
 
188
- # Returns the primary payload.
189
- def primary_payload
190
- ordered_payloads.find { |p| p.payload_type == 'primary_payload' }
191
- end
192
198
 
193
199
  # Returns the attributes for the updated relations.
194
200
  def updated_relations_attrs
@@ -3,5 +3,5 @@
3
3
  # Version of the gem
4
4
  module LoggableActivity
5
5
  # Version
6
- VERSION = '0.1.55'
6
+ VERSION = '0.1.56'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggable_activity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.55
4
+ version: 0.1.56
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Max \nGroenlund"
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-01 00:00:00.000000000 Z
11
+ date: 2024-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -208,7 +208,6 @@ files:
208
208
  - docs/js/searcher.js.gz
209
209
  - docs/table_of_contents.html
210
210
  - help/loggable_activity_help.txt
211
- - lib/.DS_Store
212
211
  - lib/generators/.DS_Store
213
212
  - lib/generators/loggable_activity/.DS_Store
214
213
  - lib/generators/loggable_activity/install_generator.rb
@@ -219,9 +218,10 @@ files:
219
218
  - lib/generators/loggable_activity/templates/config/loggable_activity.yaml
220
219
  - lib/generators/loggable_activity/templates/create_loggable_activities.rb
221
220
  - lib/generators/loggable_activity/templates/current_user.rb
222
- - lib/generators/loggable_activity/templates/helpers/loggable_activity_helper.rb
221
+ - lib/generators/loggable_activity/templates/helpers/activity_helper.rb
222
+ - lib/generators/loggable_activity/templates/helpers/router.rb
223
+ - lib/generators/loggable_activity/templates/helpers/routes_helper.rb
223
224
  - lib/generators/loggable_activity/templates/loggable_activity.en.yaml
224
- - lib/generators/loggable_activity/templates/loggable_activity_helper.rb
225
225
  - lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_create.html.erb
226
226
  - lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_create.html.slim
227
227
  - lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_destroy.html.erb
data/lib/.DS_Store DELETED
Binary file
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LoggableActivityHelper
4
- include ApplicationHelper
5
-
6
- def render_activity(activity)
7
- render partial: template_path(activity), locals: { activity: }
8
- end
9
-
10
- def primary_type(activity)
11
- I18n.t("loggable.activity.models.#{activity.record_type}")
12
- end
13
-
14
- def relation_type(relation_attrs)
15
- I18n.t("loggable.activity.models.#{relation_attrs[:record_type]}")
16
- end
17
-
18
- def update_relation_class(update_attrs)
19
- I18n.t("loggable.activity.models.#{update_attrs[:record_type]}")
20
- end
21
-
22
- private
23
-
24
- def action_template_path(activity)
25
- "loggable_activity/templates/#{activity.action.gsub('.', '/')}"
26
- end
27
-
28
- def template_path(activity)
29
- template_path = action_template_path(activity)
30
- if lookup_context.template_exists?(template_path, [], true)
31
- template_path
32
- else
33
- action = activity.action.split('.').last || 'default'
34
- "loggable_activity/templates/default/#{action}"
35
- end
36
- end
37
-
38
- def activity_payload(activity)
39
- @activity_payload ||= build_payload(activity)
40
- end
41
-
42
- def activity_attrs(activity)
43
- @activity_attrs ||= activity_payload(activity).fetch(:activity, {})
44
- end
45
-
46
- def build_payload(activity)
47
- Loggable::JsonPayloadFactory.new(activity).build_payload
48
- end
49
- end
@@ -1,58 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module LoggableActivityHelper
4
- include ApplicationHelper
5
- # include Rails.application.routes.url_helpers
6
-
7
- def render_activity(activity)
8
- render partial: template_path(activity), locals: { activity: }
9
- end
10
-
11
- def primary_type(activity)
12
- title = I18n.t("loggable.activity.models.#{activity.record_type}")
13
- if (path = activity.path)
14
- link_to title, send(path, activity.record_id.to_s)
15
- else
16
- title
17
- end
18
- end
19
-
20
- def relation_type(relation_attrs)
21
- title = I18n.t("loggable.activity.models.#{relation_attrs[:record_type]}")
22
- if (path = relation_attrs[:path])
23
- link_to title, send(path, relation_attrs[:record_id])
24
- else
25
- title
26
- end
27
- end
28
-
29
- def link_to_payload; end
30
-
31
- private
32
-
33
- def action_template_path(activity)
34
- "loggable_activity/templates/#{activity.action.gsub('.', '/')}"
35
- end
36
-
37
- def template_path(activity)
38
- template_path = action_template_path(activity)
39
- if lookup_context.template_exists?(template_path, [], true)
40
- template_path
41
- else
42
- action = activity.action.split('.').last || 'default'
43
- "loggable_activity/templates/default/#{action}"
44
- end
45
- end
46
-
47
- def activity_payload(activity)
48
- @activity_payload ||= build_payload(activity)
49
- end
50
-
51
- def activity_attrs(activity)
52
- @activity_attrs ||= activity_payload(activity).fetch(:activity, {})
53
- end
54
-
55
- def build_payload(activity)
56
- Loggable::JsonPayloadFactory.new(activity).build_payload
57
- end
58
- end