diff --git a/app/javascript/src/styles/specific/forum.scss b/app/javascript/src/styles/specific/forum.scss index 69d1a8cad..c672db6e9 100644 --- a/app/javascript/src/styles/specific/forum.scss +++ b/app/javascript/src/styles/specific/forum.scss @@ -49,7 +49,7 @@ div#c-forum-topics { white-space: nowrap; } - span.topic-status { + .topic-status { margin-right: 0.25em; vertical-align: bottom; diff --git a/app/models/bulk_update_request.rb b/app/models/bulk_update_request.rb index d84f5c213..cc9bce9df 100644 --- a/app/models/bulk_update_request.rb +++ b/app/models/bulk_update_request.rb @@ -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)} diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index f1e157ddd..4c7c054c4 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -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 diff --git a/app/views/forum_topics/_listing.html.erb b/app/views/forum_topics/_listing.html.erb index 7296d3af5..8b6baa356 100644 --- a/app/views/forum_topics/_listing.html.erb +++ b/app/views/forum_topics/_listing.html.erb @@ -1,31 +1,33 @@ <%= table_for forum_topics, width: "100%" do |t| %> <% t.column "Title" do |topic| %> <% if !topic.is_read? %> - New + <%= link_to forum_topics_path(search: { is_read: false }) do %> + New + <% end %> <% end %> <% if topic.is_sticky? %> - - - + <%= link_to forum_topics_path(search: { is_sticky: true }) do %> + + <% end %> <% end %> <% if topic.is_locked? %> - - - + <%= link_to forum_topics_path(search: { is_locked: true }) do %> + + <% end %> <% end %> <% if topic.is_deleted? %> - - - + <%= link_to forum_topics_path(search: { is_deleted: true }) do %> + + <% end %> <% end %> - <% if topic.min_level > 0 %> - - - + <% if topic.is_private? %> + <%= link_to forum_topics_path(search: { is_private: true }) do %> + + <% 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) %> - <%= status %> + <%= link_to forum_topics_path(search: { status: status }) do %> + <%= status %> + <% end %> <% end %> <% t.column "Creator", width: "8%" do |topic| %> <%= link_to_user topic.creator %> diff --git a/app/views/forum_topics/index.html.erb b/app/views/forum_topics/index.html.erb index ba4393780..ba03d71f8 100644 --- a/app/views/forum_topics/index.html.erb +++ b/app/views/forum_topics/index.html.erb @@ -10,8 +10,9 @@
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 %>
diff --git a/app/views/forum_topics/show.html.erb b/app/views/forum_topics/show.html.erb index 4c04b7eb5..001a39068 100644 --- a/app/views/forum_topics/show.html.erb +++ b/app/views/forum_topics/show.html.erb @@ -9,7 +9,7 @@