mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
Events pagination and fixes for browse pagination
This commit is contained in:
parent
be32867860
commit
17119d369c
4 changed files with 45 additions and 7 deletions
10
app.rb
10
app.rb
|
@ -132,12 +132,18 @@ get '/?' do
|
||||||
@suggestions = current_site.suggestions
|
@suggestions = current_site.suggestions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@current_page = params[:current_page].to_i
|
||||||
|
@current_page = 1 if @current_page == 0
|
||||||
|
|
||||||
if params[:activity] == 'mine'
|
if params[:activity] == 'mine'
|
||||||
@events = current_site.latest_events
|
events_dataset = current_site.latest_events(@current_page, 10)
|
||||||
else
|
else
|
||||||
@events = current_site.news_feed
|
events_dataset = current_site.news_feed(@current_page, 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@page_count = events_dataset.page_count || 1
|
||||||
|
@events = events_dataset.all
|
||||||
|
|
||||||
halt erb :'home', locals: {site: current_site}
|
halt erb :'home', locals: {site: current_site}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -512,13 +512,13 @@ class Site < Sequel::Model
|
||||||
'Supporter Plan'
|
'Supporter Plan'
|
||||||
end
|
end
|
||||||
|
|
||||||
def latest_events(limit=10, offset=0)
|
def latest_events(current_page=1, limit=10)
|
||||||
events_dataset.order(:created_at.desc).limit(limit, offset).all
|
events_dataset.order(:created_at.desc).paginate(current_page, limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def news_feed(limit=10, offset=0)
|
def news_feed(current_page=1, limit=10)
|
||||||
following_ids = self.followings_dataset.select(:site_id).all.collect {|f| f.site_id}
|
following_ids = self.followings_dataset.select(:site_id).all.collect {|f| f.site_id}
|
||||||
Event.filter(site_id: following_ids+[self.id]).order(:created_at.desc).limit(limit, offset).all
|
Event.filter(site_id: following_ids+[self.id]).order(:created_at.desc).paginate(current_page, limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def host
|
def host
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
<script type="text/javascript">
|
||||||
|
function getPage(currentPage) {
|
||||||
|
document.location.href = '?current_page='+currentPage+'&activity=<%= Rack::Utils.escape(params[:activity]) %>'
|
||||||
|
}
|
||||||
|
</script>
|
||||||
<script src="/assets/scripts/news/template.js"></script>
|
<script src="/assets/scripts/news/template.js"></script>
|
||||||
<script src="/assets/scripts/news/like.js"></script>
|
<script src="/assets/scripts/news/like.js"></script>
|
||||||
<script src="/assets/scripts/news/comment.js"></script>
|
<script src="/assets/scripts/news/comment.js"></script>
|
||||||
|
@ -92,4 +97,27 @@
|
||||||
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<div class="content">
|
||||||
|
<% if @page_count > 1 %>
|
||||||
|
<div class="txt-Center content eps">
|
||||||
|
<% if @current_page != 1 %>
|
||||||
|
<a href="#" onclick="getPage(<%= @current_page - 1 %>); return false"><i class="icon-arrow-left" style="text-decoration: none"></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="icon-arrow-right" style="text-decoration: none"></i></a>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
||||||
<%== erb :'_news_templates', layout: false %>
|
<%== erb :'_news_templates', layout: false %>
|
||||||
|
|
|
@ -95,7 +95,11 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% 1.upto(@page_count) do |num| %>
|
<% 1.upto(@page_count) do |num| %>
|
||||||
<a href="#" onclick="getPage(<%= num %>); return false" style="<%= num == @current_page ? 'text-decoration: none' : '' %>"><%= num %></a>
|
<% if num == @current_page %>
|
||||||
|
<%= num %>
|
||||||
|
<% else %>
|
||||||
|
<a href="#" onclick="getPage(<%= num %>); return false"><%= num %></a>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if @current_page != @page_count %>
|
<% if @current_page != @page_count %>
|
||||||
|
|
Loading…
Add table
Reference in a new issue