Skip to content

Commit

Permalink
Display gist owner and star state in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
rwdaigle committed Nov 21, 2012
1 parent 743a1e2 commit 4f304e6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
Binary file modified app/assets/images/star.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions app/models/gist.rb
Expand Up @@ -3,7 +3,7 @@ class Gist < ActiveRecord::Base
include Tire::Model::Search

attr_accessible :gh_id, :user_id, :owner_gh_id, :owner_gh_username, :owner_gh_avatar_url, :description, :url, :git_pull_url, :git_push_url, :public,
:comment_count, :gh_created_at, :gh_updated_at, :starred
:comment_count, :gh_created_at, :gh_updated_at, :starred, :owned

belongs_to :user
has_many :files, :class_name => 'GistFile', :dependent => :delete_all
Expand Down Expand Up @@ -31,12 +31,13 @@ class << self
def import(user_id, gh_gist, overrides = {})

user = User.find(user_id)
owned = (user.gh_id == gh_gist.user['id'])
gh_id = gh_gist['id']

attributes = {
gh_id: gh_id, user_id: user.id, owner_gh_id: gh_gist.user['id'], owner_gh_username: gh_gist.user.login, owner_gh_avatar_url: gh_gist.user.avatar_url,
description: gh_gist.description, url: gh_gist.html_url, git_push_url: gh_gist.git_push_url,
git_pull_url: gh_gist.git_pull_url, public: gh_gist.public, comment_count: gh_gist.comments,
git_pull_url: gh_gist.git_pull_url, public: gh_gist.public, comment_count: gh_gist.comments, owned: owned,
gh_created_at: gh_gist.created_at, gh_updated_at: gh_gist.updated_at
}.merge(overrides)

Expand Down
3 changes: 2 additions & 1 deletion app/views/gists/_results.html.haml
Expand Up @@ -7,7 +7,8 @@
%span.meta
- if result.starred?
= image_tag("star.png")
%img(src="#{result.owner_gh_avatar_url}&s=13" title="#{result.owner_gh_username}" alt="#{result.owner_gh_username}")
- if !result.owned?
%img(src="#{result.owner_gh_avatar_url}&s=13" title="#{result.owner_gh_username}" alt="#{result.owner_gh_username}")
.hints
%em keyboard:
↑ = up, ↓ = down, enter = follow link, / = search
Expand Down
3 changes: 2 additions & 1 deletion db/migrate/20121121002434_add_starred_gist_support.rb
Expand Up @@ -3,7 +3,7 @@ class AddStarredGistSupport < ActiveRecord::Migration
def up
change_table :gists do |t|
t.string :owner_gh_id, :owner_gh_username, :owner_gh_avatar_url
t.boolean :starred
t.boolean :starred, :owned
end
end

Expand All @@ -12,5 +12,6 @@ def down
remove_column :gists, :owner_gh_username
remove_column :gists, :owner_gh_avatar_url
remove_column :gists, :starred
remove_column :gists, :owned
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Expand Up @@ -45,6 +45,7 @@
t.string "owner_gh_username"
t.string "owner_gh_avatar_url"
t.boolean "starred"
t.boolean "owned"
end

add_index "gists", ["gh_id"], :name => "index_gists_on_gh_id"
Expand Down

0 comments on commit 4f304e6

Please sign in to comment.