mirror of
https://github.com/neocities/neocities.git
synced 2025-05-15 00:47:16 +02:00
improvements to pagination
This commit is contained in:
parent
7714dc7c53
commit
32b4fe0d49
9 changed files with 38 additions and 69 deletions
1
Gemfile
1
Gemfile
|
@ -34,6 +34,7 @@ gem 'base32'
|
||||||
gem 'coveralls', require: false
|
gem 'coveralls', require: false
|
||||||
gem 'sanitize'
|
gem 'sanitize'
|
||||||
gem 'linnaeus', git: 'https://github.com/neocities/linnaeus.git', branch: 'soften_redis_gemspec'
|
gem 'linnaeus', git: 'https://github.com/neocities/linnaeus.git', branch: 'soften_redis_gemspec'
|
||||||
|
gem 'will_paginate'
|
||||||
|
|
||||||
platform :mri, :rbx do
|
platform :mri, :rbx do
|
||||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
get '/browse/?' do
|
get '/browse/?' do
|
||||||
@current_page = params[:current_page]
|
|
||||||
@current_page = @current_page.to_i
|
@page = params[:page].to_i
|
||||||
@current_page = 1 if @current_page == 0
|
@page = 1 if @page == 0
|
||||||
|
|
||||||
params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty?
|
params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty?
|
||||||
|
|
||||||
|
@ -11,12 +11,14 @@ get '/browse/?' do
|
||||||
site_dataset = browse_sites_dataset
|
site_dataset = browse_sites_dataset
|
||||||
end
|
end
|
||||||
|
|
||||||
site_dataset = site_dataset.paginate @current_page, Site::BROWSE_PAGINATION_LENGTH
|
site_dataset = site_dataset.paginate @page, Site::BROWSE_PAGINATION_LENGTH
|
||||||
@page_count = site_dataset.page_count || 1
|
@pagination_dataset = site_dataset
|
||||||
@sites = site_dataset.all
|
@sites = site_dataset.all
|
||||||
|
|
||||||
if params[:tag]
|
if params[:tag]
|
||||||
@title = "Sites tagged #{params[:tag]}"
|
@title = "Sites tagged #{params[:tag]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
erb :browse
|
erb :browse
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
12
app/index.rb
12
app/index.rb
|
@ -6,23 +6,23 @@ get '/?' do
|
||||||
|
|
||||||
@suggestions = current_site.suggestions
|
@suggestions = current_site.suggestions
|
||||||
|
|
||||||
@current_page = params[:current_page].to_i
|
@page = params[:page].to_i
|
||||||
@current_page = 1 if @current_page == 0
|
@page = 1 if @page == 0
|
||||||
|
|
||||||
if params[:activity] == 'mine'
|
if params[:activity] == 'mine'
|
||||||
events_dataset = current_site.latest_events(@current_page, 10)
|
events_dataset = current_site.latest_events(@page, 10)
|
||||||
elsif params[:event_id]
|
elsif params[:event_id]
|
||||||
event = Event.select(:id).where(id: params[:event_id]).first
|
event = Event.select(:id).where(id: params[:event_id]).first
|
||||||
not_found if event.nil?
|
not_found if event.nil?
|
||||||
not_found if event.is_deleted
|
not_found if event.is_deleted
|
||||||
events_dataset = Event.where(id: params[:event_id]).paginate(1, 1)
|
events_dataset = Event.where(id: params[:event_id]).paginate(1, 1)
|
||||||
elsif params[:activity] == 'global'
|
elsif params[:activity] == 'global'
|
||||||
events_dataset = Event.global_dataset @current_page
|
events_dataset = Event.global_dataset @page
|
||||||
else
|
else
|
||||||
events_dataset = current_site.news_feed(@current_page, 10)
|
events_dataset = current_site.news_feed(@page, 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
@page_count = events_dataset.page_count || 1
|
@pagination_dataset = events_dataset
|
||||||
@events = events_dataset.all
|
@events = events_dataset.all
|
||||||
|
|
||||||
current_site.events_dataset.update notification_seen: true
|
current_site.events_dataset.update notification_seen: true
|
||||||
|
|
|
@ -13,9 +13,9 @@ get '/site/:username/?' do |username|
|
||||||
|
|
||||||
@title = site.title
|
@title = site.title
|
||||||
|
|
||||||
@current_page = params[:current_page]
|
@page = params[:page]
|
||||||
@current_page = @current_page.to_i
|
@page = @page.to_i
|
||||||
@current_page = 1 if @current_page == 0
|
@page = 1 if @page == 0
|
||||||
|
|
||||||
if params[:event_id]
|
if params[:event_id]
|
||||||
not_found unless params[:event_id].is_integer?
|
not_found unless params[:event_id].is_integer?
|
||||||
|
@ -23,10 +23,11 @@ get '/site/:username/?' do |username|
|
||||||
not_found if event.nil?
|
not_found if event.nil?
|
||||||
events_dataset = Event.where(id: params[:event_id]).paginate(1, 1)
|
events_dataset = Event.where(id: params[:event_id]).paginate(1, 1)
|
||||||
else
|
else
|
||||||
events_dataset = site.latest_events(@current_page, 10)
|
events_dataset = site.latest_events(@page, 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
@page_count = events_dataset.page_count || 1
|
@page_count = events_dataset.page_count || 1
|
||||||
|
@pagination_dataset = events_dataset
|
||||||
@latest_events = events_dataset.all
|
@latest_events = events_dataset.all
|
||||||
|
|
||||||
erb :'site', locals: {site: site, is_current_site: site == current_site}
|
erb :'site', locals: {site: site, is_current_site: site == current_site}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
get '/surf/?' do
|
get '/surf/?' do
|
||||||
@current_page = params[:current_page].to_i || 1
|
@page = params[:page].to_i || 1
|
||||||
params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty?
|
params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty?
|
||||||
site_dataset = browse_sites_dataset
|
site_dataset = browse_sites_dataset
|
||||||
site_dataset = site_dataset.paginate @current_page, 1
|
site_dataset = site_dataset.paginate @page, 1
|
||||||
@page_count = site_dataset.page_count || 1
|
@page_count = site_dataset.page_count || 1
|
||||||
@site = site_dataset.first
|
@site = site_dataset.first
|
||||||
redirect "/browse?#{Rack::Utils.build_query params}" if @site.nil?
|
redirect "/browse?#{Rack::Utils.build_query params}" if @site.nil?
|
||||||
|
|
|
@ -33,6 +33,8 @@ raise 'hash_ip_salt is required' unless $config['ip_hash_salt']
|
||||||
DB = Sequel.connect $config['database'], sslmode: 'disable', max_connections: $config['database_pool']
|
DB = Sequel.connect $config['database'], sslmode: 'disable', max_connections: $config['database_pool']
|
||||||
DB.extension :pagination
|
DB.extension :pagination
|
||||||
|
|
||||||
|
require 'will_paginate/sequel'
|
||||||
|
|
||||||
# :nocov:
|
# :nocov:
|
||||||
=begin
|
=begin
|
||||||
if defined?(Pry)
|
if defined?(Pry)
|
||||||
|
|
|
@ -126,26 +126,7 @@
|
||||||
|
|
||||||
<% if params[:activity] != 'global' %>
|
<% if params[:activity] != 'global' %>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<% if @page_count > 1 %>
|
<%== erb :_pagination, layout: false %>
|
||||||
<div class="txt-Center content eps pagination">
|
|
||||||
<% if @current_page != 1 %>
|
|
||||||
<a href="#" onclick="getPage(<%= @current_page - 1 %>); return false"><i class="fa fa-arrow-left arrow"></i></a>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% 1.upto(@page_count) do |num| %>
|
|
||||||
<% if num == @current_page %>
|
|
||||||
<%= num %>
|
|
||||||
<% else %>
|
|
||||||
<a href="#" onclick="getPage(<%= num %>); return false"><%= num %></a>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if @current_page != @page_count %>
|
|
||||||
<a href="#" onclick="getPage(<%= @current_page + 1 %>); return false"><i class="fa fa-arrow-right arrow"></i></a>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function getPage(currentPage) {
|
function getPage(page) {
|
||||||
document.location.href = '/browse?current_page='+currentPage+'&'+$('#search_criteria').serialize();
|
document.location.href = '/browse?page='+page+'&'+$('#search_criteria').serialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
function surf(currentPage) {
|
function surf(page) {
|
||||||
document.location.href = '/surf?current_page='+currentPage+'&'+$('#search_criteria').serialize();
|
document.location.href = '/surf?page='+page+'&'+$('#search_criteria').serialize();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
<ul class="row website-Gallery content int-Gall">
|
<ul class="row website-Gallery content int-Gall">
|
||||||
<% @sites.each_with_index do |site,i| %>
|
<% @sites.each_with_index do |site,i| %>
|
||||||
<li id="username_<%= site.username %>">
|
<li id="username_<%= site.username %>">
|
||||||
<a href="<%= site.uri %>" class="neo-Screen-Shot" title="<%= site.title %>" onclick="surf(<%= ((@current_page-1)*Site::BROWSE_PAGINATION_LENGTH)+i+1 %>); return false">
|
<a href="<%= site.uri %>" class="neo-Screen-Shot" title="<%= site.title %>" onclick="surf(<%= ((@page-1)*Site::BROWSE_PAGINATION_LENGTH)+i+1 %>); return false">
|
||||||
<span class="img-Holder" style="background:url(<%= site.screenshot_url('index.html', '540x405') %>) no-repeat;">
|
<span class="img-Holder" style="background:url(<%= site.screenshot_url('index.html', '540x405') %>) no-repeat;">
|
||||||
<img src="/img/placeholder.png" alt="<%= site.title %>" />
|
<img src="/img/placeholder.png" alt="<%= site.title %>" />
|
||||||
</span>
|
</span>
|
||||||
|
@ -147,25 +147,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if params[:sort_by] != 'random' %>
|
<% if params[:sort_by] != 'random' %>
|
||||||
<% if @page_count > 1 %>
|
<%== erb :'_pagination', layout: false %>
|
||||||
<div class="txt-Center content eps pagination">
|
|
||||||
<% if @current_page != 1 %>
|
|
||||||
<a href="#" onclick="getPage(<%= @current_page - 1 %>); return false"><i class="fa fa-arrow-left arrow"></i></a>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% 1.upto(@page_count) do |num| %>
|
|
||||||
<% if num == @current_page %>
|
|
||||||
<%= num %>
|
|
||||||
<% else %>
|
|
||||||
<a href="#" onclick="getPage(<%= num %>); return false"><%= num %></a>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<% if @current_page != @page_count %>
|
|
||||||
<a href="#" onclick="getPage(<%= @current_page + 1 %>); return false"><i class="fa fa-arrow-right arrow"></i></a>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% unless is_education? %>
|
<% unless is_education? %>
|
||||||
|
|
|
@ -168,8 +168,8 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
function getPage(currentPage) {
|
function getPage(page) {
|
||||||
document.location.href = '/surf?current_page='+currentPage+'&'+$('#search_criteria').serialize()
|
document.location.href = '/surf?page='+page+'&'+$('#search_criteria').serialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
function backToBrowse() {
|
function backToBrowse() {
|
||||||
|
@ -180,9 +180,9 @@
|
||||||
<div id="top-bar">
|
<div id="top-bar">
|
||||||
<ul class="browse-actions">
|
<ul class="browse-actions">
|
||||||
<li>
|
<li>
|
||||||
<a href="/browse" onclick="backToBrowse(<%= @current_page %>); return false">Neocities</a>
|
<a href="/browse" onclick="backToBrowse(<%= @page %>); return false">Neocities</a>
|
||||||
</li>
|
</li>
|
||||||
<% if @current_page %>
|
<% if @page %>
|
||||||
<li>
|
<li>
|
||||||
<form id="search_criteria" onsubmit="getPage(1); return false">
|
<form id="search_criteria" onsubmit="getPage(1); return false">
|
||||||
<input type="hidden" name="sort_by" value="<%= params[:sort_by] %>">
|
<input type="hidden" name="sort_by" value="<%= params[:sort_by] %>">
|
||||||
|
@ -191,15 +191,15 @@
|
||||||
</form>
|
</form>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<% if @current_page > 1 %>
|
<% if @page > 1 %>
|
||||||
<a href="" onclick="getPage(<%= @current_page - 1 %>); return false">
|
<a href="" onclick="getPage(<%= @page - 1 %>); return false">
|
||||||
<i class="fa fa-caret-left"></i> Prev
|
<i class="fa fa-caret-left"></i> Prev
|
||||||
</a>
|
</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<% if @current_page != @page_count %>
|
<% if @page != @page_count %>
|
||||||
<a href="" onclick="getPage(<%= @current_page + 1 %>); return false">Next <i class="fa fa-caret-right"></i></a>
|
<a href="" onclick="getPage(<%= @page + 1 %>); return false">Next <i class="fa fa-caret-right"></i></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue