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
|
class ApplicationController < ActionController::Base
|
||||||
has_mobile_fu
|
has_mobile_fu
|
||||||
|
helper_method :all_aspects
|
||||||
protect_from_forgery :except => :receive
|
protect_from_forgery :except => :receive
|
||||||
|
|
||||||
before_filter :ensure_http_referer_is_set
|
before_filter :ensure_http_referer_is_set
|
||||||
before_filter :set_header_data, :except => [:create, :update]
|
before_filter :set_header_data, :except => [:create, :update]
|
||||||
before_filter :set_invites
|
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}")
|
@unread_message_count = ConversationVisibility.sum(:unread, :conditions => "person_id = #{current_user.person.id}")
|
||||||
end
|
end
|
||||||
@object_aspect_ids = []
|
@object_aspect_ids = []
|
||||||
@all_aspects = current_user.aspects
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def all_aspects
|
||||||
|
if user_signed_in?
|
||||||
|
@all_aspects ||= current_user.aspects
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def ensure_page
|
def ensure_page
|
||||||
params[:page] = params[:page] ? params[:page].to_i : 1
|
params[:page] = params[:page] ? params[:page].to_i : 1
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ class AspectsController < ApplicationController
|
||||||
def manage
|
def manage
|
||||||
@aspect = :manage
|
@aspect = :manage
|
||||||
@contacts = current_user.contacts.includes(:person => :profile)
|
@contacts = current_user.contacts.includes(:person => :profile)
|
||||||
@aspects = @all_aspects.includes(:contacts => {:person => :profile})
|
@aspects = all_aspects.includes(:contacts => {:person => :profile})
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
|
|
||||||
|
|
@ -6,20 +6,34 @@ class SocketsController < ApplicationController
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include SocketsHelper
|
include SocketsHelper
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
|
helper_method :all_aspects
|
||||||
|
|
||||||
|
|
||||||
def incoming(msg)
|
def incoming(msg)
|
||||||
Rails.logger.info("Socket received connection to: #{msg}")
|
Rails.logger.info("Socket received connection to: #{msg}")
|
||||||
end
|
end
|
||||||
|
|
||||||
def outgoing(user_or_id, object, opts={})
|
def outgoing(user_or_id, object, opts={})
|
||||||
if user_or_id.instance_of?(Fixnum)
|
#this should be the actual params of the controller
|
||||||
user_id = user_or_id
|
@params = {:user_or_id => user_or_id, :object => object}.merge(opts)
|
||||||
else
|
|
||||||
user_id = user_or_id.id
|
|
||||||
@user = user_or_id
|
|
||||||
end
|
|
||||||
return unless Diaspora::WebSocket.is_connected?(user_id)
|
return unless Diaspora::WebSocket.is_connected?(user_id)
|
||||||
@_request = ActionDispatch::Request.new({})
|
@_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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -34,17 +34,16 @@ module SocketsHelper
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
:current_user => user,
|
:current_user => user,
|
||||||
:all_aspects => user.aspects,
|
:all_aspects => all_aspects,
|
||||||
}
|
}
|
||||||
v = render_to_string(:partial => 'shared/stream_element', :locals => post_hash)
|
v = render_to_string(:partial => 'shared/stream_element', :locals => post_hash)
|
||||||
elsif object.is_a? Person
|
elsif object.is_a? Person
|
||||||
person_hash = {
|
person_hash = {
|
||||||
:single_aspect_form => opts["single_aspect_form"],
|
:single_aspect_form => opts["single_aspect_form"],
|
||||||
:person => object,
|
:person => object,
|
||||||
:all_aspects => user.aspects,
|
:all_aspects => all_aspects,
|
||||||
:contact => user.contact_for(object),
|
:contact => user.contact_for(object),
|
||||||
:current_user => user}
|
:current_user => user}
|
||||||
@all_aspects = user.aspects
|
|
||||||
v = render_to_string(:partial => 'people/person', :locals => person_hash)
|
v = render_to_string(:partial => 'people/person', :locals => person_hash)
|
||||||
|
|
||||||
elsif object.is_a? Comment
|
elsif object.is_a? Comment
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
.wrapper
|
.wrapper
|
||||||
%ul.dropdown_list{:unSelectable => 'on', 'data-person_id' => ((person.id) if person)}
|
%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)
|
= aspect_dropdown_list_item(aspect, contact, person)
|
||||||
|
|
||||||
- if defined?(@aspect) && ( @aspect == :profile || @aspect == :tag || @aspect == :search || @aspect == :notification)
|
- if defined?(@aspect) && ( @aspect == :profile || @aspect == :tag || @aspect == :search || @aspect == :notification)
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
%h4
|
%h4
|
||||||
= t('.aspect')
|
= 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
|
||||||
%br
|
%br
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
%li{:class => ('selected' if @aspect == :all)}
|
%li{:class => ('selected' if @aspect == :all)}
|
||||||
= link_to t('all_aspects'), aspects_path, :class => 'home_selector'
|
= 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))}
|
%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))
|
= 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'}}
|
%ul{:data => {:role => 'listview', :inset => 'true'}}
|
||||||
%li
|
%li
|
||||||
= link_to t('all_aspects'), aspects_path
|
= link_to t('all_aspects'), aspects_path
|
||||||
- for aspect in @all_aspects
|
- for aspect in all_aspects
|
||||||
%li
|
%li
|
||||||
= link_to aspect, aspects_path('a_ids[]' => aspect.id)
|
= link_to aspect, aspects_path('a_ids[]' => aspect.id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
- elsif current_user.invites > 0
|
- elsif current_user.invites > 0
|
||||||
= form_tag service_inviter_path(:provider => 'facebook') do
|
= 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
|
= hidden_field_tag :uid, friend.uid
|
||||||
= submit_tag t('.invite')
|
= submit_tag t('.invite')
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
.inset
|
.inset
|
||||||
%b= t('.your_aspects')
|
%b= t('.your_aspects')
|
||||||
%div{:data => {:role => 'controlgroup', :type => 'horizontal'}}
|
%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)
|
= link_to aspect, aspects_path('a_ids[]' => aspect.id)
|
||||||
|
|
|
|
||||||
.ui-bar
|
.ui-bar
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,5 @@
|
||||||
= render :partial => 'shared/stream_element',
|
= render :partial => 'shared/stream_element',
|
||||||
:collection => posts,
|
:collection => posts,
|
||||||
:as => :post,
|
:as => :post,
|
||||||
:locals => {:all_aspects => @all_aspects,
|
:locals => { :commenting_disabled => defined?(@commenting_disabled)}
|
||||||
:commenting_disabled => defined?(@commenting_disabled)}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ describe SocketsController do
|
||||||
|
|
||||||
describe 'actionhash' do
|
describe 'actionhash' do
|
||||||
it 'actionhashes posts' do
|
it 'actionhashes posts' do
|
||||||
|
@controller.instance_variable_set(:@params, {:user_or_id => @user, :object => @message})
|
||||||
json = @controller.action_hash(@user, @message)
|
json = @controller.action_hash(@user, @message)
|
||||||
json.include?(@message.text).should be_true
|
json.include?(@message.text).should be_true
|
||||||
json.include?('status_message').should be_true
|
json.include?('status_message').should be_true
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue