Merge branch 'open-aspects'
Conflicts: app/controllers/aspects_controller.rb app/controllers/home_controller.rb app/helpers/application_helper.rb db/migrate/20110201013408_add_open_aspects_to_user.rb spec/controllers/aspects_controller_spec.rb spec/controllers/home_controller_spec.rb
This commit is contained in:
commit
21e3c2ae73
9 changed files with 88 additions and 8 deletions
|
|
@ -18,6 +18,7 @@ class ApplicationController < ActionController::Base
|
|||
@object_aspect_ids = []
|
||||
@all_aspects = current_user.aspects.includes(:aspect_memberships)
|
||||
@notification_count = Notification.for(current_user, :unread =>true).count
|
||||
@user_id = current_user.id
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ class HomeController < ApplicationController
|
|||
|
||||
def show
|
||||
if current_user
|
||||
redirect_to aspects_path
|
||||
if params[:home]
|
||||
redirect_to :controller => 'aspects', :action => 'index'
|
||||
else
|
||||
redirect_to :controller => 'aspects', :action => 'index', :a_ids => current_user.aspects.where(:open => true).select(:id).all
|
||||
end
|
||||
elsif is_mobile_device?
|
||||
redirect_to user_session_path
|
||||
else
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ class UsersController < ApplicationController
|
|||
params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
|
||||
params[:user].delete(:language) if params[:user][:language].blank?
|
||||
|
||||
|
||||
|
||||
# change email notifications
|
||||
if params[:user][:disable_mail]
|
||||
@user.update_attributes(:disable_mail => params[:user][:disable_mail])
|
||||
|
|
@ -39,6 +41,11 @@ class UsersController < ApplicationController
|
|||
else
|
||||
flash[:error] = I18n.t 'users.update.language_not_changed'
|
||||
end
|
||||
elsif params[:user][:a_ids]
|
||||
@user.aspects.update_all(:open => false)
|
||||
unless params[:user][:a_ids] == ["home"]
|
||||
@user.aspects.where(:id => params[:user][:a_ids]).update_all(:open => true)
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to edit_user_path(@user)
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ module ApplicationHelper
|
|||
end
|
||||
|
||||
def person_image_tag(person, size=:thumb_small)
|
||||
"<img alt=\"#{h(person.name)}\" class=\"avatar\" data-person_id=\"#{person.id}\" src=\"#{person.profile.image_url(size)}\" title=\"#{h(person.name)}\">".html_safe
|
||||
"<img alt=\"#{h(person.name)}\" class=\"avatar\" #{("data-owner_id="+@user_id.to_s) if @user_id} data-person_id=\"#{person.id}\" src=\"#{image_or_default(person, size)}\" title=\"#{h(person.name)}\">".html_safe
|
||||
end
|
||||
|
||||
def person_link(person)
|
||||
|
|
|
|||
9
db/migrate/20110201013408_add_open_aspects_to_user.rb
Normal file
9
db/migrate/20110201013408_add_open_aspects_to_user.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class AddOpenAspectsToUser < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column(:aspects, :open, :boolean, :default => false)
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column(:aspects, :open)
|
||||
end
|
||||
end
|
||||
|
|
@ -31,6 +31,7 @@ ActiveRecord::Schema.define(:version => 20110130072907) do
|
|||
t.string "mongo_id"
|
||||
t.string "user_mongo_id"
|
||||
t.boolean "contacts_visible", :default => true, :null => false
|
||||
t.boolean "open", :default => false
|
||||
end
|
||||
|
||||
add_index "aspects", ["mongo_id"], :name => "index_aspects_on_mongo_id"
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ $(document).ready(function(){
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
$("a.hard_aspect_link").live("click", function(e){
|
||||
e.preventDefault();
|
||||
requests++;
|
||||
|
|
@ -101,6 +102,31 @@ $(document).ready(function(){
|
|||
return baseURL;
|
||||
}
|
||||
|
||||
$("a.home_selector").live("click", function(e){
|
||||
performAspectUpdate("home");
|
||||
});
|
||||
|
||||
function performAspectUpdate(home){
|
||||
// update the open aspects in the user
|
||||
updateURL = "/users/" + $('div.avatar').children('img').attr("data-owner_id");
|
||||
updateURL += '?';
|
||||
if(home == 'home'){
|
||||
updateURL += 'user[a_ids][]=home';
|
||||
} else {
|
||||
for(i=0; i < selectedGUIDS.length; i++){
|
||||
updateURL += 'user[a_ids][]='+ selectedGUIDS[i] +'&';
|
||||
}
|
||||
}
|
||||
|
||||
//alert(updateURL);
|
||||
$.ajax({
|
||||
url : updateURL,
|
||||
type: "PUT",
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function performAjax(newURL) {
|
||||
var post = $("#publisher textarea").val(),
|
||||
photos = {};
|
||||
|
|
@ -155,9 +181,11 @@ $(document).ready(function(){
|
|||
if(requests == 0){
|
||||
$("#aspect_stream_container").fadeTo(100, 1);
|
||||
$("#aspect_contact_pictures").fadeTo(100, 1);
|
||||
performAspectUpdate();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -22,8 +22,19 @@ describe HomeController do
|
|||
|
||||
it 'redirects to aspects index if user is logged in' do
|
||||
sign_in @user
|
||||
get :show, :home => true
|
||||
response.should redirect_to( :controller => 'aspects', :action => 'index')
|
||||
end
|
||||
|
||||
it 'redirects to aspects index with stored aspects' do
|
||||
sign_in @user
|
||||
@aspect0 = @user.aspects.all[0]
|
||||
@aspect1 = @user.aspects.create(:name => "Yeaaaah!")
|
||||
@index_params = {:a_ids => [@aspect0.id.to_s, @aspect1.id.to_s]}
|
||||
@user.aspects.where(:id => @index_params[:a_ids]).update_all(:open => true)
|
||||
@user.save
|
||||
get :show
|
||||
response.should redirect_to aspects_path
|
||||
response.should redirect_to( :controller => 'aspects', :action => 'index', :a_ids => @index_params[:a_ids] )
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ describe UsersController do
|
|||
before do
|
||||
@user = alice
|
||||
@aspect = @user.aspects.first
|
||||
@aspect1 = @user.aspects.create(:name => "super!!")
|
||||
sign_in :user, @user
|
||||
end
|
||||
|
||||
|
|
@ -29,6 +30,24 @@ describe UsersController do
|
|||
}.should_not change(@user, :diaspora_handle)
|
||||
end
|
||||
|
||||
context "open aspects" do
|
||||
before do
|
||||
@index_params = {:id => @user.id, :user => {:a_ids => [@aspect.id.to_s, @aspect1.id.to_s]} }
|
||||
end
|
||||
|
||||
it "stores the aspect params in the user" do
|
||||
put :update, @index_params
|
||||
@user.reload.aspects.where(:open => true).all.to_set.should == [@aspect, @aspect1].to_set
|
||||
end
|
||||
|
||||
it "correctly resets the home state" do
|
||||
@index_params[:user][:a_ids] = ["home"]
|
||||
|
||||
put :update, @index_params
|
||||
@user.aspects.where(:open => true).should == []
|
||||
end
|
||||
end
|
||||
|
||||
context 'password updates' do
|
||||
before do
|
||||
@password_params = {:current_password => 'bluepin7',
|
||||
|
|
|
|||
Loading…
Reference in a new issue