Skip to content

A platform for community discussion. Free, open, simple.

FIX: when deleting a tag, the warning modal has the wrong topic count

Neil Lalonde298ee2690898
diff --git a/app/assets/javascripts/discourse/controllers/tags-show.js.es6 b/app/assets/javascripts/discourse/controllers/tags-show.js.es6
index d1a292c2e88..dbf92517366 100644
--- a/app/assets/javascripts/discourse/controllers/tags-show.js.es6
+++ b/app/assets/javascripts/discourse/controllers/tags-show.js.es6
@@ -119,8 +119,8 @@ export default Ember.Controller.extend(BulkTopicSelection, {
deleteTag() {
const self = this;
- const topicsLength = this.get('list.topic_list.topics.length');
- const confirmText = topicsLength === 0 ? I18n.t("tagging.delete_confirm_no_topics") : I18n.t("tagging.delete_confirm", {count: topicsLength});
+ const numTopics = this.get('list.topic_list.tags.firstObject.topic_count') || 0;
+ const confirmText = numTopics === 0 ? I18n.t("tagging.delete_confirm_no_topics") : I18n.t("tagging.delete_confirm", {count: numTopics});
bootbox.confirm(confirmText, function(result) {
if (!result) { return; }
diff --git a/app/models/topic_list.rb b/app/models/topic_list.rb
index 0e02b74fe15..dbb468cb489 100644
--- a/app/models/topic_list.rb
+++ b/app/models/topic_list.rb
@@ -35,7 +35,8 @@ class TopicList
:for_period,
:per_page,
:top_tags,
- :current_user
+ :current_user,
+ :tags
def initialize(filter, current_user, topics, opts = nil)
@filter = filter
@@ -46,6 +47,10 @@ class TopicList
if @opts[:category]
@category = Category.find_by(id: @opts[:category_id])
end
+
+ if @opts[:tags]
+ @tags = Tag.where(id: @opts[:tags]).all
+ end
end
def top_tags
diff --git a/app/serializers/tag_serializer.rb b/app/serializers/tag_serializer.rb
index 206a0256fa7..9f050800295 100644
--- a/app/serializers/tag_serializer.rb
+++ b/app/serializers/tag_serializer.rb
@@ -1,3 +1,3 @@
class TagSerializer < ApplicationSerializer
- attributes :id, :name
+ attributes :id, :name, :topic_count
end
diff --git a/app/serializers/topic_list_serializer.rb b/app/serializers/topic_list_serializer.rb
index 0a9300790f2..994ea84950c 100644
--- a/app/serializers/topic_list_serializer.rb
+++ b/app/serializers/topic_list_serializer.rb
@@ -7,9 +7,11 @@ class TopicListSerializer < ApplicationSerializer
:draft_sequence,
:for_period,
:per_page,
- :top_tags
+ :top_tags,
+ :tags
has_many :topics, serializer: TopicListItemSerializer, embed: :objects
+ has_many :tags, serializer: TagSerializer, embed: :objects
def can_create_topic
scope.can_create?(Topic)
@@ -26,4 +28,8 @@ class TopicListSerializer < ApplicationSerializer
def include_top_tags?
Tag.include_tags?
end
+
+ def include_tags?
+ SiteSetting.tagging_enabled && object.tags.present?
+ end
end