Add curated posts page.
Add a curated posts page at /explore/posts/curated. Curated posts are the most favorited posts by contributor-level users (users with unlimited upload permissions). Also add an order:curated tag using for use in regular searches.
This commit is contained in:
@@ -11,6 +11,15 @@ module Explore
|
||||
respond_with(@posts)
|
||||
end
|
||||
|
||||
def curated
|
||||
@date, @scale, @min_date, @max_date = parse_date(params)
|
||||
|
||||
limit = params.fetch(:limit, CurrentUser.user.per_page)
|
||||
@posts = curated_posts(@min_date, @max_date).paginate(params[:page], limit: limit)
|
||||
|
||||
respond_with(@posts)
|
||||
end
|
||||
|
||||
def viewed
|
||||
@date, @scale, @min_date, @max_date = parse_date(params)
|
||||
@posts = PostViewCountService.new.popular_posts(@date)
|
||||
@@ -40,5 +49,9 @@ module Explore
|
||||
def popular_posts(min_date, max_date)
|
||||
Post.where(created_at: min_date..max_date).tag_match("order:score")
|
||||
end
|
||||
|
||||
def curated_posts(min_date, max_date)
|
||||
Post.where(created_at: min_date..max_date).tag_match("order:curated")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,4 +20,14 @@ module PopularPostsHelper
|
||||
1.month.ago(date)
|
||||
end
|
||||
end
|
||||
|
||||
def date_range_description(date, scale, min_date, max_date)
|
||||
if scale == "day"
|
||||
date.strftime("%B %d, %Y")
|
||||
elsif scale == "week"
|
||||
"#{min_date.strftime("%B %d, %Y")} - #{max_date.strftime("%B %d, %Y")}"
|
||||
elsif scale == "month"
|
||||
date.strftime("%B %Y")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -473,7 +473,7 @@ div#c-explore-posts {
|
||||
margin: 0 0.5em;
|
||||
}
|
||||
|
||||
#popular-nav-links {
|
||||
.date-nav-links {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
@@ -596,6 +596,16 @@ class PostQueryBuilder
|
||||
when "rank"
|
||||
relation = relation.order(Arel.sql("log(3, posts.score) + (extract(epoch from posts.created_at) - extract(epoch from timestamp '2005-05-24')) / 35000 DESC"))
|
||||
|
||||
when "curated"
|
||||
contributors = User.bit_prefs_match(:can_upload_free, true)
|
||||
|
||||
relation = relation
|
||||
.joins(:favorites)
|
||||
.where(favorites: { user: contributors })
|
||||
.group("posts.id")
|
||||
.select("posts.*, COUNT(*) AS contributor_fav_count")
|
||||
.order("contributor_fav_count DESC, posts.fav_count DESC, posts.id DESC")
|
||||
|
||||
when "custom"
|
||||
if q[:post_id].present? && q[:post_id][0] == :in
|
||||
relation = relation.find_ordered(q[:post_id][1])
|
||||
|
||||
@@ -37,6 +37,7 @@ class Tag < ApplicationRecord
|
||||
filesize filesize_asc
|
||||
tagcount tagcount_asc
|
||||
rank
|
||||
curated
|
||||
random
|
||||
custom
|
||||
] +
|
||||
|
||||
@@ -1,17 +1,7 @@
|
||||
<%# date, selected_scale, scale %>
|
||||
<%# path, date, scale, %>
|
||||
|
||||
<span class="period">
|
||||
<% if selected_scale == scale %>
|
||||
<%= link_to "« prev", popular_explore_posts_path(date: prev_date_for_scale(date, scale), scale: scale), id: "paginator-prev", rel: "prev", "data-shortcut": "a left" %>
|
||||
<% else %>
|
||||
<%= link_to "« prev", popular_explore_posts_path(date: prev_date_for_scale(date, scale), scale: scale) %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to scale.capitalize, popular_explore_posts_path(date: date, scale: scale), class: "desc" %>
|
||||
|
||||
<% if selected_scale == scale %>
|
||||
<%= link_to "next »", popular_explore_posts_path(date: next_date_for_scale(date, scale), scale: scale), id: "paginator-next", rel: "next", "data-shortcut": "d right" %>
|
||||
<% else %>
|
||||
<%= link_to "next »", popular_explore_posts_path(date: next_date_for_scale(date, scale), scale: scale) %>
|
||||
<% end %>
|
||||
</span>
|
||||
<p class="date-nav-links">
|
||||
<%= render "explore/posts/nav_links_for_scale", path: path, date: date, selected_scale: scale, scale: "day" %>
|
||||
<%= render "explore/posts/nav_links_for_scale", path: path, date: date, selected_scale: scale, scale: "week" %>
|
||||
<%= render "explore/posts/nav_links_for_scale", path: path, date: date, selected_scale: scale, scale: "month" %>
|
||||
</p>
|
||||
|
||||
17
app/views/explore/posts/_nav_links_for_scale.html.erb
Normal file
17
app/views/explore/posts/_nav_links_for_scale.html.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
<%# path, date, selected_scale, scale %>
|
||||
|
||||
<span class="period">
|
||||
<% if selected_scale == scale %>
|
||||
<%= link_to "« prev", send(path, date: prev_date_for_scale(date, scale), scale: scale), id: "paginator-prev", rel: "prev", "data-shortcut": "a left" %>
|
||||
<% else %>
|
||||
<%= link_to "« prev", send(path, date: prev_date_for_scale(date, scale), scale: scale) %>
|
||||
<% end %>
|
||||
|
||||
<%= link_to scale.capitalize, send(path, date: date, scale: scale), class: "desc" %>
|
||||
|
||||
<% if selected_scale == scale %>
|
||||
<%= link_to "next »", send(path, date: next_date_for_scale(date, scale), scale: scale), id: "paginator-next", rel: "next", "data-shortcut": "d right" %>
|
||||
<% else %>
|
||||
<%= link_to "next »", send(path, date: next_date_for_scale(date, scale), scale: scale) %>
|
||||
<% end %>
|
||||
</span>
|
||||
15
app/views/explore/posts/curated.html.erb
Normal file
15
app/views/explore/posts/curated.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<% page_title "Curated Posts" %>
|
||||
<% meta_description "The best posts of #{date_range_description(@date, @scale, @min_date, @max_date)}" %>
|
||||
|
||||
<%= render "posts/partials/common/secondary_links" %>
|
||||
|
||||
<div id="c-explore-posts">
|
||||
<div id="a-curated">
|
||||
<h1>Curated: <%= date_range_description(@date, @scale, @min_date, @max_date) %></h1>
|
||||
|
||||
<%= render "explore/posts/nav_links", path: :curated_explore_posts_path, date: @date, scale: @scale %>
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
|
||||
<%= post_previews_html(@posts) %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,28 +1,13 @@
|
||||
<% page_title "Popular Posts" %>
|
||||
<% meta_description "The most popular posts per #{@scale}" %>
|
||||
<% meta_description "The most popular posts of #{date_range_description(@date, @scale, @min_date, @max_date)}" %>
|
||||
|
||||
<%= render "posts/partials/common/secondary_links" %>
|
||||
|
||||
<div id="c-explore-posts">
|
||||
<div id="a-popular">
|
||||
<h1>
|
||||
Popular:
|
||||
|
||||
<% if @scale == "day" %>
|
||||
<%= @date.strftime("%B %d, %Y") %>
|
||||
<% elsif @scale == "week" %>
|
||||
<%= @min_date.strftime("%B %d, %Y") %> - <%= @max_date.strftime("%B %d, %Y") %>
|
||||
<% elsif @scale == "month" %>
|
||||
<%= @date.strftime("%B %Y") %>
|
||||
<% end %>
|
||||
</h1>
|
||||
|
||||
<p id="popular-nav-links">
|
||||
<%= render "explore/posts/nav_links", date: @date, selected_scale: @scale, scale: "day" %>
|
||||
<%= render "explore/posts/nav_links", date: @date, selected_scale: @scale, scale: "week" %>
|
||||
<%= render "explore/posts/nav_links", date: @date, selected_scale: @scale, scale: "month" %>
|
||||
</p>
|
||||
<h1>Popular: <%= date_range_description(@date, @scale, @min_date, @max_date) %></h1>
|
||||
|
||||
<%= render "explore/posts/nav_links", path: :popular_explore_posts_path, date: @date, scale: @scale %>
|
||||
<%= render "posts/partials/common/inline_blacklist" %>
|
||||
|
||||
<%= post_previews_html(@posts) %>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<% if discover_mode? %>
|
||||
<li id="secondary-links-posts-hot"><%= link_to "Hot", posts_path(:tags => "order:rank") %></li>
|
||||
<li id="secondary-links-posts-popular"><%= link_to "Popular", popular_explore_posts_path %></li>
|
||||
<li id="secondary-links-posts-curated"><%= link_to "Curated", curated_explore_posts_path %></li>
|
||||
<% if PopularSearchService.enabled? %>
|
||||
<li><%= link_to "Searches", searches_explore_posts_path %></li>
|
||||
<% end %>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
<li><%= link_to("Upload", new_upload_path) %></li>
|
||||
<li><%= link_to("Upload Listing", uploads_path) %></li>
|
||||
<li><%= link_to("Popular", popular_explore_posts_path) %></li>
|
||||
<li><%= link_to("Curated", curated_explore_posts_path) %></li>
|
||||
<li><%= link_to("Most Viewed", viewed_explore_posts_path) %></li>
|
||||
<li><%= link_to("Votes", post_votes_path) %></li>
|
||||
<% if CurrentUser.can_approve_posts? %>
|
||||
|
||||
@@ -43,6 +43,7 @@ Rails.application.routes.draw do
|
||||
resources :posts, :only => [] do
|
||||
collection do
|
||||
get :popular
|
||||
get :curated
|
||||
get :viewed
|
||||
get :searches
|
||||
get :missed_searches
|
||||
|
||||
Reference in New Issue
Block a user