mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
sorting for browse
This commit is contained in:
parent
63957c225e
commit
ce59bbac9b
2 changed files with 54 additions and 9 deletions
17
app.rb
17
app.rb
|
@ -36,9 +36,22 @@ end
|
|||
get '/browse' do
|
||||
@current_page = params[:current_page] || 1
|
||||
@current_page = @current_page.to_i
|
||||
site_dataset = Site.order(:updated_at.desc, :hits.desc).filter(is_banned: false).filter(site_changed: true).paginate(@current_page, 300)
|
||||
|
||||
site_dataset.filter! is_nsfw: (!params[:is_nsfw].nil? ? true : false)
|
||||
site_dataset = Site.filter(is_banned: false).filter(site_changed: true).paginate(@current_page, 2) # 300
|
||||
|
||||
case params[:sort_by]
|
||||
when 'hits'
|
||||
site_dataset.order!(:hits.desc)
|
||||
when 'newest'
|
||||
site_dataset.order!(:created_at.desc)
|
||||
when 'oldest'
|
||||
site_dataset.order!(:created_at.desc)
|
||||
else
|
||||
params[:sort_by] = 'last_updated'
|
||||
site_dataset.order!(:updated_at.desc, :hits.desc)
|
||||
end
|
||||
|
||||
site_dataset.filter!(is_nsfw: true) if params[:is_nsfw] == 'true'
|
||||
|
||||
@page_count = site_dataset.page_count || 1
|
||||
@sites = site_dataset.all
|
||||
|
|
|
@ -1,10 +1,42 @@
|
|||
<script type="text/javascript">
|
||||
function getPage(currentPage) {
|
||||
document.location.href = '/browse?current_page='+currentPage+'&'+$('#search_criteria').serialize();
|
||||
}
|
||||
</script>
|
||||
<div class="content">
|
||||
<ul class="row website-Gallery">
|
||||
|
||||
<div>
|
||||
<h2>Web Sites on NeoCities</h2>
|
||||
<p>If you like a site, don't forget to bookmark it!<br>Visitor counts are updated hourly.</p>
|
||||
<div style="margin-bottom: 40px; width: 280px;"><a class="btn-Action" style="padding-top: 10px; padding-bottom: 10px" href="/new">Create your NeoCities site now</a></div>
|
||||
<div class="row">
|
||||
<div class="col col-50">
|
||||
<h2>Web Sites on NeoCities</h2>
|
||||
<p>If you like a site, don't forget to bookmark it!<br>Visitor counts are updated hourly.</p>
|
||||
<div style="margin-bottom: 40px; width: 280px;"><a class="btn-Action" style="padding-top: 10px; padding-bottom: 10px" href="/new">Create your NeoCities site now</a></div>
|
||||
</div>
|
||||
|
||||
<div class="col col-50" style="padding-top: 50px">
|
||||
|
||||
<form id="search_criteria" action="/browse" method="GET">
|
||||
<fieldset class="grouping">
|
||||
<label class="text-Label" for="sort_by">Sort By:</label>
|
||||
<div class="select-Container">
|
||||
<select name="sort_by" class="input-Select">
|
||||
<option value="last_updated" <%= 'selected' if params[:sort_by] == 'last_updated' %>>Last Updated</option>
|
||||
<option value="hits" <%= 'selected' if params[:sort_by] == 'hits' %>>Most Hits</option>
|
||||
<option value="newest" <%= 'selected' if params[:sort_by] == 'newest' %>>Newest</option>
|
||||
<option value="oldest" <%= 'selected' if params[:sort_by] == 'oldest' %>>Oldest</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input name="is_nsfw" type="checkbox" value="true" <%= 'checked' if params[:is_nsfw].to_s == 'true' %>> Show 18+ content
|
||||
</div>
|
||||
|
||||
<div style="margin-top: 10px">
|
||||
<input class="btn-Action" type="submit" value="Update">
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<% @sites.each do |site| %>
|
||||
|
@ -19,15 +51,15 @@
|
|||
<% if @page_count > 1 %>
|
||||
<div style="font-size: 30pt">
|
||||
<% if @current_page != 1 %>
|
||||
<a href="/browse?current_page=<%= @current_page - 1 %>"><i class="icon-arrow-left" style="text-decoration: none"></i></a>
|
||||
<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| %>
|
||||
<a href="/browse?current_page=<%= num %>" style="<%= "text-decoration: none" if num == @current_page %>"><%= num %></a>
|
||||
<a href="#" onclick="getPage(<%= num %>); return false" style="<%= "text-decoration: none" if num == @current_page %>"><%= num %></a>
|
||||
<% end %>
|
||||
|
||||
<% if @current_page != @page_count %>
|
||||
<a href="/browse?current_page=<%= @current_page + 1 %>"><i class="icon-arrow-right" style="text-decoration: none"></i></a>
|
||||
<a href="#" onclick="getPage(<%= @current_page + 1 %>); return false"><i class="icon-arrow-right" style="text-decoration: none"></i></a>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
Loading…
Add table
Reference in a new issue