effective_reports 0.2.0 → 0.2.1

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: 7e8af98bc740da567e5817f47c85c8c6fdc84b3c426d87dfa2ebd27e43f68cc2
4
- data.tar.gz: 6243524e413ddb99b6c5ea1d87b9bb70f9fe581a7379f07cc5342728cac5cf83
3
+ metadata.gz: c8f0160d7a3eeab66cc8efa955bb852413cbb7440e997c203f24b628fc573734
4
+ data.tar.gz: 707e208abe7ca336245094a91c934b8a9b37a19f4e267b7a79f39e76f5ca4f4d
5
5
  SHA512:
6
- metadata.gz: a999a402c388c5c1f4c6324ca65461366277fd7ba1395ebbf7e00b104f929dcdbbb48717dec71ddc0488be131b4b2d2f9062d1341b25007c8467f98297f8f813
7
- data.tar.gz: a007445b4207e5a57362aeaad6efa004149d201991ddb449bd4752cc1dea6020be0866e7df56c2016abd1b7e05d28747dd7e2a68e20e4e9b3faf42c4ccea701e
6
+ metadata.gz: 400664a1606650241176dfb5f883a60a649f50a4411077437cbe672e54259b0e60548fe9df3494d27febe110cf94501010cf0a975903ea2055754e09134383d8
7
+ data.tar.gz: eaf63a27d36604502fd73556df6ac575fbbc7a5585938acd5dc90b1c088b49c93a36362787c4bbd35b61a6c1fbd1b918bad8880e4aefd64c2c02da7b14250ae4
@@ -3,6 +3,7 @@
3
3
  $(document).on('change', "[name^='effective_report[report_columns_attributes]'][name$='[filter]']", function(event) {
4
4
  let $filter = $(event.currentTarget);
5
5
  let $values = $filter.closest('.row').find('.effective-report-filter');
6
+
6
7
  let $inputs = $values.find('input,textarea,select,button');
7
8
 
8
9
  if($filter.is(':checked')) {
@@ -12,4 +13,24 @@ $(document).on('change', "[name^='effective_report[report_columns_attributes]'][
12
13
  $values.hide();
13
14
  $inputs.prop('disabled', true);
14
15
  }
16
+
17
+ $values.find("[data-effective-reports-date-operation]").trigger('change');
18
+ });
19
+
20
+ // The date operation can be either a date or an integet days field
21
+ $(document).on('change', "[data-effective-reports-date-operation]", function(event) {
22
+ let $select = $(event.currentTarget);
23
+ let $dateValues = $select.closest('.row').find('.effective-report-filter');
24
+
25
+ let value = $select.val() || ''
26
+
27
+ if(value.includes('days')) {
28
+ // Enable days (integer) and disable date
29
+ $dateValues.filter('.effective-report-days-filter').show().find('input').removeAttr('disabled');
30
+ $dateValues.filter('.effective-report-date-filter').hide().find('input').prop('disabled', true);
31
+ } else {
32
+ // Enable date and disable days (integer)
33
+ $dateValues.filter('.effective-report-date-filter').show().find('input').removeAttr('disabled');
34
+ $dateValues.filter('.effective-report-days-filter').hide().find('input').prop('disabled', true);
35
+ }
15
36
  });
@@ -36,7 +36,19 @@ module EffectiveReportsHelper
36
36
  ['Starts with', :starts_with],
37
37
  ['Ends with', :ends_with]
38
38
  ]
