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