Skip to content

Commit

Permalink
Merge pull request #135 from robotmay/profile-background-options
Browse files Browse the repository at this point in the history
Add options for profile backgrounds
  • Loading branch information
Robert May committed Jul 31, 2013
2 parents b25be23 + 4bde519 commit 3f3969d
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 19 deletions.
1 change: 0 additions & 1 deletion app/assets/stylesheets/layout.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ body.blur
color: #fff
font-weight: bold


// Sticky footer
html, body
height: 100%
Expand Down
13 changes: 9 additions & 4 deletions app/assets/stylesheets/users.css.sass
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#users-show
#user-profile
@include white-box
background-color: rgba(0,0,0,.7)
padding: 20px
margin:
bottom: 60px
Expand All @@ -13,8 +12,6 @@
margin-right: 20px

#user-panel
h1, h5
color: #fff
h1
margin: 0

Expand All @@ -23,7 +20,15 @@

#user-biography
font-size: 0.9em
color: #fff

body.blur
#users-show
#user-profile
background-color: rgba(0,0,0,.7)

h1, h2, h3, h4, h5, h6, p, span
color: #fff


#users-new, #sessions-new, #invitations-new, #invitations-edit
#sign-up-area, #sign-in-area
Expand Down
26 changes: 15 additions & 11 deletions app/controllers/devise_extensions/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,21 @@ def after_update_path_for(resource)

private
def user_params
params.require(:user).permit(:email, :password, :password_confirmation,
:name, :location, :avatar, :retained_avatar,
:remove_avatar, :show_copyright_info,
:show_location_data, :show_nsfw_content,
:default_license_id, :website_url, :biography,
:receive_notification_emails, :notify_favourites,
:show_social_buttons, :username, :locale,
:enable_comments_by_default,
:default_comment_threads_attributes => [
:id, :subject, :_destroy
])
params.require(:user).permit(
:email, :password, :password_confirmation,
:name, :location, :avatar, :retained_avatar,
:remove_avatar, :show_copyright_info,
:show_location_data, :show_nsfw_content,
:default_license_id, :website_url, :biography,
:receive_notification_emails, :notify_favourites,
:show_social_buttons, :username, :locale,
:enable_comments_by_default,
:show_profile_background,
:profile_background_photo_id,
:default_comment_threads_attributes => [
:id, :subject, :_destroy
]
)
end

def configure_permitted_parameters
Expand Down
11 changes: 9 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class User < ActiveRecord::Base
validates :email, :name, presence: true
validates :username, presence: true, uniqueness: { case_sensitive: false }, format: { with: /\A[a-zA-Z0-9_]*[a-zA-Z][a-zA-Z0-9_]*\z/, message: I18n.t("users.username_format") }, length: { maximum: 50 }
validates :website_url, format: URI::regexp(%w(http https)), allow_blank: true
validates :profile_background_photo_id, inclusion: { in: -> (user) { user.photographs.pluck(:id) } }, allow_blank: true
validate :username_has_not_been_used
validate :username_quota_not_exceeded

Expand Down Expand Up @@ -165,8 +166,14 @@ def unread_notifications
end

def profile_background_photo
#TODO Allow user to choose this
photographs.visible.order("RANDOM()").first
if show_profile_background
id = profile_background_photo_id
if id.present?
photographs.find(id)
else
photographs.visible.order("RANDOM()").first
end
end
end

def build_default_comment_threads
Expand Down
7 changes: 7 additions & 0 deletions app/views/devise/registrations/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
div class="large-3 columns"
= f.input :locale, as: :select, collection: t("locales", default: []).map(&:reverse), include_blank: false

div class="row"
div class="large-3 columns"
= f.input :show_profile_background, as: :radio_buttons

div class="large-3 columns"
= f.input :profile_background_photo_id, collection: f.object.photographs.order("created_at DESC")

div class="row"
div class="large-8 columns"
div class="panel"
Expand Down
10 changes: 10 additions & 0 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ en:
show_social_buttons: "Show social buttons"
locale: "Locale"
enable_comments_by_default: "Enable comments by default"
show_profile_background: "Show profile background"
profile_background_photo_id: "Profile background photo"

placeholders:
comment_thread:
Expand Down Expand Up @@ -159,6 +161,14 @@ en:
Set the default comment threads to be used for your photographs here.
You can set defaults without enabling commenting by default.
show_profile_background: >
If you don't want to display a large photograph as the background to your
public profile page, you can disable it here.
profile_background_photo_id: >
You can pick a specific photo for your profile background. By default it
will be a random public photo from your uploads.
helpers:
submit:
comment:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddProfileBackgroundFieldsToUser < ActiveRecord::Migration
def change
add_column :users, :show_profile_background, :boolean, default: true
add_column :users, :profile_background_photo_id, :integer
end
end
6 changes: 5 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,9 @@ CREATE TABLE users (
username character varying(255),
locale character varying(255) DEFAULT 'en'::character varying,
enable_comments_by_default boolean DEFAULT false,
moderator boolean DEFAULT false
moderator boolean DEFAULT false,
show_profile_background boolean DEFAULT true,
profile_background_photo_id integer
);


Expand Down Expand Up @@ -1439,3 +1441,5 @@ INSERT INTO schema_migrations (version) VALUES ('20130718220746');
INSERT INTO schema_migrations (version) VALUES ('20130719122054');

INSERT INTO schema_migrations (version) VALUES ('20130728122457');

INSERT INTO schema_migrations (version) VALUES ('20130731183731');
34 changes: 34 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,40 @@
end
end

describe "#profile_background_photo" do
let(:user) { User.make }

context "show profile background" do
let(:photograph) { Photograph.make }
before { user.stub(:show_profile_background) { true } }

context "photo is set" do
before { user.stub(:profile_background_photo_id) { 1 } }
before { user.stub_chain(:photographs, :find) { photograph } }

it "returns the chosen photo" do
user.profile_background_photo.should eq(photograph)
end
end

context "photo is not set" do
before { user.stub_chain(:photographs, :visible, :order, :first) { photograph } }

it "displays a random photo" do
user.profile_background_photo.should eq(photograph)
end
end
end

context "don't show profile background" do
before { user.stub(:show_profile_background) { false } }

it "returns nil" do
user.profile_background_photo.should be_nil
end
end
end

describe "destroy" do
let(:mock_args) do
{ :[]= => true, :save => true, :destroyed_by_association= => true }
Expand Down

0 comments on commit 3f3969d

Please sign in to comment.