diff --git a/app/assets/stylesheets/layout.css.sass b/app/assets/stylesheets/layout.css.sass index 036b0f36..dcfb4a67 100644 --- a/app/assets/stylesheets/layout.css.sass +++ b/app/assets/stylesheets/layout.css.sass @@ -187,7 +187,6 @@ body.blur color: #fff font-weight: bold - // Sticky footer html, body height: 100% diff --git a/app/assets/stylesheets/users.css.sass b/app/assets/stylesheets/users.css.sass index 0357bd52..2d1bfe4c 100644 --- a/app/assets/stylesheets/users.css.sass +++ b/app/assets/stylesheets/users.css.sass @@ -1,7 +1,6 @@ #users-show #user-profile @include white-box - background-color: rgba(0,0,0,.7) padding: 20px margin: bottom: 60px @@ -13,8 +12,6 @@ margin-right: 20px #user-panel - h1, h5 - color: #fff h1 margin: 0 @@ -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 diff --git a/app/controllers/devise_extensions/registrations_controller.rb b/app/controllers/devise_extensions/registrations_controller.rb index f3e7f7e5..5d130d4e 100644 --- a/app/controllers/devise_extensions/registrations_controller.rb +++ b/app/controllers/devise_extensions/registrations_controller.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 21a2ca3e..1338492b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 @@ -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 diff --git a/app/views/devise/registrations/edit.html.slim b/app/views/devise/registrations/edit.html.slim index ebc4515c..29e88cbc 100644 --- a/app/views/devise/registrations/edit.html.slim +++ b/app/views/devise/registrations/edit.html.slim @@ -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" diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml index 5b71b3f0..14b52fc7 100644 --- a/config/locales/simple_form.en.yml +++ b/config/locales/simple_form.en.yml @@ -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: @@ -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: diff --git a/db/migrate/20130731183731_add_profile_background_fields_to_user.rb b/db/migrate/20130731183731_add_profile_background_fields_to_user.rb new file mode 100644 index 00000000..4b9ce2fc --- /dev/null +++ b/db/migrate/20130731183731_add_profile_background_fields_to_user.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index e33fe549..26a5d9b6 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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 ); @@ -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'); diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index fb5fac9c..58e1bf56 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -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 }