[issue #195] Added blame view.

This commit is contained in:
George Vinogradov 2012-03-05 19:29:05 +04:00
parent 5290f0c712
commit 93e2caccc8
6 changed files with 146 additions and 5 deletions

View File

@ -321,3 +321,52 @@ table.tablesorter tr td.centered {
header div.user div.avatar img {
border: 1px solid #DDDDDD;
}
div.blame_data {
font-size: 80%;
}
div.blame_data tr.firstrow {
border-top: 1px solid #DDDDDD;
}
div.blame_data tr td.commit_info {
padding: 0.5em !important;
vertical-align: top;
width: 210px;
border-right: 1px solid #DDDDDD;
}
div.blame_data tr td.commit_info .date {
display: block;
float: left;
color: #666666;
}
div.blame_data tr td.commit_info .message {
width: 210px;
display: block;
float: right;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 12px;
}
div.blame_data tr td.lines {
padding: 0 0.5em !important;
width: 1%;
font-size: 12px;
line-height: 1.4em;
}
div.blame_data tr td.code {
padding: 0 10px !important;
font-size: 12px;
}
div.blame_data tr td.code pre {
padding: 0;
margin: 0;
}

View File

@ -41,4 +41,10 @@ module CommitHelper
truncate(message, :length => 42, :omission => "...").encode_to_default
end
def commit_author_link(author)
name = author.name.encode_to_default
email = author.email
u = User.where(:email => email).first
u.present? ? link_to(name, user_path(u)) : mail_to(email, name)
end
end

View File

@ -0,0 +1,42 @@
%table.table.blame
- index = 1
- @blame.each do |elem|
%tr.firstrow
%td.commit_info{ :rowspan => elem[1].length, :nowrap => 'nowrap' }
%code
#{link_to shortest_hash_id(elem[0].id), commit_path(@project, elem[0].id)} by
- author = elem[0].author
- committer = elem[0].committer
-##{elem[0].author.to_s.encode_to_default} #{elem[0].author != elem[0].committer ? "(#{elem[0].committer.to_s.encode_to_default})" : "" }
= commit_author_link(author)
- if author.email != committer.email
(#{commit_author_link(committer)})
%br
%span.date= commit_date(elem[0].committed_date)
%span.message{:title => elem[0].message.encode_to_default}= short_commit_message(elem[0].message)
%td.lines
= index
- index += 1
%td.code.cm-s-default
%pre
%div= elem[1].first.encode_to_default
- elem[1][1..-1].each do |line|
%tr
%td.lines
= index
- index += 1
%td.code.cm-s-default
%pre
%div= line.encode_to_default
:javascript
$(document).ready(function() {
var $code_rows = $('.code.cm-s-default pre div');
var mode = "#{File.extname(@blob.name) == '.spec' ? 'text/x-rpm-spec' : @blob.mime_type}"
$code_rows.each(function() {
CodeMirror.runMode($(this).text().replace(/&/gi, '&'), mode, this.parentElement.parentElement);
});
});

View File

@ -17,7 +17,8 @@
- if render_way == :text and can? :write, @project and @treeish.in? @project.branches.map(&:name)
= raw "#{link_to "Edit", edit_blob_path(@project, @treeish, @path) } | "
= raw "#{link_to "Raw", raw_path(@project, @treeish, @path)} | "
=# raw "#{link_to "Blame", blame_path(@project, @treeish, @path)} | "
- if render_way == :text
= raw "#{link_to "Blame", blame_path(@project, @treeish, @path)} | "
= link_to "History", commits_path(@project, @treeish, @path)
.both
.data

View File

@ -1,15 +1,55 @@
.block
= render :partial => 'projects/submenu'
= render :partial => 'projects/repo_block', :locals => {:project => @project}
.description
%h3= t("layout.projects.about_subheader")
%p
= @project.description
= link_to t('layout.read_more'), '#'
%h3= t("layout.projects.last_commit")
- GitPresenters::CommitAsMessagePresenter.present(@commit, :branch => @branch, :project => @project) do |presenter|
= render :partial => 'shared/feed_message', :locals => {:presenter => presenter, :item_no => 1}
.both
#repo-wrapper
%h3= t("layout.projects.files_in_project")
.files
.l
= render :partial => 'git/shared/whereami'
.both
- render_way = choose_render_way(@blob)
.file
.top
.l
= @blob.mode + ' | '
- if (render_way == :text)
- text = @blob.data.split("\n")
= "#{text.length} lines (#{text.select{|s| s.strip.length > 0}.length} sloc) | "
= "#{(@blob.size / 1024.0).round(3)} Kb"
.r
= raw "#{link_to "Normal", blob_path(@project, @treeish, @path) } | "
= raw "#{link_to "Raw", raw_path(@project, @treeish, @path)} | "
=# raw "#{link_to "Blame", blame_path(@project, @treeish, @path)} | "
= link_to "History", commits_path(@project, @treeish, @path)
.both
.blame_data
= render :partial => 'blame_table'
-#.block
= render :partial => "git/shared/navigation"
= render :partial => "git/shared/info"
- if @commit
-#- if @commit
.block
.content
.inner
= render :partial => "git/commits/commits", :object => [@commit]
.block
-#.block
.content
.inner
%h3= render_path
@ -53,4 +93,4 @@
%pre
%div= line.encode_to_default
- content_for :sidebar, render(:partial => 'git/shared/sidebar')
-#- content_for :sidebar, render(:partial => 'git/shared/sidebar')

View File

@ -9,3 +9,6 @@
@import "codemirror";
@import "codemirror/themes/eclipse";
@import "codemirror/modes/diff";
@import "codemirror/modes/rpm-spec";
@import "codemirror/modes/tiddlywiki";