effective_reports 0.2.2 → 0.2.3

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: 3fdd496c78cd961c97fd7fdcac5a24fe50dd30d9b924df9dd3373a9dd9968ca0
4
- data.tar.gz: be36d71a6214183561fc381c9e74c28ce8875ff394ac91571bac8e2c5ebd9bfb
3
+ metadata.gz: 114ad37c7da77453343c93c770d85db4d7dc03a75a151e7fead6f94110ecd6e3
4
+ data.tar.gz: 6b0a1b43d71bef9780bffeaccb546146316dc3ce5f918fed73bfac0be0ce860c
5
5
  SHA512:
6
- metadata.gz: a7b6ce19b19f82a91518b9b9de083935eb213c15a1cfc09ea4b25c07cddbd8282f68622cf15749550df48170dabc42ed565fea368b0f096d00911e772abbbcb2
7
- data.tar.gz: 0bb82f6cb3fb21984886cfdb7faa36d221b3dd800364d3bfe1176a93ad8fe159f19ea4d012bac985893b68b5b2badd841918e7878e21466b1c06fe1b2f326192
6
+ metadata.gz: 4ab9954ca02cdd90510cfbc8c28c8554d9c17acc5014d2b8cdc502d5318cec92d325c2396e8f952df70dbbaf07d0355f3757e56b9c88582da82c5b4a266fb705
7
+ data.tar.gz: 25d4851233da531115e1d480a765f50a5b26c6d6f54782e631a3c26a64af45cb70d20002f3cc8b2604c574ff48f9e85cacc4124d011c3cb9ace5faf68dac0b8b
@@ -16,6 +16,10 @@ module Admin
16
16
  col :report_columns, label: 'Columns', visible: false
17
17
  col :report_scopes, label: 'Scopes', visible: false
18
18
 
19
+ if defined?(EffectiveMessaging)
20
+ col :notifications, label: 'Notifications'
21
+ end
22
+
19
23
  col(:current_rows_count) do |report|
20
24
  report.collection().count
21
25
  end
@@ -8,6 +8,10 @@ class EffectiveReportDatatable < Effective::Datatable
8
8
 
9
9
  col :id, visible: false
10
10
 
11
+ if report.reportable.column_names.include?('token')
12
+ col :token, visible: false
13
+ end
14
+
11
15
  report.report_columns.each do |column|
12
16
  col(column.name, as: column.as.to_sym)
13
17
  end
@@ -29,6 +29,11 @@ module ActsAsReportable
29
29
  {}
30
30
  end
31
31
 
32
+ # Something that returns an email
33
+ def reportable_email
34
+ try(:email) || try(:user).try(:email) || try(:owner).try(:email) || raise("No reportable_email found")
35
+ end
36
+
32
37
  private
33
38
 
34
39
  def all_reportable_attributes
@@ -10,6 +10,11 @@ module Effective
10
10
  has_many :report_scopes, -> { ReportScope.sorted }, inverse_of: :report, dependent: :delete_all
11
11
  accepts_nested_attributes_for :report_scopes, allow_destroy: true, reject_if: proc { |atts| atts['name'].blank? }
12
12
 
13
+ if defined?(EffectiveMessaging)
14
+ has_many :notifications, inverse_of: :report, dependent: :delete_all
15
+ accepts_nested_attributes_for :notifications, allow_destroy: true
16
+ end
17
+
13
18
  log_changes if respond_to?(:log_changes)
14
19
 
15
20
  DATATYPES = [:boolean, :date, :decimal, :integer, :price, :string, :belongs_to, :belongs_to_polymorphic, :has_many, :has_one]
@@ -26,7 +31,7 @@ module Effective
26
31
 
27
32
  scope :deep, -> { includes(:report_columns, :report_scopes) }
28
33
  scope :sorted, -> { order(:title) }
29
- scope :emails, -> { where(id: ReportColumn.emails.select(:report_id)) }
34
+ scope :notifiable, -> { where(id: ReportColumn.notifiable.select(:report_id)) }
30
35
 
31
36
  validates :title, presence: true, uniqueness: true
32
37
  validates :reportable_class_name, presence: true
@@ -39,6 +44,23 @@ module Effective
39
44
  reportable_class_name.constantize if reportable_class_name.present?
40
45
  end
41
46
 
