Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
bf6aa155
Commit
bf6aa155
authored
Feb 17, 2016
by
Johann Pardanaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve avatar cropping internals, based on suggestions made by @rspeicher on !2773
parent
fb6d7df3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
6 additions
and
15 deletions
+6
-15
app/assets/javascripts/profile.js.coffee
app/assets/javascripts/profile.js.coffee
+1
-1
app/models/user.rb
app/models/user.rb
+2
-4
app/uploaders/avatar_uploader.rb
app/uploaders/avatar_uploader.rb
+1
-8
app/views/profiles/show.html.haml
app/views/profiles/show.html.haml
+2
-2
No files found.
app/assets/javascripts/profile.js.coffee
View file @
bf6aa155
...
@@ -53,7 +53,7 @@ class @Profile
...
@@ -53,7 +53,7 @@ class @Profile
$avatarInput
.
on
"change"
,
->
$avatarInput
.
on
"change"
,
->
form
=
$
(
this
).
closest
(
"form"
)
form
=
$
(
this
).
closest
(
"form"
)
filename
=
$
(
this
).
val
().
replace
(
/^.*[\\\/]/
,
''
)
filename
=
$
(
this
).
val
().
replace
(
/^.*[\\\/]/
,
''
)
$filename
.
text
(
filename
)
$filename
.
data
(
'label'
,
$filename
.
text
()).
text
(
filename
)
reader
=
new
FileReader
reader
=
new
FileReader
...
...
app/models/user.rb
View file @
bf6aa155
...
@@ -99,9 +99,7 @@ class User < ActiveRecord::Base
...
@@ -99,9 +99,7 @@ class User < ActiveRecord::Base
attr_accessor
:login
attr_accessor
:login
# Virtual attributes to define avatar cropping
# Virtual attributes to define avatar cropping
[
:avatar_crop_x
,
:avatar_crop_y
,
:avatar_crop_size
].
each
do
|
field
|
attr_accessor
:avatar_crop_x
,
:avatar_crop_y
,
:avatar_crop_size
attr_accessor
field
end
#
#
# Relations
# Relations
...
@@ -169,7 +167,7 @@ class User < ActiveRecord::Base
...
@@ -169,7 +167,7 @@ class User < ActiveRecord::Base
validates
:avatar
,
file_size:
{
maximum:
200
.
kilobytes
.
to_i
}
validates
:avatar
,
file_size:
{
maximum:
200
.
kilobytes
.
to_i
}
[
:avatar_crop_x
,
:avatar_crop_y
,
:avatar_crop_size
].
each
do
|
field
|
[
:avatar_crop_x
,
:avatar_crop_y
,
:avatar_crop_size
].
each
do
|
field
|
validates
field
,
numericality:
{
only_integer:
true
},
allow_blank:
true
validates
field
,
numericality:
{
only_integer:
true
},
presence:
true
,
if:
->
(
user
)
{
user
.
avatar_changed?
}
end
end
before_validation
:generate_password
,
on: :create
before_validation
:generate_password
,
on: :create
...
...
app/uploaders/avatar_uploader.rb
View file @
bf6aa155
...
@@ -10,15 +10,8 @@ class AvatarUploader < CarrierWave::Uploader::Base
...
@@ -10,15 +10,8 @@ class AvatarUploader < CarrierWave::Uploader::Base
process
:cropper
process
:cropper
def
is_integer?
string
true
if
Integer
(
string
)
rescue
false
end
def
cropper
def
cropper
is_compliant
=
model
.
kind_of?
(
User
)
&&
is_integer?
(
model
.
avatar_crop_size
)
if
model
.
kind_of?
(
User
)
&&
model
.
valid?
is_compliant
=
is_compliant
&&
is_integer?
(
model
.
avatar_crop_x
)
&&
is_integer?
(
model
.
avatar_crop_y
)
if
is_compliant
manipulate!
do
|
img
|
manipulate!
do
|
img
|
img
.
crop
"
#{
model
.
avatar_crop_size
}
x
#{
model
.
avatar_crop_size
}
+
#{
model
.
avatar_crop_x
}
+
#{
model
.
avatar_crop_y
}
"
img
.
crop
"
#{
model
.
avatar_crop_size
}
x
#{
model
.
avatar_crop_size
}
+
#{
model
.
avatar_crop_x
}
+
#{
model
.
avatar_crop_y
}
"
end
end
...
...
app/views/profiles/show.html.haml
View file @
bf6aa155
...
@@ -88,7 +88,7 @@
...
@@ -88,7 +88,7 @@
%i
.fa.fa-paperclip
%i
.fa.fa-paperclip
%span
Choose File ...
%span
Choose File ...
%span
.file_name.js-avatar-filename
{
:'data-label'
=>
'File name...'
}
File name...
%span
.file_name.js-avatar-filename
File name...
=
f
.
file_field
:avatar
,
class:
"js-user-avatar-input hidden"
=
f
.
file_field
:avatar
,
class:
"js-user-avatar-input hidden"
=
f
.
hidden_field
:avatar_crop_x
=
f
.
hidden_field
:avatar_crop_x
=
f
.
hidden_field
:avatar_crop_y
=
f
.
hidden_field
:avatar_crop_y
...
@@ -107,7 +107,7 @@
...
@@ -107,7 +107,7 @@
.modal-dialog
.modal-dialog
.modal-content
.modal-content
.modal-header
.modal-header
%button
.close
{
:type
=>
"button"
,
:'data-dismiss'
=>
"modal"
}
%button
.close
{
type:
'button'
,
data:
{
dismiss:
'modal'
}
}
%span
%span
×
×
%h4
.modal-title
%h4
.modal-title
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment