diff --git a/app/assets/stylesheets/sections/tree.scss b/app/assets/stylesheets/sections/tree.scss index fd12ed00a2ae2d183081e640efcce9bffaf26f6a..9f78a6b6ae3d272cb61def33ced1b810537934a6 100644 --- a/app/assets/stylesheets/sections/tree.scss +++ b/app/assets/stylesheets/sections/tree.scss @@ -52,14 +52,26 @@ } } - .tree-commit-link { - color:#333; + .tree_author { + padding-right: 8px; + + img.avatar { + border: 0 none; + float: none; + margin-right: 0; + padding: 0; + width: 16px; + } } - a.tree-commit-link { - color: #666; - &:hover { - text-decoration: underline; + .tree_commit { + color: gray; + + .tree-commit-link { + color: #444; + &:hover { + text-decoration: underline; + } } } } diff --git a/app/decorators/commit_decorator.rb b/app/decorators/commit_decorator.rb index 777580a6d5eea13543e2e7429f9b5317cca8d17f..2472394103709380e265695dc4b9797fc9934f86 100644 --- a/app/decorators/commit_decorator.rb +++ b/app/decorators/commit_decorator.rb @@ -42,6 +42,28 @@ class CommitDecorator < ApplicationDecorator end end + # Returns a link to the commit author. If the author has a matching user and + # is a member of the current @project it will link to the team member page. + # Otherwise it will link to the author email as specified in the commit. + # + # options: + # avatar: true will prepend avatar image + def author_link(options) + text = if options[:avatar] + avatar = h.image_tag h.gravatar_icon(author_email), class: "avatar", width: 16 + "#{avatar} #{author_name}" + else + author_name + end + team_member = @project.try(:team_member_by_name_or_email, author_name, author_email) + + if team_member.nil? + h.mail_to author_email, text.html_safe, class: "commit-author-link" + else + h.link_to text, h.project_team_member_path(@project, team_member), class: "commit-author-link" + end + end + protected def no_commit_message diff --git a/app/roles/team.rb b/app/roles/team.rb index 8aef405aaf36d8691a7121f209cdaadf301742e2..a7ba0588cf5a974b933abf1de4036e1c33845174 100644 --- a/app/roles/team.rb +++ b/app/roles/team.rb @@ -1,7 +1,7 @@ module Team - def team_member_by_name_or_email(email = nil, name = nil) - user = users.where("email like ? or name like ?", email, name).first - users_projects.find_by_user_id(user.id) if user + def team_member_by_name_or_email(name = nil, email = nil) + user = users.where("name like ? or email like ?", name, email).first + users_projects.where(user: user) if user end # Get Team Member record by user id diff --git a/app/views/refs/logs_tree.js.haml b/app/views/refs/logs_tree.js.haml index b0ac0c4b0fd6b4b04c5faac74cf72f03a4278c33..23a6dae7810360e03a86fbd25cf23b8dab89113f 100644 --- a/app/views/refs/logs_tree.js.haml +++ b/app/views/refs/logs_tree.js.haml @@ -1,9 +1,8 @@ - @logs.each do |content_data| - file_name = content_data[:file_name] - - content_commit = content_data[:commit] - - tm = @project.team_member_by_name_or_email(content_commit.author_email, content_commit.author_name) + - commit = content_data[:commit] :plain var row = $("table.table_#{@hex_path} tr.file_#{hexdigest(file_name)}"); - row.find("td.tree_time_ago").html('#{escape_javascript(time_ago_in_words(content_commit.committed_date))} ago'); - row.find("td.tree_commit").html('#{escape_javascript(render("tree/tree_commit", tm: tm, content_commit: content_commit))}'); + row.find("td.tree_time_ago").html('#{escape_javascript time_ago_in_words(commit.committed_date)} ago'); + row.find("td.tree_commit").html('#{escape_javascript render("tree/tree_commit_column", commit: commit)}'); diff --git a/app/views/tree/_tree_commit.html.haml b/app/views/tree/_tree_commit.html.haml deleted file mode 100644 index 1bcf1a7ea1d430e3ae3ab4db3b186fde9c53c1d0..0000000000000000000000000000000000000000 --- a/app/views/tree/_tree_commit.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -- if tm - = link_to "[#{tm.user_name}]", project_team_member_path(@project, tm) -= link_to_gfm truncate(content_commit.title, length: tm ? 30 : 50), project_commit_path(@project, content_commit.id), class: "tree-commit-link" diff --git a/app/views/tree/_tree_commit_column.html.haml b/app/views/tree/_tree_commit_column.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..9d02132b0f4451939c16bb95ef720cc86d190ce1 --- /dev/null +++ b/app/views/tree/_tree_commit_column.html.haml @@ -0,0 +1,2 @@ +%span.tree_author= commit.author_link avatar: true += link_to_gfm truncate(commit.title, length: 80), project_commit_path(@project, commit.id), class: "tree-commit-link"