Hiding folders with no unread stories in Unread/Focus mode.

This commit is contained in:
Samuel Clay 2013-01-02 17:44:14 -08:00
parent 54ecb3305c
commit ef772ff0d3
6 changed files with 100 additions and 7 deletions

View file

@ -784,6 +784,7 @@ body.NB-theme-serif #story_pane .NB-feed-story-content {
opacity: 1;
}
.NB-feedlist.NB-selector-active .NB-folder-collapsed .folder,
.NB-feedlist.NB-selector-active .NB-hidden,
.NB-socialfeeds-folder.NB-selector-active {
display: block !important;
opacity: 1 !important;

View file

@ -6,6 +6,7 @@ NEWSBLUR.Models.Feed = Backbone.Model.extend({
this.bind('change:ps', this.update_folder_counts);
this.bind('change:nt', this.update_folder_counts);
this.bind('change:ng', this.update_folder_counts);
this.bind('change:selected', this.update_folder_visibility);
this.views = [];
this.folders = [];
},
@ -19,9 +20,12 @@ NEWSBLUR.Models.Feed = Backbone.Model.extend({
update_folder_counts: function() {
_.each(this.folders, function(folder) {
folder.trigger('change:counts');
if (folder.parent_folder) {
folder.parent_folder.trigger('change:counts');
}
});
},
update_folder_visibility: function() {
_.each(this.folders, function(folder) {
folder.trigger('change:feed_selected');
});
},
@ -106,6 +110,23 @@ NEWSBLUR.Models.Feed = Backbone.Model.extend({
nt: this.get('nt'),
ng: this.get('ng')
};
},
has_unreads: function(options) {
options = options || {};
var unread_view = NEWSBLUR.assets.preference('unread_view');
if (options.include_selected && this.get('selected')) {
return true;
}
if (unread_view <= -1) {
return !!(this.get('ng') || this.get('nt') || this.get('ps'));
} else if (unread_view == 0) {
return !!(this.get('nt') || this.get('ps'));
} else if (unread_view > 0) {
return !!(this.get('ps'));
}
}
});

View file

@ -84,6 +84,16 @@ NEWSBLUR.Models.FeedOrFolder = Backbone.Model.extend({
var feed_ids_in_folder = this.feed_ids_in_folder();
NEWSBLUR.assets.delete_folder(folder_title, in_folder, feed_ids_in_folder);
this.trigger('delete');
},
has_unreads: function(options) {
options = options || {};
if (options.include_selected && this.get('selected')) {
return true;
}
return this.folders.has_unreads(options);
}
});
@ -95,9 +105,12 @@ NEWSBLUR.Collections.Folders = Backbone.Collection.extend({
},
initialize: function(models, options) {
_.bindAll(this, 'propagate_feed_selected');
this.options = options || {};
this.parent_folder = options && options.parent_folder;
this.comparator = NEWSBLUR.Collections.Folders.comparator;
this.bind('change:feed_selected', this.propagate_feed_selected);
this.bind('change:counts', this.propagate_change_counts);
},
model: NEWSBLUR.Models.FeedOrFolder,
@ -199,12 +212,46 @@ NEWSBLUR.Collections.Folders = Backbone.Collection.extend({
ng: 0
});
this.counts = counts;
return counts;
},
has_unreads: function(options) {
options = options || {};
return this.any(function(item) {
if (item.is_feed()) {
return item.feed.has_unreads(options);
} else if (item.is_folder()) {
return item.has_unreads(options);
}
});
},
propagate_feed_selected: function() {
if (this.parent_folder) {
this.parent_folder.trigger('change:feed_selected');
}
},
propagate_change_counts: function() {
if (this.parent_folder) {
this.parent_folder.trigger('change:counts');
}
},
update_all_folder_visibility: function() {
this.each(function(item) {
if (item.is_folder()) {
item.folders.trigger('change:counts');
item.folders.update_all_folder_visibility();
}
});
}
}, {
comparator: function(modelA, modelB) {
var sort_order = NEWSBLUR.assets.preference('feed_order');

View file

@ -3544,6 +3544,7 @@
}
this.show_story_titles_above_intelligence_level({'animate': true, 'follow': true});
NEWSBLUR.app.sidebar_header.toggle_hide_read_preference();
NEWSBLUR.assets.folders.update_all_folder_visibility();
NEWSBLUR.app.feed_list.scroll_to_show_selected_feed();
NEWSBLUR.app.feed_list.scroll_to_show_selected_folder();

View file

@ -197,6 +197,10 @@ NEWSBLUR.Views.FeedTitleView = Backbone.View.extend({
select_feed: function() {
this.$el.toggleClass('selected', this.model.get('selected'));
this.$el.toggleClass('NB-selected', this.model.get('selected'));
_.each(this.folders, function(folder) {
folder.view.update_hidden();
});
},
flash_changes: function() {

View file

@ -23,7 +23,8 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
},
initialize: function() {
_.bindAll(this, 'update_title', 'update_selected', 'delete_folder', 'check_collapsed');
_.bindAll(this, 'update_title', 'update_selected', 'delete_folder', 'check_collapsed',
'update_hidden');
this.options.folder_title = this.model && this.model.get('folder_title');
@ -31,6 +32,9 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
// Root folder does not have a model.
this.model.bind('change:folder_title', this.update_title);
this.model.bind('change:selected', this.update_selected);
this.model.bind('change:selected', this.update_hidden);
this.collection.bind('change:feed_selected', this.update_hidden);
this.collection.bind('change:counts', this.update_hidden);
this.model.bind('delete', this.delete_folder);
if (!this.options.feedbar) {
this.model.folder_view = this;
@ -85,6 +89,7 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
}
this.check_collapsed({skip_animation: true});
this.update_hidden();
this.$('.folder_title').eq(0).bind('contextmenu', _.bind(this.show_manage_menu, this));
return this;
@ -140,6 +145,17 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
this.$el.toggleClass('NB-selected', this.model.get('selected'));
},
update_hidden: function() {
if (!this.model) return;
var has_unreads = this.model.has_unreads({include_selected: true});
if (has_unreads || !NEWSBLUR.assets.preference('hide_read_feeds')) {
this.$el.removeClass('NB-hidden');
} else {
this.$el.addClass('NB-hidden');
}
},
// ===========
// = Actions =
// ===========
@ -174,7 +190,10 @@ NEWSBLUR.Views.Folder = Backbone.View.extend({
});
}
var $counts = new NEWSBLUR.Views.FolderCount({collection: this.collection}).render().$el;
this.folder_count = new NEWSBLUR.Views.FolderCount({
collection: this.collection
}).render();
var $counts = this.folder_count.$el;
if (this.options.feedbar) {
this.$('.NB-story-title-indicator-count').html($counts.clone());
} else {