effective_messaging 0.2.2 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eaebf1e8bccc037bfa5c5234f1c30ea60f454da39dded702004e8048fc440dfb
4
- data.tar.gz: 95415065976237d4c6008351e79d11f5174ce9671d53b248862eee8b9d3ff190
3
+ metadata.gz: f51a06c64a043da3819c077710fe75189bf0c9de2480c8bc7229fff8c1c984b8
4
+ data.tar.gz: 9a271eff256b981894a89f6fca51ff4e6c0abe731d2b1d7177ef3dd31a77287e
5
5
  SHA512:
6
- metadata.gz: 15919df42267f976f10ffbcf37f2e1314ee904825eb90d22273f10f02de0844b3c42e541827cbb6ca23da33ac961ebe069cbbbd25ac9153dfe7291beff7114a9
7
- data.tar.gz: 4294c145b19e78868f0f5a000c8f84731093e4cc46f7ceb65c5237a3955f26ad9ab72b72fd8ccf4654d2651c15ab2259cb570572f6355d9e28f6ae021568dd1f
6
+ metadata.gz: 9d41b44b4829586760bdb2d177fab1aa2bf871f9250ed8679605f98a3704196560f8fc6489b90a78c264b66a9c400a91ae051388ccf379953c799d9fab04b3ef
7
+ data.tar.gz: 9c6fe1ace4437ac55f032a8834dab9156afa0c3290e5ecd9ec59e9567459af404298dc76cd3a6b98dc39115e05abb1b83cf8a79856cd2823bec64e9be6b75998
@@ -34,6 +34,10 @@ module Admin
34
34
 
35
35
  col :report, search: Effective::Report.notifiable.sorted
36
36
 
37
+ col(:rows_count) do |notification|
38
+ notification.report.collection().count
39
+ end
40
+
37
41
  col :subject
38
42
  col :body, visible: false
39
43
 
@@ -6,8 +6,8 @@ module Effective
6
6
  raise('expected an Effective::Notification') unless notification.kind_of?(Effective::Notification)
7
7
 
8
8
  # Returns a Hash of params to pass to mail()
9
- # Includes a :to, :from, etc
10
- rendered = notification.render_email
9
+ # Includes a :to, :from, :subject and :body, etc
10
+ rendered = notification.assign_renderer(view_context).render_email
11
11
 
12
12
  # Attach report
13
13
  attach_report!(notification)
@@ -31,8 +31,8 @@ module Effective
31
31
  raise('expected an acts_as_reportable resource') unless resource.class.try(:acts_as_reportable?)
32
32
 
33
33
  # Returns a Hash of params to pass to mail()
34
- # Includes a :to, :from, etc
35
- rendered = notification.render_email(resource)
34
+ # Includes a :to, :from, :subject and :body
35
+ rendered = notification.assign_renderer(view_context).render_email(resource)
36
36
 
37
37
  # Works with effective_logging to associate this email with the notification
38
38
  headers = headers_for(notification, opts)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Effective
4
4
  class Chat < ActiveRecord::Base
5
- self.table_name = EffectiveMessaging.chats_table_name.to_s
5
+ self.table_name = (EffectiveMessaging.chats_table_name || :chats).to_s
6
6
 
7
7
  NOTIFY_AFTER = 2.minutes
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Effective
4
4
  class ChatMessage < ActiveRecord::Base
5
- self.table_name = EffectiveMessaging.chat_messages_table_name.to_s
5
+ self.table_name = (EffectiveMessaging.chat_messages_table_name || :chat_messages).to_s
6
6
 
7
7
  log_changes(to: :chat) if respond_to?(:log_changes)
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Effective
4
4
  class ChatUser < ActiveRecord::Base
5
- self.table_name = EffectiveMessaging.chat_users_table_name.to_s
5
+ self.table_name = (EffectiveMessaging.chat_users_table_name || :chat_users).to_s
6
6
 
