Skip to content
Extraits de code Groupes Projets
Valider a05b1413 rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Add tagged posts to db seed, make people#show and tags#show infinite scroll

parent d8ac8d13
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -38,6 +38,9 @@ class ApplicationController < ActionController::Base ...@@ -38,6 +38,9 @@ class ApplicationController < ActionController::Base
@request_count = Request.where(:recipient_id => current_user.person.id).count if current_user @request_count = Request.where(:recipient_id => current_user.person.id).count if current_user
end end
def ensure_page
params[:page] = params[:page] ? params[:page].to_i : 1
end
def set_invites def set_invites
if user_signed_in? if user_signed_in?
@invites = current_user.invites @invites = current_user.invites
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
class AspectsController < ApplicationController class AspectsController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
before_filter :save_sort_order, :only => :index before_filter :save_sort_order, :only => :index
before_filter :ensure_page, :only => :index
respond_to :html respond_to :html
respond_to :json, :only => [:show, :create] respond_to :json, :only => [:show, :create]
...@@ -25,8 +26,6 @@ class AspectsController < ApplicationController ...@@ -25,8 +26,6 @@ class AspectsController < ApplicationController
redirect_to getting_started_path redirect_to getting_started_path
return return
end end
params[:page] = params[:page] ? params[:page].to_i : 1
@selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq unless params[:only_posts] @selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq unless params[:only_posts]
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
class PeopleController < ApplicationController class PeopleController < ApplicationController
before_filter :authenticate_user!, :except => [:show] before_filter :authenticate_user!, :except => [:show]
before_filter :ensure_page, :only => :show
respond_to :html respond_to :html
respond_to :json, :only => [:index, :show] respond_to :json, :only => [:index, :show]
...@@ -76,7 +77,7 @@ class PeopleController < ApplicationController ...@@ -76,7 +77,7 @@ class PeopleController < ApplicationController
@incoming_request = current_user.request_from(@person) @incoming_request = current_user.request_from(@person)
@contact = current_user.contact_for(@person) @contact = current_user.contact_for(@person)
@aspects_with_person = [] @aspects_with_person = []
if @contact if @contact && !params[:only_posts]
@aspects_with_person = @contact.aspects @aspects_with_person = @contact.aspects
@aspect_ids = @aspects_with_person.map(&:id) @aspect_ids = @aspects_with_person.map(&:id)
@contacts_of_contact = @contact.contacts @contacts_of_contact = @contact.contacts
...@@ -91,14 +92,18 @@ class PeopleController < ApplicationController ...@@ -91,14 +92,18 @@ class PeopleController < ApplicationController
else else
@commenting_disabled = false @commenting_disabled = false
end end
@posts = current_user.posts_from(@person).where(:type => "StatusMessage").includes(:comments).paginate(:per_page => 15, :page => params[:page]) @posts = current_user.posts_from(@person).where(:type => "StatusMessage").includes(:comments).limit(15).offset(15*(params[:page]-1))
else else
@commenting_disabled = true @commenting_disabled = true
@posts = @person.posts.where(:type => "StatusMessage", :public => true).includes(:comments).paginate(:per_page => 15, :page => params[:page], :order => 'created_at DESC') @posts = @person.posts.where(:type => "StatusMessage", :public => true).includes(:comments).limit(15).offset(15*(params[:page]-1))
end end
@fakes = PostsFake.new(@posts) @posts = PostsFake.new(@posts)
respond_with @person, :locals => {:post_type => :all} if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @posts}
else
respond_with @person, :locals => {:post_type => :all}
end
else else
flash[:error] = I18n.t 'people.show.does_not_exist' flash[:error] = I18n.t 'people.show.does_not_exist'
......
...@@ -7,6 +7,7 @@ class TagsController < ApplicationController ...@@ -7,6 +7,7 @@ class TagsController < ApplicationController
skip_before_filter :set_invites skip_before_filter :set_invites
skip_before_filter :which_action_and_user skip_before_filter :which_action_and_user
skip_before_filter :set_grammatical_gender skip_before_filter :set_grammatical_gender
before_filter :ensure_page, :only => :show
respond_to :html, :only => [:show] respond_to :html, :only => [:show]
respond_to :json, :only => [:index] respond_to :json, :only => [:index]
...@@ -51,13 +52,17 @@ class TagsController < ApplicationController ...@@ -51,13 +52,17 @@ class TagsController < ApplicationController
end end
@posts = @posts.tagged_with(params[:name]) @posts = @posts.tagged_with(params[:name])
@posts = @posts.includes(:comments, :photos).paginate(:page => params[:page], :per_page => 15, :order => 'created_at DESC') @posts = @posts.includes(:comments, :photos).order('created_at DESC').limit(15).offset(15*(params[:page]-1))
profiles = Profile.tagged_with(params[:name]).where(:searchable => true).select('profiles.id, profiles.person_id') @posts = PostsFake.new(@posts)
@people = Person.where(:id => profiles.map{|p| p.person_id}).limit(15)
@people_count = Person.where(:id => profiles.map{|p| p.person_id}).count
@fakes = PostsFake.new(@posts)
@commenting_disabled = true @commenting_disabled = true
if params[:only_posts]
render :partial => 'shared/stream', :locals => {:posts => @posts}
else
profiles = Profile.tagged_with(params[:name]).where(:searchable => true).select('profiles.id, profiles.person_id')
@people = Person.where(:id => profiles.map{|p| p.person_id}).limit(15)
@people_count = Person.where(:id => profiles.map{|p| p.person_id}).count
end
end end
end end
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
module ApplicationHelper module ApplicationHelper
@@youtube_title_cache = Hash.new("no-title") @@youtube_title_cache = Hash.new("no-title")
def next_page
params[:page] ? (params[:page].to_i + 1) : 2
end
def timeago(time, options = {}) def timeago(time, options = {})
options[:class] ||= "timeago" options[:class] ||= "timeago"
content_tag(:abbr, time.to_s, options.merge(:title => time.iso8601)) if time content_tag(:abbr, time.to_s, options.merge(:title => time.iso8601)) if time
...@@ -48,7 +51,7 @@ module ApplicationHelper ...@@ -48,7 +51,7 @@ module ApplicationHelper
link = opts.delete(:link) link = opts.delete(:link)
if !link if !link
str << link_to(aspect.name, "#", 'data-guid' => aspect.id, :class => 'hard_aspect_link').html_safe str << link_to(aspect.name, "#", 'data-guid' => aspect.id, :class => 'hard_aspect_link').html_safe
else else
str << link_for_aspect(aspect).html_safe str << link_for_aspect(aspect).html_safe
end end
str << "</span>" str << "</span>"
...@@ -167,7 +170,7 @@ module ApplicationHelper ...@@ -167,7 +170,7 @@ module ApplicationHelper
message = process_emphasis(message) message = process_emphasis(message)
message = process_youtube(message, options[:youtube_maps]) message = process_youtube(message, options[:youtube_maps])
message = process_vimeo(message, options[:vimeo_maps]) message = process_vimeo(message, options[:vimeo_maps])
message.gsub!(/&lt;3/, "&hearts;") message.gsub!(/&lt;3/, "&hearts;")
if options[:newlines] if options[:newlines]
......
...@@ -13,6 +13,6 @@ ...@@ -13,6 +13,6 @@
- if posts.length > 0 - if posts.length > 0
= render 'shared/stream', :posts => posts = render 'shared/stream', :posts => posts
#pagination #pagination
=link_to(t('more'), aspects_path(:page => (params[:page] + 1), :a_ids => params[:a_ids]), :class => 'paginate') =link_to(t('more'), aspects_path(:page => next_page, :a_ids => params[:a_ids]), :class => 'paginate')
- else - else
= render 'aspects/no_posts_message', :post_count => posts.length = render 'aspects/no_posts_message', :post_count => posts.length
...@@ -74,15 +74,14 @@ ...@@ -74,15 +74,14 @@
%hr %hr
- if @posts.count > 0 - if @posts.length > 0
-if @post_type == :photos -if @post_type == :photos
= render 'photos/index', :photos => @posts = render 'photos/index', :photos => @posts
- else - else
#main_stream.stream #main_stream.stream
= render 'shared/stream', :posts => @fakes, :commenting_disabled => @commenting_disabled = render 'shared/stream', :posts => @posts, :commenting_disabled => @commenting_disabled
%a.paginate #pagination
= t("more") =link_to(t('more'), person_path(@person, :page => next_page), :class => 'paginate')
= will_paginate @posts
- else - else
#stream #stream
......
...@@ -20,13 +20,12 @@ ...@@ -20,13 +20,12 @@
.span-15 .span-15
#main_stream.stream #main_stream.stream
- if @fakes.length > 0 - if @posts.length > 0
= render 'shared/stream', :posts => @fakes = render 'shared/stream', :posts => @posts
%a.paginate #pagination
= t("more") =link_to(t('more'), tag_path(params[:name], :page => next_page), :class => 'paginate')
- else - else
= t('.nobody_talking', :tag => "##{params[:name]}") = t('.nobody_talking', :tag => "##{params[:name]}")
= will_paginate @posts
.prepend-2.span-7.last .prepend-2.span-7.last
%h3 %h3
......
...@@ -33,7 +33,7 @@ require 'spec/support/user_methods' ...@@ -33,7 +33,7 @@ require 'spec/support/user_methods'
time_interval = 1000 time_interval = 1000
(1..25).each do |n| (1..25).each do |n|
[alice, bob, eve].each do |u| [alice, bob, eve].each do |u|
post = u.post :status_message, :text => "#{u.username} - #{n}", :to => u.aspects.first.id post = u.post :status_message, :text => "#{u.username} - #{n} - #seeded", :to => u.aspects.first.id
post.created_at = post.created_at + time_interval post.created_at = post.created_at + time_interval
post.updated_at = post.updated_at + time_interval post.updated_at = post.updated_at + time_interval
post.save post.save
......
...@@ -123,7 +123,7 @@ describe PeopleController do ...@@ -123,7 +123,7 @@ describe PeopleController do
@user.post(:status_message, :text => "public", :to => 'all', :public => true) @user.post(:status_message, :text => "public", :to => 'all', :public => true)
@user.reload.posts.length.should == 3 @user.reload.posts.length.should == 3
get :show, :id => @user.person.to_param get :show, :id => @user.person.to_param
assigns(:posts).should =~ @user.posts assigns(:posts).models.should =~ @user.posts
end end
it "renders the comments on the user's posts" do it "renders the comments on the user's posts" do
...@@ -152,7 +152,7 @@ describe PeopleController do ...@@ -152,7 +152,7 @@ describe PeopleController do
get :show, :id => @person.id get :show, :id => @person.id
assigns[:posts].should =~ public_posts assigns[:posts].models.should =~ public_posts
end end
it 'throws 404 if the person is remote' do it 'throws 404 if the person is remote' do
...@@ -182,7 +182,7 @@ describe PeopleController do ...@@ -182,7 +182,7 @@ describe PeopleController do
bob.reload.posts.length.should == 4 bob.reload.posts.length.should == 4
get :show, :id => @person.id get :show, :id => @person.id
assigns(:posts).should =~ posts_user_can_see assigns(:posts).models.should =~ posts_user_can_see
end end
end end
...@@ -204,7 +204,7 @@ describe PeopleController do ...@@ -204,7 +204,7 @@ describe PeopleController do
eve.reload.posts.length.should == 3 eve.reload.posts.length.should == 3
get :show, :id => @person.id get :show, :id => @person.id
assigns[:posts].should =~ [public_post] assigns[:posts].models.should =~ [public_post]
end end
end end
end end
......
...@@ -46,19 +46,19 @@ describe TagsController do ...@@ -46,19 +46,19 @@ describe TagsController do
it 'displays your own post' do it 'displays your own post' do
my_post = alice.post(:status_message, :text => "#what", :to => 'all') my_post = alice.post(:status_message, :text => "#what", :to => 'all')
get :show, :name => 'what' get :show, :name => 'what'
assigns(:posts).should == [my_post] assigns(:posts).models.should == [my_post]
response.status.should == 200 response.status.should == 200
end end
it "displays a friend's post" do it "displays a friend's post" do
other_post = bob.post(:status_message, :text => "#hello", :to => 'all') other_post = bob.post(:status_message, :text => "#hello", :to => 'all')
get :show, :name => 'hello' get :show, :name => 'hello'
assigns(:posts).should == [other_post] assigns(:posts).models.should == [other_post]
response.status.should == 200 response.status.should == 200
end end
it 'displays a public post' do it 'displays a public post' do
other_post = eve.post(:status_message, :text => "#hello", :public => true, :to => 'all') other_post = eve.post(:status_message, :text => "#hello", :public => true, :to => 'all')
get :show, :name => 'hello' get :show, :name => 'hello'
assigns(:posts).should == [other_post] assigns(:posts).models.should == [other_post]
response.status.should == 200 response.status.should == 200
end end
end end
...@@ -89,7 +89,7 @@ describe TagsController do ...@@ -89,7 +89,7 @@ describe TagsController do
end end
it "assigns the right set of posts" do it "assigns the right set of posts" do
get :show, :name => 'what' get :show, :name => 'what'
assigns[:posts].should == [@post] assigns[:posts].models.should == [@post]
end end
it 'succeeds with comments' do it 'succeeds with comments' do
alice.comment('what WHAT!', :on => @post) alice.comment('what WHAT!', :on => @post)
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter