BUGFIX: show uncategorized in tracking etc

BUGFIX: allow emptying of lists of watched / tracked
BUGFIX: page scrolls when clicking on [x]
This commit is contained in:
Sam 2014-01-08 17:10:16 +11:00
parent e27e8a65b3
commit e8dcd8ab71
5 changed files with 20 additions and 13 deletions

View File

@ -19,7 +19,7 @@ Discourse.CategoryGroupComponent = Ember.Component.extend({
},
template: Discourse.CategoryGroupComponent.templateFunction(),
transformComplete: function(category){
return Discourse.HTML.categoryLink(category);
return Discourse.HTML.categoryLink(category, {allowUncategorized: true});
}
});
}
@ -32,7 +32,7 @@ Discourse.CategoryGroupComponent.reopenClass({
"<ul>" +
"{{#each options}}" +
"<li>" +
"{{categoryLinkRaw this}}" +
"{{categoryLinkRaw this allowUncategorized=true}}" +
"</li>" +
"{{/each}}" +
"</ul>" +

View File

@ -114,6 +114,7 @@ $.fn.autocomplete = function(options) {
if (options.onChangeItems) {
options.onChangeItems(inputSelectedItems);
}
return false;
});
};

View File

@ -209,6 +209,12 @@ Discourse.Category.reopenClass({
return Discourse.Category.list().findBy('id', id);
},
findByIds: function(ids){
return ids.map(function(id){
return Discourse.Category.findById(id);
});
},
findBySlug: function(slug, parentSlug) {
var categories = Discourse.Category.list(),

View File

@ -181,8 +181,12 @@ Discourse.User = Discourse.Model.extend({
'external_links_in_new_tab',
'watch_new_topics',
'enable_quoting');
_.each(['muted','watched','tracked'], function(s){
data[s + '_category_ids'] = user.get(s + 'Categories').map(function(c){ return c.get('id')});
var cats = user.get(s + 'Categories').map(function(c){ return c.get('id')});
// HACK: denote lack of categories
if(cats.length === 0) { cats = [-1]; }
data[s + '_category_ids'] = cats;
});
return Discourse.ajax("/users/" + this.get('username_lower'), {
@ -358,22 +362,17 @@ Discourse.User = Discourse.Model.extend({
}.property("trust_level", "hasBeenSeenInTheLastMonth"),
updateMutedCategories: function() {
this.set("mutedCategories", _.map(this.muted_category_ids, function(id){
return Discourse.Category.findById(id);
}));
this.set("mutedCategories", Discourse.Category.findByIds(this.muted_category_ids));
}.observes("muted_category_ids"),
updateTrackedCategories: function() {
this.set("trackedCategories", _.map(this.tracked_category_ids, function(id){
return Discourse.Category.findById(id);
}));
this.set("trackedCategories", Discourse.Category.findByIds(this.tracked_category_ids));
}.observes("tracked_category_ids"),
updateWatchedCategories: function() {
this.set("watchedCategories", _.map(this.watched_category_ids, function(id){
return Discourse.Category.findById(id);
}));
this.set("watchedCategories", Discourse.Category.findByIds(this.watched_category_ids));
}.observes("watched_category_ids")
});
Discourse.User.reopenClass(Discourse.Singleton, {

View File

@ -21,9 +21,10 @@ class CategoryUser < ActiveRecord::Base
def self.batch_set(user, level, category_ids)
records = CategoryUser.where(user: user, notification_level: notification_levels[level])
old_ids = records.pluck(:category_id)
category_ids = Category.where('id in (?)', category_ids).pluck(:id)
remove = (old_ids - category_ids)
if remove.present?
records.where('category_id in (?)', remove).destroy_all