mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Adding user statistics (with fake data). Also showing shared/starred stories as shared/starred in the Feed view.
This commit is contained in:
parent
f91d20a857
commit
bb7ae99ba4
7 changed files with 142 additions and 56 deletions
|
@ -58,17 +58,23 @@ def index(request):
|
|||
login_form = LoginForm(prefix='login')
|
||||
signup_form = SignupForm(prefix='signup')
|
||||
|
||||
user = get_user(request)
|
||||
authed = request.user.is_authenticated()
|
||||
features = Feature.objects.all()[:3]
|
||||
feature_form = FeatureForm() if request.user.is_staff else None
|
||||
feed_count = UserSubscription.objects.filter(user=request.user).count() if authed else 0
|
||||
active_count = UserSubscription.objects.filter(user=request.user, active=True).count() if authed else 0
|
||||
train_count = UserSubscription.objects.filter(user=request.user, active=True, is_trained=False, feed__stories_last_month__gte=1).count() if authed else 0
|
||||
recommended_feeds = RecommendedFeed.objects.filter(is_public=True, approved_date__lte=datetime.datetime.now()).select_related('feed')[:2]
|
||||
unmoderated_feeds = RecommendedFeed.objects.filter(is_public=False, declined_date__isnull=True).select_related('feed')[:2]
|
||||
statistics = MStatistics.all()
|
||||
feedbacks = MFeedback.all()
|
||||
user = get_user(request)
|
||||
authed = request.user.is_authenticated()
|
||||
features = Feature.objects.all()[:3]
|
||||
feature_form = FeatureForm() if request.user.is_staff else None
|
||||
feed_count = UserSubscription.objects.filter(user=request.user).count() if authed else 0
|
||||
active_count = UserSubscription.objects.filter(user=request.user, active=True).count() if authed else 0
|
||||
train_count = UserSubscription.objects.filter(user=request.user, active=True, is_trained=False,
|
||||
feed__stories_last_month__gte=1).count() if authed else 0
|
||||
recommended_feeds = RecommendedFeed.objects.filter(is_public=True,
|
||||
approved_date__lte=datetime.datetime.now())\
|
||||
.select_related('feed')[:2]
|
||||
unmoderated_feeds = RecommendedFeed.objects.filter(is_public=False,
|
||||
declined_date__isnull=True).select_related('feed')[:2]
|
||||
statistics = MStatistics.all()
|
||||
user_statistics = MStatistics.user(request.user)
|
||||
feedbacks = MFeedback.all()
|
||||
|
||||
start_import_from_google_reader = request.session.get('import_from_google_reader', False)
|
||||
if start_import_from_google_reader:
|
||||
del request.session['import_from_google_reader']
|
||||
|
@ -86,6 +92,7 @@ def index(request):
|
|||
'recommended_feeds' : recommended_feeds,
|
||||
'unmoderated_feeds' : unmoderated_feeds,
|
||||
'statistics' : statistics,
|
||||
'user_statistics' : user_statistics,
|
||||
'feedbacks' : feedbacks,
|
||||
'start_import_from_google_reader': start_import_from_google_reader,
|
||||
}, context_instance=RequestContext(request))
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import datetime
|
||||
import mongoengine as mongo
|
||||
import urllib2
|
||||
import random
|
||||
from django.db.models import Avg, Count
|
||||
from apps.rss_feeds.models import MFeedFetchHistory, MPageFetchHistory, FeedLoadtime
|
||||
from apps.profile.models import Profile
|
||||
|
@ -33,6 +34,18 @@ class MStatistics(mongo.Document):
|
|||
values[key] = float(value)
|
||||
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
def user(cls, user):
|
||||
share_reads = [random.randint(0, 30) for x in xrange(30)]
|
||||
values = {
|
||||
'followers': random.randint(0, 1200),
|
||||
'following': random.randint(0, 300),
|
||||
'shared_stories': random.randint(0, 5000),
|
||||
'share_reads': share_reads,
|
||||
'max_share_reads': max(share_reads),
|
||||
}
|
||||
return values
|
||||
|
||||
@classmethod
|
||||
def collect_statistics(cls):
|
||||
|
|
|
@ -1930,6 +1930,7 @@ background: transparent;
|
|||
margin: 0 200px 32px 28px;
|
||||
padding: 12px 0px;
|
||||
max-width: 700px;
|
||||
min-height: 66px;
|
||||
}
|
||||
|
||||
#story_pane .NB-feed-story-sideoptions-container {
|
||||
|
@ -1990,8 +1991,10 @@ background: transparent;
|
|||
#story_pane .NB-sideoption:hover .NB-sideoption-title,
|
||||
#story_pane .NB-sideoption.NB-active .NB-sideoption-icon,
|
||||
#story_pane .NB-sideoption.NB-active .NB-sideoption-title,
|
||||
#story_pane .NB-sideoption.NB-shared .NB-sideoption-icon,
|
||||
#story_pane .NB-sideoption.NB-shared .NB-sideoption-title {
|
||||
#story_pane .NB-story-starred .NB-sideoption.NB-feed-story-save .NB-sideoption-icon,
|
||||
#story_pane .NB-story-starred .NB-sideoption.NB-feed-story-save .NB-sideoption-title,
|
||||
#story_pane .NB-story-shared .NB-sideoption.NB-feed-story-share .NB-sideoption-icon,
|
||||
#story_pane .NB-story-shared .NB-sideoption.NB-feed-story-share .NB-sideoption-title {
|
||||
background-color: #2B478C;
|
||||
color: #D7DDF7;
|
||||
opacity: 1;
|
||||
|
@ -3722,6 +3725,18 @@ background: transparent;
|
|||
display: none;
|
||||
}
|
||||
|
||||
.NB-account .NB-module.NB-module-account .NB-module-account-stats {
|
||||
min-height: 0;
|
||||
}
|
||||
.NB-account .NB-module.NB-module-account .NB-module-stats-count {
|
||||
margin: 0;
|
||||
}
|
||||
.NB-account .NB-module.NB-module-account .NB-module-stats-count-graph {
|
||||
width: 33%;
|
||||
margin: 0 0 0 72px;
|
||||
clear: none;
|
||||
}
|
||||
|
||||
/* ======================= */
|
||||
/* = How it Works Module = */
|
||||
/* ======================= */
|
||||
|
@ -3840,7 +3855,6 @@ background: transparent;
|
|||
text-transform: uppercase;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.NB-module-stats .NB-module-stats-count-number {
|
||||
clear: both;
|
||||
font-size: 18px;
|
||||
|
@ -3852,6 +3866,7 @@ background: transparent;
|
|||
.NB-module-stats .NB-module-stats-count-description {
|
||||
margin: 4px 0 0 0;
|
||||
color: #808080;
|
||||
clear: both;
|
||||
}
|
||||
|
||||
.NB-module-stats .NB-module-stats-count-graph {
|
||||
|
|
|
@ -193,8 +193,8 @@ NEWSBLUR.AssetModel.Reader.prototype = {
|
|||
}, callback);
|
||||
},
|
||||
|
||||
save_shared_story: function(story_id, feed_id, comments, callback, error_callback) {
|
||||
this.make_request('/social/save_shared_story', {
|
||||
mark_story_as_shared: function(story_id, feed_id, comments, callback, error_callback) {
|
||||
this.make_request('/social/mark_story_as_shared', {
|
||||
story_id: story_id,
|
||||
feed_id: feed_id,
|
||||
comments: comments
|
||||
|
|
|
@ -1779,6 +1779,7 @@
|
|||
this.make_story_feed_entries(stories, first_load);
|
||||
this.show_feed_hidden_story_title_indicator(true);
|
||||
this.show_story_titles_above_intelligence_level({'animate': false});
|
||||
this.scroll_story_titles_to_show_selected_story_title();
|
||||
this.fill_out_story_titles();
|
||||
$('.NB-feedbar-last-updated-date').text(data.last_update + ' ago');
|
||||
if (this.counts['find_next_unread_on_page_of_feed_stories_load']) {
|
||||
|
@ -1961,6 +1962,7 @@
|
|||
// $('.NB-feedbar-last-updated-date').text(data.last_update + ' ago');
|
||||
this.flags['story_titles_loaded'] = true;
|
||||
this.prefetch_story_locations_in_feed_view();
|
||||
this.scroll_story_titles_to_show_selected_story_title();
|
||||
this.fill_out_story_titles();
|
||||
}
|
||||
},
|
||||
|
@ -2038,6 +2040,7 @@
|
|||
} else if (this.counts['find_last_unread_on_page_of_feed_stories_load']) {
|
||||
this.show_last_unread_story(true);
|
||||
}
|
||||
this.scroll_story_titles_to_show_selected_story_title();
|
||||
this.fill_out_story_titles();
|
||||
this.prefetch_story_locations_in_feed_view();
|
||||
this.hide_stories_progress_bar();
|
||||
|
@ -2624,10 +2627,18 @@
|
|||
}
|
||||
},
|
||||
|
||||
mark_story_as_starred: function(story_id, $story) {
|
||||
mark_story_as_starred: function(story_id) {
|
||||
var story = this.model.get_story(story_id);
|
||||
var $star = $('.NB-storytitles-star', $story);
|
||||
$story.addClass('NB-story-starred');
|
||||
var $story_title = this.find_story_in_story_titles(story_id);
|
||||
var $feed_story = this.find_story_in_feed_view(story_id);
|
||||
var $star = $('.NB-storytitles-star', $story_title);
|
||||
var $sideoption_title = $('.NB-feed-story-save .NB-sideoption-title', $feed_story);
|
||||
|
||||
this.scroll_story_titles_to_show_selected_story_title($story_title);
|
||||
|
||||
$feed_story.addClass('NB-story-starred');
|
||||
$story_title.addClass('NB-story-starred');
|
||||
$sideoption_title.text('Saved');
|
||||
$star.attr({'title': 'Saved!'});
|
||||
$star.tipsy({
|
||||
gravity: 'sw',
|
||||
|
@ -2641,16 +2652,31 @@
|
|||
$star.tipsy('hide');
|
||||
$star.tipsy('disable');
|
||||
}, 850);
|
||||
|
||||
this.model.mark_story_as_starred(story_id, story.story_feed_id, function() {});
|
||||
this.update_starred_count();
|
||||
},
|
||||
|
||||
mark_story_as_unstarred: function(story_id, $story) {
|
||||
var $star = $('.NB-storytitles-star', $story);
|
||||
$story.one('mouseout', function() {
|
||||
$story.removeClass('NB-unstarred');
|
||||
mark_story_as_unstarred: function(story_id) {
|
||||
var $story_title = this.find_story_in_story_titles(story_id);
|
||||
var $feed_story = this.find_story_in_feed_view(story_id);
|
||||
var $star = $('.NB-storytitles-star', $story_title);
|
||||
var $sideoption_title = $('.NB-feed-story-save .NB-sideoption-title', $feed_story);
|
||||
|
||||
this.scroll_story_titles_to_show_selected_story_title($story_title);
|
||||
|
||||
$story_title.one('mouseout', function() {
|
||||
$story_title.removeClass('NB-unstarred');
|
||||
});
|
||||
$star.attr({'title': 'Removed'});
|
||||
$sideoption_title.text('Removed');
|
||||
$sideoption_title.one('mouseleave', function() {
|
||||
_.delay(function() {
|
||||
if (!$feed_story.hasClass('NB-story-starred')) {
|
||||
$sideoption_title.text('Share this story');
|
||||
}
|
||||
}, 200);
|
||||
});
|
||||
$star.tipsy({
|
||||
gravity: 'sw',
|
||||
fade: true,
|
||||
|
@ -2663,12 +2689,15 @@
|
|||
$star.tipsy('hide');
|
||||
$star.tipsy('disable');
|
||||
}, 850);
|
||||
$story.removeClass('NB-story-starred');
|
||||
|
||||
$story_title.removeClass('NB-story-starred');
|
||||
$feed_story.removeClass('NB-story-starred');
|
||||
|
||||
this.model.mark_story_as_unstarred(story_id, function() {});
|
||||
this.update_starred_count();
|
||||
},
|
||||
|
||||
open_feed_story_share: function(story_id, feed_id) {
|
||||
toggle_feed_story_share_dialog: function(story_id, feed_id) {
|
||||
var $feed_story = this.find_story_in_feed_view(story_id);
|
||||
var $sideoption = $('.NB-sideoption.NB-feed-story-share', $feed_story);
|
||||
var $share = $('.NB-sideoption-share-wrapper', $feed_story);
|
||||
|
@ -2752,18 +2781,20 @@
|
|||
});
|
||||
},
|
||||
|
||||
save_shared_story: function($story) {
|
||||
var story_id = $story.data('story_id');
|
||||
var feed_id = $story.data('feed_id');
|
||||
var comments = $('.NB-sideoption-share-comments', $story).val();
|
||||
mark_story_as_shared: function(story_id) {
|
||||
var story = this.model.get_story(story_id);
|
||||
var $story_title = this.find_story_in_story_titles(story_id);
|
||||
var $feed_story = this.find_story_in_feed_view(story_id);
|
||||
var $share_button = $('.NB-sideoption-share-save', $story);
|
||||
var $share_sideoption = $('.NB-feed-story-share .NB-sideoption-title', $story);
|
||||
var comments = $('.NB-sideoption-share-comments', $story).val();
|
||||
|
||||
$share_button.addClass('NB-saving').text('Sharing...');
|
||||
this.model.save_shared_story(story_id, feed_id, comments, _.bind(function() {
|
||||
this.open_feed_story_share(story_id, feed_id);
|
||||
this.model.mark_story_as_shared(story_id, story.story_feed_id, comments, _.bind(function() {
|
||||
this.toggle_feed_story_share_dialog(story_id, story.story_feed_id);
|
||||
$share_button.removeClass('NB-saving').text('Share');
|
||||
$share_sideoption.text('Shared').closest('.NB-sideoption').addClass('NB-shared');
|
||||
$share_sideoption.text('Shared').closest('.NB-sideoption');
|
||||
$feed_story.addClass('NB-story-shared');
|
||||
}, this));
|
||||
},
|
||||
|
||||
|
@ -3557,6 +3588,7 @@
|
|||
|
||||
var story = stories[s];
|
||||
var story_has_modifications = false;
|
||||
var starred = story.starred ? ' NB-story-starred ' : '';
|
||||
if (options.river_stories) feed = this.model.get_feed(story.story_feed_id);
|
||||
var read = story.read_status
|
||||
? ' read '
|
||||
|
@ -3577,7 +3609,7 @@
|
|||
if (this.cache.last_feed_view_story_feed_id == story.story_feed_id) {
|
||||
river_same_feed = 'NB-feed-story-river-same-feed';
|
||||
}
|
||||
var $story = $.make('li', { className: 'NB-feed-story ' + read + river_stories + ' NB-story-' + score_color }, [
|
||||
var $story = $.make('li', { className: 'NB-feed-story ' + read + starred + river_stories + ' NB-story-' + score_color }, [
|
||||
$.make('div', { className: 'NB-feed-story-header' }, [
|
||||
$.make('div', { className: 'NB-feed-story-header-feed' }, [
|
||||
(options.river_stories && feed && // !river_same_feed
|
||||
|
@ -3620,16 +3652,10 @@
|
|||
$.make('div', { className: 'NB-sideoption-icon'}, ' '),
|
||||
$.make('div', { className: 'NB-sideoption-title'}, 'Train this story')
|
||||
]),
|
||||
(story.starred_date &&
|
||||
$.make('div', { className: 'NB-sideoption NB-feed-story-save NB-active' }, [
|
||||
$.make('div', { className: 'NB-sideoption-icon'}, ' '),
|
||||
$.make('div', { className: 'NB-sideoption-title'}, 'Saved')
|
||||
])),
|
||||
(!story.starred_date &&
|
||||
$.make('div', { className: 'NB-sideoption NB-feed-story-save' }, [
|
||||
$.make('div', { className: 'NB-sideoption-icon'}, ' '),
|
||||
$.make('div', { className: 'NB-sideoption-title'}, 'Save this story')
|
||||
])),
|
||||
$.make('div', { className: 'NB-sideoption NB-feed-story-save' }, [
|
||||
$.make('div', { className: 'NB-sideoption-icon'}, ' '),
|
||||
$.make('div', { className: 'NB-sideoption-title'}, story.starred_date ? 'Saved' : 'Save this story')
|
||||
]),
|
||||
$.make('div', { className: 'NB-sideoption NB-feed-story-share' }, [
|
||||
$.make('div', { className: 'NB-sideoption-icon'}, ' '),
|
||||
$.make('div', { className: 'NB-sideoption-title'}, 'Share this story')
|
||||
|
@ -6041,16 +6067,16 @@
|
|||
var story_id = $t.closest('.NB-menu-manage-story').data('story_id');
|
||||
var $story = self.find_story_in_story_titles(story_id);
|
||||
if ($story.hasClass('NB-story-starred')) {
|
||||
self.mark_story_as_unstarred(story_id, $story);
|
||||
self.mark_story_as_unstarred(story_id);
|
||||
} else {
|
||||
self.mark_story_as_starred(story_id, $story);
|
||||
self.mark_story_as_starred(story_id);
|
||||
}
|
||||
story_prevent_bubbling = true;
|
||||
});
|
||||
$.targetIs(e, { tagSelector: '.NB-sideoption-share-save' }, function($t, $p){
|
||||
e.preventDefault();
|
||||
var $story = $t.closest('.NB-feed-story');
|
||||
self.save_shared_story($story);
|
||||
var story_id = $t.closest('.NB-feed-story').data('story_id');
|
||||
self.mark_story_as_shared(story_id);
|
||||
});
|
||||
$.targetIs(e, { tagSelector: '.NB-feed-story-hide-changes' }, function($t, $p){
|
||||
e.preventDefault();
|
||||
|
@ -6093,13 +6119,12 @@
|
|||
|
||||
$.targetIs(e, { tagSelector: '.NB-feed-story-save' }, function($t, $p){
|
||||
e.preventDefault();
|
||||
var $feed_story = $t.closest('.NB-feed-story');
|
||||
var story_id = $feed_story.data('story_id');
|
||||
var story_id = $t.closest('.NB-feed-story').data('story_id');
|
||||
var $story = self.find_story_in_story_titles(story_id);
|
||||
if ($story.hasClass('NB-story-starred')) {
|
||||
self.mark_story_as_unstarred(story_id, $story);
|
||||
self.mark_story_as_unstarred(story_id);
|
||||
} else {
|
||||
self.mark_story_as_starred(story_id, $story);
|
||||
self.mark_story_as_starred(story_id);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -6108,7 +6133,7 @@
|
|||
var $story = $t.closest('.NB-feed-story');
|
||||
var feed_id = $story.data('feed_id');
|
||||
var story_id = $story.data('story_id');
|
||||
self.open_feed_story_share(story_id, feed_id);
|
||||
self.toggle_feed_story_share_dialog(story_id, feed_id);
|
||||
});
|
||||
|
||||
|
||||
|
@ -6861,9 +6886,9 @@
|
|||
var story_id = self.active_story.id;
|
||||
var $story = self.find_story_in_story_titles(story_id);
|
||||
if ($story.hasClass('NB-story-starred')) {
|
||||
self.mark_story_as_unstarred(story_id, $story);
|
||||
self.mark_story_as_unstarred(story_id);
|
||||
} else {
|
||||
self.mark_story_as_starred(story_id, $story);
|
||||
self.mark_story_as_starred(story_id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -266,7 +266,7 @@ $(document).ready(function() {
|
|||
|
||||
{% else %}
|
||||
|
||||
<div class="NB-module">
|
||||
<div class="NB-module NB-module-account">
|
||||
<h5 class="NB-module-header">
|
||||
Welcome, <span class="NB-module-account-username">{{ user.username }}</span>
|
||||
<div class="NB-module-header-right">
|
||||
|
@ -326,6 +326,32 @@ $(document).ready(function() {
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="NB-module-content-header">
|
||||
Your statistics
|
||||
</h3>
|
||||
|
||||
<div class="NB-module-item NB-module-stats NB-module-account-stats">
|
||||
<div class="NB-module-stats-count">
|
||||
<div class="NB-module-stats-count-number">{{ user_statistics.following|commify }}</div>
|
||||
<div class="NB-module-stats-count-description">Following</div>
|
||||
</div>
|
||||
<div class="NB-module-stats-count">
|
||||
<div class="NB-module-stats-count-number">{{ user_statistics.followers|commify }}</div>
|
||||
<div class="NB-module-stats-count-description">Follower{{ user_statistics.followers|pluralize }}</div>
|
||||
</div>
|
||||
<div class="NB-module-stats-count">
|
||||
<div class="NB-module-stats-count-number">{{ user_statistics.shared_stories|commify }}</div>
|
||||
<div class="NB-module-stats-count-description">Shared stor{{ user_statistics.shared_stories|pluralize:"y,ies" }}</div>
|
||||
</div>
|
||||
{# <div class="NB-module-stats-count NB-module-stats-count-graph"> #}
|
||||
{# {% for i in user_statistics.share_reads %}<div class="NB-graph-value"> #}
|
||||
{# <div class="NB-graph-label">{{ i|commify }}</div> #}
|
||||
{# <div class="NB-graph-bar" style="height:{{ i|format_graph:user_statistics.max_share_reads }}px"></div> #}
|
||||
{# </div>{% endfor %} #}
|
||||
{# <div class="NB-module-stats-count-description">Your shared stories<br />read by others<br />this month</div> #}
|
||||
{# </div> #}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if not user_profile.tutorial_finished %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% load utils_tags statistics_tags %}
|
||||
<div class="NB-module NB-module-stats">
|
||||
<h5 class="NB-module-header">
|
||||
Status and Statistics
|
||||
Site Performance and Statistics
|
||||
</h5>
|
||||
|
||||
<h3 class="NB-module-content-header">
|
||||
|
|
Loading…
Add table
Reference in a new issue