Module: RailsErrorDashboard::ApplicationHelper

Defined in:
app/helpers/rails_error_dashboard/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#current_user_nameString

Returns the current user name for filtering “My Errors” Uses configured dashboard username or system username

Returns:

  • (String)

    Current user identifier



80
81
82
# File 'app/helpers/rails_error_dashboard/application_helper.rb', line 80

def current_user_name
  RailsErrorDashboard.configuration.dashboard_username || ENV["USER"] || "unknown"
end

Generates a link to a git commit if repository URL is configured

Parameters:

  • git_sha (String)

    The git commit SHA

  • short (Boolean) (defaults to: true)

    Whether to show short SHA (7 chars) or full SHA

Returns:

  • (String)

    HTML safe link to commit or plain text if no repo configured



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/helpers/rails_error_dashboard/application_helper.rb', line 119

def git_commit_link(git_sha, short: true)
  return "" if git_sha.blank?

  config = RailsErrorDashboard.configuration
  display_sha = short ? git_sha[0..6] : git_sha

  if config.git_repository_url.present?
    # Support GitHub, GitLab, Bitbucket URL formats
    commit_url = "#{config.git_repository_url.chomp("/")}/commit/#{git_sha}"
    link_to display_sha, commit_url, class: "text-decoration-none font-monospace", target: "_blank", rel: "noopener"
  else
    (:code, display_sha, class: "font-monospace")
  end
end

#local_time(time, format: :full, fallback: "N/A") ⇒ String

Renders a timestamp that will be automatically converted to user’s local timezone Server sends UTC timestamp, JavaScript converts to local timezone on page load

Parameters:

  • time (Time, DateTime, nil)

    The timestamp to display

  • format (Symbol) (defaults to: :full)

    Format preset (:full, :short, :date_only, :time_only, :datetime)

  • fallback (String) (defaults to: "N/A")

    Text to show if time is nil

Returns:

  • (String)

    HTML safe span with data attributes for JS conversion



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'app/helpers/rails_error_dashboard/application_helper.rb', line 140

def local_time(time, format: :full, fallback: "N/A")
  return fallback if time.nil?

  # Convert to UTC if not already
  utc_time = time.respond_to?(:utc) ? time.utc : time

  # ISO 8601 format for JavaScript parsing
  iso_time = utc_time.iso8601

  # Format presets for data-format attribute
  format_string = case format
  when :full
    "%B %d, %Y %I:%M:%S %p"  # December 31, 2024 11:59:59 PM
  when :short
    "%m/%d %I:%M%p"          # 12/31 11:59PM
  when :date_only
    "%B %d, %Y"              # December 31, 2024
  when :time_only
    "%I:%M:%S %p"            # 11:59:59 PM
  when :datetime
    "%b %d, %Y %H:%M"        # Dec 31, 2024 23:59
  else
    format.to_s
  end

  (
    :span,
    utc_time.strftime(format_string + " UTC"),  # Fallback for non-JS browsers
    class: "local-time",
    data: {
      utc: iso_time,
      format: format_string
    }
  )
end

#local_time_ago(time, fallback: "N/A") ⇒ String

Renders a relative time (“3 hours ago”) that updates automatically

Parameters:

  • time (Time, DateTime, nil)

    The timestamp to display

  • fallback (String) (defaults to: "N/A")

    Text to show if time is nil

Returns:

  • (String)

    HTML safe span with data attributes for JS conversion



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'app/helpers/rails_error_dashboard/application_helper.rb', line 180

def local_time_ago(time, fallback: "N/A")
  return fallback if time.nil?

  # Convert to UTC if not already
  utc_time = time.respond_to?(:utc) ? time.utc : time
  iso_time = utc_time.iso8601

  (
    :span,
    time_ago_in_words(time) + " ago",  # Fallback for non-JS browsers
    class: "local-time-ago",
    data: {
      utc: iso_time
    }
  )
end

#platform_color_var(platform) ⇒ String

Returns platform-specific color class

Parameters:

  • platform (String)

    Platform name (ios, android, web, api)

Returns:

  • (String)

    CSS color variable



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/rails_error_dashboard/application_helper.rb', line 44

def platform_color_var(platform)
  case platform&.downcase
  when "ios"
    "var(--platform-ios)"
  when "android"
    "var(--platform-android)"
  when "web"
    "var(--platform-web)"
  when "api"
    "var(--platform-api)"
  else
    "var(--text-color)"
  end
end

#platform_icon(platform) ⇒ String

Returns platform icon

Parameters:

  • platform (String)

    Platform name (ios, android, web, api)

Returns:

  • (String)

    Bootstrap icon class



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/rails_error_dashboard/application_helper.rb', line 62

def platform_icon(platform)
  case platform&.downcase
  when "ios"
    "bi-apple"
  when "android"
    "bi-android2"
  when "web"
    "bi-globe"
  when "api"
    "bi-server"
  else
    "bi-question-circle"
  end
end

#severity_color(severity) ⇒ String

Returns Bootstrap color class for error severity Uses Catppuccin Mocha colors in dark theme via CSS variables

Parameters:

  • severity (Symbol)

    The severity level (:critical, :high, :medium, :low, :info)

Returns:

  • (String)

    Bootstrap color class (danger, warning, info, secondary)



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/rails_error_dashboard/application_helper.rb', line 7

def severity_color(severity)
  case severity&.to_sym
  when :critical
    "danger"   # Maps to --ctp-red in dark mode
  when :high
    "warning"  # Maps to --ctp-peach in dark mode
  when :medium
    "info"     # Maps to --ctp-blue in dark mode
  when :low
    "secondary" # Maps to --ctp-overlay1 in dark mode
  else
    "secondary"
  end
end

#severity_color_var(severity) ⇒ String

Returns CSS variable for severity color (for inline styles) Useful when you need to set background-color or color directly

Parameters:

  • severity (Symbol)

    The severity level

Returns:

  • (String)

    CSS variable reference



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/helpers/rails_error_dashboard/application_helper.rb', line 26

def severity_color_var(severity)
  case severity&.to_sym
  when :critical
    "var(--ctp-red)"
  when :high
    "var(--ctp-peach)"
  when :medium
    "var(--ctp-blue)"
  when :low
    "var(--ctp-overlay1)"
  else
    "var(--ctp-overlay1)"
  end
end

#sortable_header(label, column) ⇒ String

Generates a sortable column header link

Parameters:

  • label (String)

    The column label to display

  • column (String)

    The column name to sort by

Returns:

  • (String)

    HTML safe link with sort indicator



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/helpers/rails_error_dashboard/application_helper.rb', line 88

def sortable_header(label, column)
  current_sort = params[:sort_by]
  current_direction = params[:sort_direction] || "desc"

  # Determine new direction: if clicking same column, toggle; otherwise default to desc
  new_direction = if current_sort == column
    current_direction == "asc" ? "desc" : "asc"
  else
    "desc"
  end

  # Choose icon based on current state
  icon = if current_sort == column
    current_direction == "asc" ? "" : ""
  else
    ""  # Unsorted indicator
  end

  # Preserve existing filter params while adding sort params
  link_params = params.permit!.to_h.merge(sort_by: column, sort_direction: new_direction)

  link_to errors_path(link_params), class: "text-decoration-none" do
    (:span, "#{label} ", class: current_sort == column ? "fw-bold" : "") +
    (:span, icon, class: "text-muted small")
  end
end