Module: NdrError::ErrorsHelper

Defined in:
app/helpers/ndr_error/errors_helper.rb

Overview

Error-specific view helpers

Instance Method Summary collapse

Instance Method Details

#digest_for(fingerprint, search) ⇒ Object



111
112
113
114
# File 'app/helpers/ndr_error/errors_helper.rb', line 111

def digest_for(fingerprint, search)
  digest = search_matches(fingerprint.id, search)
  (:span, digest, class: 'text-muted')
end


52
53
54
55
56
57
# File 'app/helpers/ndr_error/errors_helper.rb', line 52

def downstream_fingerprint_link(print)
  hash = (:span, print.id, class: 'text-muted')
  text = print.error_logs.first.try(:error_class) || 'N/A'

  bootstrap_list_link_to hash + ' - ' + text, error_fingerprint_path(print)
end

#edit_button_for(fingerprint) ⇒ Object



68
69
70
71
72
73
# File 'app/helpers/ndr_error/errors_helper.rb', line 68

def edit_button_for(fingerprint)
  css   = 'btn btn-default'
  text  = glyphicon_tag('pencil') + ' Edit Ticket'

  link_to(text, edit_error_fingerprint_path(fingerprint), class: css)
end

#highlighted_trace_for(error) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/ndr_error/errors_helper.rb', line 9

def highlighted_trace_for(error)
  highlighting = error.application_trace

  error.backtrace.map do |line|
    css_classes = 'trace-item'
    css_classes << ' stack-only' unless highlighting.include?(line)

    (:span, line, class: css_classes)
  end
end

#latest_timestamp_for(fingerprint) ⇒ Object



20
21
22
# File 'app/helpers/ndr_error/errors_helper.rb', line 20

def latest_timestamp_for(fingerprint)
  fingerprint.updated_at.to_formatted_s(:db)
end

#latest_user_for(fingerprint, search) ⇒ Object



24
25
26
27
28
29
# File 'app/helpers/ndr_error/errors_helper.rb', line 24

def latest_user_for(fingerprint, search)
  latest = fingerprint.latest_occurrence
  text   = latest ? search_matches(latest.user_id, search) : 'N/A'

  (:span, text, class: 'text-muted')
end


106
107
108
109
# File 'app/helpers/ndr_error/errors_helper.rb', line 106

def link_to_fingerprint(fingerprint, latest)
  text = truncate(latest.error_string, length: 120)
  link_to search_matches(text, @keywords), error_fingerprint_path(fingerprint)
end

#multiple_occurrences_badge_for(fingerprint) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/helpers/ndr_error/errors_helper.rb', line 31

def multiple_occurrences_badge_for(fingerprint)
  return unless fingerprint.count > 1

  text = "+ #{fingerprint.count - 1}"
  opts = {
    'class'          => 'badge badge-info',
    'data-toggle'    => 'tooltip',
    'data-placement' => 'right',
    'title'          => "Since #{fingerprint.created_at.to_formatted_s(:db)}"
  }

  (:span, text, opts)
end

#next_button_for(error) ⇒ Object



97
98
99
100
101
102
103
104
# File 'app/helpers/ndr_error/errors_helper.rb', line 97

def next_button_for(error)
  css = 'btn btn-default'
  css << ' disabled' if error.nil?
  text = glyphicon_tag('chevron-right')
  path = error.nil? ? '#' : error_fingerprint_path(error.error_fingerprint, log_id: error)

  link_to(text, path, class: css)
end

#previous_button_for(error) ⇒ Object



88
89
90
91
92
93
94
95
# File 'app/helpers/ndr_error/errors_helper.rb', line 88

def previous_button_for(error)
  css = 'btn btn-default'
  css << ' disabled' if error.nil?
  text = glyphicon_tag('chevron-left')
  path = error.nil? ? '#' : error_fingerprint_path(error.error_fingerprint, log_id: error)

  link_to(text, path, class: css)
end

#purge_button_for(fingerprint) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/helpers/ndr_error/errors_helper.rb', line 75

def purge_button_for(fingerprint)
  css   = 'btn btn-danger'
  text  = glyphicon_tag('trash icon-white') + ' Purge'

  options = {
    'method'       => :delete,
    'class'        => css,
    'data-confirm' => 'Delete all logs of this error? - only the fingerprint will be kept.'
  }

  link_to(text, error_fingerprint_path(fingerprint), options)
end

#search_matches(string, keywords) ⇒ Object



4
5
6
7
# File 'app/helpers/ndr_error/errors_helper.rb', line 4

def search_matches(string, keywords)
  return string if keywords.blank?
  highlight(string.to_s, keywords, highlighter: '<strong class="text-danger">\1</strong>')
end


45
46
47
48
49
50
# File 'app/helpers/ndr_error/errors_helper.rb', line 45

def similar_error_link(error)
  user = error.user_id && (:span, error.user_id, class: 'text-muted')
  text = safe_join([user, error.created_at.to_formatted_s(:db)].compact, ' - ')

  bootstrap_list_link_to text, error_fingerprint_path(error.error_fingerprint, log_id: error)
end

#sorted_parameters_for(error) ⇒ Object



116
117
118
# File 'app/helpers/ndr_error/errors_helper.rb', line 116

def sorted_parameters_for(error)
  error.parameters.to_a.sort_by { |key, _value| key.to_s }
end


59
60
61
62
63
64
65
66
# File 'app/helpers/ndr_error/errors_helper.rb', line 59

def ticket_link_for(fingerprint, small = false)
  text = glyphicon_tag('asterisk') + ' View ticket'
  css  = 'btn btn-default'
  css << ' btn-xs' if small

  url = fingerprint.ticket_url
  link_to(text, /^http/i =~ url ? url : "http://#{url}", class: css)
end