Module: EffectiveLoggingHelper

Defined in:
app/helpers/effective_logging_helper.rb

Constant Summary collapse

ALLOWED_TAGS =
[
  "a", "abbr", "acronym", "address", "b", "big", "blockquote", "br", "cite", "code", "dd", "del", "dfn", "div", "dl", "dt", "em",
  "h1", "h2", "h3", "h4", "h5", "h6", "hr", "i", "img", "ins", "kbd", "li", "ol", "p", "pre", "samp", "small", "span", "strong",
  "sub", "sup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "tt", "ul", "var"
]
ALLOWED_ATTRIBUTES =
[
  "abbr", "alt", "cite", "class", "colspan", "datetime", "height", "href", "name", "rowspan", "src", "title", "width", "xml:lang"
]

Instance Method Summary collapse

Instance Method Details

#bootstrap_class_for_status(status) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/effective_logging_helper.rb', line 12

def bootstrap_class_for_status(status)
  case status
    when 'success'  ; 'success'
    when 'info'     ; 'info'
    when 'warning'  ; 'warning'
    when 'error'    ; 'danger'
    when 'change'   ; 'info'
    else 'primary'
  end
end

This is called on the Logs#show Admin page, and is intended for override by the application



34
35
36
37
38
39
40
41
42
# File 'app/helpers/effective_logging_helper.rb', line 34

def effective_logging_object_link_to(obj, action = :show)
  if obj.kind_of?(User)
    if action == :show && defined?(admin_user_path)
      link_to('View', admin_user_path(obj))
    elsif action == :edit && defined?(edit_admin_user_path)
      link_to('Edit', edit_admin_user_path(obj))
    end
  end
end

#format_log_details_resource_value(value) ⇒ Object



70
71
72
# File 'app/helpers/effective_logging_helper.rb', line 70

def format_log_details_resource_value(value)
  simple_format(sanitize(value.to_s, tags: ALLOWED_TAGS, attributes: ALLOWED_ATTRIBUTES), {}, sanitize: false)
end

#format_log_details_value(log, key) ⇒ Object

tabelize_hash and format_resource_value are from effective_resources



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/helpers/effective_logging_helper.rb', line 45

def format_log_details_value(log, key)
  value = log.details[key]

  return tableize_hash(value) unless value.kind_of?(String)

  open = value.index('<!DOCTYPE html') || value.index('<html')
  close = value.rindex('</html>') if open.present?
  return format_log_details_resource_value(value) unless (open.present? && close.present?)

  before = value[0...open]
  after = value[(close+7)..-1]
  divide = before.sub!('<hr>', '').present?

  [
    h(before).gsub("\n", '<br>'),
    ((:hr) if divide),
    (:iframe, '',
      src: effective_logging.html_part_log_path(log, key: key),
      style: 'frameborder: 0; border: 0; width: 100%; height: 100%;',
      onload: "this.style.height=(this.contentDocument.body.scrollHeight + 30) + 'px';",
      scrolling: 'no'),
    h(after).gsub("\n", '<br>')
  ].compact.join.html_safe
end

#parents_of_log(log) ⇒ Object



27
28
29
30
31
# File 'app/helpers/effective_logging_helper.rb', line 27

def parents_of_log(log)
  parents = [log.parent]
  parents << parents.last.parent while(parents.last.try(:parent_id).present?)
  parents.compact.reverse
end

#render_log(log) ⇒ Object



23
24
25
# File 'app/helpers/effective_logging_helper.rb', line 23

def render_log(log)
  render(partial: 'effective/logs/log', locals: { log: log })
end