7
7
  log_changes(to: :chat) if respond_to?(:log_changes)
8
8
 
@@ -2,10 +2,11 @@
2
2
 
3
3
  module Effective
4
4
  class Notification < ActiveRecord::Base
5
- self.table_name = EffectiveMessaging.notifications_table_name.to_s
5
+ self.table_name = (EffectiveMessaging.notifications_table_name || :notifications).to_s
6
6
 
7
7
  attr_accessor :current_user
8
8
  attr_accessor :current_resource
9
+ attr_accessor :view_context
9
10
 
10
11
  log_changes if respond_to?(:log_changes)
11
12
 
@@ -192,7 +193,17 @@ module Effective
192
193
  end
193
194
 
194
195
  def report_variables
195
- Array(report&.report_columns).map(&:name)
196
+ assigns_for().keys
197
+ end
198
+
199
+ def assign_renderer(view_context)
200
+ raise('expected renderer to respond to') unless view_context.respond_to?(:root_url)
201
+ assign_attributes(view_context: view_context)
202
+ self
203
+ end
204
+
205
+ def renderer
206
+ view_context || ApplicationController.renderer
196
207
  end
197
208
 
198
209
  def rows_count
@@ -316,13 +327,25 @@ module Effective
316
327
  }.compact
317
328
  end
318
329
 
319
- def assigns_for(resource)
320
- return {} unless resource.present?
330
+ # We pull the Assigns from 3 places:
331
+ # 1. The report.report_columns
332
+ # 2. The class's def reportable_view_assigns(view) method
333
+ def assigns_for(resource = nil)
334
+ return {} unless report.present?
321
335
 
322
- Array(report&.report_columns).inject({}) do |h, column|
336
+ resource ||= report.reportable.new
337
+ raise('expected an acts_as_reportable resource') unless resource.class.try(:acts_as_reportable?)
338
+
339
+ report_assigns = Array(report.report_columns).inject({}) do |h, column|
323
340
  value = resource.send(column.name)
324
341
  h[column.name] = column.format(value); h
325
342
  end
343
+
344
+ reportable_view_assigns = resource.reportable_view_assigns(renderer).deep_stringify_keys
345
+ raise('expected notification assigns to return a Hash') unless reportable_view_assigns.kind_of?(Hash)
346
+
347
+ # Merge all 3
348
+ report_assigns.merge(reportable_view_assigns)
326
349
  end
327
350
 
328
351
  def build_notification_log(resource: nil)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Effective
4
4
  class NotificationLog < ActiveRecord::Base
5
- self.table_name = EffectiveMessaging.notification_logs_table_name.to_s
5
+ self.table_name = (EffectiveMessaging.notification_logs_table_name || :notification_logs).to_s
6
6
 
7
7
  belongs_to :notification
8
8
 
@@ -3,7 +3,7 @@
3
3
  = render 'admin/notifications/form_notification', notification: notification
4
4
 
5
5
  - if notification.persisted? && notification.respond_to?(:logs_datatable)
6
- = tab 'Notification Logs' do
6
+ = tab 'Email Logs' do
7
7
  - datatable = Admin::EffectiveNotificationLogsDatatable.new(notification: notification)
8
8
  = render_inline_datatable(datatable)
9
9
 
@@ -59,7 +59,7 @@
59
59
 
60
60
  = f.email_field :bcc
61
61
  = f.text_field :subject
62
- = f.text_area :body
62
+ = f.text_area :body, rows: 20
63
63
 
64
64
  #effective-messaging-ajax
65
65
  - if f.object.report.present?
@@ -13,7 +13,7 @@
13
13
 
14
14
  = card('Preview of Notification') do
15
15
  - resource = notification.report.collection.order('RANDOM()').first
16
- - rendered = notification.render_email(resource)
16
+ - rendered = notification.assign_renderer(self).render_email(resource)
17
17
 
18
18
  %table.table
19
19
  %tbody
