diff --git a/app/assets/javascripts/discourse/components/tag-list.js.es6 b/app/assets/javascripts/discourse/components/tag-list.js.es6 new file mode 100644 index 0000000000..df2c024cb8 --- /dev/null +++ b/app/assets/javascripts/discourse/components/tag-list.js.es6 @@ -0,0 +1,21 @@ +export default Ember.Component.extend({ + classNameBindings: [':tag-list', 'categoryClass'], + + sortedTags: Ember.computed.sort('tags', 'sortProperties'), + + title: function() { + if (this.get('titleKey')) { return I18n.t(this.get('titleKey')); } + }.property('titleKey'), + + category: function() { + if (this.get('categoryId')) { + return Discourse.Category.findById(this.get('categoryId')); + } + }.property('categoryId'), + + categoryClass: function() { + if (this.get('category')) { + return "tag-list-" + this.get('category.fullSlug'); + } + }.property('category') +}); diff --git a/app/assets/javascripts/discourse/controllers/tags-index.js.es6 b/app/assets/javascripts/discourse/controllers/tags-index.js.es6 index e2a49fee20..8f2ee7ce79 100644 --- a/app/assets/javascripts/discourse/controllers/tags-index.js.es6 +++ b/app/assets/javascripts/discourse/controllers/tags-index.js.es6 @@ -1,8 +1,6 @@ export default Ember.Controller.extend({ sortProperties: ['count:desc', 'id'], - sortedTags: Ember.computed.sort('model', 'sortProperties'), - actions: { sortByCount() { this.set('sortProperties', ['count:desc', 'id']); diff --git a/app/assets/javascripts/discourse/templates/components/tag-list.hbs b/app/assets/javascripts/discourse/templates/components/tag-list.hbs new file mode 100644 index 0000000000..ff34843a81 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/tag-list.hbs @@ -0,0 +1,13 @@ +{{#if title}} +

{{title}}

+{{/if}} +{{#if category}} + {{category-title-link category=category}} +{{/if}} +{{#each sortedTags as |tag|}} +
+ {{discourse-tag tag.id}} x {{tag.count}} +
+{{/each}} +
+
diff --git a/app/assets/javascripts/discourse/templates/tags/index.hbs b/app/assets/javascripts/discourse/templates/tags/index.hbs index 5661fd0dd4..239b2b6c1a 100644 --- a/app/assets/javascripts/discourse/templates/tags/index.hbs +++ b/app/assets/javascripts/discourse/templates/tags/index.hbs @@ -2,18 +2,17 @@ {{discourse-banner user=currentUser banner=site.banner}}
-

{{i18n "tagging.all_tags"}}

+

{{i18n "tagging.tags"}}

{{i18n "tagging.sort_by"}} {{i18n "tagging.sort_by_count"}} {{i18n "tagging.sort_by_name"}}
+
-
- {{#each sortedTags as |tag|}} -
- {{discourse-tag tag.id}} x {{tag.count}} -
- {{/each}} -
+{{#each model.extras.categories as |category|}} + {{tag-list tags=category.tags sortProperties=sortProperties categoryId=category.id}} +{{/each}} + +{{tag-list tags=model sortProperties=sortProperties titleKey="tagging.all_tags"}} diff --git a/app/assets/stylesheets/common/base/tagging.scss b/app/assets/stylesheets/common/base/tagging.scss index 0a14a1c4ca..9fd6e39230 100644 --- a/app/assets/stylesheets/common/base/tagging.scss +++ b/app/assets/stylesheets/common/base/tagging.scss @@ -8,6 +8,10 @@ margin-top: 2em; } +#list-area .tag-list h3 { + margin-bottom: 20px; +} + .tag-box { display: inline-block; width: 300px; @@ -180,8 +184,11 @@ header .discourse-tag {color: $tag-color !important; } padding-top: 2px; } -.tag-sort-options a { - text-decoration: underline; +.tag-sort-options { + margin-bottom: 20px; + a { + text-decoration: underline; + } } .autocomplete { diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 035febb601..847d5b62d9 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -12,15 +12,23 @@ class TagsController < ::ApplicationController before_filter :set_category_from_params, except: [:index, :update, :destroy, :tag_feed, :search, :notifications, :update_notifications] def index + categories = Category.where("id in (select category_id from category_tags)") + .where("id in (?)", guardian.allowed_category_ids) + .preload(:tags) + category_tag_counts = categories.map { |c| {id: c.id, tags: self.class.tag_counts_json(Tag.category_tags_by_count_query(c, limit: 300).count)} } + tag_counts = self.class.tags_by_count(guardian, limit: 300).count - @tags = tag_counts.map {|t, c| { id: t, text: t, count: c } } + @tags = self.class.tag_counts_json(tag_counts) respond_to do |format| format.html do render :index end format.json do - render json: { tags: @tags } + render json: { + tags: @tags, + extras: { categories: category_tag_counts } + } end end end @@ -154,6 +162,10 @@ class TagsController < ::ApplicationController guardian.filter_allowed_categories(Tag.tags_by_count_query(opts)) end + def self.tag_counts_json(tag_counts) + tag_counts.map {|t, c| { id: t, text: t, count: c } } + end + def set_category_from_params slug_or_id = params[:category] return true if slug_or_id.nil? diff --git a/app/models/tag.rb b/app/models/tag.rb index df544cd022..12d7adf99b 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -15,6 +15,11 @@ class Tag < ActiveRecord::Base q end + def self.category_tags_by_count_query(category, opts={}) + tags_by_count_query(opts).where("tags.id in (select tag_id from category_tags where category_id = ?)", category.id) + .where("topics.category_id = ?", category.id) + end + def self.top_tags(limit_arg=nil) self.tags_by_count_query(limit: limit_arg || SiteSetting.max_tags_in_filter_list) .count