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 = []
|
@object_aspect_ids = []
|
||||||
@all_aspects = current_user.aspects.includes(:aspect_memberships)
|
@all_aspects = current_user.aspects.includes(:aspect_memberships)
|
||||||
@notification_count = Notification.for(current_user, :unread =>true).count
|
@notification_count = Notification.for(current_user, :unread =>true).count
|
||||||
|
@user_id = current_user.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,11 @@ class HomeController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
if current_user
|
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?
|
elsif is_mobile_device?
|
||||||
redirect_to user_session_path
|
redirect_to user_session_path
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,10 @@ class UsersController < ApplicationController
|
||||||
params[:user].delete(:password) if params[:user][:password].blank?
|
params[:user].delete(:password) if params[:user][:password].blank?
|
||||||
params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank?
|
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?
|
params[:user].delete(:language) if params[:user][:language].blank?
|
||||||
|
|
||||||
|
|
||||||
# change email notifications
|
|
||||||
|
# change email notifications
|
||||||
if params[:user][:disable_mail]
|
if params[:user][:disable_mail]
|
||||||
@user.update_attributes(:disable_mail => params[:user][:disable_mail])
|
@user.update_attributes(:disable_mail => params[:user][:disable_mail])
|
||||||
flash[:notice] = I18n.t 'users.update.email_notifications_changed'
|
flash[:notice] = I18n.t 'users.update.email_notifications_changed'
|
||||||
|
|
@ -39,6 +41,11 @@ class UsersController < ApplicationController
|
||||||
else
|
else
|
||||||
flash[:error] = I18n.t 'users.update.language_not_changed'
|
flash[:error] = I18n.t 'users.update.language_not_changed'
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
redirect_to edit_user_path(@user)
|
redirect_to edit_user_path(@user)
|
||||||
|
|
|
||||||
|
|
@ -135,7 +135,7 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def person_image_tag(person, size=:thumb_small)
|
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
|
end
|
||||||
|
|
||||||
def person_link(person)
|
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
|
||||||
|
|
@ -24,13 +24,14 @@ ActiveRecord::Schema.define(:version => 20110130072907) do
|
||||||
add_index "aspect_memberships", ["contact_id"], :name => "index_aspect_memberships_on_contact_id"
|
add_index "aspect_memberships", ["contact_id"], :name => "index_aspect_memberships_on_contact_id"
|
||||||
|
|
||||||
create_table "aspects", :force => true do |t|
|
create_table "aspects", :force => true do |t|
|
||||||
t.string "name", :null => false
|
t.string "name", :null => false
|
||||||
t.integer "user_id", :null => false
|
t.integer "user_id", :null => false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.string "mongo_id"
|
t.string "mongo_id"
|
||||||
t.string "user_mongo_id"
|
t.string "user_mongo_id"
|
||||||
t.boolean "contacts_visible", :default => true, :null => false
|
t.boolean "contacts_visible", :default => true, :null => false
|
||||||
|
t.boolean "open", :default => false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "aspects", ["mongo_id"], :name => "index_aspects_on_mongo_id"
|
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){
|
$("a.hard_aspect_link").live("click", function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
requests++;
|
requests++;
|
||||||
|
|
@ -101,6 +102,31 @@ $(document).ready(function(){
|
||||||
return baseURL;
|
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) {
|
function performAjax(newURL) {
|
||||||
var post = $("#publisher textarea").val(),
|
var post = $("#publisher textarea").val(),
|
||||||
photos = {};
|
photos = {};
|
||||||
|
|
@ -150,14 +176,16 @@ $(document).ready(function(){
|
||||||
// reinit listeners on stream
|
// reinit listeners on stream
|
||||||
photozone.html(photos_html);
|
photozone.html(photos_html);
|
||||||
Stream.initialize();
|
Stream.initialize();
|
||||||
|
|
||||||
// fade contents back in
|
// fade contents back in
|
||||||
if(requests == 0){
|
if(requests == 0){
|
||||||
$("#aspect_stream_container").fadeTo(100, 1);
|
$("#aspect_stream_container").fadeTo(100, 1);
|
||||||
$("#aspect_contact_pictures").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
|
it 'redirects to aspects index if user is logged in' do
|
||||||
sign_in @user
|
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
|
get :show
|
||||||
response.should redirect_to aspects_path
|
response.should redirect_to( :controller => 'aspects', :action => 'index', :a_ids => @index_params[:a_ids] )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ describe UsersController do
|
||||||
before do
|
before do
|
||||||
@user = alice
|
@user = alice
|
||||||
@aspect = @user.aspects.first
|
@aspect = @user.aspects.first
|
||||||
|
@aspect1 = @user.aspects.create(:name => "super!!")
|
||||||
sign_in :user, @user
|
sign_in :user, @user
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -29,6 +30,24 @@ describe UsersController do
|
||||||
}.should_not change(@user, :diaspora_handle)
|
}.should_not change(@user, :diaspora_handle)
|
||||||
end
|
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
|
context 'password updates' do
|
||||||
before do
|
before do
|
||||||
@password_params = {:current_password => 'bluepin7',
|
@password_params = {:current_password => 'bluepin7',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue