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 'sanitize'
|
||||
gem 'linnaeus', git: 'https://github.com/neocities/linnaeus.git', branch: 'soften_redis_gemspec'
|
||||
gem 'will_paginate'
|
||||
|
||||
platform :mri, :rbx do
|
||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
get '/browse/?' do
|
||||
@current_page = params[:current_page]
|
||||
@current_page = @current_page.to_i
|
||||
@current_page = 1 if @current_page == 0
|
||||
|
||||
@page = params[:page].to_i
|
||||
@page = 1 if @page == 0
|
||||
|
||||
params.delete 'tag' if params[:tag].nil? || params[:tag].strip.empty?
|
||||
|
||||
|
@ -11,12 +11,14 @@ get '/browse/?' do
|
|||
site_dataset = browse_sites_dataset
|
||||
end
|
||||
|
||||
site_dataset = site_dataset.paginate @current_page, Site::BROWSE_PAGINATION_LENGTH
|
||||
@page_count = site_dataset.page_count || 1
|
||||
site_dataset = site_dataset.paginate @page, Site::BROWSE_PAGINATION_LENGTH
|
||||
@pagination_dataset = site_dataset
|
||||
@sites = site_dataset.all
|
||||
|
||||
if params[:tag]
|
||||
@title = "Sites tagged #{params[:tag]}"
|
||||
end
|
||||
|
||||
erb :browse
|
||||
end
|
||||
|
||||
|
|
12
app/index.rb
12
app/index.rb
|
@ -6,23 +6,23 @@ get '/?' do
|
|||
|
||||
@suggestions = current_site.suggestions
|
||||
|
||||
@current_page = params[:current_page].to_i
|
||||
@current_page = 1 if @current_page == 0
|
||||
@page = params[:page].to_i
|
||||
@page = 1 if @page == 0
|
||||
|
||||
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]
|
||||
event = Event.select(:id).where(id: params[:event_id]).first
|
||||
not_found if event.nil?
|
||||
not_found if event.is_deleted
|
||||
events_dataset = Event.where(id: params[:event_id]).paginate(1, 1)
|
||||
elsif params[:activity] == 'global'
|
||||
events_dataset = Event.global_dataset @current_page
|
||||
events_dataset = Event.global_dataset @page
|
||||
else
|
||||
events_dataset = current_site.news_feed(@current_page, 10)
|
||||
events_dataset = current_site.news_feed(@page, 10)
|
||||
end
|
||||
|
||||
@page_count = events_dataset.page_count || 1
|
||||
@pagination_dataset = events_dataset
|
||||
@events = events_dataset.all
|
||||
|
||||
current_site.events_dataset.update notification_seen: true
|
||||
|
|
|
@ -13,9 +13,9 @@ get '/site/:username/?' do |username|
|
|||
|
||||
@title = site.title
|
||||
|
||||
@current_page = params[:current_page]
|
||||
@current_page = @current_page.to_i
|
||||
@current_page = 1 if @current_page == 0
|
||||
@page = params[:page]
|
||||
@page = @page.to_i
|
||||
@page = 1 if @page == 0
|
||||
|
||||
if params[:event_id]
|
||||
not_found unless params[:event_id].is_integer?
|
||||
|
@ -23,10 +23,11 @@ get '/site/:username/?' do |username|
|
|||
not_found if event.nil?
|
||||
events_dataset = Event.where(id: params[:event_id]).paginate(1, 1)
|
||||
else
|
||||
events_dataset = site.latest_events(@current_page, 10)
|
||||
events_dataset = site.latest_events(@page, 10)
|
||||
end
|
||||
|
||||
@page_count = events_dataset.page_count || 1
|
||||
@pagination_dataset = events_dataset
|
||||
@latest_events = events_dataset.all
|
||||
|
||||
erb :'site', locals: {site: site, is_current_site: site == current_site}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
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?
|
||||
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
|
||||
@site = site_dataset.first
|
||||
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.extension :pagination
|
||||
|
||||
require 'will_paginate/sequel'
|
||||
|
||||
# :nocov:
|
||||
=begin
|
||||
if defined?(Pry)
|
||||
|
|
|
@ -126,26 +126,7 @@
|
|||
|
||||
<% if params[:activity] != 'global' %>
|
||||
<div class="content">
|
||||
<% if @page_count > 1 %>
|
||||
<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 %>
|
||||
<%== erb :_pagination, layout: false %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<script type="text/javascript">
|
||||
function getPage(currentPage) {
|
||||
document.location.href = '/browse?current_page='+currentPage+'&'+$('#search_criteria').serialize();
|
||||
function getPage(page) {
|
||||
document.location.href = '/browse?page='+page+'&'+$('#search_criteria').serialize();
|
||||
}
|
||||
|
||||
function surf(currentPage) {
|
||||
document.location.href = '/surf?current_page='+currentPage+'&'+$('#search_criteria').serialize();
|
||||
function surf(page) {
|
||||
document.location.href = '/surf?page='+page+'&'+$('#search_criteria').serialize();
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -76,7 +76,7 @@
|
|||
<ul class="row website-Gallery content int-Gall">
|
||||
<% @sites.each_with_index do |site,i| %>
|
||||
<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;">
|
||||
<img src="/img/placeholder.png" alt="<%= site.title %>" />
|
||||
</span>
|
||||
|
@ -147,25 +147,7 @@
|
|||
<% end %>
|
||||
|
||||
<% if params[:sort_by] != 'random' %>
|
||||
<% if @page_count > 1 %>
|
||||
<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 %>
|
||||
<%== erb :'_pagination', layout: false %>
|
||||
<% end %>
|
||||
|
||||
<% unless is_education? %>
|
||||
|
|
|
@ -168,8 +168,8 @@
|
|||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
function getPage(currentPage) {
|
||||
document.location.href = '/surf?current_page='+currentPage+'&'+$('#search_criteria').serialize()
|
||||
function getPage(page) {
|
||||
document.location.href = '/surf?page='+page+'&'+$('#search_criteria').serialize()
|
||||
}
|
||||
|
||||
function backToBrowse() {
|
||||
|
@ -180,9 +180,9 @@
|
|||
<div id="top-bar">
|
||||
<ul class="browse-actions">
|
||||
<li>
|
||||
<a href="/browse" onclick="backToBrowse(<%= @current_page %>); return false">Neocities</a>
|
||||
<a href="/browse" onclick="backToBrowse(<%= @page %>); return false">Neocities</a>
|
||||
</li>
|
||||
<% if @current_page %>
|
||||
<% if @page %>
|
||||
<li>
|
||||
<form id="search_criteria" onsubmit="getPage(1); return false">
|
||||
<input type="hidden" name="sort_by" value="<%= params[:sort_by] %>">
|
||||
|
@ -191,15 +191,15 @@
|
|||
</form>
|
||||
</li>
|
||||
<li>
|
||||
<% if @current_page > 1 %>
|
||||
<a href="" onclick="getPage(<%= @current_page - 1 %>); return false">
|
||||
<% if @page > 1 %>
|
||||
<a href="" onclick="getPage(<%= @page - 1 %>); return false">
|
||||
<i class="fa fa-caret-left"></i> Prev
|
||||
</a>
|
||||
<% end %>
|
||||
</li>
|
||||
<li>
|
||||
<% if @current_page != @page_count %>
|
||||
<a href="" onclick="getPage(<%= @current_page + 1 %>); return false">Next <i class="fa fa-caret-right"></i></a>
|
||||
<% if @page != @page_count %>
|
||||
<a href="" onclick="getPage(<%= @page + 1 %>); return false">Next <i class="fa fa-caret-right"></i></a>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue