[#369] pull request: diff tab

This commit is contained in:
Alexander Machehin 2015-01-20 18:40:52 +05:00
parent ec285dae39
commit 33fd426afb
5 changed files with 68 additions and 52 deletions

View File

@ -78,8 +78,5 @@ table.table.diff.inline
margin-top: 5px
div.file div.top
height: 28px
min-height: 28px
background: #ededed
.pull-left, .pull-right
margin: 6px 10px 0px 10px

View File

@ -1,4 +1,7 @@
module DiffHelper
MAX_FILES_WITHOUT_COLLAPSE = 25
MAX_LINES_WITHOUT_COLLAPSE = 50
def render_diff_stats(stats)
path = @pull.try(:id) ? polymorphic_path([@project, @pull]) : ''
@ -20,7 +23,7 @@ module DiffHelper
end
def wrap_header_list(stats, list)
is_stats_open = stats.count <= 25 ? 'in' : ''
is_stats_open = stats.count <= MAX_FILES_WITHOUT_COLLAPSE ? 'in' : ''
res = ["<div class='panel-group' id='diff_header' role='tablist' aria-multiselectable='false'>"]
res << "<div class='panel panel-default'>"
res << "<div class='panel-heading' role='tab' id='heading'>"

View File

@ -1,40 +0,0 @@
-title = "#{t('diff')} #{shortest_hash_id @commit1.id}...#{shortest_hash_id @commit.id}"
-set_meta_tags title: [title_object(@project), title]
=render 'submenu'
%h3=title
.both
#repo-wrapper
.leftside
-total_additions = @stats.inject(0) {|sum, n| sum + n.additions}
-total_deletions = @stats.inject(0) {|sum, n| sum + n.deletions}
%h5= t("layout.projects.diff_show_header",
files: t("layout.projects.commit_files_count", count: @stats.count),
additions: t("layout.projects.commit_additions_count", count: total_additions),
deletions: t("layout.projects.commit_deletions_count", count: total_deletions))
.both
-begin
=render_diff_stats @stats
- Grit::Commit.diff(@project.repo, @common_ancestor.id, @commit.id).each_with_index do |commit_diff, diff_counter|
- commit_id = commit_diff.deleted_file ? @common_ancestor.id : @commit.id
.file
%a{name: "diff-#{diff_counter}"}
.top
.l= h(commit_diff.a_path.rtruncate 120)
- if commit_diff.b_path.present?
.r= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, commit_diff.b_path)
.clear
-if commit_diff.diff.present?
.diff_data
- blob = @project.repo.tree(commit_id) / commit_diff.b_path
- if blob.render_as == :image
%table.diff.inline{ cellspacing: 0, cellpadding: 0 }
%tr
%td.lines
%td.blob.diff-image
%span.diff-image
%img{ src: "data:#{blob.mime_type};base64,#{Base64.encode64(blob.data)}",
style: 'max-width: 600px;' }
= render_diff(commit_diff, diff_counter: diff_counter) unless blob.binary?
- rescue Grit::Git::GitTimeout
%p= t 'layout.git.repositories.commit_diff_too_big'

View File

@ -0,0 +1,46 @@
-title = "#{t('diff')} #{shortest_hash_id @commit1.id}...#{shortest_hash_id @commit.id}"
-set_meta_tags title: [title_object(@project), title]
== render 'submenu'
h3= title
#repo-wrapper
.leftside
-total_additions = @stats.inject(0) {|sum, n| sum + n.additions}
-total_deletions = @stats.inject(0) {|sum, n| sum + n.deletions}
h5= t("layout.projects.diff_show_header",
files: t("layout.projects.commit_files_count", count: @stats.count),
additions: t("layout.projects.commit_additions_count", count: total_additions),
deletions: t("layout.projects.commit_deletions_count", count: total_deletions))
-begin
== render_diff_stats @stats
- Grit::Commit.diff(@project.repo, @common_ancestor.id, @commit.id).each_with_index do |commit_diff, diff_counter|
- commit_id = commit_diff.deleted_file ? @common_ancestor.id : @commit.id
.file
a name = "diff-#{diff_counter}"
.top
.pull-left
a[ type = 'button'
class = 'btn btn-danger'
data-toggle = 'collapse'
data-target = "#demo"
aria-expanded = 'true'
aria-controls = "demo" ]
= h(commit_diff.a_path.rtruncate 120)
- if commit_diff.b_path.present?
.pull-right= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@project, commit_id, commit_diff.b_path)
.clearfix
-if commit_diff.diff.present?
.diff_data
- blob = @project.repo.tree(commit_id) / commit_diff.b_path
- if blob.render_as == :image
table.table.diff.inline.table-bordered[ cellspacing = 0 cellpadding = 0 ]
tr
td.diff-image
span.diff-image
img[ src = "data:#{blob.mime_type};base64,#{Base64.encode64(blob.data)}"
style = 'max-width: 600px;' ]
== render_diff(commit_diff, diff_counter: diff_counter) unless blob.binary?
- rescue Grit::Git::GitTimeout
p= t 'layout.git.repositories.commit_diff_too_big'

View File

@ -1,15 +1,25 @@
- commit_id = pull_diff.deleted_file ? @pull.to_commit.id : @pull.from_commit.id
.file
a name = "diff-#{pull_diff_counter}"
- commit_id = pull_diff.deleted_file ? @pull.to_commit.id : @pull.from_commit.id
- diff_counter = "diff-#{pull_diff_counter}"
- diff_counter_content = "#{diff_counter}_content"
.file.offset20
a name = diff_counter
.top
.pull-left= h(pull_diff.renamed_file ? "#{pull_diff.a_path.rtruncate 60}=>#{pull_diff.b_path.rtruncate 60}" : pull_diff.b_path.rtruncate(120))
button.btn.btn-link.pull-left[ type = 'button'
data-toggle = 'collapse'
data-target = "##{diff_counter_content}"
aria-expanded = 'true'
aria-controls = diff_counter_content ]
= h(pull_diff.renamed_file ? "#{pull_diff.a_path.rtruncate 60}=>#{pull_diff.b_path.rtruncate 60}" : pull_diff.b_path.rtruncate(120))
- if @pull.from_project.present?
.pull-right= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@pull.from_project, commit_id, pull_diff.b_path)
button.btn.btn-link.pull-right
= link_to "view file @ #{short_hash_id(commit_id)}", blob_path(@pull.from_project, commit_id, pull_diff.b_path)
.clearfix
-if pull_diff.diff.present?
.diff_data
- blob = @pull.repo.tree(commit_id) / pull_diff.b_path
- blob = @pull.repo.tree(commit_id) / pull_diff.b_path
- is_file_open = 'in' if !blob.binary? && pull_diff.diff.split("\n").count <= DiffHelper::MAX_LINES_WITHOUT_COLLAPSE
.diff_data.collapse[ id = diff_counter_content class = is_file_open ]
- if blob.render_as == :image
table.table.diff.inline.table-bordered[ cellspacing = 0 cellpadding = 0 ]
tr