FEATURE: added UI for tracking categories

This commit is contained in:
Sam 2014-01-06 11:57:17 +11:00
parent 3a2ae0061b
commit f91163e146
5 changed files with 25 additions and 2 deletions

View File

@ -181,8 +181,9 @@ Discourse.User = Discourse.Model.extend({
'external_links_in_new_tab', 'external_links_in_new_tab',
'watch_new_topics', 'watch_new_topics',
'enable_quoting'); 'enable_quoting');
data.watched_category_ids = this.get('watchedCategories').map(function(c){ return c.get('id')}); _.each(['muted','watched','tracked'], function(s){
data.muted_category_ids = this.get('mutedCategories').map(function(c){ return c.get('id')}); data[s + '_category_ids'] = user.get(s + 'Categories').map(function(c){ return c.get('id')});
});
return Discourse.ajax("/users/" + this.get('username_lower'), { return Discourse.ajax("/users/" + this.get('username_lower'), {
data: data, data: data,
@ -362,6 +363,12 @@ Discourse.User = Discourse.Model.extend({
})); }));
}.observes("muted_category_ids"), }.observes("muted_category_ids"),
updateTrackedCategories: function() {
this.set("trackedCategories", _.map(this.tracked_category_ids, function(id){
return Discourse.Category.findById(id);
}));
}.observes("tracked_category_ids"),
updateWatchedCategories: function() { updateWatchedCategories: function() {
this.set("watchedCategories", _.map(this.watched_category_ids, function(id){ this.set("watchedCategories", _.map(this.watched_category_ids, function(id){
return Discourse.Category.findById(id); return Discourse.Category.findById(id);

View File

@ -141,6 +141,11 @@
{{category-group categories=watchedCategories}} {{category-group categories=watchedCategories}}
<div class="instructions">{{i18n user.watched_categories_instructions}}</div> <div class="instructions">{{i18n user.watched_categories_instructions}}</div>
</div> </div>
<div class="controls">
<label>{{i18n user.tracked_categories}}</label>
{{category-group categories=trackedCategories}}
<div class="instructions">{{i18n user.tracked_categories_instructions}}</div>
</div>
<div class="controls"> <div class="controls">
<label>{{i18n user.muted_categories}}</label> <label>{{i18n user.muted_categories}}</label>
{{category-group categories=mutedCategories}} {{category-group categories=mutedCategories}}

View File

@ -62,6 +62,7 @@ class UserSerializer < BasicUserSerializer
:gravatar_template, :gravatar_template,
:uploaded_avatar_template, :uploaded_avatar_template,
:muted_category_ids, :muted_category_ids,
:tracked_category_ids,
:watched_category_ids :watched_category_ids
@ -112,6 +113,10 @@ class UserSerializer < BasicUserSerializer
CategoryUser.lookup(object, :muted).pluck(:category_id) CategoryUser.lookup(object, :muted).pluck(:category_id)
end end
def tracked_category_ids
CategoryUser.lookup(object, :tracking).pluck(:category_id)
end
def watched_category_ids def watched_category_ids
CategoryUser.lookup(object, :watching).pluck(:category_id) CategoryUser.lookup(object, :watching).pluck(:category_id)
end end

View File

@ -15,6 +15,10 @@ class UserUpdater
CategoryUser.batch_set(user, :watching, ids) CategoryUser.batch_set(user, :watching, ids)
end end
if ids = attributes[:tracked_category_ids]
CategoryUser.batch_set(user, :tracking, ids)
end
if ids = attributes[:muted_category_ids] if ids = attributes[:muted_category_ids]
CategoryUser.batch_set(user, :muted, ids) CategoryUser.batch_set(user, :muted, ids)
end end

View File

@ -230,6 +230,8 @@ en:
watch_new_topics: "Automatically watch all new topics posted on the forum" watch_new_topics: "Automatically watch all new topics posted on the forum"
watched_categories: "Watched" watched_categories: "Watched"
watched_categories_instructions: "You will automatically watch all topics in these categories" watched_categories_instructions: "You will automatically watch all topics in these categories"
tracked_categories: "Tracked"
tracked_categories_instructions: "You will automatically recieve notifications for topics in these categories"
muted_categories: "Muted" muted_categories: "Muted"
muted_categories_instructions: "You will automatically mute all topics in these categories" muted_categories_instructions: "You will automatically mute all topics in these categories"