From 24ae35aa96a3eec7bd5bc1a4a881877e8c64438a Mon Sep 17 00:00:00 2001 From: BrokenEagle Date: Sat, 15 Feb 2020 22:04:47 +0000 Subject: [PATCH] Add BUR counters to forum topics index --- app/controllers/forum_topics_controller.rb | 2 +- app/helpers/forum_topics_helper.rb | 8 ++++++++ app/models/forum_topic.rb | 13 +++++++++++++ app/views/forum_topics/_listing.html.erb | 9 ++++++--- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/controllers/forum_topics_controller.rb b/app/controllers/forum_topics_controller.rb index 4e7346101..fd6fc3043 100644 --- a/app/controllers/forum_topics_controller.rb +++ b/app/controllers/forum_topics_controller.rb @@ -28,7 +28,7 @@ class ForumTopicsController < ApplicationController if request.format.atom? @forum_topics = @forum_topics.includes(:creator, :original_post) elsif request.format.html? - @forum_topics = @forum_topics.includes(:creator, :updater, :forum_topic_visit_by_current_user) + @forum_topics = @forum_topics.includes(:creator, :updater, :forum_topic_visit_by_current_user, :bulk_update_requests) end respond_with(@forum_topics) diff --git a/app/helpers/forum_topics_helper.rb b/app/helpers/forum_topics_helper.rb index f96eac9c9..8e537f088 100644 --- a/app/helpers/forum_topics_helper.rb +++ b/app/helpers/forum_topics_helper.rb @@ -10,4 +10,12 @@ module ForumTopicsHelper def new_forum_topic?(topic, read_forum_topics) !read_forum_topics.map(&:id).include?(topic.id) end + + def bulk_update_request_counts(topic) + requests = [] + requests << %(Pending: #{topic.pending_bur_count}) if topic.pending_bur_count.positive? + requests << %(Approved: #{topic.approved_bur_count}) if topic.approved_bur_count.positive? + requests << %(Rejected: #{topic.rejected_bur_count}) if topic.rejected_bur_count.positive? + requests.join(" | ").html_safe + end end diff --git a/app/models/forum_topic.rb b/app/models/forum_topic.rb index 70f0e6fb7..f3b1be415 100644 --- a/app/models/forum_topic.rb +++ b/app/models/forum_topic.rb @@ -18,6 +18,7 @@ class ForumTopic < ApplicationRecord has_one :forum_topic_visit_by_current_user, -> { where(user_id: CurrentUser.id) }, class_name: "ForumTopicVisit" has_many :moderation_reports, through: :posts has_one :original_post, -> {order("forum_posts.id asc")}, class_name: "ForumPost", foreign_key: "topic_id", inverse_of: :topic + has_many :bulk_update_requests, :foreign_key => "forum_topic_id" before_validation :initialize_is_deleted, :on => :create validates_presence_of :title @@ -176,6 +177,18 @@ class ForumTopic < ApplicationRecord original_post&.update_columns(:updater_id => updater.id, :updated_at => Time.now) end + def pending_bur_count + bulk_update_requests.select {|request| request.status == "pending"}.size + end + + def approved_bur_count + bulk_update_requests.select {|request| request.status == "approved"}.size + end + + def rejected_bur_count + bulk_update_requests.select {|request| request.status == "rejected"}.size + end + def self.available_includes [:creator, :updater, :original_post] end diff --git a/app/views/forum_topics/_listing.html.erb b/app/views/forum_topics/_listing.html.erb index 8314e1435..489c8815d 100644 --- a/app/views/forum_topics/_listing.html.erb +++ b/app/views/forum_topics/_listing.html.erb @@ -22,13 +22,16 @@ (<%= User.level_string(topic.min_level).downcase %> only) <% end %> <% end %> - <% t.column "Creator" do |topic| %> + <% t.column "BURs", width: "20%" do |topic| %> + <%= bulk_update_request_counts(topic) %> + <% end %> + <% t.column "Creator", width: "8%" do |topic| %> <%= link_to_user topic.creator %> <% end %> - <% t.column "Updated by" do |topic| %> + <% t.column "Updated by", width: "8%" do |topic| %> <%= link_to_user topic.updater %> <% end %> - <% t.column "Updated at" do |topic| %> + <% t.column "Updated at", width: "8%" do |topic| %> <%= compact_time topic.updated_at %> <% end %> <% end %>