Adding manage feed intelligence information. Just need to add it as a view in JS.

This commit is contained in:
Samuel Clay 2010-03-16 23:18:54 -04:00
parent e966cd1ff8
commit 7bc7873db9
6 changed files with 121 additions and 35 deletions

View file

@ -97,7 +97,7 @@ def apply_classifier_feeds(classifiers, feed):
def apply_classifier_authors(classifiers, story):
for classifier in classifiers:
if classifier.author.id == story['story_author_id']:
if classifier.author.author_name in story.get('story_authors'):
# print 'Authors: %s -- %s' % (classifier.author.id, story['story_author_id'])
return classifier.score
return 0

View file

@ -5,4 +5,5 @@ urlpatterns = patterns('',
(r'^$', views.index),
(r'^save/story/?', views.save_classifier_story),
(r'^save/publisher/?', views.save_classifier_publisher),
(r'^get/publisher/?', views.get_classifiers_feed),
)

View file

@ -102,4 +102,26 @@ def save_classifier_publisher(request):
feed=feed)
response = dict(code=code, message=message, payload=payload)
return response
@json.json_view
def get_classifiers_feed(request):
feed = request.POST['feed_id']
user = get_user(request)
code = 0
classifier_feeds = ClassifierFeed.objects.filter(user=user, feed=feed)
classifier_authors = ClassifierAuthor.objects.filter(user=user, feed=feed)
classifier_titles = ClassifierTitle.objects.filter(user=user, feed=feed)
classifier_tags = ClassifierTag.objects.filter(user=user, feed=feed)
payload = {
'feeds': classifier_feeds,
'authors': dict([(a.author.pk, a.author.author_name) for a in classifier_authors]),
'titles': [t.title for t in classifier_titles],
'tags': dict([(t.tag.pk, t.tag.name) for t in classifier_tags]),
}
response = dict(code=code, payload=payload)
return response

View file

