Commit cd9f135a660d835763d63a7ffaefb325f03faaeb

Authored by Dmitriy Zaporozhets
2 parents 0189ee97 4fd73683

Merge pull request #1717 from riyad/add-author-to-tree-listing

Update author info in tree listing
app/assets/stylesheets/sections/tree.scss
... ... @@ -52,14 +52,26 @@
52 52 }
53 53 }
54 54  
55   - .tree-commit-link {
56   - color:#333;
  55 + .tree_author {
  56 + padding-right: 8px;
  57 +
  58 + img.avatar {
  59 + border: 0 none;
  60 + float: none;
  61 + margin-right: 0;
  62 + padding: 0;
  63 + width: 16px;
  64 + }
57 65 }
58 66  
59   - a.tree-commit-link {
60   - color: #666;
61   - &:hover {
62   - text-decoration: underline;
  67 + .tree_commit {
  68 + color: gray;
  69 +
  70 + .tree-commit-link {
  71 + color: #444;
  72 + &:hover {
  73 + text-decoration: underline;
  74 + }
63 75 }
64 76 }
65 77 }
... ...
app/decorators/commit_decorator.rb
... ... @@ -42,6 +42,28 @@ class CommitDecorator < ApplicationDecorator
42 42 end
43 43 end
44 44  
  45 + # Returns a link to the commit author. If the author has a matching user and
  46 + # is a member of the current @project it will link to the team member page.
  47 + # Otherwise it will link to the author email as specified in the commit.
  48 + #
  49 + # options:
  50 + # avatar: true will prepend avatar image
  51 + def author_link(options)
  52 + text = if options[:avatar]
  53 + avatar = h.image_tag h.gravatar_icon(author_email), class: "avatar", width: 16
  54 + "#{avatar} #{author_name}"
  55 + else
  56 + author_name
  57 + end
  58 + team_member = @project.try(:team_member_by_name_or_email, author_name, author_email)
  59 +
  60 + if team_member.nil?
  61 + h.mail_to author_email, text.html_safe, class: "commit-author-link"
  62 + else
  63 + h.link_to text, h.project_team_member_path(@project, team_member), class: "commit-author-link"
  64 + end
  65 + end
  66 +
45 67 protected
46 68  
47 69 def no_commit_message
... ...
app/roles/team.rb
1 1 module Team
2   - def team_member_by_name_or_email(email = nil, name = nil)
3   - user = users.where("email like ? or name like ?", email, name).first
4   - users_projects.find_by_user_id(user.id) if user
  2 + def team_member_by_name_or_email(name = nil, email = nil)
  3 + user = users.where("name like ? or email like ?", name, email).first
  4 + users_projects.where(user: user) if user
5 5 end
6 6  
7 7 # Get Team Member record by user id
... ...
app/views/refs/logs_tree.js.haml
1 1 - @logs.each do |content_data|
2 2 - file_name = content_data[:file_name]
3   - - content_commit = content_data[:commit]
4   - - tm = @project.team_member_by_name_or_email(content_commit.author_email, content_commit.author_name)
  3 + - commit = content_data[:commit]
5 4  
6 5 :plain
7 6 var row = $("table.table_#{@hex_path} tr.file_#{hexdigest(file_name)}");
8   - row.find("td.tree_time_ago").html('#{escape_javascript(time_ago_in_words(content_commit.committed_date))} ago');
9   - row.find("td.tree_commit").html('#{escape_javascript(render("tree/tree_commit", tm: tm, content_commit: content_commit))}');
  7 + row.find("td.tree_time_ago").html('#{escape_javascript time_ago_in_words(commit.committed_date)} ago');
  8 + row.find("td.tree_commit").html('#{escape_javascript render("tree/tree_commit_column", commit: commit)}');
... ...
app/views/tree/_tree_commit.html.haml
... ... @@ -1,3 +0,0 @@
1   -- if tm
2   - = link_to "[#{tm.user_name}]", project_team_member_path(@project, tm)
3   -= link_to_gfm truncate(content_commit.title, length: tm ? 30 : 50), project_commit_path(@project, content_commit.id), class: "tree-commit-link"
app/views/tree/_tree_commit_column.html.haml 0 → 100644
... ... @@ -0,0 +1,2 @@
  1 +%span.tree_author= commit.author_link avatar: true
  2 += link_to_gfm truncate(commit.title, length: 80), project_commit_path(@project, commit.id), class: "tree-commit-link"
... ...