move all aspects to be a method, and cleaned up some sockets helper uglyness ms iz
This commit is contained in:
parent
dd67107ab1
commit
86f4f983f6
13 changed files with 43 additions and 23 deletions
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
class ApplicationController < ActionController::Base
|
||||
has_mobile_fu
|
||||
helper_method :all_aspects
|
||||
protect_from_forgery :except => :receive
|
||||
|
||||
before_filter :ensure_http_referer_is_set
|
||||
before_filter :set_header_data, :except => [:create, :update]
|
||||
before_filter :set_invites
|
||||
|
|
@ -29,10 +29,17 @@ class ApplicationController < ActionController::Base
|
|||
@unread_message_count = ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}")
|
||||
end
|
||||
@object_aspect_ids = []
|
||||
@all_aspects = current_user.aspects
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
def all_aspects
|
||||
if user_signed_in?
|
||||
@all_aspects ||= current_user.aspects
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def ensure_page
|
||||
params[:page] = params[:page] ? params[:page].to_i : 1
|
||||
end
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ class AspectsController < ApplicationController
|
|||
def manage
|
||||
@aspect = :manage
|
||||
@contacts = current_user.contacts.includes(:person => :profile)
|
||||
@aspects = @all_aspects.includes(:contacts => {:person => :profile})
|
||||
@aspects = all_aspects.includes(:contacts => {:person => :profile})
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
|||
|
|
@ -6,20 +6,34 @@ class SocketsController < ApplicationController
|
|||
include ApplicationHelper
|
||||
include SocketsHelper
|
||||
include Rails.application.routes.url_helpers
|
||||
|
||||
helper_method :all_aspects
|
||||
|
||||
|
||||
def incoming(msg)
|
||||
Rails.logger.info("Socket received connection to: #{msg}")
|
||||
end
|
||||
|
||||
def outgoing(user_or_id, object, opts={})
|
||||
if user_or_id.instance_of?(Fixnum)
|
||||
user_id = user_or_id
|
||||
else
|
||||
user_id = user_or_id.id
|
||||
@user = user_or_id
|
||||
end
|
||||
#this should be the actual params of the controller
|
||||
@params = {:user_or_id => user_or_id, :object => object}.merge(opts)
|
||||
return unless Diaspora::WebSocket.is_connected?(user_id)
|
||||
@_request = ActionDispatch::Request.new({})
|
||||
Diaspora::WebSocket.queue_to_user(user_id, action_hash(@user || User.find(user_id), object, opts))
|
||||
Diaspora::WebSocket.queue_to_user(user_id, action_hash(user, object, opts))
|
||||
end
|
||||
|
||||
def user_id
|
||||
if @params[:user_or_id].instance_of?(Fixnum)
|
||||
@user_id ||= @params[:user_or_id]
|
||||
else
|
||||
@user_id ||= @params[:user_or_id].id
|
||||
end
|
||||
end
|
||||
|
||||
def user
|
||||
@user ||= ((@params[:user_or_id].instance_of? User )? @params[:user_or_id] : User.find(user_id))
|
||||
end
|
||||
|
||||
def all_aspects
|
||||
@all_aspects ||= user.aspects
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -34,17 +34,16 @@ module SocketsHelper
|
|||
}
|
||||
},
|
||||
:current_user => user,
|
||||
:all_aspects => user.aspects,
|
||||
:all_aspects => all_aspects,
|
||||
}
|
||||
v = render_to_string(:partial => 'shared/stream_element', :locals => post_hash)
|
||||
elsif object.is_a? Person
|
||||
person_hash = {
|
||||
:single_aspect_form => opts["single_aspect_form"],
|
||||
:person => object,
|
||||
:all_aspects => user.aspects,
|
||||
:all_aspects => all_aspects,
|
||||
:contact => user.contact_for(object),
|
||||
:current_user => user}
|
||||
@all_aspects = user.aspects
|
||||
v = render_to_string(:partial => 'people/person', :locals => person_hash)
|
||||
|
||||
elsif object.is_a? Comment
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
.wrapper
|
||||
%ul.dropdown_list{:unSelectable => 'on', 'data-person_id' => ((person.id) if person)}
|
||||
- for aspect in @all_aspects
|
||||
- for aspect in all_aspects
|
||||
= aspect_dropdown_list_item(aspect, contact, person)
|
||||
|
||||
- if defined?(@aspect) && ( @aspect == :profile || @aspect == :tag || @aspect == :search || @aspect == :notification)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
%h4
|
||||
= t('.aspect')
|
||||
= invite.select(:aspects, options_from_collection_for_select(@all_aspects, 'id', 'name'))
|
||||
= invite.select(:aspects, options_from_collection_for_select(all_aspects, 'id', 'name'))
|
||||
|
||||
%br
|
||||
%br
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
%li{:class => ('selected' if @aspect == :all)}
|
||||
= link_to t('all_aspects'), aspects_path, :class => 'home_selector'
|
||||
|
||||
- for aspect in @all_aspects
|
||||
- for aspect in all_aspects
|
||||
%li{:data=>{:guid=>aspect.id}, :class => ("selected" if @object_aspect_ids.include?(aspect.id))}
|
||||
= link_for_aspect(aspect, :class => 'aspect_selector name', :title => t('contacts', :count => aspect.contacts.size))
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@
|
|||
%ul{:data => {:role => 'listview', :inset => 'true'}}
|
||||
%li
|
||||
= link_to t('all_aspects'), aspects_path
|
||||
- for aspect in @all_aspects
|
||||
- for aspect in all_aspects
|
||||
%li
|
||||
= link_to aspect, aspects_path('a_ids[]' => aspect.id)
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
- elsif current_user.invites > 0
|
||||
= form_tag service_inviter_path(:provider => 'facebook') do
|
||||
= select_tag(:aspect_id, options_from_collection_for_select(@all_aspects, 'id', 'name'))
|
||||
= select_tag(:aspect_id, options_from_collection_for_select(all_aspects, 'id', 'name'))
|
||||
= hidden_field_tag :uid, friend.uid
|
||||
= submit_tag t('.invite')
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
.inset
|
||||
%b= t('.your_aspects')
|
||||
%div{:data => {:role => 'controlgroup', :type => 'horizontal'}}
|
||||
- for aspect in @all_aspects
|
||||
- for aspect in all_aspects
|
||||
= link_to aspect, aspects_path('a_ids[]' => aspect.id)
|
||||
|
|
||||
.ui-bar
|
||||
|
|
|
|||
|
|
@ -6,6 +6,5 @@
|
|||
= render :partial => 'shared/stream_element',
|
||||
:collection => posts,
|
||||
:as => :post,
|
||||
:locals => {:all_aspects => @all_aspects,
|
||||
:commenting_disabled => defined?(@commenting_disabled)}
|
||||
:locals => { :commenting_disabled => defined?(@commenting_disabled)}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ describe SocketsController do
|
|||
|
||||
describe 'actionhash' do
|
||||
it 'actionhashes posts' do
|
||||
@controller.instance_variable_set(:@params, {:user_or_id => @user, :object => @message})
|
||||
json = @controller.action_hash(@user, @message)
|
||||
json.include?(@message.text).should be_true
|
||||
json.include?('status_message').should be_true
|
||||
|
|
@ -52,4 +53,4 @@ describe SocketsController do
|
|||
@controller.outgoing(@user, @message)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue