Module: LlmCostTracker::DashboardFilterHelper

Included in:
ApplicationHelper
Defined in:
app/helpers/llm_cost_tracker/dashboard_filter_helper.rb

Constant Summary collapse

FILTER_PARAM_KEYS =
%i[from to provider model tag sort page per].freeze

Instance Method Summary collapse

Instance Method Details

#active_tag_filtersObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/llm_cost_tracker/dashboard_filter_helper.rb', line 11

def active_tag_filters
  tag_params = normalized_query_tags(params[:tag])
  return [] unless tag_params.is_a?(Hash)

  tag_params.filter_map do |key, value|
    next if key.blank? || value.blank?

    {
      label: "Tag",
      value: "#{key}=#{value}",
      path: dashboard_filter_path(current_query(tag: tag_params.except(key.to_s).presence, page: nil))
    }
  end
end

#any_filter_applied?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'app/helpers/llm_cost_tracker/dashboard_filter_helper.rb', line 7

def any_filter_applied?
  FILTER_PARAM_KEYS.any? { |key| params[key].present? }
end

#dashboard_date_range_label(from, to) ⇒ Object



26
27
28
29
30
# File 'app/helpers/llm_cost_tracker/dashboard_filter_helper.rb', line 26

def dashboard_date_range_label(from, to)
  from_label = short_date_label(from) || "Any time"
  to_label = short_date_label(to) || "Now"
  "#{from_label} - #{to_label}"
end