Initial pagination implementation
This commit is contained in:
parent
ba0b5f1dbb
commit
c4fe000861
6 changed files with 68 additions and 15 deletions
2
Gemfile
2
Gemfile
|
@ -9,6 +9,8 @@ gem 'sinatra-redirect-with-flash'
|
||||||
gem 'rake'
|
gem 'rake'
|
||||||
gem 'json'
|
gem 'json'
|
||||||
gem 'mechanize'
|
gem 'mechanize'
|
||||||
|
gem 'padrino-helpers'
|
||||||
|
gem 'kaminari', :require => 'kaminari/sinatra'
|
||||||
|
|
||||||
group :production do
|
group :production do
|
||||||
gem 'pg'
|
gem 'pg'
|
||||||
|
|
45
Gemfile.lock
45
Gemfile.lock
|
@ -1,6 +1,19 @@
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
|
actionpack (4.2.1)
|
||||||
|
actionview (= 4.2.1)
|
||||||
|
activesupport (= 4.2.1)
|
||||||
|
rack (~> 1.6)
|
||||||
|
rack-test (~> 0.6.2)
|
||||||
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||||
|
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
||||||
|
actionview (4.2.1)
|
||||||
|
activesupport (= 4.2.1)
|
||||||
|
builder (~> 3.1)
|
||||||
|
erubis (~> 2.7.0)
|
||||||
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||||
|
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
||||||
activemodel (4.2.1)
|
activemodel (4.2.1)
|
||||||
activesupport (= 4.2.1)
|
activesupport (= 4.2.1)
|
||||||
builder (~> 3.1)
|
builder (~> 3.1)
|
||||||
|
@ -18,12 +31,21 @@ GEM
|
||||||
builder (3.2.2)
|
builder (3.2.2)
|
||||||
domain_name (0.5.24)
|
domain_name (0.5.24)
|
||||||
unf (>= 0.0.5, < 1.0.0)
|
unf (>= 0.0.5, < 1.0.0)
|
||||||
|
erubis (2.7.0)
|
||||||
foreman (0.78.0)
|
foreman (0.78.0)
|
||||||
thor (~> 0.19.1)
|
thor (~> 0.19.1)
|
||||||
http-cookie (1.0.2)
|
http-cookie (1.0.2)
|
||||||
domain_name (~> 0.5)
|
domain_name (~> 0.5)
|
||||||
|
http_router (0.5.4)
|
||||||
|
rack (>= 1.0.0)
|
||||||
|
url_mount (~> 0.2.1)
|
||||||
i18n (0.7.0)
|
i18n (0.7.0)
|
||||||
json (1.8.2)
|
json (1.8.2)
|
||||||
|
kaminari (0.16.3)
|
||||||
|
actionpack (>= 3.0.0)
|
||||||
|
activesupport (>= 3.0.0)
|
||||||
|
loofah (2.0.1)
|
||||||
|
nokogiri (>= 1.5.9)
|
||||||
mechanize (2.7.3)
|
mechanize (2.7.3)
|
||||||
domain_name (~> 0.5, >= 0.5.1)
|
domain_name (~> 0.5, >= 0.5.1)
|
||||||
http-cookie (~> 1.0)
|
http-cookie (~> 1.0)
|
||||||
|
@ -41,10 +63,29 @@ GEM
|
||||||
nokogiri (1.6.6.2)
|
nokogiri (1.6.6.2)
|
||||||
mini_portile (~> 0.6.0)
|
mini_portile (~> 0.6.0)
|
||||||
ntlm-http (0.1.1)
|
ntlm-http (0.1.1)
|
||||||
|
padrino-core (0.9.21)
|
||||||
|
activesupport (>= 3.0.0)
|
||||||
|
http_router (~> 0.5.4)
|
||||||
|
sinatra (>= 1.1.0)
|
||||||
|
thor (>= 0.14.3)
|
||||||
|
tzinfo
|
||||||
|
padrino-helpers (0.9.21)
|
||||||
|
i18n (>= 0.4.1)
|
||||||
|
padrino-core (= 0.9.21)
|
||||||
pg (0.18.1)
|
pg (0.18.1)
|
||||||
rack (1.6.0)
|
rack (1.6.0)
|
||||||
rack-protection (1.5.3)
|
rack-protection (1.5.3)
|
||||||
rack
|
rack
|
||||||
|
rack-test (0.6.3)
|
||||||
|
rack (>= 1.0)
|
||||||
|
rails-deprecated_sanitizer (1.0.3)
|
||||||
|
activesupport (>= 4.2.0.alpha)
|
||||||
|
rails-dom-testing (1.0.6)
|
||||||
|
activesupport (>= 4.2.0.beta, < 5.0)
|
||||||
|
nokogiri (~> 1.6.0)
|
||||||
|
rails-deprecated_sanitizer (>= 1.0.1)
|
||||||
|
rails-html-sanitizer (1.0.2)
|
||||||
|
loofah (~> 2.0)
|
||||||
rake (10.4.2)
|
rake (10.4.2)
|
||||||
sinatra (1.4.6)
|
sinatra (1.4.6)
|
||||||
rack (~> 1.4)
|
rack (~> 1.4)
|
||||||
|
@ -66,6 +107,8 @@ GEM
|
||||||
unf (0.1.4)
|
unf (0.1.4)
|
||||||
unf_ext
|
unf_ext
|
||||||
unf_ext (0.0.7.1)
|
unf_ext (0.0.7.1)
|
||||||
|
url_mount (0.2.1)
|
||||||
|
rack
|
||||||
webrobots (0.1.1)
|
webrobots (0.1.1)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
|
@ -75,7 +118,9 @@ DEPENDENCIES
|
||||||
activerecord
|
activerecord
|
||||||
foreman
|
foreman
|
||||||
json
|
json
|
||||||
|
kaminari
|
||||||
mechanize
|
mechanize
|
||||||
|
padrino-helpers
|
||||||
pg
|
pg
|
||||||
rake
|
rake
|
||||||
sinatra
|
sinatra
|
||||||
|
|
6
app.rb
6
app.rb
|
@ -1,6 +1,3 @@
|
||||||
require 'sinatra'
|
|
||||||
require 'sinatra/activerecord'
|
|
||||||
require 'json'
|
|
||||||
require './environments'
|
require './environments'
|
||||||
|
|
||||||
require './models/raid'
|
require './models/raid'
|
||||||
|
@ -12,8 +9,7 @@ set :public_folder, 'public'
|
||||||
|
|
||||||
# CONTROLLER
|
# CONTROLLER
|
||||||
get '/' do
|
get '/' do
|
||||||
@raids = Raid.all.reverse
|
@raids = Raid.order('created_at DESC').page(params[:page])
|
||||||
|
|
||||||
leaders = Leader.all
|
leaders = Leader.all
|
||||||
last_update = leaders.first ? leaders.first.created_at : DateTime.new(0)
|
last_update = leaders.first ? leaders.first.created_at : DateTime.new(0)
|
||||||
rebuild_leaders if last_update + 300 < DateTime.now
|
rebuild_leaders if last_update + 300 < DateTime.now
|
||||||
|
|
|
@ -1,17 +1,29 @@
|
||||||
|
require 'rubygems'
|
||||||
|
require 'bundler'
|
||||||
|
Bundler.require
|
||||||
|
|
||||||
|
register Kaminari::Helpers::SinatraHelpers
|
||||||
|
|
||||||
|
require './models/raid'
|
||||||
|
require './models/leader'
|
||||||
|
require './helpers/raids_helper'
|
||||||
|
require './jobs/leaders'
|
||||||
|
|
||||||
|
|
||||||
configure :development do
|
configure :development do
|
||||||
set :database, 'sqlite3:dev.db'
|
set :database, 'sqlite3:dev.db'
|
||||||
set :show_exceptions, true
|
set :show_exceptions, true
|
||||||
end
|
end
|
||||||
|
|
||||||
configure :production do
|
configure :production do
|
||||||
db = URI.parse(ENV['DATABASE_URL'] || 'postgres:///localhost/mydb')
|
db = URI.parse(ENV['DATABASE_URL'] || 'postgres:///localhost/mydb')
|
||||||
|
|
||||||
ActiveRecord::Base.establish_connection(
|
ActiveRecord::Base.establish_connection(
|
||||||
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
|
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
|
||||||
:host => db.host,
|
:host => db.host,
|
||||||
:username => db.user,
|
:username => db.user,
|
||||||
:password => db.password,
|
:password => db.password,
|
||||||
:database => db.path[1..-1],
|
:database => db.path[1..-1],
|
||||||
:encoding => 'utf8'
|
:encoding => 'utf8'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
require 'sinatra/activerecord'
|
require './environments'
|
||||||
require 'mechanize'
|
|
||||||
require 'nokogiri'
|
|
||||||
|
|
||||||
require './models/leader'
|
|
||||||
|
|
||||||
def rebuild_leaders
|
def rebuild_leaders
|
||||||
puts "rebuilding_leaders called"
|
puts "rebuilding_leaders called"
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<%= paginate @raids %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
|
|
Loading…
Reference in a new issue