Some view helper cleanup
This commit is contained in:
parent
1cd3ef4971
commit
af6547815e
8 changed files with 17 additions and 61 deletions
|
|
@ -16,8 +16,8 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
inflection_method :grammatical_gender => :gender
|
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
|
def ensure_http_referer_is_set
|
||||||
request.env['HTTP_REFERER'] ||= '/aspects'
|
request.env['HTTP_REFERER'] ||= '/aspects'
|
||||||
end
|
end
|
||||||
|
|
@ -34,16 +34,8 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
|
|
||||||
##helpers
|
##helpers
|
||||||
def object_aspect_ids
|
|
||||||
if user_signed_in?
|
|
||||||
@object_aspect_ids ||= []
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def all_aspects
|
def all_aspects
|
||||||
if user_signed_in?
|
@all_aspects ||= current_user.aspects
|
||||||
@all_aspects ||= current_user.aspects
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def all_contacts_count
|
def all_contacts_count
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,11 @@ class AspectsController < ApplicationController
|
||||||
params[:max_time] ||= Time.now + 1
|
params[:max_time] ||= Time.now + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
helper_method :all_aspects_selected?
|
||||||
|
def all_aspects_selected?
|
||||||
|
@aspect == :all
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def save_sort_order
|
def save_sort_order
|
||||||
if params[:sort_order].present?
|
if params[:sort_order].present?
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@
|
||||||
class PhotosController < ApplicationController
|
class PhotosController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
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
|
respond_to :html, :json
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@post_type = :photos
|
@post_type = :photos
|
||||||
@person = Person.find_by_id(params[:person_id])
|
@person = Person.find_by_id(params[:person_id])
|
||||||
|
|
@ -181,15 +181,6 @@ class PhotosController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
# helpers
|
# 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
|
def ownership
|
||||||
@ownership ||= current_user.owns? photo
|
@ownership ||= current_user.owns? photo
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,6 @@ class StatusMessagesController < ApplicationController
|
||||||
respond_to :json, :only => :show
|
respond_to :json, :only => :show
|
||||||
|
|
||||||
|
|
||||||
helper_method :object_aspect_ids
|
|
||||||
|
|
||||||
# Called when a user clicks "Mention" on a profile page
|
# Called when a user clicks "Mention" on a profile page
|
||||||
# @option [Integer] person_id The id of the person to be mentioned
|
# @option [Integer] person_id The id of the person to be mentioned
|
||||||
def new
|
def new
|
||||||
|
|
@ -110,7 +108,6 @@ class StatusMessagesController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@status_message = current_user.find_visible_post_by_id params[:id]
|
@status_message = current_user.find_visible_post_by_id params[:id]
|
||||||
if @status_message
|
if @status_message
|
||||||
@object_aspect_ids = @status_message.aspects.map{|a| a.id}
|
|
||||||
|
|
||||||
# mark corresponding notification as read
|
# mark corresponding notification as read
|
||||||
if notification = Notification.where(:recipient_id => current_user.id, :target_id => @status_message.id).first
|
if notification = Notification.where(:recipient_id => current_user.id, :target_id => @status_message.id).first
|
||||||
|
|
@ -126,11 +123,4 @@ class StatusMessagesController < ApplicationController
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ class VannaController < Vanna::Base
|
||||||
before_filter :set_git_header if (AppConfig[:git_update] && AppConfig[:git_revision])
|
before_filter :set_git_header if (AppConfig[:git_update] && AppConfig[:git_revision])
|
||||||
before_filter :which_action_and_user
|
before_filter :which_action_and_user
|
||||||
before_filter :all_aspects
|
before_filter :all_aspects
|
||||||
before_filter :object_aspect_ids
|
|
||||||
prepend_before_filter :clear_gc_stats
|
prepend_before_filter :clear_gc_stats
|
||||||
before_filter :set_grammatical_gender
|
before_filter :set_grammatical_gender
|
||||||
|
|
||||||
|
|
@ -41,7 +40,6 @@ class VannaController < Vanna::Base
|
||||||
@notification_count = Notification.for(current_user, :unread =>true).count
|
@notification_count = Notification.for(current_user, :unread =>true).count
|
||||||
@unread_message_count = ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}")
|
@unread_message_count = ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}")
|
||||||
end
|
end
|
||||||
@object_aspect_ids = []
|
|
||||||
@all_aspects = current_user.aspects
|
@all_aspects = current_user.aspects
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -56,16 +54,8 @@ class VannaController < Vanna::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def object_aspect_ids
|
|
||||||
if user_signed_in?
|
|
||||||
@object_aspect_ids ||= []
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def all_aspects
|
def all_aspects
|
||||||
if user_signed_in?
|
@all_aspects ||= current_user.aspects
|
||||||
@all_aspects ||= current_user.aspects
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_git_header
|
def set_git_header
|
||||||
|
|
@ -130,6 +120,6 @@ class VannaController < Vanna::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_sign_in_path_for(resource)
|
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -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' ))
|
= link_to_if(session[:sort_order] == 'updated_at', t('.posted'), aspects_path(:a_ids => params[:a_ids], :sort_order => 'created_at' ))
|
||||||
|
|
||||||
%h3
|
%h3
|
||||||
- if @aspect == :all
|
- if all_aspects_selected?
|
||||||
= t('.stream')
|
= t('.stream')
|
||||||
- else
|
- else
|
||||||
= @aspects.to_sentence
|
= @aspects.to_sentence
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#selected_aspect_contacts.section
|
#selected_aspect_contacts.section
|
||||||
.title.no_icon
|
.title.no_icon
|
||||||
%h5
|
%h5
|
||||||
- if @aspect == :all || @aspect_ids.size > 1
|
- if @aspect_ids.size > 1
|
||||||
= "#{t('_contacts')}"
|
= "#{t('_contacts')}"
|
||||||
- else
|
- else
|
||||||
= @aspect.name
|
= @aspect.name
|
||||||
|
|
|
||||||
|
|
@ -186,26 +186,14 @@ describe PhotosController do
|
||||||
|
|
||||||
|
|
||||||
describe 'data helpers' 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
|
describe '.ownership' do
|
||||||
it 'is true if current user owns the photo' 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
|
@controller.ownership.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'is true if current user owns the photo' do
|
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
|
@controller.ownership.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -229,7 +217,7 @@ describe PhotosController do
|
||||||
it 'returns a visible photo, based on the :id param' do
|
it 'returns a visible photo, based on the :id param' do
|
||||||
get :show, :id => @alices_photo.id
|
get :show, :id => @alices_photo.id
|
||||||
@controller.photo.id.should == @alices_photo.id
|
@controller.photo.id.should == @alices_photo.id
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue