Skip to content

Commit

Permalink
FEATURE: added UI for tracking categories
Browse files Browse the repository at this point in the history
  • Loading branch information
SamSaffron committed Jan 6, 2014
1 parent 3a2ae00 commit f91163e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/assets/javascripts/discourse/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ Discourse.User = Discourse.Model.extend({
'external_links_in_new_tab',
'watch_new_topics',
'enable_quoting');
data.watched_category_ids = this.get('watchedCategories').map(function(c){ return c.get('id')});
data.muted_category_ids = this.get('mutedCategories').map(function(c){ return c.get('id')});
_.each(['muted','watched','tracked'], function(s){
data[s + '_category_ids'] = user.get(s + 'Categories').map(function(c){ return c.get('id')});
});

return Discourse.ajax("/users/" + this.get('username_lower'), {
data: data,
Expand Down Expand Up @@ -362,6 +363,12 @@ Discourse.User = Discourse.Model.extend({
}));
}.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() {
this.set("watchedCategories", _.map(this.watched_category_ids, function(id){
return Discourse.Category.findById(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@
{{category-group categories=watchedCategories}}
<div class="instructions">{{i18n user.watched_categories_instructions}}</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">
<label>{{i18n user.muted_categories}}</label>
{{category-group categories=mutedCategories}}
Expand Down
5 changes: 5 additions & 0 deletions app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def bio_excerpt
:gravatar_template,
:uploaded_avatar_template,
:muted_category_ids,
:tracked_category_ids,
:watched_category_ids


Expand Down Expand Up @@ -112,6 +113,10 @@ def muted_category_ids
CategoryUser.lookup(object, :muted).pluck(:category_id)
end

def tracked_category_ids
CategoryUser.lookup(object, :tracking).pluck(:category_id)
end

def watched_category_ids
CategoryUser.lookup(object, :watching).pluck(:category_id)
end
Expand Down
4 changes: 4 additions & 0 deletions app/services/user_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def update(attributes = {})
CategoryUser.batch_set(user, :watching, ids)
end

if ids = attributes[:tracked_category_ids]
CategoryUser.batch_set(user, :tracking, ids)
end

if ids = attributes[:muted_category_ids]
CategoryUser.batch_set(user, :muted, ids)
end
Expand Down
2 changes: 2 additions & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ en:
watch_new_topics: "Automatically watch all new topics posted on the forum"
watched_categories: "Watched"
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_instructions: "You will automatically mute all topics in these categories"

Expand Down

0 comments on commit f91163e

Please sign in to comment.