Module: LlmCostTracker::PaginationHelper

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

Constant Summary collapse

PER_PAGE_CHOICES =
[25, 50, 100, 200].freeze

Instance Method Summary collapse

Instance Method Details

#pagination_page_items(current, total_pages, window: 1) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/llm_cost_tracker/pagination_helper.rb', line 7

def pagination_page_items(current, total_pages, window: 1)
  return (1..total_pages).to_a if total_pages <= (window * 2) + 5

  anchors = [1, total_pages, current, current - window, current + window]
  pages = anchors.grep(1..total_pages).uniq.sort
  pages.each_with_index.flat_map do |page, index|
    gap = index.positive? && page - pages[index - 1] > 1 ? [:gap] : []
    gap << page
  end
end