39
- when :integer, :price, :date, :decimal
39
+ when :date
40
+ [
41
+ ['Days ago Equals =', :days_ago_eq],
42
+ ['Days ago Greater than or equal to >=', :days_ago_gteq],
43
+ ['Days ago Less than or equal to <=', :days_ago_lteq],
44
+ ['Date Equals =', :eq],
45
+ ['Date Does Not Equal !=', :not_eq],
46
+ ['Date Greater than >', :gt],
47
+ ['Date Greater than or equal to >=', :gteq],
48
+ ['Date Less than <', :lt],
49
+ ['Date Less than or equal to <=', :lteq],
50
+ ]
51
+ when :integer, :price, :decimal
40
52
  [
41
53
  ['Equals =', :eq],
42
54
  ['Does Not Equal !=', :not_eq],
@@ -67,7 +67,7 @@ module Effective
67
67
  scopes.each do |scope, type|
68
68
  raise("#{reportable}.reportable_scopes #{scope} => #{type || 'nil'} is invalid. Key must be a symbol") unless scope.kind_of?(Symbol)
69
69
  raise("#{reportable}.reportable_scopes :#{scope} => #{type || 'nil'} is invalid. Value must be one of #{DATATYPES.map { |s| ":#{s}"}.join(', ')}") if type.present? && !DATATYPES.include?(type)
70
- raise("#{reportable} must respond to reportable scope :#{name}") unless reportable.respond_to?(scope)
70
+ raise("#{reportable} must respond to reportable scope :#{scope}") unless reportable.respond_to?(scope)
71
71
  end
72
72
 
73
73
  scopes
@@ -55,7 +55,7 @@ module Effective
55
55
  end
56
56
 
57
57
  def to_s
58
- [name, operation_label, value].compact.join(' ').presence || 'report column'
58
+ [name, operation_label, value, days_label].compact.join(' ').presence || 'report column'
59
59
  end
60
60
 
61
61
  def format(value)
@@ -63,7 +63,7 @@ module Effective
63
63
 
64
64
  case as.to_sym
65
65
  when :boolean then value.to_s
66
- when :date then value.strftime('%F')
66
+ when :date then value.try(:strftime, '%F') || value.to_s
67
67
  when :decimal then value.to_s
68
68
  when :integer then value.to_s
69
69
  when :price then '$' + ('%0.2f' % (value / 100.0))
@@ -77,11 +77,21 @@ module Effective
77
77
  end
78
78
  end
79
79
 
80
+ # Days Since functionality
81
+ def days_filter?
82
+ as == 'date' && operation.to_s.include?('days')
83
+ end
84
+
85
+ def date_filter?
86
+ as == 'date' && operation.to_s.exclude?('days')
87
+ end
88
+
80
89
  def as_associated?
81
90
  [:belongs_to, :belongs_to_polymorphic, :has_many, :has_one].include?(as.to_sym)
82
91
  end
83
92
 
84
93
  def value
94
+ return value_integer if days_filter?
85
95
  value_date || value_decimal || value_integer || value_price || value_string.presence || value_associated.presence || value_boolean
86
96
  end
87
97
 
@@ -100,10 +110,23 @@ module Effective
100
110
  when :lt then '<'
101
111
  when :lteq then '<='
102
112
  when :sql then 'sql'
113
+ when :days_ago_eq then '='
114
+ when :days_ago_gteq then '>='
115
+ when :days_ago_lteq then '<='
103
116
  else
104
117
  raise("unexpected operation: #{operation}")
105
118
  end
106
119
  end
107
120
 
121
+ def days_label
122
+ case operation.to_sym
123
+ when :days_ago_eq then 'days ago'
124
+ when :days_ago_gteq then 'days ago'
125
+ when :days_ago_lteq then 'days ago'
126
+ else
127
+ ''
128
+ end
129
+ end
130
+
108
131
  end
109
132
  end
@@ -60,11 +60,14 @@
60
60
  = frc.hidden_field :as, value: :date
61
61
 
62
62
  .col.effective-report-filter{style: ('display: none;' unless frc.object.filter?)}
63
- = frc.select :operation, reportable_operations_collection(:date), label: false
63
+ = frc.select :operation, reportable_operations_collection(:date), label: false, 'data-effective-reports-date-operation': true
64
64
 
65
- .col.effective-report-filter{style: ('display: none;' unless frc.object.filter?)}
65
+ .col.effective-report-filter.effective-report-date-filter{style: ('display: none;' unless frc.object.filter? && frc.object.date_filter?)}
66
66
  = frc.date_field :value_date, label: false
67
67
 
68
+ .col.effective-report-filter.effective-report-days-filter{style: ('display: none;' unless frc.object.filter? && frc.object.days_filter?)}
69
+ = frc.integer_field :value_integer, label: false
70
+
68
71
  = frc.show_if_any(:name, value_decimals) do
69
72
  .row
70
73
  .col.mt-2
@@ -1,3 +1,3 @@
1
1
  module EffectiveReports
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.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.0
4
+ version: 0.2.1
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-02-02 00:00:00.000000000 Z
11
+ date: 2023-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails