Skip to content

Commit b28a8e2

Browse files
committed
FIX: Categories are ordered by topic_count.
1 parent eba5465 commit b28a8e2

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

app/assets/javascripts/discourse/models/category.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Discourse.Category.reopenClass({
195195
},
196196

197197
list: function() {
198-
return Discourse.Site.currentProp('categories');
198+
return Discourse.Site.currentProp('sortedCategories');
199199
},
200200

201201
findSingleBySlug: function(slug) {

app/assets/javascripts/discourse/models/site.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ Discourse.Site = Discourse.Model.extend({
2222
return postActionTypes.filterProperty('is_flag', true);
2323
}.property('post_action_types.@each'),
2424

25+
sortedCategories: Em.computed.sort('categories', function(a, b) {
26+
return (b.get('topic_count') || 0) - (a.get('topic_count') || 0);
27+
}),
28+
2529
postActionTypeById: function(id) {
2630
return this.get("postActionByIdLookup.action" + id);
2731
},

test/javascripts/models/nav_item_test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module("Discourse.NavItem", {
22
setup: function() {
33
this.site = Discourse.Site.current();
4-
this.originalCategories = Discourse.Site.currentProp('categories') || [];
5-
this.site.set('categories', this.originalCategories.concat( [Discourse.Category.create({name: '确实是这样', id: 343434})] ));
4+
this.asianCategory = Discourse.Category.create({name: '确实是这样', id: 343434});
5+
this.site.get('categories').addObject(this.asianCategory);
66
},
77

88
teardown: function() {
9-
this.site.set('categories', this.originalCategories);
9+
this.site.get('categories').removeObject(this.asianCategory);
1010
}
1111
});
1212

0 commit comments

Comments
 (0)