effective_reports 0.4.0 → 0.4.2

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: bc5e577b9e0f7dbcd5425889023bc698c029deda52104a0a36e9ab3c5eb4a353
4
- data.tar.gz: 01ebdb1ecff80758de3a495dee72919e514ded99b4c831e1995ab1f6ca7b28d3
3
+ metadata.gz: 1305cf7f8937e178a2d5eb94df49644b7249f01a856e1cd42b47277fca4f70b8
4
+ data.tar.gz: aeb156bd5fdaef4b66bb31546511ed06735374f939280d952a0530b9ff3b0a76
5
5
  SHA512:
6
- metadata.gz: fed92ce6f5d9c049fae81dea487c1f061c4b05aed86202042fcbd5f4eb01de6b2bb2662d89b73fb9917fc79e188e500e3ab76be94e5c845f5005cad77734e6ff
7
- data.tar.gz: 7b90bca9c8cc801a7cdf5cb4e25603e94ee313a8a6ae607e30fedbe0c95dfc134f832af88467b2c7b3bbf348c1cad62370f789d98d014d9945a025bef9e66a8e
6
+ metadata.gz: 46a1c37be1ab24c71263269ef3b981a66bb9854b18349821190c298a24d96b7bace90565173153eb468b32ec3fe5c9f9f3295201f8e1359a5236c6ea5cd1dd68
7
+ data.tar.gz: fef84a63e254279dfb27d8b0c9c31991c7f6232e6fc4af6923e1607ae440575eba691fff37dbe46ef2800dbdc283fa87d8e0ef8f1754e94d441c2bc4b2ba7494
@@ -23,7 +23,7 @@ class EffectiveReportDatatable < Effective::Datatable
23
23
  end
24
24
 
25
25
  def report
26
- Effective::Report.find(attributes[:report_id])
26
+ Effective::Report.deep.find(attributes[:report_id])
27
27
  end
28
28
 
29
29
  end
@@ -6,6 +6,7 @@ module ActsAsReportable
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  PRICE_NAME_ATTRIBUTES = ['price', 'subtotal', 'tax', 'total', 'current_revenue', 'current_revenue_subtotal', 'current_revenue_tax', 'deferred_revenue', 'deferred_revenue_subtotal', 'deferred_revenue_tax', 'amount_owing', 'surcharge']
9
+ DENY_LIST = [:logged_changes, :password, :encrypted_password]
9
10
 
10
11
  module Base
11
12
  def acts_as_reportable(options = nil)
@@ -80,7 +81,7 @@ module ActsAsReportable
80
81
  end; h
81
82
  end
82
83
 
83
- atts.merge(associated)
84
+ atts.merge(associated).except(*DENY_LIST)
84
85
  end
85
86
 
86
87
  end
@@ -29,13 +29,28 @@ module Effective
29
29
  timestamps
30
30
  end
31
31
 
32
- scope :deep, -> { includes(:report_columns, :report_scopes) }
32
+ scope :deep, -> {
33
+ base = includes(:report_columns, :report_scopes)
34
+ base = base.includes(:notifications) if defined?(EffectiveMessaging)
35
+ base
36
+ }
37
+
33
38
  scope :sorted, -> { order(:title) }
34
39
  scope :notifiable, -> { where(id: ReportColumn.notifiable.select(:report_id)) }
35
40
 
36
41
  validates :title, presence: true, uniqueness: true
37
42
  validates :reportable_class_name, presence: true
38
43
 
44
+ validate do
45
+ error = begin
46
+ collection().to_sql; nil
47
+ rescue StandardError => e
48
+ e.message
49
+ end
50
+
51
+ errors.add(:base, "Invalid Report: #{error}") if error.present?
52
+ end
53
+
39
54
  def to_s
40
55
  title.presence || 'report'
41
56
  end
@@ -107,7 +122,7 @@ module Effective
107
122
 
108
123
  # Apply Scopes
109
124
  report_scopes.each do |scope|
110
- collection = (scope.value.nil? ? collection.send(scope.name) : collection.send(scope.name, scope.value))
125
+ collection = scope.apply_scope(collection)
111
126
  end
112
127
 
113
128
  # Apply Includes
@@ -37,9 +37,19 @@ module Effective
37
37
  end
38
38
 
39
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")
40
+ reportable = report.reportable
41
+
42
+ if reportable.new.reportable_scopes.key?(name.to_sym) == false
43
+ errors.add(:name, "acts_as_reportable #{reportable} reportable_scopes() missing :#{name} scope")
44
+ end
45
+
46
+ scope_error = begin
47
+ apply_scope(reportable.all).to_sql; nil
48
+ rescue StandardError => e
49
+ e.message
42
50
  end
51
+
52
+ self.errors.add(:name, scope_error) if scope_error.present?
43
53
  end
44
54
 
45
55
  def to_s
@@ -54,5 +64,9 @@ module Effective
54
64
  return '=' if advanced?
55
65
  end
56
66
 
67
+ def apply_scope(collection)
68
+ value.nil? ? collection.send(name) : collection.send(name, value)
69
+ end
70
+
57
71
  end
58
72
  end
@@ -1,23 +1,24 @@
1
- - if report.description.present?
2
- %p= simple_format(report.description)
1
+ = card do
2
+ - if report.description.present?
3
+ %p= simple_format(report.description)
3
4
 
4
- - if report.filtered_report_columns.present? || report.report_scopes.present?
5
- %p The results of this report have been filtered by the following:
5
+ - if report.filtered_report_columns.present? || report.report_scopes.present?
6
+ %p The results of this report have been filtered by the following:
6
7
 
7
- - if report.filtered_report_columns.present?
8
- %p= badges(report.filtered_report_columns.map(&:to_s))
8
+ - if report.filtered_report_columns.present?
9
+ %p= badges(report.filtered_report_columns.map(&:to_s))
9
10
 
10
- - if report.report_scopes.present?
11
- %p= badges(report.report_scopes.map(&:to_s))
11
+ - if report.report_scopes.present?
12
+ %p= badges(report.report_scopes.map(&:to_s))
12
13
 
13
- = collapse('Show SQL') do
14
- %p= report.collection.to_sql
14
+ = collapse('Show SQL') do
15
+ %p= report.collection.to_sql
15
16
 
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')
17
+ - if (notifications = report.try(:notifications)).present?
18
+ %p.mt-3
19
+ The following notifications are sent based on this report:
20
+ - notifications.each do |notification|
21
+ = link_to(notification, effective_messaging.edit_admin_notification_path(notification), target: '_blank')
21
22
 
22
- - datatable = EffectiveReportDatatable.new(report: report)
23
- = render_datatable(datatable)
23
+ - datatable = EffectiveReportDatatable.new(report: report)
24
+ = render_datatable(datatable)
@@ -1,3 +1,3 @@
1
1
  module EffectiveReports
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.2'.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.4.0
4
+ version: 0.4.2
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-10-26 00:00:00.000000000 Z
11
+ date: 2023-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails