Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/assets/stylesheets/projects.css.sass
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@
.donor-list
.amount
text-align: right

#avatar_th
width: 50px

.project_avatar_img
position: relative
width: 32px
height: 32px

#project_header
.project_avatar_img
top: -5px
28 changes: 28 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def show
return
end
commontator_thread_show(@project)

load_github_repo
update_project_avatar_url
end

def new
Expand Down Expand Up @@ -149,4 +152,29 @@ def load_project
redirect_to root_path, alert: "Project not found"
end
end

def load_github_repo
return if @project.nil?

github_repo_uri = URI "#{GITHUBAPI_REPO_URL}/#{@project.full_name}"
github_repo_resp = Net::HTTP.get_response github_repo_uri
return unless github_repo_resp.is_a? Net::HTTPSuccess

github_repo_json = JSON.parse github_repo_resp.body
return if github_repo_json["id"].nil?

@github_repo = github_repo_json
@github_owner = @github_repo["owner"]
@github_org = @github_repo["organization"]
@is_organization = @github_org.present?
end

def update_project_avatar_url
return if @project.nil? || !@is_organization

avatar_url = @github_org["avatar_url"]
is_unchanged = avatar_url.eql? @project.avatar_url

@project.update_attribute :avatar_url , avatar_url unless is_unchanged
end
end
3 changes: 3 additions & 0 deletions app/views/projects/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
%table.table.table-hover
%thead
%tr
%th#avatar_th
%th.name Name
%th.description Description
%th.amount Funds
%th.actions
%tbody
- @projects.each do |project|
%tr
%td
= image_tag project.avatar_url , class: 'project_avatar_img' if project.avatar_url
%td.name
%strong= link_to project.name, project
%td.description= project.description
Expand Down
10 changes: 6 additions & 4 deletions app/views/projects/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
= @project.name
- content_for :description do
= @project.description

.row
.col-md-8
%h1
= @project.name
%h1#project_header
- if (url = @project.github_url).present?
%small= link_to glyph(:github), url, target: '_blank'
= (@project.avatar_url.nil?)? (glyph :github) : (image_tag @project.avatar_url , class: 'project_avatar_img')
= link_to @project.name, url, target: '_blank'
- else
= @project.name
- unless @project.description.blank?
%h3= @project.description
- unless @project.detailed_description.blank?
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/constants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

GITHUBAPI_REPO_URL = "https://api.github.com/repos"
5 changes: 5 additions & 0 deletions db/migrate/20141020034918_add_avatar_to_projects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAvatarToProjects < ActiveRecord::Migration
def change
add_column :projects, :avatar_url, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20140714074128) do
ActiveRecord::Schema.define(version: 20141020034918) do

create_table "cold_storage_transfers", force: true do |t|
t.integer "project_id"
Expand Down Expand Up @@ -151,6 +151,7 @@
t.integer "account_balance", limit: 8
t.string "disabled_reason"
t.text "detailed_description"
t.string "avatar_url"
end

create_table "record_changes", force: true do |t|
Expand Down