Skip to content

Commit

Permalink
Merge branch 'angular_frontend' of github.com:openhq/openhq into show…
Browse files Browse the repository at this point in the history
…_project

* 'angular_frontend' of github.com:openhq/openhq:
  thin story serialzer and list out recent stories on the projects
  put template in directives and eager load the users
  update current_user_serializer and remove default url from avatar
  rubocop
  template for avatar
  user avatars - using gravatar
  • Loading branch information
phawk committed Oct 29, 2015
2 parents ae8e443 + ba012ed commit 9205c69
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 7 deletions.
10 changes: 10 additions & 0 deletions app/assets/javascripts/directives/user_avatar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
angular.module("OpenHq").directive("userAvatar", function() {
return {
restrict: "E",
scope: {
user: '=',
size: '=',
},
template: JST['templates/directives/user_avatar'],
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<a href="#" title="{{ user.display_name }}">
<img alt="{{ user.display_name }}" class="avatar" width="{{ size || 30 }}" src="{{ user.avatar_url }}">
</a>
10 changes: 7 additions & 3 deletions app/assets/javascripts/templates/projects/index.jst.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@
<h3>
<a href="/projects/{{ project.slug }}">
{{ project.name }}
<small>Last updated <human-time datetime="project.updated_at" /></small>
<small>Last updated <human-time datetime="project.updated_at"></human-time></small>
</a>
</h3>

<ul class="recent-stories">
<li>No recent stories</li>
<li ng-hide="project.stories.length > 0">No recent stories</li>
<li ng-repeat="story in project.stories">
<span class="when">{{ story.updated_at }}</span>
<a href="/projects/{{ project.slug }}/stories/{{ story.slug }}">{{ story.name }}</a>
</li>
</ul>
</section>

<footer>
<div class="members">
avatars
<user-avatar user="user" ng-repeat="user in project.users"></user-avatar>
</div>
</footer>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ProjectsController < BaseController

api! "Fetch all projects"
def index
render json: current_user.projects.all
render json: current_user.projects.includes(:users, :stories).all
end

api! "Fetch a single project"
Expand Down
15 changes: 14 additions & 1 deletion app/serializers/current_user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ def filter(keys)
end

def avatar_url
object.avatar.url(:thumb)
if object.avatar_file_name.present?
user.avatar.url(:thumb)
else
gravatar_url
end
end

def gravatar_url(size = 200)
base_url = "https://www.gravatar.com/avatar/"
opts = "?d=blank&s="

hash = Digest::MD5.hexdigest(object.email)

base_url + hash + opts + size.to_s
end
end
7 changes: 6 additions & 1 deletion app/serializers/project_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
class ProjectSerializer < ActiveModel::Serializer
attributes :id, :name, :slug, :owner_id, :created_at, :updated_at, :deleted_at, :team_id
# has_many :users
has_many :users, serializer: UserSerializer
has_many :stories, serializer: ThinStorySerializer

def stories
object.stories.order(updated_at: :desc).take(5)
end
end
3 changes: 3 additions & 0 deletions app/serializers/thin_story_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class ThinStorySerializer < ActiveModel::Serializer
attributes :id, :name, :slug, :updated_at
end
15 changes: 14 additions & 1 deletion app/serializers/user_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ class UserSerializer < ActiveModel::Serializer
attributes :id, :display_name, :first_name, :last_name, :username, :job_title, :avatar_url

def avatar_url
object.avatar.url(:thumb)
if object.avatar_file_name.present?
user.avatar.url(:thumb)
else
gravatar_url
end
end

def gravatar_url(size = 200)
base_url = "https://www.gravatar.com/avatar/"
opts = "?d=blank&s="

hash = Digest::MD5.hexdigest(object.email)

base_url + hash + opts + size.to_s
end
end

0 comments on commit 9205c69

Please sign in to comment.