mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Refactoring how folders see their unread children.
This commit is contained in:
parent
5e42bcd4fb
commit
83e6f951cc
5 changed files with 63 additions and 84 deletions
|
@ -8,6 +8,8 @@ NEWSBLUR.Models.FeedOrFolder = Backbone.Model.extend({
|
|||
if (this.feed) {
|
||||
this.set('is_feed', true);
|
||||
}
|
||||
} else if (model && model.fake) {
|
||||
this.folders = model.folders;
|
||||
} else if (model) {
|
||||
var title = _.keys(model)[0];
|
||||
var children = model[title];
|
||||
|
@ -58,6 +60,14 @@ NEWSBLUR.Models.FeedOrFolder = Backbone.Model.extend({
|
|||
}
|
||||
},
|
||||
|
||||
feeds_with_unreads: function(options) {
|
||||
if (this.is_feed()) {
|
||||
return this.feed.has_unreads(options) && this.feed;
|
||||
} else if (this.is_folder()) {
|
||||
return this.folders.feeds_with_unreads(options);
|
||||
}
|
||||
},
|
||||
|
||||
move_to_folder: function(to_folder, options) {
|
||||
options = options || {};
|
||||
var view = options.view || this.get_view();
|
||||
|
@ -176,6 +186,14 @@ NEWSBLUR.Collections.Folders = Backbone.Collection.extend({
|
|||
})));
|
||||
},
|
||||
|
||||
feeds_with_unreads: function(options) {
|
||||
options = options || {};
|
||||
|
||||
return _.compact(_.flatten(this.map(function(item) {
|
||||
return item.feeds_with_unreads(options);
|
||||
})));
|
||||
},
|
||||
|
||||
selected: function() {
|
||||
var selected_folder;
|
||||
this.any(function(folder) {
|
||||
|
@ -200,7 +218,7 @@ NEWSBLUR.Collections.Folders = Backbone.Collection.extend({
|
|||
});
|
||||
},
|
||||
|
||||
unread_counts: function() {
|
||||
unread_counts: function(sum_total) {
|
||||
var counts = this.reduce(function(counts, item) {
|
||||
if (item.is_feed()) {
|
||||
var feed_counts = item.feed.unread_counts();
|
||||
|
@ -222,6 +240,12 @@ NEWSBLUR.Collections.Folders = Backbone.Collection.extend({
|
|||
|
||||
this.counts = counts;
|
||||
|
||||
if (sum_total) {
|
||||
var unread_view = this.get_unread_view_name();
|
||||
if (unread_view == 'positive') return counts['ps'];
|
||||
if (unread_view == 'neutral') return counts['ps'] + counts['nt'];
|
||||
if (unread_view == 'negative') return counts['ps'] + counts['nt'] + counts['ng'];
|
||||
}
|
||||
return counts;
|
||||
},
|
||||
|
||||
|
@ -237,18 +261,6 @@ NEWSBLUR.Collections.Folders = Backbone.Collection.extend({
|
|||
});
|
||||
},
|
||||
|
||||
feeds_with_unreads: function(options) {
|
||||
options = options || {};
|
||||
|
||||
return _.compact(_.flatten(this.map(function(item) {
|
||||
if (item.is_feed()) {
|
||||
return item.feed.has_unreads(options) && item.feed;
|
||||
} else if (item.is_folder()) {
|
||||
return item.folders.feeds_with_unreads(options);
|
||||
}
|
||||
})));
|
||||
},
|
||||
|
||||
propagate_feed_selected: function() {
|
||||
if (this.parent_folder) {
|
||||
this.parent_folder.trigger('change:feed_selected');
|
||||
|
|
|
@ -1331,17 +1331,14 @@
|
|||
|
||||
this.reset_feed(options);
|
||||
this.hide_splash_page();
|
||||
this.active_folder = folder || new Backbone.Model({
|
||||
folder_title: folder_title,
|
||||
fake: true
|
||||
});
|
||||
if (!folder || folder.get('fake')) {
|
||||
if (!folder || folder.get('fake') || !folder.get('folder_title')) {
|
||||
this.active_feed = 'river:';
|
||||
this.$s.$river_sites_header.addClass('NB-selected');
|
||||
} else {
|
||||
this.active_feed = 'river:' + folder_title;
|
||||
folder_view.model.set('selected', true);
|
||||
}
|
||||
this.active_folder = folder || NEWSBLUR.assets.folders;
|
||||
|
||||
this.iframe_scroll = null;
|
||||
this.flags['opening_feed'] = true;
|
||||
|
@ -1351,7 +1348,7 @@
|
|||
$('.task_view_page', this.$s.$taskbar).addClass('NB-disabled');
|
||||
var explicit_view_setting = this.model.view_setting(this.active_feed, 'view');
|
||||
if (!explicit_view_setting || explicit_view_setting == 'page') {
|
||||
explicit_view_setting = 'feed';
|
||||
explicit_view_setting = 'feed';
|
||||
}
|
||||
this.set_correct_story_view_for_feed(this.active_feed, explicit_view_setting);
|
||||
this.switch_taskbar_view(this.story_view);
|
||||
|
@ -1371,7 +1368,7 @@
|
|||
var visible_only = this.model.view_setting(this.active_feed, 'read_filter') == 'unread';
|
||||
var feeds;
|
||||
if (visible_only) {
|
||||
feeds = this.list_feeds_with_unreads_in_folder(this.active_folder.folders, false, visible_only);
|
||||
feeds = _.pluck(this.active_folder.feeds_with_unreads(), 'id');
|
||||
} else {
|
||||
feeds = this.active_folder.feed_ids_in_folder();
|
||||
}
|
||||
|
@ -1422,34 +1419,6 @@
|
|||
}
|
||||
},
|
||||
|
||||
list_feeds_with_unreads_in_folder: function(folder, counts_only, visible_only) {
|
||||
var model = this.model;
|
||||
var unread_view = this.get_unread_view_name();
|
||||
folder = folder || this.active_folder.folders;
|
||||
|
||||
if (!folder || folder.get('fake')) {
|
||||
folder = NEWSBLUR.assets.folders;
|
||||
}
|
||||
|
||||
var feeds = _.compact(_.map(folder.feeds_with_unreads(), function(feed) {
|
||||
if (counts_only && !visible_only) {
|
||||
return feed.get('ps') + feed.get('nt') + feed.get('ng');
|
||||
} else if (counts_only && visible_only) {
|
||||
if (unread_view == 'positive') return feed.get('ps');
|
||||
if (unread_view == 'neutral') return feed.get('ps') + feed.get('nt');
|
||||
if (unread_view == 'negative') return feed.get('ps') + feed.get('nt') + feed.get('ng');
|
||||
} else if (!counts_only && visible_only) {
|
||||
if (unread_view == 'positive') return feed.get('ps') && feed.id;
|
||||
if (unread_view == 'neutral') return (feed.get('ps') || feed.get('nt')) && feed.id;
|
||||
if (unread_view == 'negative') return (feed.get('ps') || feed.get('nt') || feed.get('ng')) && feed.id;
|
||||
} else {
|
||||
return (feed.get('ps') || feed.get('nt') || feed.get('ng')) && feed.id;
|
||||
}
|
||||
}));
|
||||
|
||||
return feeds;
|
||||
},
|
||||
|
||||
// ===================
|
||||
// = River Blurblogs =
|
||||
// ===================
|
||||
|
@ -1462,11 +1431,12 @@
|
|||
this.reset_feed(options);
|
||||
this.hide_splash_page();
|
||||
|
||||
this.active_feed = options.global ? 'river:global' : 'river:blurblogs';
|
||||
this.active_folder = new Backbone.Model({
|
||||
id: this.active_feed,
|
||||
folder_title: options.global ? "Global Shared Stories" : "All Shared Stories",
|
||||
fake: true
|
||||
});
|
||||
this.active_feed = options.global ? 'river:global' : 'river:blurblogs';
|
||||
|
||||
if (options.global) {
|
||||
this.$s.$river_global_header.addClass('NB-selected');
|
||||
|
@ -3634,8 +3604,7 @@
|
|||
}
|
||||
return total;
|
||||
} else if (this.flags['river_view'] && !this.flags['social_view']) {
|
||||
var counts = this.list_feeds_with_unreads_in_folder(this.active_folder.folders, true, visible_only);
|
||||
return _.reduce(counts, function(m, c) { return m + c; }, 0);
|
||||
return this.active_folder.unread_counts(true);
|
||||
} else if (this.flags['river_view'] && this.flags['social_view']) {
|
||||
var unread_score = this.get_unread_view_score();
|
||||
return NEWSBLUR.assets.social_feeds.reduce(function(m, feed) {
|
||||
|
|
|
@ -90,20 +90,9 @@ NEWSBLUR.FeedOptionsPopover = NEWSBLUR.ReaderPopover.extend({
|
|||
|
||||
update_feed: function(setting) {
|
||||
var changed = NEWSBLUR.assets.view_setting(this.options.feed_id, setting);
|
||||
|
||||
if (!changed) return;
|
||||
|
||||
if (this.options.feed_id == NEWSBLUR.reader.active_feed &&
|
||||
NEWSBLUR.reader.flags.social_view) {
|
||||
NEWSBLUR.reader.open_social_stories(this.options.feed_id);
|
||||
} else if (this.options.feed_id == NEWSBLUR.reader.active_feed &&
|
||||
NEWSBLUR.reader.flags.river_view) {
|
||||
var folder = NEWSBLUR.reader.active_folder;
|
||||
$feed = folder.folder_view.$el;
|
||||
NEWSBLUR.reader.open_river_stories($feed, folder);
|
||||
} else if (this.options.feed_id == NEWSBLUR.reader.active_feed) {
|
||||
NEWSBLUR.reader.open_feed(this.options.feed_id);
|
||||
}
|
||||
NEWSBLUR.reader.reload_feed();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -328,7 +328,7 @@ NEWSBLUR.Views.StoryDetailView = Backbone.View.extend({
|
|||
|
||||
if (content_height > max_height &&
|
||||
content_height < max_height + this.FUDGE_CONTENT_HEIGHT_OVERAGE) {
|
||||
console.log(["Height over but within fudge", this.model.get('story_title').substr(0, 30), content_height, max_height]);
|
||||
// console.log(["Height over but within fudge", this.model.get('story_title').substr(0, 30), content_height, max_height]);
|
||||
$wrapper.addClass('NB-story-content-wrapper-height-fudged');
|
||||
} else if (content_height > max_height) {
|
||||
$expander.css('display', 'block');
|
||||
|
@ -338,11 +338,11 @@ NEWSBLUR.Views.StoryDetailView = Backbone.View.extend({
|
|||
var pages = Math.round(content_height / max_height, true);
|
||||
var dots = _.map(_.range(pages), function() { return '·'; }).join(' ');
|
||||
|
||||
console.log(["Height over, truncating...", this.model.get('story_title').substr(0, 30), content_height, max_height, pages]);
|
||||
// console.log(["Height over, truncating...", this.model.get('story_title').substr(0, 30), content_height, max_height, pages]);
|
||||
this.$(".NB-story-content-expander-pages").html(dots);
|
||||
this._truncated = true;
|
||||
} else {
|
||||
console.log(["Height under.", this.model.get('story_title').substr(0, 30), content_height, max_height]);
|
||||
// console.log(["Height under.", this.model.get('story_title').substr(0, 30), content_height, max_height]);
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ NEWSBLUR.Views.StoryTitlesHeader = Backbone.View.extend({
|
|||
initialize: function() {
|
||||
this.showing_fake_folder = NEWSBLUR.reader.flags['river_view'] &&
|
||||
NEWSBLUR.reader.active_folder &&
|
||||
NEWSBLUR.reader.active_folder.get('fake');
|
||||
(NEWSBLUR.reader.active_folder.get('fake') || !NEWSBLUR.reader.active_folder.get('folder_title'));
|
||||
},
|
||||
|
||||
render: function() {
|
||||
|
@ -28,14 +28,6 @@ NEWSBLUR.Views.StoryTitlesHeader = Backbone.View.extend({
|
|||
}).render();
|
||||
$view.append(this.view.$el);
|
||||
} else if (this.showing_fake_folder) {
|
||||
var title = "All Site Stories";
|
||||
if (NEWSBLUR.reader.flags['social_view']) {
|
||||
if (NEWSBLUR.reader.flags['global_blurblogs']) {
|
||||
title = "Global Shared Stories";
|
||||
} else {
|
||||
title = "All Shared Stories";
|
||||
}
|
||||
}
|
||||
$view = $(_.template('\
|
||||
<div class="NB-folder NB-no-hover">\
|
||||
<div class="NB-story-title-indicator">\
|
||||
|
@ -44,16 +36,20 @@ NEWSBLUR.Views.StoryTitlesHeader = Backbone.View.extend({
|
|||
</div>\
|
||||
<div class="NB-folder-icon"></div>\
|
||||
<div class="NB-feedlist-manage-icon"></div>\
|
||||
<div class="folder_title_text"><%= folder_title %></div>\
|
||||
<span class="NB-feedbar-options">\
|
||||
<div class="NB-icon"></div>\
|
||||
<%= NEWSBLUR.assets.view_setting("river:"+folder_title, "read_filter") %>\
|
||||
·\
|
||||
<%= NEWSBLUR.assets.view_setting("river:"+folder_title, "order") %>\
|
||||
</span>\
|
||||
<span class="folder_title_text"><%= folder_title %></span>\
|
||||
<% if (show_options) { %>\
|
||||
<span class="NB-feedbar-options">\
|
||||
<div class="NB-icon"></div>\
|
||||
<%= NEWSBLUR.assets.view_setting(folder_id, "read_filter") %>\
|
||||
·\
|
||||
<%= NEWSBLUR.assets.view_setting(folder_id, "order") %>\
|
||||
</span>\
|
||||
<% } %>\
|
||||
</div>\
|
||||
', {
|
||||
folder_title: title
|
||||
folder_title: this.fake_folder_title(),
|
||||
folder_id: NEWSBLUR.reader.active_folder.id,
|
||||
show_options: !NEWSBLUR.reader.active_folder.get('fake')
|
||||
}));
|
||||
} else if (NEWSBLUR.reader.flags['river_view'] &&
|
||||
NEWSBLUR.reader.active_folder &&
|
||||
|
@ -80,6 +76,19 @@ NEWSBLUR.Views.StoryTitlesHeader = Backbone.View.extend({
|
|||
return this;
|
||||
},
|
||||
|
||||
fake_folder_title: function() {
|
||||
var title = "All Site Stories";
|
||||
if (NEWSBLUR.reader.flags['social_view']) {
|
||||
if (NEWSBLUR.reader.flags['global_blurblogs']) {
|
||||
title = "Global Shared Stories";
|
||||
} else {
|
||||
title = "All Shared Stories";
|
||||
}
|
||||
}
|
||||
|
||||
return title;
|
||||
},
|
||||
|
||||
remove: function() {
|
||||
if (this.view) {
|
||||
this.view.remove();
|
||||
|
@ -174,7 +183,7 @@ NEWSBLUR.Views.StoryTitlesHeader = Backbone.View.extend({
|
|||
|
||||
NEWSBLUR.FeedOptionsPopover.create({
|
||||
anchor: this.$(".NB-feedbar-options"),
|
||||
feed_id: this.model.id
|
||||
feed_id: NEWSBLUR.reader.active_feed
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue