From cdce54bbdaf7b95805576e82ba38dbbcc5d55f6f Mon Sep 17 00:00:00 2001 From: Maxwell Salzberg Date: Wed, 5 Oct 2011 21:11:37 -0700 Subject: [PATCH] MS SM featured users stream. because we do what we want --- app/controllers/featured_users_controller.rb | 15 ++++++++++ app/helpers/featured_users_helper.rb | 2 ++ app/helpers/stream_helper.rb | 2 ++ .../aspects/_selected_contacts.html.haml | 2 +- app/views/aspects/index.html.haml | 5 ++++ app/views/contacts/index.html.haml | 2 +- app/views/shared/_contact_sidebar.html.haml | 2 +- config/locales/diaspora/en.yml | 3 +- config/routes.rb | 8 +++-- lib/base_stream.rb | 4 +++ lib/messagebus/mailer.rb | 1 - lib/stream/featured_users_stream.rb | 29 +++++++++++++++++++ .../javascripts/pages/featured-users-index.js | 9 ++++++ .../featured_users_controller_spec.rb | 13 +++++++++ spec/helpers/featured_users_helper_spec.rb | 15 ++++++++++ spec/lib/stream/featured_users_spec.rb | 12 ++++++++ .../featured_users/index.html.haml_spec.rb | 5 ++++ 17 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 app/controllers/featured_users_controller.rb create mode 100644 app/helpers/featured_users_helper.rb create mode 100644 lib/stream/featured_users_stream.rb create mode 100644 public/javascripts/pages/featured-users-index.js create mode 100644 spec/controllers/featured_users_controller_spec.rb create mode 100644 spec/helpers/featured_users_helper_spec.rb create mode 100644 spec/lib/stream/featured_users_spec.rb create mode 100644 spec/views/featured_users/index.html.haml_spec.rb diff --git a/app/controllers/featured_users_controller.rb b/app/controllers/featured_users_controller.rb new file mode 100644 index 000000000..9b5ffff39 --- /dev/null +++ b/app/controllers/featured_users_controller.rb @@ -0,0 +1,15 @@ +require File.join(Rails.root, 'lib', 'stream', 'featured_users_stream') + +class FeaturedUsersController < ApplicationController + before_filter :authenticate_user! + before_filter :save_sort_order, :only => :index + + def index + @stream = FeaturedUsersStream.new(current_user, :max_time => params[:max_time], :order => sort_order) + if params[:only_posts] + render :partial => 'shared/stream', :locals => {:posts => @stream.posts} + else + render 'aspects/index' + end + end +end diff --git a/app/helpers/featured_users_helper.rb b/app/helpers/featured_users_helper.rb new file mode 100644 index 000000000..1fd44f15c --- /dev/null +++ b/app/helpers/featured_users_helper.rb @@ -0,0 +1,2 @@ +module FeaturedUsersHelper +end diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index 68ef837cd..757c20e7c 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -12,6 +12,8 @@ module StreamHelper person_path(@person, :max_time => @posts.last.created_at.to_i) elsif controller.instance_of?(TagFollowingsController) tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order]) + elsif controller.instance_of?(FeaturedUsersController) + featured_users_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order]) elsif controller.instance_of?(MentionsController) mentions_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order]) elsif controller.instance_of?(AspectsController) diff --git a/app/views/aspects/_selected_contacts.html.haml b/app/views/aspects/_selected_contacts.html.haml index 04291e3a2..f844d8c44 100644 --- a/app/views/aspects/_selected_contacts.html.haml +++ b/app/views/aspects/_selected_contacts.html.haml @@ -7,7 +7,7 @@ - if @stream.people.size > 0 - for person in @stream.people.sample(15) = person_image_link(person) - = link_to t('.view_all_contacts'), @stream.contacts_link, :id => "view_all_contacts_link" + = link_to @stream.contacts_link_title, @stream.contacts_link, :id => "view_all_contacts_link" - else = t('.no_contacts') = link_to t('.manage_your_aspects'), contacts_link diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 005764d9a..1910875b7 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -26,6 +26,11 @@ .li %b= link_to t('.mentions'), mentions_path, :class => 'home_selector' + .section + %ul.left_nav + .li + %b= link_to t('.featured_users'), featured_path, :class => 'home_selector' + .section#followed_tags_listing = render 'tags/followed_tags_listings' diff --git a/app/views/contacts/index.html.haml b/app/views/contacts/index.html.haml index 4c3e2c929..eaef6a803 100644 --- a/app/views/contacts/index.html.haml +++ b/app/views/contacts/index.html.haml @@ -60,7 +60,7 @@ %br %br = t('.check_out') - = link_to t('contacts.featured.featured_users'), "/featured" + = link_to t('contacts.featured.featured_users'), featured_users_path - if @aspect or = link_to t('.add_to_aspect', :name => @aspect.name).downcase, edit_aspect_path(@aspect), :rel => "facebox" diff --git a/app/views/shared/_contact_sidebar.html.haml b/app/views/shared/_contact_sidebar.html.haml index 0ed82280c..5e560ea6b 100644 --- a/app/views/shared/_contact_sidebar.html.haml +++ b/app/views/shared/_contact_sidebar.html.haml @@ -10,7 +10,7 @@ %ul.left_nav - if AppConfig[:featured_users] %li{:class => ("active" if @featured)} - = link_to t('contacts.featured.featured_users'), "/featured", :class => "element_selector" + = link_to t('contacts.featured.featured_users'), featured_users_path, :class => "element_selector" %li{:class => ("active" if @finder)} = link_to "Facebook Friends", friend_finder_path('facebook'), :class => "element_selector" diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 0c3d7ca65..e3a981189 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -122,8 +122,8 @@ en: aspect_listings: edit_aspect: "Edit %{name}" add_an_aspect: "+ Add an aspect" - selected_contacts: + view_all_featured_users: "See all Featured Users" view_all_contacts: "View all contacts" no_contacts: "You don't have any contacts here yet." manage_your_aspects: "Manage your aspects." @@ -158,6 +158,7 @@ en: friends: "Friends" index: mentions: "Mentions" + featured_users: "Featured Users" donate: "Donate" keep_us_running: "Keep %{pod} running fast and buy servers their coffee fix with a monthly donation!" your_aspects: "Your Aspects" diff --git a/config/routes.rb b/config/routes.rb index ed1338728..2b00f555e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,6 +4,7 @@ Diaspora::Application.routes.draw do + # Posting and Reading resources :reshares @@ -107,7 +108,11 @@ Diaspora::Application.routes.draw do resources :aspect_memberships, :only => [:destroy, :create, :update] resources :post_visibilities, :only => [:update] - get 'featured' => "contacts#featured", :as => 'featured_users' + get 'featured' => 'featured_users#index', :as => 'featured' + + get 'featured_users' => "contacts#featured", :as => 'featured_users' + + resources :people, :except => [:edit, :update] do resources :status_messages resources :photos @@ -120,7 +125,6 @@ Diaspora::Application.routes.draw do end get '/u/:username' => 'people#show', :as => 'user_profile' get '/u/:username/profile_photo' => 'users#user_photo' - # Federation controller :publics do diff --git a/lib/base_stream.rb b/lib/base_stream.rb index 780ed6e37..e4da04ccd 100644 --- a/lib/base_stream.rb +++ b/lib/base_stream.rb @@ -30,6 +30,10 @@ class BaseStream [] end + def contacts_link_title + I18n.translate('aspects.selected_contacts.view_all_contacts') + end + def contacts_title "title for a stream" end diff --git a/lib/messagebus/mailer.rb b/lib/messagebus/mailer.rb index 967c45f57..0b0b91404 100644 --- a/lib/messagebus/mailer.rb +++ b/lib/messagebus/mailer.rb @@ -6,7 +6,6 @@ module Messagebus def initialize(api_key) @client = MessagebusRubyApi::Client.new(api_key) - end attr_accessor :settings diff --git a/lib/stream/featured_users_stream.rb b/lib/stream/featured_users_stream.rb new file mode 100644 index 000000000..b58ad0816 --- /dev/null +++ b/lib/stream/featured_users_stream.rb @@ -0,0 +1,29 @@ +class FeaturedUsersStream < BaseStream + def title + "Featured users doing cool stuff!" + end + + def link(opts={}) + Rails.application.routes.url_helpers.featured_path(opts) + end + + def contacts_title + "This week's featured users" + end + + def contacts_link + Rails.application.routes.url_helpers.featured_users_path + end + + def contacts_link_title + I18n.translate('aspects.selected_contacts.view_all_featured_users') + end + + def posts + Post.all_public.where(:author_id => people.map{|x| x.id}).for_a_stream(max_time, order) + end + + def people + Person.featured_users + end +end diff --git a/public/javascripts/pages/featured-users-index.js b/public/javascripts/pages/featured-users-index.js new file mode 100644 index 000000000..9d58eaca1 --- /dev/null +++ b/public/javascripts/pages/featured-users-index.js @@ -0,0 +1,9 @@ +Diaspora.Pages.FeaturedUsersIndex = function() { + var self = this; + + this.subscribe("page/ready", function(evt, document) { + self.aspectNavigation = self.instantiate("AspectNavigation", document.find("ul#aspect_nav")); + self.stream = self.instantiate("Stream", document.find("#aspect_stream_container")); + self.infiniteScroll = self.instantiate("InfiniteScroll"); + }); +}; diff --git a/spec/controllers/featured_users_controller_spec.rb b/spec/controllers/featured_users_controller_spec.rb new file mode 100644 index 000000000..0a32f1e32 --- /dev/null +++ b/spec/controllers/featured_users_controller_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper' + +describe FeaturedUsersController do + + describe "GET 'index'" do + it "should be successful" do + sign_in alice + get 'index' + response.should be_success + end + end + +end diff --git a/spec/helpers/featured_users_helper_spec.rb b/spec/helpers/featured_users_helper_spec.rb new file mode 100644 index 000000000..f3882b66c --- /dev/null +++ b/spec/helpers/featured_users_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the FeaturedUsersHelper. For example: +# +# describe FeaturedUsersHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe FeaturedUsersHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/lib/stream/featured_users_spec.rb b/spec/lib/stream/featured_users_spec.rb new file mode 100644 index 000000000..e592dcc1b --- /dev/null +++ b/spec/lib/stream/featured_users_spec.rb @@ -0,0 +1,12 @@ +require 'spec_helper' +require File.join(Rails.root, 'spec', 'shared_behaviors', 'stream') + +describe FeaturedUsersStream do + before do + @stream = FeaturedUsersStream.new(Factory(:user), :max_time => Time.now, :order => 'updated_at') + end + + describe 'shared behaviors' do + it_should_behave_like 'it is a stream' + end +end diff --git a/spec/views/featured_users/index.html.haml_spec.rb b/spec/views/featured_users/index.html.haml_spec.rb new file mode 100644 index 000000000..d919ae3ec --- /dev/null +++ b/spec/views/featured_users/index.html.haml_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe "featured_users/index.html.haml" do + pending "add some examples to (or delete) #{__FILE__}" +end