mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Saved search for feeds now works. Need to fix scroll to selected feed (and keyboard shortcuts). Also need to hook up other search types.
This commit is contained in:
parent
83dcf3c7a6
commit
2c0bf76e20
16 changed files with 151 additions and 19 deletions
|
@ -59,4 +59,5 @@ urlpatterns = patterns('',
|
|||
url(r'^retrain_all_sites', views.retrain_all_sites, name='retrain-all-sites'),
|
||||
url(r'^load_tutorial', views.load_tutorial, name='load-tutorial'),
|
||||
url(r'^save_search', views.save_search, name='save-search'),
|
||||
url(r'^delete_search', views.delete_search, name='delete-search'),
|
||||
)
|
||||
|
|
|
@ -2497,4 +2497,17 @@ def save_search(request):
|
|||
return {
|
||||
'saved_searches': saved_searches,
|
||||
}
|
||||
|
||||
|
||||
@required_params('query', 'feed_id')
|
||||
@json.json_view
|
||||
def delete_search(request):
|
||||
feed_id = request.POST['feed_id']
|
||||
query = request.POST['query']
|
||||
|
||||
MSavedSearch.delete_search(user_id=request.user.pk, feed_id=feed_id, query=query)
|
||||
|
||||
saved_searches = MSavedSearch.user_searches(request.user.pk)
|
||||
|
||||
return {
|
||||
'saved_searches': saved_searches,
|
||||
}
|
||||
|
|
|
@ -2970,6 +2970,19 @@ class MSavedSearch(mongo.Document):
|
|||
|
||||
return saved_search
|
||||
|
||||
@classmethod
|
||||
def delete_search(cls, user_id, feed_id, query):
|
||||
user = User.objects.get(pk=user_id)
|
||||
params = dict(user_id=user_id,
|
||||
feed_id=feed_id,
|
||||
query=query)
|
||||
try:
|
||||
saved_search = cls.objects.get(**params)
|
||||
logging.user(user, "~FCDeleting saved search: ~SB%s" % query)
|
||||
saved_search.delete()
|
||||
except cls.DoesNotExist:
|
||||
logging.user(user, "~FRCan't delete saved search, missing: ~SB%s~SN/~SB%s" % (feed_id, query))
|
||||
|
||||
|
||||
class MFetchHistory(mongo.Document):
|
||||
feed_id = mongo.IntField(unique=True)
|
||||
|
|
|
@ -4459,6 +4459,9 @@ body {
|
|||
border-bottom: 1px solid #E9EBEE;
|
||||
background-color: #E9EBEE;
|
||||
}
|
||||
.NB-searches-feeds .feed_title {
|
||||
padding-right: 4px;
|
||||
}
|
||||
.NB-feeds-header-searches.NB-empty .NB-feeds-header-count {
|
||||
display: none;
|
||||
}
|
||||
|
@ -4466,6 +4469,7 @@ body {
|
|||
.NB-searches-folder .NB-searches-feeds.NB-feedlist .feed {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* ===================== */
|
||||
/* = Header - Try Feed = */
|
||||
/* ===================== */
|
||||
|
|
|
@ -1059,6 +1059,8 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
return this.searches_feeds.get(feed_id);
|
||||
} else if (_.string.startsWith(feed_id, 'river:')) {
|
||||
return this.get_folder(feed_id);
|
||||
} else if (_.string.startsWith(feed_id, 'feed:')) {
|
||||
return this.feeds.get(parseInt(feed_id.replace('feed:', ''), 10));
|
||||
} else {
|
||||
return this.feeds.get(feed_id);
|
||||
}
|
||||
|
@ -1091,10 +1093,16 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
return this.starred_feeds;
|
||||
},
|
||||
|
||||
get_searches_feeds: function() {
|
||||
get_searches_feeds: function(feed_id, query) {
|
||||
var self = this;
|
||||
|
||||
return this.searches_feeds;
|
||||
if (!feed_id && !query) {
|
||||
return this.searches_feeds;
|
||||
}
|
||||
|
||||
return this.searches_feeds.detect(function(feed) {
|
||||
return feed.get('query') == query && feed.get('feed_id') == feed_id;
|
||||
});
|
||||
},
|
||||
|
||||
get_folders: function() {
|
||||
|
@ -1511,6 +1519,26 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
}
|
||||
},
|
||||
|
||||
delete_saved_search: function(feed_id, query, callback) {
|
||||
var self = this;
|
||||
var pre_callback = function(data) {
|
||||
if (data.saved_searches) {
|
||||
self.searches_feeds.reset(data.saved_searches, {parse: true});
|
||||
}
|
||||
|
||||
if (callback) callback(data);
|
||||
};
|
||||
|
||||
if (NEWSBLUR.Globals.is_authenticated) {
|
||||
this.make_request('/reader/delete_search', {
|
||||
'feed_id': feed_id,
|
||||
'query': query
|
||||
}, pre_callback);
|
||||
} else {
|
||||
if ($.isFunction(callback)) callback();
|
||||
}
|
||||
},
|
||||
|
||||
get_feed_statistics: function(feed_id, callback) {
|
||||
this.make_request('/rss_feeds/statistics/'+feed_id, {}, callback, callback, {
|
||||
'ajax_group': 'statistics',
|
||||
|
|
|
@ -148,6 +148,10 @@ NEWSBLUR.Models.Feed = Backbone.Model.extend({
|
|||
return false;
|
||||
},
|
||||
|
||||
is_search: function() {
|
||||
return false;
|
||||
},
|
||||
|
||||
is_light: function() {
|
||||
var is_light = this._is_light;
|
||||
if (!_.isUndefined(is_light)) {
|
||||
|
|
|
@ -3,9 +3,9 @@ NEWSBLUR.Models.SavedSearchFeed = Backbone.Model.extend({
|
|||
initialize: function() {
|
||||
var feed_title = this.feed_title();
|
||||
var favicon_url = this.favicon_url();
|
||||
this.set('feed_title', "\"<b>" + this.get('query') + "</b>\" on <b>" + feed_title + "</b>");
|
||||
this.set('feed_title', "\"<b>" + this.get('query') + "</b>\" in <b>" + feed_title + "</b>");
|
||||
this.set('favicon_url', favicon_url);
|
||||
this.views = [];
|
||||
this.list_view;
|
||||
},
|
||||
|
||||
feed_title: function() {
|
||||
|
@ -15,7 +15,6 @@ NEWSBLUR.Models.SavedSearchFeed = Backbone.Model.extend({
|
|||
if (feed_id == 'river:') {
|
||||
feed_title = "All Site Stories";
|
||||
} else if (_.string.startsWith(feed_id, 'river:')) {
|
||||
console.log(['river feed?', feed_id, NEWSBLUR.assets.get_feed(feed_id)]);
|
||||
feed_title = NEWSBLUR.assets.get_feed(feed_id).get('folder_title');
|
||||
} else if (feed_id == "read") {
|
||||
feed_title = "Read Stories";
|
||||
|
@ -23,7 +22,6 @@ NEWSBLUR.Models.SavedSearchFeed = Backbone.Model.extend({
|
|||
feed_title = "Saved Stories";
|
||||
var tag = feed_id.replace('starred:', '');
|
||||
var model = NEWSBLUR.assets.starred_feeds.detect(function(feed) {
|
||||
console.log(['tag?', feed.tag_slug(), tag]);
|
||||
return feed.tag_slug() == tag || feed.get('tag') == tag;
|
||||
});
|
||||
if (model) {
|
||||
|
|
|
@ -41,6 +41,10 @@ NEWSBLUR.Models.SocialSubscription = Backbone.Model.extend({
|
|||
return false;
|
||||
},
|
||||
|
||||
is_search: function() {
|
||||
return false;
|
||||
},
|
||||
|
||||
unread_counts: function() {
|
||||
return {
|
||||
ps: this.get('ps') || 0,
|
||||
|
|
|
@ -17,6 +17,10 @@ NEWSBLUR.Models.StarredFeed = Backbone.Model.extend({
|
|||
return true;
|
||||
},
|
||||
|
||||
is_search: function() {
|
||||
return false;
|
||||
},
|
||||
|
||||
unread_counts: function() {
|
||||
return {
|
||||
ps: this.get('count') || 0,
|
||||
|
|
|
@ -1294,6 +1294,8 @@
|
|||
'select_story_in_feed': 0
|
||||
});
|
||||
|
||||
// console.log(['reset feed', options, options.search]);
|
||||
|
||||
if (_.isUndefined(options.search)) {
|
||||
this.flags.search = "";
|
||||
this.flags.searching = false;
|
||||
|
@ -1415,7 +1417,11 @@
|
|||
feed.set("selected_title_view", selected_title_view, {silent: true});
|
||||
}
|
||||
}
|
||||
feed.set('selected', true, options);
|
||||
if (options.feed) {
|
||||
options.feed.set('selected', true, options);
|
||||
} else {
|
||||
feed.set('selected', true, options);
|
||||
}
|
||||
if (NEWSBLUR.app.story_unread_counter) {
|
||||
NEWSBLUR.app.story_unread_counter.remove();
|
||||
}
|
||||
|
@ -1711,6 +1717,42 @@
|
|||
});
|
||||
},
|
||||
|
||||
// ==================
|
||||
// = Saved Searches =
|
||||
// ==================
|
||||
|
||||
open_saved_search: function(options) {
|
||||
var search_model = options.search_model;
|
||||
var feed_id = search_model.get('feed_id');
|
||||
var query = search_model.get('query');
|
||||
var feed_model = NEWSBLUR.assets.get_feed(feed_id);
|
||||
NEWSBLUR.reader.flags.searching = true;
|
||||
NEWSBLUR.reader.flags.search = query;
|
||||
options['search'] = query;
|
||||
options['router'] = true;
|
||||
search_model.set('selected', true);
|
||||
|
||||
if (feed_id == 'river:') {
|
||||
this.open_river_stories(options);
|
||||
} else if (_.string.startsWith(feed_id, 'river:')) {
|
||||
NEWSBLUR.reader.open_river_stories(options.$feed, feed_model, options);
|
||||
} else if (feed_id == "read") {
|
||||
this.open_read_stories(options);
|
||||
} else if (_.string.startsWith(feed_id, 'starred:')) {
|
||||
this.open_starred_stories(options);
|
||||
} else if (_.string.startsWith(feed_id, 'feed:')) {
|
||||
options.feed = options.search_model;
|
||||
this.open_feed(parseInt(feed_id.replace('feed:', ''), 10), options);
|
||||
} else if (_.string.startsWith(feed_id, 'social:')) {
|
||||
this.open_social_stories(options);
|
||||
}
|
||||
|
||||
window.history.replaceState({}, "", $.updateQueryString('search', query, window.location.pathname));
|
||||
|
||||
NEWSBLUR.reader.reload_feed(options);
|
||||
NEWSBLUR.app.story_titles_header.show_hidden_story_titles();
|
||||
},
|
||||
|
||||
// ===================
|
||||
// = Starred Stories =
|
||||
// ===================
|
||||
|
|
|
@ -215,7 +215,7 @@ NEWSBLUR.Views.FeedList = Backbone.View.extend({
|
|||
depth: 0,
|
||||
saved_search: true
|
||||
}).render();
|
||||
feed.views.push(feed_view);
|
||||
feed.list_view = feed_view;
|
||||
return feed_view.el;
|
||||
}));
|
||||
|
||||
|
@ -314,7 +314,8 @@ NEWSBLUR.Views.FeedList = Backbone.View.extend({
|
|||
var $feed_lists = this.$s.$feed_lists;
|
||||
var model = NEWSBLUR.assets.feeds.selected() ||
|
||||
NEWSBLUR.assets.social_feeds.selected() ||
|
||||
NEWSBLUR.assets.starred_feeds.selected();
|
||||
NEWSBLUR.assets.starred_feeds.selected() ||
|
||||
NEWSBLUR.assets.searches_feeds.selected();
|
||||
if (!model) return;
|
||||
var feed_view = model.get("selected_title_view");
|
||||
if (!feed_view) {
|
||||
|
|
|
@ -19,8 +19,12 @@ NEWSBLUR.Views.FeedSearchHeader = Backbone.View.extend({
|
|||
|
||||
if (NEWSBLUR.reader.flags.search || NEWSBLUR.reader.flags.searching) {
|
||||
this.$el.removeClass("NB-hidden");
|
||||
|
||||
var $title = this.make_title();
|
||||
this.$(".NB-search-header-title").html($title);
|
||||
|
||||
var saved = this.is_saved() ? 'Saved' : 'Save Search';
|
||||
this.$(".NB-search-header-save").text(saved);
|
||||
} else {
|
||||
this.unload();
|
||||
}
|
||||
|
@ -48,18 +52,33 @@ NEWSBLUR.Views.FeedSearchHeader = Backbone.View.extend({
|
|||
return $view;
|
||||
},
|
||||
|
||||
is_saved: function() {
|
||||
return !!NEWSBLUR.assets.get_searches_feeds(this.saved_feed_id(), NEWSBLUR.reader.flags.search);
|
||||
},
|
||||
|
||||
saved_feed_id: function() {
|
||||
var feed_id = NEWSBLUR.reader.active_feed;
|
||||
if (_.isNumber(feed_id)) {
|
||||
feed_id = "feed:" + feed_id;
|
||||
}
|
||||
return feed_id;
|
||||
},
|
||||
|
||||
// ==========
|
||||
// = Events =
|
||||
// ==========
|
||||
|
||||
save_search: function(e) {
|
||||
var feed_id = NEWSBLUR.reader.active_feed;
|
||||
if (_.isNumber(feed_id)) {
|
||||
feed_id = "feed:" + feed_id;
|
||||
var feed_id = this.saved_feed_id();
|
||||
if (this.is_saved()) {
|
||||
NEWSBLUR.assets.delete_saved_search(feed_id, NEWSBLUR.reader.flags.search, function(e) {
|
||||
console.log(['Saved searches', e]);
|
||||
});
|
||||
} else {
|
||||
NEWSBLUR.assets.save_search(feed_id, NEWSBLUR.reader.flags.search, function(e) {
|
||||
console.log(['Saved searches', e]);
|
||||
});
|
||||
}
|
||||
NEWSBLUR.assets.save_search(feed_id, NEWSBLUR.reader.flags.search, function(e) {
|
||||
console.log(['Saved searches', e]);
|
||||
});
|
||||
}
|
||||
|
||||
});
|
|
@ -19,7 +19,6 @@ NEWSBLUR.Views.FeedSearchView = Backbone.View.extend({
|
|||
|
||||
render: function() {
|
||||
if (NEWSBLUR.app.active_search) {
|
||||
NEWSBLUR.app.active_search.blur_search();
|
||||
NEWSBLUR.app.active_search.remove();
|
||||
}
|
||||
NEWSBLUR.app.active_search = this;
|
||||
|
|
|
@ -317,6 +317,8 @@ NEWSBLUR.Views.FeedTitleView = Backbone.View.extend({
|
|||
|
||||
if (this.model.get('has_exception') && this.model.get('exception_type') == 'feed') {
|
||||
NEWSBLUR.reader.open_feed_exception_modal(this.model.id);
|
||||
} else if (this.model.is_search()) {
|
||||
NEWSBLUR.reader.open_saved_search({search_model: this.model, $feed: this.$el});
|
||||
} else if (this.model.is_social()) {
|
||||
NEWSBLUR.reader.open_social_stories(this.model.id, {force: true, $feed: this.$el});
|
||||
} else if (this.model.is_starred()) {
|
||||
|
|
|
@ -216,7 +216,7 @@ NEWSBLUR.Views.StoryTitlesHeader = Backbone.View.extend({
|
|||
return story.score() < 0;
|
||||
});
|
||||
|
||||
NEWSBLUR.log(['show_hidden_story_titles', hidden_stories_at_threshold, hidden_stories_below_threshold, unread_view_name, temp_unread_view_name, NEWSBLUR.reader.flags['unread_threshold_temporarily']]);
|
||||
// NEWSBLUR.log(['show_hidden_story_titles', hidden_stories_at_threshold, hidden_stories_below_threshold, unread_view_name, temp_unread_view_name, NEWSBLUR.reader.flags['unread_threshold_temporarily']]);
|
||||
|
||||
// First click, open neutral. Second click, open negative.
|
||||
if (temp_unread_view_name == 'positive' &&
|
||||
|
|
|
@ -275,7 +275,7 @@
|
|||
<div id="story_titles" class="right-north">
|
||||
<div class="NB-search-header">
|
||||
<div class="NB-search-header-icon"></div>
|
||||
<div class="NB-search-header-save">Save Search</div>
|
||||
<div class="NB-search-header-save"></div>
|
||||
<div class="NB-search-header-title"></div>
|
||||
</div>
|
||||
<div class="NB-story-titles"></div>
|
||||
|
|
Loading…
Add table
Reference in a new issue