Module: ProactiveSupport::FlagsHelper

Defined in:
app/helpers/proactive_support/flags_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_flag_groupings(customer_id = nil, filter_transients = true) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/proactive_support/flags_helper.rb', line 3

def get_flag_groupings(customer_id = nil, filter_transients = true)
  flags = {}
  ar = ::ProactiveSupport::Flag.includes(:customer).where(is_active: true)
  ar = ar.where(customer_id: customer_id) if customer_id
  ar = ar.filter_transients if filter_transients
  ar.each do |f|
    next if customer_id.nil? && (f.customer.nil? || f.customer.is_deleted)
    flags[f.level] ||= {}
    flags[f.level][f.source] ||= {}
    flags[f.level][f.source][f.identifier] ||= {message: f.message, count: 0, transients: 0}
    flags[f.level][f.source][f.identifier][:count] += 1
    flags[f.level][f.source][f.identifier][:transients] += 1 if f.is_transient
  end
  Hash[flags.sort.reverse] # errors first...
end