Class: RailsErrorDashboard::ErrorsController

Inherits:
ApplicationController show all
Includes:
Pagy::Backend
Defined in:
app/controllers/rails_error_dashboard/errors_controller.rb

Instance Method Summary collapse

Instance Method Details

#analyticsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/rails_error_dashboard/errors_controller.rb', line 46

def analytics
  days = (params[:days] || 30).to_i
  @days = days

  # Use Query to get analytics data
  analytics = Queries::AnalyticsStats.call(days)

  @error_stats = analytics[:error_stats]
  @errors_over_time = analytics[:errors_over_time]
  @errors_by_type = analytics[:errors_by_type]
  @errors_by_platform = analytics[:errors_by_platform]
  @errors_by_environment = analytics[:errors_by_environment]
  @errors_by_hour = analytics[:errors_by_hour]
  @top_users = analytics[:top_users]
  @resolution_rate = analytics[:resolution_rate]
  @mobile_errors = analytics[:mobile_errors]
  @api_errors = analytics[:api_errors]
end

#batch_actionObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/controllers/rails_error_dashboard/errors_controller.rb', line 65

def batch_action
  error_ids = params[:error_ids] || []
  action_type = params[:action_type]

  result = case action_type
  when "resolve"
    Commands::BatchResolveErrors.call(
      error_ids,
      resolved_by_name: params[:resolved_by_name],
      resolution_comment: params[:resolution_comment]
    )
  when "delete"
    Commands::BatchDeleteErrors.call(error_ids)
  else
    { success: false, count: 0, errors: [ "Invalid action type" ] }
  end

  if result[:success]
    flash[:notice] = "Successfully #{action_type}d #{result[:count]} error(s)"
  else
    flash[:alert] = "Batch operation failed: #{result[:errors].join(', ')}"
  end

  redirect_to errors_path
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/rails_error_dashboard/errors_controller.rb', line 9

def index
  # Use Query to get filtered errors
  errors_query = Queries::ErrorsList.call(filter_params)

  # Paginate with Pagy
  @pagy, @errors = pagy(errors_query, items: params[:per_page] || 25)

  # Get dashboard stats using Query
  @stats = Queries::DashboardStats.call

  # Get filter options using Query
  filter_options = Queries::FilterOptions.call
  @environments = filter_options[:environments]
  @error_types = filter_options[:error_types]
  @platforms = filter_options[:platforms]
end

#resolveObject



34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/rails_error_dashboard/errors_controller.rb', line 34

def resolve
  # Use Command to resolve error
  @error = Commands::ResolveError.call(
    params[:id],
    resolved_by_name: params[:resolved_by_name],
    resolution_comment: params[:resolution_comment],
    resolution_reference: params[:resolution_reference]
  )

  redirect_to error_path(@error)
end

#showObject



26
27
28
29
30
31
32
# File 'app/controllers/rails_error_dashboard/errors_controller.rb', line 26

def show
  @error = ErrorLog.find(params[:id])
  @related_errors = @error.related_errors(limit: 5)

  # Dispatch plugin event for error viewed
  RailsErrorDashboard::PluginRegistry.dispatch(:on_error_viewed, @error)
end