mirror of
https://github.com/viq/NewsBlur.git
synced 2025-08-05 16:49:45 +00:00
Showing saved searches. Titles need work. And they don't show the feed yet.
This commit is contained in:
parent
e1fe5f10a0
commit
3435bac504
9 changed files with 141 additions and 11 deletions
|
@ -58,4 +58,5 @@ urlpatterns = patterns('',
|
|||
url(r'^send_story_email', views.send_story_email, name='send-story-email'),
|
||||
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'),
|
||||
)
|
||||
|
|
|
@ -2483,3 +2483,18 @@ def load_tutorial(request):
|
|||
return {
|
||||
'newsblur_feed': newsblur_feed.canonical()
|
||||
}
|
||||
|
||||
@required_params('query', 'feed_id')
|
||||
@json.json_view
|
||||
def save_search(request):
|
||||
feed_id = request.POST['feed_id']
|
||||
query = request.POST['query']
|
||||
|
||||
MSavedSearch.save_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,
|
||||
}
|
||||
|
|
@ -2924,8 +2924,7 @@ class MStarredStoryCounts(mongo.Document):
|
|||
class MSavedSearch(mongo.Document):
|
||||
user_id = mongo.IntField()
|
||||
query = mongo.StringField(max_length=1024)
|
||||
feed_id = mongo.IntField()
|
||||
folder = mongo.StringField()
|
||||
feed_id = mongo.StringField()
|
||||
slug = mongo.StringField(max_length=128)
|
||||
|
||||
meta = {
|
||||
|
@ -2949,14 +2948,28 @@ class MSavedSearch(mongo.Document):
|
|||
def user_searches(cls, user_id):
|
||||
searches = cls.objects.filter(user_id=user_id)
|
||||
searches = sorted([{'query': s.query,
|
||||
'count': s.count,
|
||||
'feed_address': s.rss_url,
|
||||
'feed_id': s.feed_id,
|
||||
'folder': s.folder,
|
||||
} for s in searches],
|
||||
key=lambda x: (x.get('query', '') or '').lower())
|
||||
return searches
|
||||
|
||||
@classmethod
|
||||
def save_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,
|
||||
slug=slugify(query))
|
||||
try:
|
||||
saved_search = cls.objects.get(**params)
|
||||
logging.user(user, "~FRSaved search already exists: ~SB%s" % query)
|
||||
except cls.DoesNotExist:
|
||||
logging.user(user, "~FCCreating a saved search: ~SB%s~SN/~SB%s" % (feed_id, query))
|
||||
saved_search = cls.objects.create(**params)
|
||||
|
||||
return saved_search
|
||||
|
||||
|
||||
class MFetchHistory(mongo.Document):
|
||||
feed_id = mongo.IntField(unique=True)
|
||||
|
|
|
@ -4382,6 +4382,7 @@ body {
|
|||
border-top: 1px solid #B7BBAA;
|
||||
}
|
||||
.NB-feeds-header-read.NB-feeds-header,
|
||||
.NB-feeds-header-searches.NB-feeds-header,
|
||||
.NB-feeds-header-starred.NB-feeds-header {
|
||||
border-bottom: 1px solid #B7BBAA;
|
||||
}
|
||||
|
@ -4436,6 +4437,35 @@ body {
|
|||
display: none;
|
||||
}
|
||||
|
||||
|
||||
/* =========================== */
|
||||
/* = Header - Saved Searches = */
|
||||
/* =========================== */
|
||||
|
||||
.NB-feeds-header-searches .NB-feeds-header-icon {
|
||||
background: transparent url('/media/embed/icons/circular/g_icn_search_black.png') no-repeat 1px 1px;
|
||||
background-size: 14px;
|
||||
}
|
||||
|
||||
.NB-feeds-header-searches .NB-feeds-header-count {
|
||||
background-color: #506B9A;
|
||||
margin-top: 4px;
|
||||
margin-right: 3px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.NB-searches-feeds .feed {
|
||||
border-top: 1px solid #E9EBEE;
|
||||
border-bottom: 1px solid #E9EBEE;
|
||||
background-color: #E9EBEE;
|
||||
}
|
||||
.NB-feeds-header-searches.NB-empty .NB-feeds-header-count {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.NB-searches-folder .NB-searches-feeds.NB-feedlist .feed {
|
||||
display: block;
|
||||
}
|
||||
/* ===================== */
|
||||
/* = Header - Try Feed = */
|
||||
/* ===================== */
|
||||
|
|
|
@ -457,9 +457,9 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
self.folders.reset(_.compact(subscriptions.folders), {parse: true});
|
||||
self.starred_count = subscriptions.starred_count;
|
||||
self.starred_feeds.reset(subscriptions.starred_counts, {parse: true});
|
||||
self.searches_feeds.reset(subscriptions.saved_searches, {parse: true});
|
||||
self.social_feeds.reset(subscriptions.social_feeds, {parse: true});
|
||||
self.user_profile.set(subscriptions.social_profile);
|
||||
self.searches_feeds.reset(subscriptions.saved_searches, {parse: true});
|
||||
self.social_services = subscriptions.social_services;
|
||||
|
||||
if (selected && self.feeds.get(selected)) {
|
||||
|
@ -1486,6 +1486,26 @@ NEWSBLUR.AssetModel = Backbone.Router.extend({
|
|||
this.make_request('/reader/save_feed_order', {'folders': $.toJSON(folders)}, callback);
|
||||
},
|
||||
|
||||
save_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/save_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',
|
||||
|
|
|
@ -1,10 +1,45 @@
|
|||
NEWSBLUR.Models.SavedSearchFeed = Backbone.Model.extend({
|
||||
|
||||
initialize: function() {
|
||||
this.set('feed_title', this.get('tag'));
|
||||
var feed_title = this.feed_title();
|
||||
this.set('feed_title', "\"<b>" + this.get('query') + "</b>\" on <b>" + feed_title + "</b>");
|
||||
this.views = [];
|
||||
},
|
||||
|
||||
feed_title: function() {
|
||||
var feed_title;
|
||||
var feed_id = this.get('feed_id');
|
||||
|
||||
if (feed_id == 'river:') {
|
||||
feed_title = "All Site Stories";
|
||||
} else if (_.isNumber(feed_id) || _.string.startsWith(feed_id, 'river:')) {
|
||||
feed_title = NEWSBLUR.assets.get_feed(this.get('feed_id')).get('feed_title');
|
||||
} else if (feed_id == "read") {
|
||||
feed_title = "Read Stories";
|
||||
} else if (_.string.startsWith(feed_id, 'starred:')) {
|
||||
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) {
|
||||
feed_title = feed_title + " - " + model.get('tag');
|
||||
}
|
||||
}
|
||||
|
||||
return feed_title;
|
||||
|
||||
if (_.string.startsWith(this.get('feed_id'), 'saved:') ||
|
||||
_.string.startsWith(this.get('feed_id'), 'read')) {
|
||||
feed_title = NEWSBLUR.reader.active_fake_folder_title();
|
||||
} else if (NEWSBLUR.reader.active_folder) {
|
||||
feed_title = NEWSBLUR.reader.active_folder.get('folder_title');
|
||||
} else if (NEWSBLUR.reader.active_feed) {
|
||||
|
||||
}
|
||||
},
|
||||
|
||||
is_social: function() {
|
||||
return false;
|
||||
},
|
||||
|
@ -14,6 +49,10 @@ NEWSBLUR.Models.SavedSearchFeed = Backbone.Model.extend({
|
|||
},
|
||||
|
||||
is_starred: function() {
|
||||
return false;
|
||||
},
|
||||
|
||||
is_search: function() {
|
||||
return true;
|
||||
},
|
||||
|
||||
|
@ -37,16 +76,15 @@ NEWSBLUR.Collections.SearchesFeeds = Backbone.Collection.extend({
|
|||
|
||||
parse: function(models) {
|
||||
_.each(models, function(feed) {
|
||||
feed.id = 'search:' + feed.get('saved_search') + ':' + feed.feed_id;
|
||||
// feed.selected = false;
|
||||
feed.id = 'search:' + feed.feed_id + ":" + feed.query;
|
||||
});
|
||||
return models;
|
||||
},
|
||||
|
||||
comparator: function(a, b) {
|
||||
var sort_order = NEWSBLUR.reader.model.preference('feed_order');
|
||||
var title_a = a.get('feed_title') || '';
|
||||
var title_b = b.get('feed_title') || '';
|
||||
var title_a = a.get('query') || '';
|
||||
var title_b = b.get('query') || '';
|
||||
title_a = title_a.toLowerCase();
|
||||
title_b = title_b.toLowerCase();
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ NEWSBLUR.Views.FeedList = Backbone.View.extend({
|
|||
NEWSBLUR.assets.social_feeds.bind('change:selected', this.scroll_to_selected, this);
|
||||
NEWSBLUR.assets.feeds.bind('change:selected', this.scroll_to_selected, this);
|
||||
NEWSBLUR.assets.starred_feeds.bind('change:selected', this.scroll_to_selected, this);
|
||||
NEWSBLUR.assets.searches_feeds.bind('change:selected', this.scroll_to_selected, this);
|
||||
if (!NEWSBLUR.assets.folders.size()) {
|
||||
NEWSBLUR.assets.load_feeds();
|
||||
}
|
||||
|
|
|
@ -53,7 +53,9 @@ NEWSBLUR.Views.FeedSearchHeader = Backbone.View.extend({
|
|||
// ==========
|
||||
|
||||
save_search: function(e) {
|
||||
|
||||
NEWSBLUR.assets.save_search(NEWSBLUR.reader.active_feed, NEWSBLUR.reader.flags.search, function(e) {
|
||||
console.log(['Saved searches', e]);
|
||||
})
|
||||
}
|
||||
|
||||
});
|
|
@ -90,6 +90,16 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="NB-feeds-header-container NB-feeds-header-searches-container NB-hidden">
|
||||
<div class="NB-feeds-header NB-feeds-header-searches">
|
||||
<div class="NB-feeds-header-icon"></div>
|
||||
<div class="NB-feeds-header-title">
|
||||
Saved Searches
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="NB-searches-folder">
|
||||
<ul class="NB-searches-feeds NB-feedlist"></ul>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue