From bb7ae99ba4463980a0a3ad002265fa2feecf86a6 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Wed, 14 Dec 2011 21:56:27 -0800 Subject: [PATCH] Adding user statistics (with fake data). Also showing shared/starred stories as shared/starred in the Feed view. --- apps/reader/views.py | 29 +++-- apps/statistics/models.py | 13 +++ media/css/reader.css | 21 +++- media/js/newsblur/assetmodel.js | 4 +- media/js/newsblur/reader.js | 101 +++++++++++------- templates/reader/feeds.xhtml | 28 ++++- .../statistics/render_statistics_graphs.xhtml | 2 +- 7 files changed, 142 insertions(+), 56 deletions(-) diff --git a/apps/reader/views.py b/apps/reader/views.py index 1a9720924..96b7b9328 100644 --- a/apps/reader/views.py +++ b/apps/reader/views.py @@ -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)) diff --git a/apps/statistics/models.py b/apps/statistics/models.py index 6d2a60be4..8088e54e7 100644 --- a/apps/statistics/models.py +++ b/apps/statistics/models.py @@ -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): diff --git a/media/css/reader.css b/media/css/reader.css index eb132e3ac..21fa58d0f 100644 --- a/media/css/reader.css +++ b/media/css/reader.css @@ -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 { diff --git a/media/js/newsblur/assetmodel.js b/media/js/newsblur/assetmodel.js index a0dd57f4e..1fa5f464d 100644 --- a/media/js/newsblur/assetmodel.js +++ b/media/js/newsblur/assetmodel.js @@ -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 diff --git a/media/js/newsblur/reader.js b/media/js/newsblur/reader.js index cd2e67375..0aea73ec3 100644 --- a/media/js/newsblur/reader.js +++ b/media/js/newsblur/reader.js @@ -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); } } }); diff --git a/templates/reader/feeds.xhtml b/templates/reader/feeds.xhtml index fb9655fc7..1d96c0583 100644 --- a/templates/reader/feeds.xhtml +++ b/templates/reader/feeds.xhtml @@ -266,7 +266,7 @@ $(document).ready(function() { {% else %} -
+
+ +

+ Your statistics +

+ +
+
+
{{ user_statistics.following|commify }}
+
Following
+
+
+
{{ user_statistics.followers|commify }}
+
Follower{{ user_statistics.followers|pluralize }}
+
+
+
{{ user_statistics.shared_stories|commify }}
+
Shared stor{{ user_statistics.shared_stories|pluralize:"y,ies" }}
+
+ {#
#} + {# {% for i in user_statistics.share_reads %}
#} + {#
{{ i|commify }}
#} + {#
#} + {#
{% endfor %} #} + {#
Your shared stories
read by others
this month
#} + {#
#} +
{% if not user_profile.tutorial_finished %} diff --git a/templates/statistics/render_statistics_graphs.xhtml b/templates/statistics/render_statistics_graphs.xhtml index beb6c37a8..d2cf95ab3 100644 --- a/templates/statistics/render_statistics_graphs.xhtml +++ b/templates/statistics/render_statistics_graphs.xhtml @@ -1,7 +1,7 @@ {% load utils_tags statistics_tags %}
- Status and Statistics + Site Performance and Statistics