diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9e00b9171..ef025efb9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 60a53a381..64665147f 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 03c4a95f8..61196f288 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -21,8 +21,10 @@ class UsersController < ApplicationController 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(:language) if params[:user][:language].blank? + - # change email notifications + + # change email notifications if params[:user][:disable_mail] @user.update_attributes(:disable_mail => params[:user][:disable_mail]) flash[:notice] = I18n.t 'users.update.email_notifications_changed' @@ -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) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6d79922d3..13839af12 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -135,7 +135,7 @@ module ApplicationHelper end def person_image_tag(person, size=:thumb_small) - "\"#{h(person.name)}\"".html_safe + "\"#{h(person.name)}\"".html_safe end def person_link(person) diff --git a/db/migrate/20110201013408_add_open_aspects_to_user.rb b/db/migrate/20110201013408_add_open_aspects_to_user.rb new file mode 100644 index 000000000..11d7f9470 --- /dev/null +++ b/db/migrate/20110201013408_add_open_aspects_to_user.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 78e1b15fe..1cffb2288 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -24,13 +24,14 @@ ActiveRecord::Schema.define(:version => 20110130072907) do add_index "aspect_memberships", ["contact_id"], :name => "index_aspect_memberships_on_contact_id" create_table "aspects", :force => true do |t| - t.string "name", :null => false - t.integer "user_id", :null => false + t.string "name", :null => false + t.integer "user_id", :null => false t.datetime "created_at" t.datetime "updated_at" t.string "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 add_index "aspects", ["mongo_id"], :name => "index_aspects_on_mongo_id" diff --git a/public/javascripts/aspect-filters.js b/public/javascripts/aspect-filters.js index 4b59482c1..83de67d5e 100644 --- a/public/javascripts/aspect-filters.js +++ b/public/javascripts/aspect-filters.js @@ -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 = {}; @@ -150,14 +176,16 @@ $(document).ready(function(){ // reinit listeners on stream photozone.html(photos_html); Stream.initialize(); - + // fade contents back in if(requests == 0){ $("#aspect_stream_container").fadeTo(100, 1); $("#aspect_contact_pictures").fadeTo(100, 1); + performAspectUpdate(); } } }); + } }); diff --git a/spec/controllers/home_controller_spec.rb b/spec/controllers/home_controller_spec.rb index fd151a0b4..ab29b6d1d 100644 --- a/spec/controllers/home_controller_spec.rb +++ b/spec/controllers/home_controller_spec.rb @@ -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 diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 628bd5531..cad5f459a 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -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',