Class: RailsPulse::ApplicationController

Inherits:
ActionController::Base
  • Object
show all
Includes:
Pagy::Backend, Pagy::Method
Defined in:
app/controllers/rails_pulse/application_controller.rb

Instance Method Summary collapse

Instance Method Details

#set_global_filtersObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/controllers/rails_pulse/application_controller.rb', line 24

def set_global_filters
  if params[:clear] == "true"
    session.delete(:global_filters)
    session[:show_non_tagged] = true  # Reset show_non_tagged to default
  else
    filters = session[:global_filters] || {}

    # Update time filters if provided
    if params[:start_time].present? && params[:end_time].present?
      filters["start_time"] = params[:start_time]
      filters["end_time"] = params[:end_time]
    end

    # Update performance threshold if provided (or remove if empty)
    if params[:performance_threshold].present?
      filters["performance_threshold"] = params[:performance_threshold]
    else
      filters.delete("performance_threshold")
    end

    # Update tag visibility - convert enabled tags to disabled tags
    all_tags = RailsPulse.configuration.tags
    enabled_tags = params[:enabled_tags] || []

    # Handle "non_tagged" separately
    session[:show_non_tagged] = enabled_tags.include?("non_tagged")
    enabled_tags = enabled_tags - [ "non_tagged" ]

    disabled_tags = all_tags - enabled_tags

    if disabled_tags.any?
      filters["disabled_tags"] = disabled_tags
    else
      filters.delete("disabled_tags")
    end

    session[:global_filters] = filters
  end

  # Redirect back to the referring page or root
  redirect_back(fallback_location: root_path)
end

#set_pagination_limit(limit = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'app/controllers/rails_pulse/application_controller.rb', line 14

def set_pagination_limit(limit = nil)
  limit = limit || params[:limit]
  session[:pagination_limit] = limit.to_i if limit.present?

# Render JSON for direct API calls or AJAX requests (but not turbo frame requests)
if (request.xhr? && !turbo_frame_request?) || (request.patch? && action_name == "set_pagination_limit")
    render json: { status: "ok" }
end
end