forum: make status labels into clickable filters.
* Make it so that you can click the stickied / locked / deleted icons or the new / approved / pending / rejected labels to filter topics by that status. * Replace the `mod_only` search param with `is_private`.
This commit is contained in:
@@ -49,7 +49,7 @@ div#c-forum-topics {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
span.topic-status {
|
||||
.topic-status {
|
||||
margin-right: 0.25em;
|
||||
vertical-align: bottom;
|
||||
|
||||
|
||||
@@ -19,6 +19,9 @@ class BulkUpdateRequest < ApplicationRecord
|
||||
|
||||
scope :pending_first, -> { order(Arel.sql("(case status when 'pending' then 0 when 'approved' then 1 else 2 end)")) }
|
||||
scope :pending, -> {where(status: "pending")}
|
||||
scope :approved, -> { where(status: "approved") }
|
||||
scope :rejected, -> { where(status: "rejected") }
|
||||
scope :has_topic, -> { where.not(forum_topic: nil) }
|
||||
scope :expired, -> {where("created_at < ?", TagRelationship::EXPIRY.days.ago)}
|
||||
scope :old, -> {where("created_at between ? and ?", TagRelationship::EXPIRY.days.ago, TagRelationship::EXPIRY_WARNING.days.ago)}
|
||||
|
||||
|
||||
@@ -33,6 +33,12 @@ class ForumTopic < ApplicationRecord
|
||||
|
||||
deletable
|
||||
|
||||
scope :public_only, -> { where(min_level: MIN_LEVELS[:None]) }
|
||||
scope :private_only, -> { where.not(min_level: MIN_LEVELS[:None]) }
|
||||
scope :pending, -> { where(id: BulkUpdateRequest.has_topic.pending.select(:forum_topic_id)) }
|
||||
scope :approved, -> { where(category_id: 1).where(id: BulkUpdateRequest.approved.has_topic.select(:forum_topic_id)).where.not(id: BulkUpdateRequest.has_topic.pending.or(BulkUpdateRequest.has_topic.rejected).select(:forum_topic_id)) }
|
||||
scope :rejected, -> { where(category_id: 1).where(id: BulkUpdateRequest.rejected.has_topic.select(:forum_topic_id)).where.not(id: BulkUpdateRequest.has_topic.pending.or(BulkUpdateRequest.has_topic.approved).select(:forum_topic_id)) }
|
||||
|
||||
module CategoryMethods
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
@@ -82,8 +88,24 @@ class ForumTopic < ApplicationRecord
|
||||
q = q.search_attributes(params, :creator, :updater, :is_sticky, :is_locked, :is_deleted, :category_id, :title, :response_count)
|
||||
q = q.text_attribute_matches(:title, params[:title_matches], index_column: :text_index)
|
||||
|
||||
if params[:mod_only].present?
|
||||
q = q.where("min_level >= ?", MIN_LEVELS[:Moderator])
|
||||
if params[:is_private].to_s.truthy?
|
||||
q = q.private_only
|
||||
elsif params[:is_private].to_s.falsy?
|
||||
q = q.public_only
|
||||
end
|
||||
|
||||
if params[:status] == "pending"
|
||||
q = q.pending
|
||||
elsif params[:status] == "approved"
|
||||
q = q.approved
|
||||
elsif params[:status] == "rejected"
|
||||
q = q.rejected
|
||||
end
|
||||
|
||||
if params[:is_read].to_s.truthy?
|
||||
q = q.read_by_user(CurrentUser.user)
|
||||
elsif params[:is_read].to_s.falsy?
|
||||
q = q.unread_by_user(CurrentUser.user)
|
||||
end
|
||||
|
||||
case params[:order]
|
||||
@@ -144,6 +166,10 @@ class ForumTopic < ApplicationRecord
|
||||
(topic_last_read_at >= updated_at) || (forum_last_read_at >= updated_at)
|
||||
end
|
||||
|
||||
def is_private?
|
||||
min_level > MIN_LEVELS[:None]
|
||||
end
|
||||
|
||||
def create_mod_action_for_delete
|
||||
ModAction.log("deleted forum topic ##{id} (title: #{title})", :forum_topic_delete)
|
||||
end
|
||||
|
||||
@@ -1,31 +1,33 @@
|
||||
<%= table_for forum_topics, width: "100%" do |t| %>
|
||||
<% t.column "Title" do |topic| %>
|
||||
<% if !topic.is_read? %>
|
||||
<span class="topic-status label new">New</span>
|
||||
<%= link_to forum_topics_path(search: { is_read: false }) do %>
|
||||
<span class="topic-status label new">New</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if topic.is_sticky? %>
|
||||
<span class="topic-status icon stickied">
|
||||
<i class="fas fa-thumbtack" title="Stickied"></i>
|
||||
</span>
|
||||
<%= link_to forum_topics_path(search: { is_sticky: true }) do %>
|
||||
<i class="topic-status icon stickied fas fa-thumbtack" title="Stickied"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if topic.is_locked? %>
|
||||
<span class="topic-status icon locked">
|
||||
<i class="fas fa-lock" title="Locked"></i>
|
||||
</span>
|
||||
<%= link_to forum_topics_path(search: { is_locked: true }) do %>
|
||||
<i class="topic-status icon locked fas fa-lock" title="Locked"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if topic.is_deleted? %>
|
||||
<span class="topic-status icon deleted">
|
||||
<i class="fas fa-trash-alt" title="Deleted"></i>
|
||||
</span>
|
||||
<%= link_to forum_topics_path(search: { is_deleted: true }) do %>
|
||||
<i class="topic-status icon deleted fas fa-trash-alt" title="Deleted"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if topic.min_level > 0 %>
|
||||
<span class="topic-status icon restricted">
|
||||
<i class="fas fa-hand-paper" title="<%= User.level_string(topic.min_level) %> only"></i>
|
||||
</span>
|
||||
<% if topic.is_private? %>
|
||||
<%= link_to forum_topics_path(search: { is_private: true }) do %>
|
||||
<i class="topic-status icon private fas fa-hand-paper" title="<%= User.level_string(topic.min_level) %> only"></i>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if forum_topic_status(topic).present? %>
|
||||
@@ -40,7 +42,9 @@
|
||||
<% end %>
|
||||
<% t.column "Status", width: "1%" do |topic| %>
|
||||
<% status = forum_topic_status(topic) %>
|
||||
<span class="topic-status label <%= status %>"><%= status %></span>
|
||||
<%= link_to forum_topics_path(search: { status: status }) do %>
|
||||
<span class="topic-status label <%= status %>"><%= status %></span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% t.column "Creator", width: "8%" do |topic| %>
|
||||
<%= link_to_user topic.creator %>
|
||||
|
||||
@@ -10,8 +10,9 @@
|
||||
<p>
|
||||
Categories:
|
||||
<%= link_to "All", forum_topics_path %>,
|
||||
<%= link_to "New", forum_topics_path(search: { is_read: false }) %>,
|
||||
<% if CurrentUser.is_moderator? %>
|
||||
<%= link_to "Mod+", forum_topics_path(:search => {:mod_only => true}) %>,
|
||||
<%= link_to "Private", forum_topics_path(search: { is_private: true }) %>,
|
||||
<% end %>
|
||||
<%= ForumTopic::CATEGORIES.map {|id, name| link_to_unless_current(name, forum_topics_path(:search => {:category_id => id}))}.join(", ").html_safe %>
|
||||
</p>
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<h1>
|
||||
<%= @forum_topic.title %>
|
||||
|
||||
<% if @forum_topic.min_level >= User::Levels::MODERATOR %>
|
||||
<% if @forum_topic.is_private? %>
|
||||
<span class="level-topic">(<%= User.level_string(@forum_topic.min_level).downcase %>+ only)</span>
|
||||
<% end %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user