@ -426,7 +426,7 @@ background: transparent;
#story_titles .NB-story-sentiment {
position: absolute;
width: 24px;
width: 22px;
height: 16px;
top: 2px;
display: none;
@ -437,13 +437,13 @@ background: transparent;
}
#story_titles .NB-story-like {
left: 24px;
background: transparent url('../img/reader/thumbs-up.png') no-repeat 0 0;
left: 22px;
background: transparent url('../img/reader/thumbs-up.png') no-repeat 2px 0;
}
#story_titles .NB-story-dislike {
left: 4px;
background: transparent url('../img/reader/thumbs-down.png') no-repeat 0 -4px;
left: 0px;
background: transparent url('../img/reader/thumbs-down.png') no-repeat 4px -4px;
}
#story_titles .story.read {
@ -978,6 +978,17 @@ form.opml_import_form input {
padding: 12px;
}
.NB-modal .NB-modal-loading {
width: 16px;
height: 16px;
float: right;
background: none;
}
.NB-modal .NB-modal-loading.NB-active {
background: transparent url('../img/reader/recycle_spinner.gif') no-repeat 0 0;
}
.NB-modal h2 {
margin: 0;
padding: 0;
@ -986,7 +997,7 @@ form.opml_import_form input {
.NB-modal h5 {
border-bottom: 1px solid #A0A0A0;
padding: 16px 0 0px;
padding: 18px 0 0px;
margin: 0 0 6px 0;
color: #808080;
text-transform: uppercase;
@ -1155,17 +1166,18 @@ form.opml_import_form input {
/* = Manage Feeds = */
/* ================ */
.NB-manage .NB-manage-field {
}
.NB-manage .NB-manage-container {
height: 300px;
overflow-y: auto;
padding: 0 18px 18px 0;
}
.NB-manage .NB-manage-feed-chooser-container {
float: right;
width: 300px;
}
.NB-manage .NB-manage-feed-chooser-container .NB-manage-feed-chooser-previous {
float: left;
}
.NB-manage .NB-manage-feed-chooser-container .NB-manage-feed-chooser-next {
float: right;
margin: 16px 0 0;
}
.NB-manage .NB-manage-feed-chooser-container .NB-manage-feed-chooser {

View file

@ -255,6 +255,14 @@ NEWSBLUR.AssetModel.Reader.prototype = {
save_classifier_publisher: function(data, callback) {
this.make_request('/classifier/save/publisher', data, callback);
},
get_feed_classifier: function(feed_id, callback) {
this.make_request('/classifier/get/publisher/', {
'feed_id': feed_id
}, callback, null, {
'ajax_group': 'feed'
});
}
};

View file

@ -7,41 +7,62 @@ NEWSBLUR.ReaderManageFeed = function(feed_id, options) {
this.feed = this.model.get_feed(feed_id);
this.feeds = this.model.get_feeds();
this.google_favicon_url = 'http://www.google.com/s2/favicons?domain_url=';
this.runner();
this.runner(feed_id);
};
NEWSBLUR.ReaderManageFeed.prototype = {
runner: function() {
this.make_modal();
this.initialize_feed(this.feed_id);
this.handle_cancel();
this.open_modal();
this.load_feed_classifier();
this.$manage.bind('change', $.rescope(this.handle_change, this));
},
initialize_feed: function(feed_id) {
this.feed_id = feed_id;
this.feed = this.model.get_feed(feed_id);
$('.NB-modal-title', this.$manage).html(this.feed['feed_title']);
$('input[name=feed_id]', this.$manage).val(this.feed_id);
$('input[name=rename_title]', this.$manage).val(this.feed['feed_title']);
},
make_modal: function() {
var self = this;
this.$manage = $.make('div', { className: 'NB-manage NB-modal' }, [
$.make('div', { className: 'NB-manage-feed-chooser-container'}, [
$.make('a', { href: '#', className: 'NB-manage-feed-chooser-next' }, '»'),
$.make('a', { href: '#', className: 'NB-manage-feed-chooser-previous' }, '«'),
this.make_feed_chooser()
]),
$.make('h2', { className: 'NB-modal-title' }, this.feed['feed_title']),
$.make('form', { method: 'post', className: 'NB-manage-form' }, [
$.make('div', { className: 'NB-manage-field' }, [
$.make('h5', [
'What you ',
$.make('span', { className: 'NB-classifier-like' }, 'like')
]),
$.make('h5', [
'What you ',
$.make('span', { className: 'NB-classifier-like' }, 'dislike')
]),
$.make('h5', 'Management')
$.make('div', { className: 'NB-manage-container'}, [
$.make('div', { className: 'NB-modal-loading' }),
$.make('h2', { className: 'NB-modal-title' }),
$.make('div', { className: 'NB-manage-field' }, [
$.make('h5', [
'What you ',
$.make('span', { className: 'NB-classifier-like' }, 'like')
]),
$.make('div', { className: 'NB-manage-classifier-likes' }),
$.make('h5', [
'What you ',
$.make('span', { className: 'NB-classifier-like' }, 'dislike')
]),
$.make('div', { className: 'NB-manage-classifier-dislikes' }),
$.make('h5', 'Management'),
$.make('div', { className: 'NB-manage-management' }, [
$.make('label', { className: 'NB-manage-rename-label', 'for': 'id_rename' }, "Title: "),
$.make('input', { name: 'rename_title', id: 'id_rename' }),
$.make('a', { className: 'NB-manage-delete'}, "Rename feed"),
$.make('a', { className: 'NB-manage-delete'}, "Delete this feed")
])
])
]),
$.make('div', { className: 'NB-manage-feed-chooser-container'}, [
this.make_feed_chooser()
]),
$.make('div', { className: 'NB-modal-submit' }, [
$.make('input', { name: 'feed_id', value: this.feed_id, type: 'hidden' }),
$.make('input', { name: 'feed_id', type: 'hidden' }),
$.make('input', { type: 'submit', disabled: 'true', className: 'NB-disabled', value: 'Check what you like above...' }),
' or ',
$.make('a', { href: '#', className: 'NB-modal-cancel' }, 'cancel')
@ -71,7 +92,19 @@ NEWSBLUR.ReaderManageFeed.prototype = {
$('option', $chooser).tsort();
return $chooser;
},
load_feed_classifier: function() {
var $loading = $('.NB-modal-loading', this.$manage);
$loading.addClass('NB-active');
this.model.get_feed_classifier(this.feed_id, this.post_load_feed_classifier);
},
post_load_feed_classifier: function(classifiers) {
var $loading = $('.NB-modal-loading', this.$manage);
$loading.removeClass('NB-active');
},
open_modal: function() {
var self = this;
@ -128,6 +161,16 @@ NEWSBLUR.ReaderManageFeed.prototype = {
this.model.save_classifier_publisher(data, function() {
$.modal.close();
});
},
handle_change: function(elem, e) {
var self = this;
$.targetIs(e, { tagSelector: '.NB-manage-feed-chooser' }, function($t, $p){
var feed_id = $t.val();
self.initialize_feed(feed_id);
self.load_feed_classifier();
});
}
};