Some view helper cleanup

This commit is contained in:
Raphael Sofaer 2011-07-03 17:54:14 -07:00
parent 1cd3ef4971
commit af6547815e
8 changed files with 17 additions and 61 deletions

View file

@ -16,8 +16,8 @@ class ApplicationController < ActionController::Base
inflection_method :grammatical_gender => :gender
helper_method :all_aspects, :object_aspect_ids, :all_contacts_count, :my_contacts_count, :only_sharing_count
helper_method :all_aspects, :all_contacts_count, :my_contacts_count, :only_sharing_count
def ensure_http_referer_is_set
request.env['HTTP_REFERER'] ||= '/aspects'
end
@ -34,16 +34,8 @@ class ApplicationController < ActionController::Base
##helpers
def object_aspect_ids
if user_signed_in?
@object_aspect_ids ||= []
end
end
def all_aspects
if user_signed_in?
@all_aspects ||= current_user.aspects
end
@all_aspects ||= current_user.aspects
end
def all_contacts_count

View file

@ -158,6 +158,11 @@ class AspectsController < ApplicationController
params[:max_time] ||= Time.now + 1
end
helper_method :all_aspects_selected?
def all_aspects_selected?
@aspect == :all
end
private
def save_sort_order
if params[:sort_order].present?

View file

@ -5,11 +5,11 @@
class PhotosController < ApplicationController
before_filter :authenticate_user!
helper_method :object_aspect_ids, :parent, :photo, :additional_photos, :next_photo, :previous_photo, :ownership
helper_method :parent, :photo, :additional_photos, :next_photo, :previous_photo, :ownership
respond_to :html, :json
def index
@post_type = :photos
@person = Person.find_by_id(params[:person_id])
@ -181,15 +181,6 @@ class PhotosController < ApplicationController
end
# helpers
# used on the show page to show which aspects are selected
def object_aspect_ids
if params[:action] == 'show' && parent_aspects = parent.aspects.where(:user_id => current_user.id).all
@object_aspect_ids ||= parent_aspects.map{|a| a.id}
else
super
end
end
def ownership
@ownership ||= current_user.owns? photo

View file

@ -10,8 +10,6 @@ class StatusMessagesController < ApplicationController
respond_to :json, :only => :show
helper_method :object_aspect_ids
# Called when a user clicks "Mention" on a profile page
# @option [Integer] person_id The id of the person to be mentioned
def new
@ -110,7 +108,6 @@ class StatusMessagesController < ApplicationController
def show
@status_message = current_user.find_visible_post_by_id params[:id]
if @status_message
@object_aspect_ids = @status_message.aspects.map{|a| a.id}
# mark corresponding notification as read
if notification = Notification.where(:recipient_id => current_user.id, :target_id => @status_message.id).first
@ -126,11 +123,4 @@ class StatusMessagesController < ApplicationController
end
end
def object_aspect_ids
if params[:action] == 'show'
@object_aspect_ids ||= @status_message.aspects.map{|a| a.id}
else
super
end
end
end

View file

@ -26,7 +26,6 @@ class VannaController < Vanna::Base
before_filter :set_git_header if (AppConfig[:git_update] && AppConfig[:git_revision])
before_filter :which_action_and_user
before_filter :all_aspects
before_filter :object_aspect_ids
prepend_before_filter :clear_gc_stats
before_filter :set_grammatical_gender
@ -41,7 +40,6 @@ class VannaController < Vanna::Base
@notification_count = Notification.for(current_user, :unread =>true).count
@unread_message_count = ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}")
end
@object_aspect_ids = []
@all_aspects = current_user.aspects
end
end
@ -56,16 +54,8 @@ class VannaController < Vanna::Base
end
end
def object_aspect_ids
if user_signed_in?
@object_aspect_ids ||= []
end
end
def all_aspects
if user_signed_in?
@all_aspects ||= current_user.aspects
end
@all_aspects ||= current_user.aspects
end
def set_git_header
@ -130,6 +120,6 @@ class VannaController < Vanna::Base
end
def after_sign_in_path_for(resource)
stored_location_for(:user) || aspects_path(:a_ids => current_user.aspects.where(:open => true).select(:id).all.map{|a| a.id})
stored_location_for(:user) || aspects_path(:a_ids => current_user.aspects.where(:open => true).select(:id).all.map{|a| a.id})
end
end

View file

@ -11,7 +11,7 @@
= link_to_if(session[:sort_order] == 'updated_at', t('.posted'), aspects_path(:a_ids => params[:a_ids], :sort_order => 'created_at' ))
%h3
- if @aspect == :all
- if all_aspects_selected?
= t('.stream')
- else
= @aspects.to_sentence

View file

@ -1,7 +1,7 @@
#selected_aspect_contacts.section
.title.no_icon
%h5
- if @aspect == :all || @aspect_ids.size > 1
- if @aspect_ids.size > 1
= "#{t('_contacts')}"
- else
= @aspect.name

View file

@ -186,26 +186,14 @@ describe PhotosController do
describe 'data helpers' do
describe '.object_aspect_ids' do
it 'on show, assigns object aspect ids' do
get :show, :id => @alices_photo.id
@controller.object_aspect_ids.should == [alice.aspects.first.id]
end
it 'on index, it is empty' do
get :index, :person_id => alice.person.id
@controller.object_aspect_ids.should == []
end
end
describe '.ownership' do
it 'is true if current user owns the photo' do
get :show, :id => @alices_photo.id
get :show, :id => @alices_photo.id
@controller.ownership.should be_true
end
it 'is true if current user owns the photo' do
get :show, :id => @bobs_photo.id
get :show, :id => @bobs_photo.id
@controller.ownership.should be_false
end
end
@ -229,7 +217,7 @@ describe PhotosController do
it 'returns a visible photo, based on the :id param' do
get :show, :id => @alices_photo.id
@controller.photo.id.should == @alices_photo.id
end
end