47
+ # Find or build
48
+ def col(name, atts = {})
49
+ atts[:name] ||= name.to_sym
50
+ atts[:as] ||= reportable_attributes[name]
51
+
52
+ report_columns.find { |col| atts.all? { |k, v| col.send(k).to_s == v.to_s } } || report_columns.build(atts)
53
+ end
54
+
55
+ def scope(name, atts = {})
56
+ atts[:name] ||= name.to_sym
57
+ report_scopes.find { |scope| scope.name == name.to_s } || report_scopes.build(atts)
58
+ end
59
+
60
+ def notification(atts = {})
61
+ notifications.find { |col| atts.all? { |k, v| col.send(k).to_s == v.to_s } } || notifications.build(atts)
62
+ end
63
+
42
64
  def filtered_report_columns
43
65
  report_columns.select(&:filter?)
44
66
  end
@@ -47,6 +69,12 @@ module Effective
47
69
  report_columns.find { |column| column.name == 'email' } || report_columns.find { |column| column.name.include?('email') }
48
70
  end
49
71
 
72
+ def user_report_column
73
+ report_columns.find { |column| column.name == 'user' } ||
74
+ report_columns.find { |column| column.name == 'owner' } ||
75
+ report_columns.find { |column| column.name.include?('user') }
76
+ end
77
+
50
78
  # Used to build the Reports form
51
79
  # { id: :integer, archived: :boolean }
52
80
  def reportable_attributes
@@ -27,7 +27,7 @@ module Effective
27
27
 
28
28
  scope :deep, -> { includes(:report) }
29
29
  scope :sorted, -> { order(:position) }
30
- scope :emails, -> { where('name ILIKE ?', "%email%") }
30
+ scope :notifiable, -> { where('name ILIKE ?', "%email%").or(where(name: 'user')).or(where(name: 'owner')) }
31
31
 
32
32
  before_validation(if: -> { report.present? }) do
33
33
  self.position ||= (report.report_columns.map(&:position).compact.max || -1) + 1
@@ -54,6 +54,12 @@ module Effective
54
54
  end
55
55
  end
56
56
 
57
+ validate(if: -> { report&.reportable }) do
58
+ unless report.reportable.new.reportable_attributes.key?(name.to_sym)
59
+ errors.add(:name, "acts_as_reportable #{report.reportable} reportable_attributes() missing :#{name} attribute")
60
+ end
61
+ end
62
+
57
63
  def to_s
58
64
  [name, operation_label, value, days_label].compact.join(' ').presence || 'report column'
59
65
  end
@@ -36,6 +36,12 @@ module Effective
36
36
  end
37
37
  end
38
38
 
39
+ validate(if: -> {report&.reportable }) do
40
+ unless report.reportable.new.reportable_scopes.key?(name.to_sym)
41
+ errors.add(:name, "acts_as_reportable #{report.reportable} reportable_scopes() missing :#{name} scope")
42
+ end
43
+ end
44
+
39
45
  def to_s
40
46
  [name, operation_label, value].compact.join(' ').presence || 'report scope'
41
47
  end
@@ -3,6 +3,11 @@
3
3
  = render 'admin/reports/form_report', report: report
4
4
 
5
5
  - if report.persisted?
6
+ - if report.respond_to?(:notifications)
7
+ = tab 'Notifications' do
8
+ - datatable = Admin::EffectiveNotificationsDatatable.new(report: report)
9
+ = render_inline_datatable(datatable)
10
+
6
11
  - if report.respond_to?(:log_changes_datatable)
7
12
  = tab 'Logs' do
8
13
  = render_inline_datatable(report.log_changes_datatable)
@@ -13,5 +13,11 @@
13
13
  = collapse('Show SQL') do
14
14
  %p= report.collection.to_sql
15
15
 
16
+ - if (notifications = report.try(:notifications)).present?
17
+ %p.mt-3
18
+ The following notifications are sent based on this report:
19
+ - notifications.each do |notification|
20
+ = link_to(notification, effective_messaging.edit_admin_notification_path(notification), target: '_blank')
21
+
16
22
  - datatable = EffectiveReportDatatable.new(report: report)
17
23
  = render_datatable(datatable)
@@ -1,3 +1,3 @@
1
1
  module EffectiveReports
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_reports
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
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-05-11 00:00:00.000000000 Z
11
+ date: 2023-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails