Module: EffectiveReportsHelper

Defined in:
app/helpers/effective_reports_helper.rb

Instance Method Summary collapse

Instance Method Details

#reportable_attributes_collection(attributes) ⇒ Object



7
8
9
10
11
12
13
14
# File 'app/helpers/effective_reports_helper.rb', line 7

def reportable_attributes_collection(attributes)
  macros = [:belongs_to, :belongs_to_polymorphic, :has_many, :has_one]

  {
    'Attributes' => attributes.select { |_, type| macros.exclude?(type) }.map { |att, _| [att, att] }.sort,
    'Associations' => attributes.select { |_, type| macros.include?(type) }.map { |att, _| [att, att] }.sort,
  }
end

#reportable_boolean_collectionObject



3
4
5
# File 'app/helpers/effective_reports_helper.rb', line 3

def reportable_boolean_collection
  [['Yes', true], ['No', false]]
end

#reportable_operations_collection(type) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/helpers/effective_reports_helper.rb', line 23

def reportable_operations_collection(type)
  case type
  when :boolean
    [
      ['Equals', :eq],
      ['Does Not Equal', :not_eq]
    ]
  when :string
    [
      ['Equals =', :eq],
      ['Does Not Equal !=', :not_eq],
      ['Includes', :matches],
      ['Does Not Include', :does_not_match],
      ['Starts with', :starts_with],
      ['Ends with', :ends_with]
    ]
  when :date
    [
      ['Days ago Equals =', :days_ago_eq],
      ['Days ago Greater than or equal to >=', :days_ago_gteq],
      ['Days ago Less than or equal to <=', :days_ago_lteq],
      ['Date Equals =', :eq],
      ['Date Does Not Equal !=', :not_eq],
      ['Date Greater than >', :gt],
      ['Date Greater than or equal to >=', :gteq],
      ['Date Less than <', :lt],
      ['Date Less than or equal to <=', :lteq],
    ]
  when :integer, :price, :decimal
    [
      ['Equals =', :eq],
      ['Does Not Equal !=', :not_eq],
      ['Greater than >', :gt],
      ['Greater than or equal to >=', :gteq],
      ['Less than <', :lt],
      ['Less than or equal to <=', :lteq],
    ]
  when :belongs_to, :belongs_to_polymorphic, :has_many, :has_one
    [
      ['ID(s) Equals =', :eq],
      ['Matches', :matches],
      ['Does Not Match', :does_not_match],
      ['SQL', :sql],
    ]
  else
    raise("unexpected reportable operations collection type: #{type || 'nil'}")
  end
end

#reportable_scopes_collection(scopes) ⇒ Object



16
17
18
19
20
21
# File 'app/helpers/effective_reports_helper.rb', line 16

def reportable_scopes_collection(scopes)
  {
    'Basic' => scopes.select { |_, type| type.blank? }.map { |scope, _| [scope, scope] }.sort,
    'Advanced' => scopes.select { |_, type| type.present? }.map { |scope, _| [scope, scope] }.sort
  }
end