Updating starred tag counts on adding/removing tags.

This commit is contained in:
Samuel Clay 2013-08-16 18:26:56 -07:00
parent 3265c018b9
commit b299453477
7 changed files with 40 additions and 15 deletions

View file

@ -1679,10 +1679,10 @@ def mark_story_as_unstarred(request):
if not starred_story:
starred_story = MStarredStory.objects(user_id=request.user.pk, story_hash=story_id)
if starred_story:
logging.user(request, "~FCUnstarring: ~SB%s" % (starred_story[0].story_title[:50]))
starred_story.delete()
MStarredStoryCounts.count_tags_for_user(request.user.pk)
starred_counts = MStarredStoryCounts.user_counts(request.user.pk)
logging.user(request, "~FCUnstarring: ~SB%s" % (starred_story[0].story_title[:50]))
else:
code = -1

View file

@ -226,21 +226,33 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
},
mark_story_as_starred: function(story_id, callback) {
var self = this;
var story = this.get_story(story_id);
var pre_callback = function(data) {
self.starred_feeds.reset(data.starred_counts, {parse: true, update: true});
if (callback) callback(data);
};
this.make_request('/reader/mark_story_as_starred', {
story_id: story_id,
feed_id: story.get('story_feed_id'),
user_tags: story.get('user_tags')
}, callback);
}, pre_callback);
},
mark_story_as_unstarred: function(story_id, callback) {
var self = this;
var story = this.get_story(story_id);
var pre_callback = function(data) {
self.starred_feeds.reset(data.starred_counts, {parse: true, update: true});
if (callback) callback(data);
};
this.make_request('/reader/mark_story_as_unstarred', {
story_id: story_id
}, callback);
}, pre_callback);
},
mark_feed_as_read: function(feed_id, callback) {

View file

@ -8,6 +8,7 @@ NEWSBLUR.Router = Backbone.Router.extend({
"site/:site_id/": "site",
"site/:site_id": "site",
"folder/saved": "starred",
"folder/saved/:tag": "starred",
"folder/:folder_name": "folder",
"folder/:folder_name/": "folder",
"social/:user_id/:slug": "social",
@ -47,8 +48,12 @@ NEWSBLUR.Router = Backbone.Router.extend({
}
},
starred: function() {
options = {router: true};
starred: function(tag) {
options = {
router: true,
tag: tag
};
console.log(["starred", options, tag]);
NEWSBLUR.reader.open_starred_stories(options);
},

View file

@ -70,6 +70,10 @@ NEWSBLUR.Collections.StarredFeeds = Backbone.Collection.extend({
}).each(function(feed){
feed.set('selected', false);
});
},
all_tags: function() {
return this.pluck('tag');
}
});

View file

@ -108,7 +108,6 @@ NEWSBLUR.Models.Story = Backbone.Model.extend({
},
change_user_tags: function(tags, options, etc) {
console.log(["change_user_tags", tags, options, etc, this.get('starred')]);
NEWSBLUR.assets.mark_story_as_starred(this.id);
},
@ -144,11 +143,13 @@ NEWSBLUR.Models.Story = Backbone.Model.extend({
var story_tags = this.get('story_tags') || [];
var user_tags = this.get('user_tags') || [];
var folder_tags = this.folder_tags();
var all_tags = _.unique(_.compact(_.reduce([story_tags, user_tags, folder_tags], function(x, m) {
var existing_tags = NEWSBLUR.assets.starred_feeds.all_tags();
var all_tags = _.unique(_.compact(_.reduce([
story_tags, user_tags, folder_tags, existing_tags
], function(x, m) {
return m.concat(x);
}, [])));
console.log(["all_tags", all_tags]);
return all_tags;
}

View file

@ -1510,8 +1510,8 @@
NEWSBLUR.app.taskbar_info.show_stories_error, true);
if (!options.silent) {
var url = "folder/saved";
if (!_.string.include(window.location.pathname, url)) {
var url = "/folder/saved";
if (window.location.pathname != url) {
NEWSBLUR.log(["Navigating to url", url]);
NEWSBLUR.router.navigate(url);
}

View file

@ -23,7 +23,6 @@ NEWSBLUR.Views.FeedList = Backbone.View.extend({
this.$s.$feed_link_loader.css({'display': 'block'});
NEWSBLUR.assets.feeds.bind('reset', _.bind(function() {
this.make_feeds();
this.make_starred_tags();
// TODO: Refactor this to load after both feeds and social feeds load.
this.load_router();
@ -33,6 +32,9 @@ NEWSBLUR.Views.FeedList = Backbone.View.extend({
NEWSBLUR.assets.social_feeds.bind('reset', _.bind(function() {
this.make_social_feeds();
}, this));
NEWSBLUR.assets.starred_feeds.bind('reset', _.bind(function(models, options) {
this.make_starred_tags(options);
}, this));
NEWSBLUR.assets.social_feeds.bind('change:selected', this.selected, this);
NEWSBLUR.assets.feeds.bind('change:selected', this.selected, this);
if (!NEWSBLUR.assets.folders.size()) {
@ -157,7 +159,8 @@ NEWSBLUR.Views.FeedList = Backbone.View.extend({
$('.NB-module-stats-count-following .NB-module-stats-count-number').text(profile.get('following_count'));
},
make_starred_tags: function() {
make_starred_tags: function(options) {
options = options || {};
var $starred_feeds = $('.NB-starred-feeds', this.$s.$starred_feeds);
var $feeds = NEWSBLUR.assets.starred_feeds.map(function(feed) {
var feed_view = new NEWSBLUR.Views.FeedTitleView({
@ -171,18 +174,18 @@ NEWSBLUR.Views.FeedList = Backbone.View.extend({
$starred_feeds.empty().css({
'display': 'block',
'opacity': 0
'opacity': options.update ? 1 : 0
});
$starred_feeds.html($feeds);
if (NEWSBLUR.assets.starred_feeds.length) {
$('.NB-feeds-header-starred-container').css({
'display': 'block',
'opacity': 0
}).animate({'opacity': 1}, {'duration': 700});
}).animate({'opacity': 1}, {'duration': options.update ? 0 : 700});
}
var collapsed = NEWSBLUR.app.sidebar.check_starred_collapsed({skip_animation: true});
$starred_feeds.animate({'opacity': 1}, {'duration': collapsed ? 0 : 700});
$starred_feeds.animate({'opacity': 1}, {'duration': (collapsed || options.update) ? 0 : 700});
},
load_router: function() {