diff --git a/app/assets/stylesheets/projects.css.sass b/app/assets/stylesheets/projects.css.sass index 198e0ad7..2b261a32 100644 --- a/app/assets/stylesheets/projects.css.sass +++ b/app/assets/stylesheets/projects.css.sass @@ -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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 5481f80e..6641d48a 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -17,6 +17,9 @@ def show return end commontator_thread_show(@project) + + load_github_repo + update_project_avatar_url end def new @@ -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 diff --git a/app/views/projects/index.html.haml b/app/views/projects/index.html.haml index 0182a3bd..44884b94 100644 --- a/app/views/projects/index.html.haml +++ b/app/views/projects/index.html.haml @@ -9,6 +9,7 @@ %table.table.table-hover %thead %tr + %th#avatar_th %th.name Name %th.description Description %th.amount Funds @@ -16,6 +17,8 @@ %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 diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 4c828619..08c89aa6 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -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? diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb new file mode 100644 index 00000000..1a3911ae --- /dev/null +++ b/config/initializers/constants.rb @@ -0,0 +1,2 @@ + +GITHUBAPI_REPO_URL = "https://api.github.com/repos" diff --git a/db/migrate/20141020034918_add_avatar_to_projects.rb b/db/migrate/20141020034918_add_avatar_to_projects.rb new file mode 100644 index 00000000..c4d9f893 --- /dev/null +++ b/db/migrate/20141020034918_add_avatar_to_projects.rb @@ -0,0 +1,5 @@ +class AddAvatarToProjects < ActiveRecord::Migration + def change + add_column :projects, :avatar_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 9e9da2e7..1465a216 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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|