From b28a8e262fab42dd644dbbd1179d95e1f2e3f5b0 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 9 Jan 2014 13:05:05 -0500 Subject: [PATCH] FIX: Categories are ordered by `topic_count`. --- app/assets/javascripts/discourse/models/category.js | 2 +- app/assets/javascripts/discourse/models/site.js | 4 ++++ test/javascripts/models/nav_item_test.js | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/models/category.js b/app/assets/javascripts/discourse/models/category.js index d4e963a68..2dae55ed8 100644 --- a/app/assets/javascripts/discourse/models/category.js +++ b/app/assets/javascripts/discourse/models/category.js @@ -195,7 +195,7 @@ Discourse.Category.reopenClass({ }, list: function() { - return Discourse.Site.currentProp('categories'); + return Discourse.Site.currentProp('sortedCategories'); }, findSingleBySlug: function(slug) { diff --git a/app/assets/javascripts/discourse/models/site.js b/app/assets/javascripts/discourse/models/site.js index e7bbcc721..52ae7ca8d 100644 --- a/app/assets/javascripts/discourse/models/site.js +++ b/app/assets/javascripts/discourse/models/site.js @@ -22,6 +22,10 @@ Discourse.Site = Discourse.Model.extend({ return postActionTypes.filterProperty('is_flag', true); }.property('post_action_types.@each'), + sortedCategories: Em.computed.sort('categories', function(a, b) { + return (b.get('topic_count') || 0) - (a.get('topic_count') || 0); + }), + postActionTypeById: function(id) { return this.get("postActionByIdLookup.action" + id); }, diff --git a/test/javascripts/models/nav_item_test.js b/test/javascripts/models/nav_item_test.js index 82647d67c..e8a619ae9 100644 --- a/test/javascripts/models/nav_item_test.js +++ b/test/javascripts/models/nav_item_test.js @@ -1,12 +1,12 @@ module("Discourse.NavItem", { setup: function() { this.site = Discourse.Site.current(); - this.originalCategories = Discourse.Site.currentProp('categories') || []; - this.site.set('categories', this.originalCategories.concat( [Discourse.Category.create({name: '确实是这样', id: 343434})] )); + this.asianCategory = Discourse.Category.create({name: '确实是这样', id: 343434}); + this.site.get('categories').addObject(this.asianCategory); }, teardown: function() { - this.site.set('categories', this.originalCategories); + this.site.get('categories').removeObject(this.asianCategory); } });