mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FEATURE: Allow a user to upload an image for their expansion background.
This commit is contained in:
parent
bde0820cd4
commit
4d465362b5
11 changed files with 112 additions and 9 deletions
|
@ -106,6 +106,16 @@
|
||||||
type="profile_background"}}
|
type="profile_background"}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="control-group pref-profile-bg">
|
||||||
|
<label class="control-label">{{i18n user.change_expansion_background.title}}</label>
|
||||||
|
<div class="controls">
|
||||||
|
{{image-uploader uploadUrl=imageUploadUrl
|
||||||
|
imageUrl=expansion_background
|
||||||
|
instantDelete="true"
|
||||||
|
type="expansion_background"}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if allowUserLocale}}
|
{{#if allowUserLocale}}
|
||||||
|
|
|
@ -7,6 +7,21 @@ var clickOutsideEventName = "mousedown.outside-user-expansion",
|
||||||
export default Discourse.View.extend(CleansUp, {
|
export default Discourse.View.extend(CleansUp, {
|
||||||
elementId: 'user-expansion',
|
elementId: 'user-expansion',
|
||||||
classNameBindings: ['controller.visible::hidden', 'controller.showBadges'],
|
classNameBindings: ['controller.visible::hidden', 'controller.showBadges'],
|
||||||
|
allowBackgrounds: Discourse.computed.setting('allow_profile_backgrounds'),
|
||||||
|
|
||||||
|
addBackground: function() {
|
||||||
|
var url = this.get('controller.user.expansion_background');
|
||||||
|
if (!this.get('allowBackgrounds')) { return; }
|
||||||
|
|
||||||
|
var $this = this.$();
|
||||||
|
if (!$this) { return; }
|
||||||
|
|
||||||
|
if (Ember.empty(url)) {
|
||||||
|
$this.css('background-image', '');
|
||||||
|
} else {
|
||||||
|
$this.css('background-image', "url(" + url + ")");
|
||||||
|
}
|
||||||
|
}.observes('controller.user.expansion_background'),
|
||||||
|
|
||||||
_setup: function() {
|
_setup: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
padding: 12px 12px 5px 12px;
|
padding: 12px 12px 5px 12px;
|
||||||
border: 1px solid scale-color-diff();
|
border: 1px solid scale-color-diff();
|
||||||
|
|
||||||
|
background-size: cover;
|
||||||
|
background-position: center center;
|
||||||
|
|
||||||
.avatar-placeholder {
|
.avatar-placeholder {
|
||||||
width: 120px;
|
width: 120px;
|
||||||
height: 120px;
|
height: 120px;
|
||||||
|
|
|
@ -461,6 +461,8 @@ class UsersController < ApplicationController
|
||||||
upload_avatar_for(user, upload)
|
upload_avatar_for(user, upload)
|
||||||
when "profile_background"
|
when "profile_background"
|
||||||
upload_profile_background_for(user.user_profile, upload)
|
upload_profile_background_for(user.user_profile, upload)
|
||||||
|
when "expansion_background"
|
||||||
|
upload_expansion_background_for(user.user_profile, upload)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
render status: 422, text: upload.errors.full_messages
|
render status: 422, text: upload.errors.full_messages
|
||||||
|
@ -490,6 +492,8 @@ class UsersController < ApplicationController
|
||||||
image_type = params.require(:image_type)
|
image_type = params.require(:image_type)
|
||||||
if image_type == 'profile_background'
|
if image_type == 'profile_background'
|
||||||
user.user_profile.clear_profile_background
|
user.user_profile.clear_profile_background
|
||||||
|
elsif image_type == 'expansion_background'
|
||||||
|
user.user_profile.clear_expansion_background
|
||||||
else
|
else
|
||||||
raise Discourse::InvalidParameters.new(:image_type)
|
raise Discourse::InvalidParameters.new(:image_type)
|
||||||
end
|
end
|
||||||
|
@ -547,8 +551,11 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
def upload_profile_background_for(user_profile, upload)
|
def upload_profile_background_for(user_profile, upload)
|
||||||
user_profile.upload_profile_background(upload)
|
user_profile.upload_profile_background(upload)
|
||||||
# TODO: add a resize job here
|
render json: { url: upload.url, width: upload.width, height: upload.height }
|
||||||
|
end
|
||||||
|
|
||||||
|
def upload_expansion_background_for(user_profile, upload)
|
||||||
|
user_profile.upload_expansion_background(upload)
|
||||||
render json: { url: upload.url, width: upload.width, height: upload.height }
|
render json: { url: upload.url, width: upload.width, height: upload.height }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ module Jobs
|
||||||
|
|
||||||
ignore_urls = []
|
ignore_urls = []
|
||||||
ignore_urls << UserProfile.uniq.where("profile_background IS NOT NULL AND profile_background != ''").pluck(:profile_background)
|
ignore_urls << UserProfile.uniq.where("profile_background IS NOT NULL AND profile_background != ''").pluck(:profile_background)
|
||||||
|
ignore_urls << UserProfile.uniq.where("expansion_background IS NOT NULL AND expansion_background != ''").pluck(:expansion_background)
|
||||||
ignore_urls << Category.uniq.where("logo_url IS NOT NULL AND logo_url != ''").pluck(:logo_url)
|
ignore_urls << Category.uniq.where("logo_url IS NOT NULL AND logo_url != ''").pluck(:logo_url)
|
||||||
ignore_urls << Category.uniq.where("background_url IS NOT NULL AND background_url != ''").pluck(:background_url)
|
ignore_urls << Category.uniq.where("background_url IS NOT NULL AND background_url != ''").pluck(:background_url)
|
||||||
ignore_urls.flatten!
|
ignore_urls.flatten!
|
||||||
|
|
|
@ -29,6 +29,16 @@ class UserProfile < ActiveRecord::Base
|
||||||
cook
|
cook
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def upload_expansion_background(upload)
|
||||||
|
self.expansion_background = upload.url
|
||||||
|
self.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
def clear_expansion_background
|
||||||
|
self.expansion_background = ""
|
||||||
|
self.save!
|
||||||
|
end
|
||||||
|
|
||||||
def upload_profile_background(upload)
|
def upload_profile_background(upload)
|
||||||
self.profile_background = upload.url
|
self.profile_background = upload.url
|
||||||
self.save!
|
self.save!
|
||||||
|
@ -96,6 +106,7 @@ end
|
||||||
# bio_cooked :text
|
# bio_cooked :text
|
||||||
# dismissed_banner_key :integer
|
# dismissed_banner_key :integer
|
||||||
# profile_background :string(255)
|
# profile_background :string(255)
|
||||||
|
# expansion_background :string(255)
|
||||||
# bio_cooked_version :integer
|
# bio_cooked_version :integer
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
|
|
|
@ -27,6 +27,7 @@ class UserSerializer < BasicUserSerializer
|
||||||
:created_at,
|
:created_at,
|
||||||
:website,
|
:website,
|
||||||
:profile_background,
|
:profile_background,
|
||||||
|
:expansion_background,
|
||||||
:location,
|
:location,
|
||||||
:can_edit,
|
:can_edit,
|
||||||
:can_edit_username,
|
:can_edit_username,
|
||||||
|
@ -117,6 +118,14 @@ class UserSerializer < BasicUserSerializer
|
||||||
profile_background.present?
|
profile_background.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def expansion_background
|
||||||
|
object.user_profile.expansion_background
|
||||||
|
end
|
||||||
|
|
||||||
|
def include_expansion_background?
|
||||||
|
expansion_background.present?
|
||||||
|
end
|
||||||
|
|
||||||
def location
|
def location
|
||||||
object.user_profile.location
|
object.user_profile.location
|
||||||
end
|
end
|
||||||
|
|
|
@ -369,6 +369,9 @@ en:
|
||||||
change_profile_background:
|
change_profile_background:
|
||||||
title: "Profile Background"
|
title: "Profile Background"
|
||||||
|
|
||||||
|
change_expansion_background:
|
||||||
|
title: "User Expansion Background"
|
||||||
|
|
||||||
email:
|
email:
|
||||||
title: "Email"
|
title: "Email"
|
||||||
instructions: "Never shown to the public."
|
instructions: "Never shown to the public."
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddExpansionBackgroundToUserProfiles < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :user_profiles, :expansion_background, :string, limit: 255
|
||||||
|
end
|
||||||
|
end
|
|
@ -1156,6 +1156,21 @@ describe UsersController do
|
||||||
json['height'].should == 200
|
json['height'].should == 200
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'is successful for expansion backgrounds' do
|
||||||
|
upload = Fabricate(:upload)
|
||||||
|
Upload.expects(:create_for).returns(upload)
|
||||||
|
xhr :post, :upload_user_image, username: user.username, file: user_image, image_type: "expansion_background"
|
||||||
|
user.reload
|
||||||
|
|
||||||
|
user.user_profile.expansion_background.should == "/uploads/default/1/1234567890123456.png"
|
||||||
|
|
||||||
|
# returns the url, width and height of the uploaded image
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
json['url'].should == "/uploads/default/1/1234567890123456.png"
|
||||||
|
json['width'].should == 100
|
||||||
|
json['height'].should == 200
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "with url" do
|
describe "with url" do
|
||||||
|
@ -1204,6 +1219,20 @@ describe UsersController do
|
||||||
json['width'].should == 100
|
json['width'].should == 100
|
||||||
json['height'].should == 200
|
json['height'].should == 200
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'is successful for expansion backgrounds' do
|
||||||
|
upload = Fabricate(:upload)
|
||||||
|
Upload.expects(:create_for).returns(upload)
|
||||||
|
xhr :post, :upload_user_image, username: user.username, file: user_image_url, image_type: "expansion_background"
|
||||||
|
user.reload
|
||||||
|
user.user_profile.expansion_background.should == "/uploads/default/1/1234567890123456.png"
|
||||||
|
|
||||||
|
# returns the url, width and height of the uploaded image
|
||||||
|
json = JSON.parse(response.body)
|
||||||
|
json['url'].should == "/uploads/default/1/1234567890123456.png"
|
||||||
|
json['width'].should == 100
|
||||||
|
json['height'].should == 200
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should handle malformed urls" do
|
it "should handle malformed urls" do
|
||||||
|
|
|
@ -32,6 +32,16 @@ describe UserSerializer do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with filled out expansion background" do
|
||||||
|
before do
|
||||||
|
user.user_profile.expansion_background = 'http://expansion.com'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "has a profile background" do
|
||||||
|
expect(json[:expansion_background]).to eq 'http://expansion.com'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "with filled out profile background" do
|
context "with filled out profile background" do
|
||||||
before do
|
before do
|
||||||
user.user_profile.profile_background = 'http://background.com'
|
user.user_profile.profile_background = 'http://background.com'
|
||||||
|
|
Loading…
Reference in a new issue