Newer
Older
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
before_filter :authenticate_user!
Daniel Grippi & Raphael Sofaer
a validé
respond_to :html
respond_to :json, :only => :show
@posts = current_user.visible_posts(:_type => "StatusMessage").paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
@aspect_hashes = hashes_for_aspects @aspects.all, @contacts
danielvincent
a validé
if current_user.getting_started == true
danielvincent
a validé
end
danielvincent
a validé
@aspect = current_user.aspects.create(params[:aspect])
flash[:notice] = I18n.t('aspects.create.success', :name => @aspect.name)
if current_user.getting_started
redirect_to :back
elsif request.env['HTTP_REFERER'].include?("aspects/manage")
redirect_to :back
flash[:error] = I18n.t('aspects.create.failure')
redirect_to :back
@aspect = current_user.aspect_by_id params[:id]
flash[:notice] = I18n.t 'aspects.destroy.success',:name => @aspect.name
rescue RuntimeError => e
flash[:error] = e.message
end
respond_with :location => aspects_manage_path
@aspect = current_user.aspect_by_id params[:id]
unless @aspect
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
danielvincent
a validé
@aspect_contacts = @aspect.contacts
danielvincent
a validé
@aspect_contacts_count = @aspect_contacts.count
@posts = @aspect.posts.find_all_by__type("StatusMessage", :order => 'created_at desc').paginate :page => params[:page], :per_page => 15
@post_hashes = hashes_for_posts @posts
@post_count = @posts.count
danielvincent
a validé
respond_with @aspect
end
def manage
@aspect = :manage
@remote_requests = current_user.requests_for_me
@aspect = current_user.aspect_by_id(params[:id])
@aspect.update_attributes( params[:aspect] )
flash[:notice] = I18n.t 'aspects.update.success',:name => @aspect.name
def move_contact
unless current_user.move_contact( :person_id => params[:person_id], :from => params[:from], :to => params[:to][:to])
flash[:error] = I18n.t 'aspects.move_contact.error',:inspect => params.inspect
if aspect = current_user.aspect_by_id(params[:to][:to])
flash[:notice] = I18n.t 'aspects.move_contact.success'
flash[:notice] = I18n.t 'aspects.move_contact.failure'
begin current_user.add_person_to_aspect( params[:person_id], params[:aspect_id])
@person_id = params[:person_id]
@aspect_id = params[:aspect_id]
flash.now[:notice] = I18n.t 'aspects.add_to_aspect.success'
respond_to do |format|
format.js { render :status => 200 }
format.html{ redirect_to aspect_path(@aspect_id)}
end
rescue Exception => e
flash.now[:error] = I18n.t 'aspects.add_to_aspect.failure'
respond_to do |format|
format.js { render :text => e, :status => 403 }
format.html{ redirect_to aspect_path(@aspect_id)}
end
def remove_from_aspect
begin current_user.delete_person_from_aspect(params[:person_id], params[:aspect_id])
@person_id = params[:person_id]
@aspect_id = params[:aspect_id]
flash.now[:notice] = I18n.t 'aspects.remove_from_aspect.success'
respond_to do |format|
format.js { render :status => 200 }
format.html{ redirect_to aspect_path(@aspect_id)}
end
rescue Exception => e
flash.now[:error] = I18n.t 'aspects.remove_from_aspect.failure'
respond_to do |format|
format.js { render :text => e, :status => 403 }
format.html{ redirect_to aspect_path(@aspect_id)}
end
danielvincent
a validé
end
end
def hashes_for_aspects aspects, contacts
aspects.map do |a|
hash = {:aspect => a}
aspect_contacts = contacts.select{|c|
c.aspect_ids.include?(a.id)}
hash[:contact_count] = aspect_contacts.count
person_ids = aspect_contacts.map{|c| c.person_id}
hash[:people] = Person.all(:id.in => person_ids, :limit => 8)
hash
end
end
post_ids = posts.map{|p| p.id}
comment_hash = Comment.hash_from_post_ids post_ids
person_hash = Person.from_post_comment_hash comment_hash
photo_hash = Photo.hash_from_post_ids post_ids
:person => post.person,
:comments => comment_hash[post.id].map do |comment|
{:comment => comment,
:person => person_hash[comment.person_id],
}
end,
}
end
end