Class: Debci::App
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Debci::App
show all
- Includes:
- HTMLHelpers, ERB::Util
- Defined in:
- lib/debci/app.rb
Defined Under Namespace
Classes: Page
Constant Summary
Constants included
from HTMLHelpers
HTMLHelpers::ICONS
Class Method Summary
collapse
Instance Method Summary
collapse
#ansi_to_html, #expand_pin_packages, #expand_url, #file_link, #history_url, #icon, #package_url, #pkg_history_url, #title_test_trigger_pin
Class Method Details
.get_page_range(current, total) ⇒ Object
94
95
96
97
98
99
100
|
# File 'lib/debci/app.rb', line 94
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
#authenticate! ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/debci/app.rb', line 45
def authenticate!
return if @user
session.options[:drop] = false
session[:original_url] = params[:original_url] || request.path
redirect('/user/login')
halt
end
|
#forbidden ⇒ Object
54
55
56
|
# File 'lib/debci/app.rb', line 54
def forbidden
halt 403, erb(:forbidden)
end
|
#get_page_params(records, page, per_page_limit) ⇒ Object
108
109
110
111
112
113
114
115
|
# File 'lib/debci/app.rb', line 108
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
102
103
104
|
# File 'lib/debci/app.rb', line 102
def get_page_range(current, total)
self.class.get_page_range(current, total)
end
|
#logged_in? ⇒ Boolean
37
38
39
|
# File 'lib/debci/app.rb', line 37
def logged_in?
!@user.nil?
end
|
#logging_in? ⇒ Boolean
41
42
43
|
# File 'lib/debci/app.rb', line 41
def logging_in?
request.path =~ %r{^/user/auth/\w+/callback$} || session.has_key?(:original_url)
end
|
117
118
119
120
121
122
123
124
125
|
# File 'lib/debci/app.rb', line 117
def (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
90
91
92
|
# File 'lib/debci/app.rb', line 90
def refresh!
@refresh = true
end
|