@@ -1,10 +1,4 @@
1
1
  EffectiveMessaging.setup do |config|
2
- config.chats_table_name = :chats
3
- config.chat_users_table_name = :chat_users
4
- config.chat_messages_table_name = :chat_messages
5
- config.notifications_table_name = :notifications
6
- config.notification_logs_table_name = :notification_logs
7
-
8
2
  # Layout Settings
9
3
  # Configure the Layout per controller, or all at once
10
4
  # config.layout = { application: 'application', admin: 'admin' }
@@ -1,6 +1,6 @@
1
1
  class CreateEffectiveMessaging < ActiveRecord::Migration[6.0]
2
2
  def change
3
- create_table <%= @chats_table_name %> do |t|
3
+ create_table :chats do |t|
4
4
  t.integer :parent_id
5
5
  t.string :parent_type
6
6
 
@@ -13,7 +13,7 @@ class CreateEffectiveMessaging < ActiveRecord::Migration[6.0]
13
13
  t.timestamps
14
14
  end
15
15
 
16
- create_table <%= @chat_users_table_name %> do |t|
16
+ create_table :chat_users do |t|
17
17
  t.integer :chat_id
18
18
 
19
19
  t.integer :user_id
@@ -27,7 +27,7 @@ class CreateEffectiveMessaging < ActiveRecord::Migration[6.0]
27
27
  t.timestamps
28
28
  end
29
29
 
30
- create_table <%= @chat_messages_table_name %> do |t|
30
+ create_table :chat_messages do |t|
31
31
  t.integer :chat_id
32
32
  t.integer :chat_user_id
33
33
 
@@ -40,7 +40,7 @@ class CreateEffectiveMessaging < ActiveRecord::Migration[6.0]
40
40
  t.timestamps
41
41
  end
42
42
 
43
- create_table <%= @notifications_table_name %> do |t|
43
+ create_table :notifications do |t|
44
44
  t.integer :parent_id
45
45
  t.string :parent_type
46
46
 
@@ -76,7 +76,7 @@ class CreateEffectiveMessaging < ActiveRecord::Migration[6.0]
76
76
  t.timestamps
77
77
  end
78
78
 
79
- create_table <%= @notification_logs_table_name %> do |t|
79
+ create_table :notification_logs do |t|
80
80
  t.integer :notification_id
81
81
  t.integer :report_id
82
82
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveMessaging
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -20,13 +20,7 @@ module EffectiveMessaging
20
20
  end
21
21
 
22
22
  def create_migration_file
23
- @chats_table_name = ':' + EffectiveMessaging.chats_table_name.to_s
24
- @chat_users_table_name = ':' + EffectiveMessaging.chat_users_table_name.to_s
25
- @chat_messages_table_name = ':' + EffectiveMessaging.chat_messages_table_name.to_s
26
- @notifications_table_name = ':' + EffectiveMessaging.notifications_table_name.to_s
27
- @notification_logs_table_name = ':' + EffectiveMessaging.notification_logs_table_name.to_s
28
-
29
- migration_template ('../' * 3) + 'db/migrate/01_create_effective_messaging.rb.erb', 'db/migrate/create_effective_messaging.rb'
23
+ migration_template ('../' * 3) + 'db/migrate/101_create_effective_messaging.rb', 'db/migrate/create_effective_messaging.rb'
30
24
  end
31
25
 
32
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_messaging
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-14 00:00:00.000000000 Z
11
+ date: 2023-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -247,7 +247,7 @@ files:
247
247
  - config/effective_messaging.rb
248
248
  - config/locales/effective_messaging.yml
249
249
  - config/routes.rb
250
- - db/migrate/01_create_effective_messaging.rb.erb
250
+ - db/migrate/101_create_effective_messaging.rb
251
251
  - db/seeds.rb
252
252
  - lib/effective_messaging.rb
253
253
  - lib/effective_messaging/engine.rb