Class: Debci::App

Inherits:
Sinatra::Base
  • Object
show all
Includes:
HTMLHelpers, ERB::Util
Defined in:
lib/debci/app.rb

Direct Known Subclasses

AuthApp, Feeds, Frontend, Home, Status, SelfDocAPI

Defined Under Namespace

Classes: Page

Constant Summary

Constants included from HTMLHelpers

HTMLHelpers::ICONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HTMLHelpers

#expand_pin_packages, #expand_url, #file_link, #history_url, #icon, #package_url, #title_test_trigger_pin

Class Method Details

.get_page_range(current, total) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/debci/app.rb', line 54

def self.get_page_range(current, total)
  full_range = (1..total)
  middle = ((current - 5)..(current + 5)).select { |i| full_range.include?(i) }
  start = middle.include?(1) ? [] : [1, nil]
  finish = middle.include?(total) ? [] : [nil, total]
  start + middle + finish
end

Instance Method Details

#get_page_params(records, page, per_page_limit) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/debci/app.rb', line 68

def get_page_params(records, page, per_page_limit)
  current_page = page || 1
  total_records = records.count
  records = records.page(current_page).per(per_page_limit)
  total_pages = records.total_pages
  pages = get_page_range(Integer(current_page), total_pages)
  Page.new(current_page, records, total_records, total_pages, pages)
end

#get_page_range(current, total) ⇒ Object



62
63
64
# File 'lib/debci/app.rb', line 62

def get_page_range(current, total)
  self.class.get_page_range(current, total)
end

#pagination_params(page) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/debci/app.rb', line 77

def pagination_params(page)
  query = {}
  request.env['rack.request.query_hash'].each do |key, value|
    key = "#{key}[]".to_sym if value.is_a?(Array)
    query[key] = value
  end
  query.merge!(page: page)
  URI.encode_www_form(query)
end

#refresh!Object



50
51
52
# File 'lib/debci/app.rb', line 50

def refresh!
  @refresh = true
end