This commit is contained in:
Maxwell Salzberg 2011-09-27 18:40:49 -07:00
parent 0f073387ac
commit b5c3f2c615
8 changed files with 58 additions and 48 deletions

View file

@ -11,20 +11,22 @@ module StreamHelper
elsif controller.instance_of?(PeopleController)
person_path(@person, :max_time => @posts.last.created_at.to_i)
elsif controller.instance_of?(TagFollowingsController)
tag_followings_path(:max_time => @stream.posts.last.created_at.to_i)
tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream))
elsif controller.instance_of?(AspectsController)
if opts[:ajax_stream]
time = (Time.now() + 1).to_i
else
time = @stream.posts.last.send(@stream.order.to_sym).to_i
end
aspects_path(:max_time => time, :sort_order => session[:sort_order], :a_ids => @stream.aspect_ids)
aspects_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :a_ids => @stream.aspect_ids)
else
raise 'in order to use pagination for this new controller, update next_page_path in stream helper'
end
end
def time_for_scroll(ajax_stream, stream)
if ajax_stream
(Time.now() + 1).to_i
else
stream.posts.last.send(stream.order.to_sym).to_i
end
end
def time_for_sort post
if controller.instance_of?(AspectsController)
post.send(session[:sort_order].to_sym)

View file

@ -6,15 +6,12 @@
#sort_by
= t('.recently')
%span.controls
= link_to_if(session[:sort_order] == 'updated_at', t('.posted'), aspects_path(:a_ids => stream.aspect_ids, :sort_order => 'created_at' ))
= link_to_if(session[:sort_order] == 'created_at', t('.commented_on'), stream.link(:sort_order => 'updated_at'))
·
= link_to_if(session[:sort_order] == 'created_at', t('.commented_on'), aspects_path(:a_ids => stream.aspect_ids, :sort_order => 'updated_at'))
= link_to_if(session[:sort_order] == 'updated_at', t('.posted'), stream.link(:sort_order => 'created_at' ))
%h3
- if stream.for_all_aspects?
= t('.stream')
- else
= stream.aspects.to_sentence
= stream.title
= render 'shared/publisher', :selected_aspects => stream.aspects, :aspect_ids => stream.aspect_ids, :for_all_aspects => stream.for_all_aspects?, :aspect => stream.aspect
= render 'aspects/no_posts_message'

View file

@ -1,12 +1,7 @@
#selected_aspect_contacts.section
.title.no_icon
%h5
- if @stream.for_all_aspects? || @stream.aspect_ids.size > 1
= "#{t('_contacts')}"
- else
= @stream.aspect.name
= "(#{@stream.people.size})"
= @stream.contacts_title
.content
- if @stream.people.size > 0

View file

@ -6,7 +6,7 @@
%ul.left_nav
%li
%div.root_element
= t('aspects.index.tags_following')
=link_to t('aspects.index.tags_following'), tag_followings_path
%ul.sub_nav
- if tags.size > 0

View file

@ -21,7 +21,6 @@ Diaspora::Application.configure do
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
#config.threadsafe!
# Monkeypatch around the nasty "2.5MB exception page" issue, caused by very large environment vars
# This snippet via: http://stackoverflow.com/questions/3114993/exception-pages-in-development-mode-take-upwards-of-15-30-seconds-to-render-why
# Relevant Rails ticket: https://rails.lighthouseapp.com/projects/8994/tickets/5027-_request_and_responseerb-and-diagnosticserb-take-an-increasingly-long-time-to-render-in-development-with-multiple-show-tables-calls

View file

@ -53,7 +53,7 @@ Diaspora::Application.routes.draw do
end
# get "tag_followings" => "tag_followings#index", :as => 'tag_followings'
get "tag_followings" => "tag_followings#index", :as => 'tag_followings'
get 'tags/:name' => 'tags#show', :as => 'tag'

View file

@ -54,6 +54,10 @@ class AspectStream
@people ||= Person.all_from_aspects(aspect_ids, @user).includes(:profile)
end
def link(opts={})
Rails.application.routes.url_helpers.aspects_path(opts.merge(:a_ids => aspect_ids))
end
# The first aspect in #aspects, given the stream is not for all aspects, or #aspects size is 1
# @note aspects.first is used for mobile. NOTE(this is a hack and should be fixed)
# @return [Aspect,Symbol]
@ -67,6 +71,14 @@ class AspectStream
for_all_aspects?
end
def title
if self.for_all_aspects?
I18n.t('.stream')
else
self.aspects.to_sentence
end
end
# Determine whether or not the stream is displaying across
# all of the user's aspects.
#
@ -74,4 +86,12 @@ class AspectStream
def for_all_aspects?
@all_aspects ||= aspect_ids.length == @user.aspects.size
end
def contacts_title
if self.for_all_aspects? || self.aspect_ids.size > 1
I18n.t('_contacts')
else
"#{self.aspect.name}(#{self.people.size})"
end
end
end

View file

@ -14,31 +14,22 @@ class TagStream
# @return [void]
def initialize(user, opts={})
@tags = user.followed_tags
@tag_string = @tags.join(', '){|tag| tag.name}.to_sym
@tag_string = @tags.join(', '){|tag| tag.name}
@user = user
@max_time = opts[:max_time]
@order = opts[:order]
end
# Filters aspects given the stream's aspect ids on initialization and the user.
# Will disclude aspects from inputted aspect ids if user is not associated with their
# target aspects.
#
# @return [ActiveRecord::Association<Aspect>] Filtered aspects given the stream's user
def aspects
[@tag_string]
def link(opts={})
Rails.application.routes.url_helpers.tag_followings_path(opts)
end
# Maps ids into an array from #aspects
#
# @return [Array<Integer>] Aspect ids
def aspect_ids
[]
def title
"Tag Stream"
end
# @return [ActiveRecord::Association<Post>] AR association of posts
def posts
# NOTE(this should be something like Post.all_for_stream(@user, aspect_ids, {}) that calls visible_posts
@posts ||= StatusMessage.tagged_with([@tag_string], :any => true)
@ -49,18 +40,24 @@ class TagStream
@people ||= posts.map{|p| p.author}.uniq
end
# The first aspect in #aspects, given the stream is not for all aspects, or #aspects size is 1
# @note aspects.first is used for mobile. NOTE(this is a hack and should be fixed)
# @return [Aspect,Symbol]
def aspect
@tags_string
def for_all_aspects?
false
end
def aspects
[]
end
# Determine whether or not the stream is displaying across
# all of the user's aspects.
#
# @return [Boolean]
def for_all_aspects?
true
def aspect
nil
end
def contacts_title
"People who like #{@tag_string}"
end
def aspect_ids
[]
end
end