-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/project avatar #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,3 +21,16 @@ | |
&.s90 { width: 90px; height: 90px; margin-right: 15px; } | ||
&.s160 { width: 160px; height: 160px; margin-right: 20px; } | ||
} | ||
|
||
.identicon { | ||
text-align: center; | ||
vertical-align: top; | ||
|
||
&.s16 { font-size: 12px; line-height: 1.33; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. er |
||
&.s24 { font-size: 18px; line-height: 1.33; } | ||
&.s26 { font-size: 20px; line-height: 1.33; } | ||
&.s32 { font-size: 24px; line-height: 1.33; } | ||
&.s60 { font-size: 45px; line-height: 1.33; } | ||
&.s90 { font-size: 68px; line-height: 1.33; } | ||
&.s160 { font-size: 120px; line-height: 1.33; } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -94,20 +94,33 @@ | |
overflow: hidden; | ||
} | ||
|
||
.project-avatar { | ||
float: left; | ||
} | ||
|
||
.project-access-icon { | ||
margin-left: 10px; | ||
float: left; | ||
margin-right: 15px; | ||
font-size: 20px; | ||
margin-bottom: 15px; | ||
|
||
border: 1px solid #EEE; | ||
padding: 8px 12px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. reer |
||
border-radius: 20px; | ||
background: #f5f5f5; | ||
text-align: center; | ||
position: relative; | ||
left: -32px; | ||
top: 38px; | ||
i { | ||
color: #888; | ||
} | ||
} | ||
|
||
.dash-project-avatar { | ||
float: left; | ||
} | ||
.dash-project-access-icon { | ||
float: left; | ||
margin-right: 3px; | ||
color: #999; | ||
width: 16px; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class Projects::AvatarsController < Projects::ApplicationController | ||
layout 'project' | ||
|
||
before_filter :project | ||
|
||
def show | ||
@blob = @project.repository.blob_at_branch('master', @project.avatar_in_git) | ||
if @blob | ||
headers['X-Content-Type-Options'] = 'nosniff' | ||
send_data( | ||
@blob.data, | ||
type: @blob.mime_type, | ||
disposition: 'inline', | ||
filename: @blob.name | ||
) | ||
else | ||
not_found! | ||
end | ||
end | ||
|
||
def destroy | ||
@project.remove_avatar! | ||
|
||
@project.save | ||
@project.reset_events_cache | ||
|
||
redirect_to edit_project_path(@project) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
# import_status :string(255) | ||
# repository_size :float default(0.0) | ||
# star_count :integer default(0), not null | ||
# avatar :string(255) | ||
# | ||
|
||
class Project < ActiveRecord::Base | ||
|
@@ -116,6 +117,13 @@ class Project < ActiveRecord::Base | |
validates :star_count, numericality: { greater_than_or_equal_to: 0 } | ||
validate :check_limit, on: :create | ||
|
||
validate :avatar_type, | ||
if: ->(project) { project.avatar && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Align the parameters of a method call if they span more than one line. |
||
project.avatar_changed? } | ||
validates :avatar, file_size: { maximum: 100.kilobytes.to_i } | ||
|
||
mount_uploader :avatar, AttachmentUploader | ||
|
||
# Scopes | ||
scope :without_user, ->(user) { where("projects.id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) } | ||
scope :without_team, ->(team) { team.projects.present? ? where("projects.id NOT IN (:ids)", ids: team.projects.map(&:id)) : scoped } | ||
|
@@ -328,6 +336,19 @@ def ci_service | |
@ci_service ||= ci_services.select(&:activated?).first | ||
end | ||
|
||
def avatar_type | ||
unless avatar.image? | ||
errors.add :avatar, 'only images allowed' | ||
end | ||
end | ||
|
||
def avatar_in_git | ||
@avatar_file ||= 'logo.png' if repository.blob_at_branch('master', 'logo.png') | ||
@avatar_file ||= 'logo.jpg' if repository.blob_at_branch('master', 'logo.jpg') | ||
@avatar_file ||= 'logo.gif' if repository.blob_at_branch('master', 'logo.gif') | ||
@avatar_file | ||
end | ||
|
||
# For compatibility with old code | ||
def code | ||
path | ||
|
@@ -561,6 +582,7 @@ def hook_attrs | |
# Since we do cache @event we need to reset cache in special cases: | ||
# * when project was moved | ||
# * when project was renamed | ||
# * when the project avatar changes | ||
# Events cache stored like events/23-20130109142513. | ||
# The cache key includes updated_at timestamp. | ||
# Thus it will automatically generate a new fragment | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,6 +333,8 @@ | |
post :preview | ||
end | ||
end | ||
|
||
resource :avatar, only: [:show, :destroy] | ||
end | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddAvatarToProjects < ActiveRecord::Migration | ||
def change | ||
add_column :projects, :avatar, :string | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foo