From 8c930c97e01ac13740fae11edbc31d30aa3532c2 Mon Sep 17 00:00:00 2001
From: Robin Ward <robin.ward@gmail.com>
Date: Mon, 27 Apr 2015 15:55:10 -0400
Subject: [PATCH] If there are pending posts in a topic, display a message at
 the bottom

---
 app/assets/javascripts/discourse/templates/topic.hbs | 11 +++++++++++
 app/assets/stylesheets/common/base/topic.scss        |  8 ++++++++
 app/models/topic.rb                                  |  5 +++++
 app/serializers/topic_view_serializer.rb             |  8 +++++++-
 config/locales/client.en.yml                         |  5 +++++
 5 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/app/assets/javascripts/discourse/templates/topic.hbs b/app/assets/javascripts/discourse/templates/topic.hbs
index 65136ab67b3..5d65e09000f 100644
--- a/app/assets/javascripts/discourse/templates/topic.hbs
+++ b/app/assets/javascripts/discourse/templates/topic.hbs
@@ -89,6 +89,17 @@
             {{view 'topic-closing' topic=model}}
             {{view 'topic-footer-buttons' topic=model}}
 
+            {{#if pending_posts_count}}
+              <div class='has-pending-posts'>
+                {{{i18n "queue.has_pending_posts" count=pending_posts_count}}}
+
+                {{#link-to 'queued-posts'}}
+                  {{fa-icon 'check'}}
+                  {{i18n 'queue.view_pending'}}
+                {{/link-to}}
+              </div>
+            {{/if}}
+
             {{plugin-outlet "topic-above-suggested"}}
 
             {{#if details.suggested_topics.length}}
diff --git a/app/assets/stylesheets/common/base/topic.scss b/app/assets/stylesheets/common/base/topic.scss
index 4eb62c3089f..443f6cb0230 100644
--- a/app/assets/stylesheets/common/base/topic.scss
+++ b/app/assets/stylesheets/common/base/topic.scss
@@ -41,3 +41,11 @@
   }
 
 }
+
+.has-pending-posts {
+  padding: 0.5em;
+  background-color: dark-light-diff($highlight, $secondary, 50%, -70%);
+  a[href] {
+    float: right;
+  }
+}
diff --git a/app/models/topic.rb b/app/models/topic.rb
index 16710ed9ad4..a61cc819697 100644
--- a/app/models/topic.rb
+++ b/app/models/topic.rb
@@ -85,6 +85,7 @@ class Topic < ActiveRecord::Base
   has_many :allowed_group_users, through: :allowed_groups, source: :users
   has_many :allowed_groups, through: :topic_allowed_groups, source: :group
   has_many :allowed_users, through: :topic_allowed_users, source: :user
+  has_many :queued_posts
 
   has_one :top_topic
   belongs_to :user
@@ -271,6 +272,10 @@ class Topic < ActiveRecord::Base
     Redcarpet::Render::SmartyPants.render(sanitized_title)
   end
 
+  def pending_posts_count
+    queued_posts.new_count
+  end
+
   # Returns hot topics since a date for display in email digest.
   def self.for_digest(user, since, opts=nil)
     opts = opts || {}
diff --git a/app/serializers/topic_view_serializer.rb b/app/serializers/topic_view_serializer.rb
index eec7b2c447a..41d296670b3 100644
--- a/app/serializers/topic_view_serializer.rb
+++ b/app/serializers/topic_view_serializer.rb
@@ -1,4 +1,5 @@
 require_dependency 'pinned_check'
+require_dependency 'new_post_manager'
 
 class TopicViewSerializer < ApplicationSerializer
   include PostStreamSerializerMixin
@@ -30,7 +31,8 @@ class TopicViewSerializer < ApplicationSerializer
                         :slug,
                         :category_id,
                         :word_count,
-                        :deleted_at
+                        :deleted_at,
+                        :pending_posts_count
 
   attributes :draft,
              :draft_key,
@@ -206,4 +208,8 @@ class TopicViewSerializer < ApplicationSerializer
     object.topic_user.try(:bookmarked)
   end
 
+  def include_pending_posts_count
+    scope.user.staff? && NewPostManager.queue_enabled?
+  end
+
 end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index e0ab53a68f4..378142c7270 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -236,6 +236,11 @@ en:
       none: "There are no posts to review."
       edit: "Edit"
       cancel: "Cancel"
+      view_pending: "view pending posts"
+      has_pending_posts:
+        one: "This topic has <b>1</b> post awaiting approval"
+        many: "This topic has <b>{{count}}</b> posts awaiting approval"
+
       confirm: "Save Changes"
       delete_prompt: "Are you sure you want to delete <b>%{username}</b>? This will remove all of their posts and block their email and ip address."