Commit e0eb4803 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor diff views

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 4ef809c7
......@@ -12,11 +12,11 @@
= link_to "Inline Diff", url_for(params_copy), {id: "commit-diff-viewtype"}
- if show_diff_size_warninig?(diffs)
= render 'projects/commits/diff_warning', diffs: diffs
= render 'projects/diffs/diff_warning', diffs: diffs
.files
- safe_diff_files(diffs).each_with_index do |diff, i|
= render 'projects/commits/diff_file', diff: diff, i: i, project: project
= render 'projects/diffs/diff_file', diff: diff_file, i: i, project: project
- if @diff_timeout
.alert.alert-danger
......
- file = project.repository.blob_for_diff(@commit, diff)
- return unless file
- blob_diff_path = diff_project_blob_path(project,
tree_join(@commit.id, diff.new_path))
- return unless diff_file.blob_exists?
- blob = diff_file.blob
- blob_diff_path = diff_project_blob_path(project, tree_join(@commit.id, diff_file.new_path))
.diff-file{id: "diff-#{i}", data: {blob_diff_path: blob_diff_path }}
.diff-header{id: "file-path-#{hexdigest(diff.new_path || diff.old_path)}"}
- if diff.deleted_file
%span= diff.old_path
.diff-header{id: "file-path-#{hexdigest(diff_file.new_path || diff_file.old_path)}"}
- if diff_file.deleted_file
%span= diff_file.old_path
.diff-btn-group
- if @commit.parent_ids.present?
= view_file_btn(@commit.parent_id, diff, project)
= view_file_btn(@commit.parent_id, diff_file, project)
- else
%span= diff.new_path
- if diff_file_mode_changed?(diff)
%span= diff_file.new_path
- if diff_file.mode_changed?
%span.file-mode= "#{diff.a_mode}#{diff.b_mode}"
.diff-btn-group
......@@ -26,23 +25,23 @@
&nbsp;
- if @merge_request && @merge_request.source_project
= link_to project_edit_tree_path(@merge_request.source_project, tree_join(@merge_request.source_branch, diff.new_path), from_merge_request_id: @merge_request.id), { class: 'btn btn-small' } do
= link_to project_edit_tree_path(@merge_request.source_project, tree_join(@merge_request.source_branch, diff_file.new_path), from_merge_request_id: @merge_request.id), { class: 'btn btn-small' } do
Edit
&nbsp;
= view_file_btn(@commit.id, diff, project)
= view_file_btn(@commit.id, diff_file, project)
.diff-content
-# Skipp all non non-supported blobs
- return unless file.respond_to?('text?')
- if file.text?
- return unless blob.respond_to?('text?')
- if blob.text?
- if params[:view] == 'parallel'
= render "projects/commits/parallel_view", diff: diff, project: project, file: file, index: i
= render "projects/diffs/parallel_view", diff_file: diff_file, project: project, blob: blob, index: i
- else
= render "projects/commits/text_file", diff: diff, index: i
- elsif file.image?
- old_file = project.repository.prev_blob_for_diff(@commit, diff)
= render "projects/commits/image", diff: diff, old_file: old_file, file: file, index: i
= render "projects/diffs/text_file", diff_file: diff_file, index: i
- elsif blob.image?
- old_file = project.repository.prev_blob_for_diff(@commit, diff_file)
= render "projects/diffs/image", diff_file: diff_file, old_file: old_file, blob: blob, index: i
- else
.nothing-here-block No preview for this file type
.row
.col-md-8
= render 'projects/diffs/diff_stats', diffs: diffs
.col-md-4
%ul.nav.nav-tabs
%li.pull-right{class: params[:view] == 'parallel' ? 'active' : ''}
- params_copy = params.dup
- params_copy[:view] = 'parallel'
= link_to "Side-by-side Diff", url_for(params_copy), {id: "commit-diff-viewtype"}
%li.pull-right{class: params[:view] != 'parallel' ? 'active' : ''}
- params_copy[:view] = 'inline'
= link_to "Inline Diff", url_for(params_copy), {id: "commit-diff-viewtype"}
- if show_diff_size_warninig?(project, diffs)
= render 'projects/diffs/diff_warning', diffs: diffs
.files
- safe_diff_files(project, diffs).each_with_index do |diff_file, i|
= render 'projects/diffs/diff_file', diff_file: diff_file, i: i, project: project
- if @diff_timeout
.alert.alert-danger
%h4
Failed to collect changes
%p
Maybe diff is really big and operation failed with timeout. Try to get diff localy
/ Side-by-side diff view
%div.text-file
%table
- parallel_diff(diff, index).each do |line|
- parallel_diff(diff_file, index).each do |line|
- type_left = line[0]
- line_number_left = line[1]
- line_content_left = line[2]
......@@ -11,7 +11,7 @@
%tr.line_holder.parallel
- if type_left == 'match'
= render "projects/commits/diffs/match_line_parallel", { line: line_content_left,
= render "projects/diffs/match_line_parallel", { line: line_content_left,
line_old: line_number_left, line_new: line_number_right }
- elsif type_left == 'old' || type_left.nil?
%td.old_line{class: "#{type_left}"}
......@@ -21,6 +21,6 @@
= link_to raw(line_number_right)
%td.line_content.parallel{class: "noteable_line #{type_right == 'new' ? 'new' : nil}"}= raw line_content_right
- if diff.diff.blank? && diff_file_mode_changed?(diff)
- if diff_file.diff.diff.blank? && diff_file.mode_changed?
.file-mode-changed
File mode changed
- too_big = diff.diff.lines.count > Commit::DIFF_SAFE_LINES
- too_big = diff_file.diff_lines.count > Commit::DIFF_SAFE_LINES
- if too_big
%a.supp_diff_link Changes suppressed. Click to show
%table.text-file{class: "#{'hide' if too_big}"}
- last_line = 0
- each_diff_line(diff, index) do |line, type, line_code, line_new, line_old, raw_line|
- last_line = line_new
- diff_file.diff_lines.each_with_index do |line, index|
- type = line.type
- last_line = line.new_pos
- line_code = line.code
- line_old = line.old_pos
%tr.line_holder{ id: line_code, class: "#{type}" }
- if type == "match"
= render "projects/commits/diffs/match_line", {line: line,
line_old: line_old, line_new: line_new, bottom: false}
= render "projects/diffs/match_line", {line: line.text,
line_old: line_old, line_new: line.new_pos, bottom: false}
- else
%td.old_line
= link_to raw(type == "new" ? "&nbsp;" : line_old), "##{line_code}", id: line_code
- if @comments_allowed
= link_to_new_diff_note(line_code)
%td.new_line{data: {linenumber: line_new}}
= link_to raw(type == "old" ? "&nbsp;" : line_new) , "##{line_code}", id: line_code
%td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line)
%td.new_line{data: {linenumber: line.new_pos}}
= link_to raw(type == "old" ? "&nbsp;" : line.new_pos) , "##{line_code}", id: line_code
%td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw diff_line_content(line.text)
- if @reply_allowed
- comments = @line_notes.select { |n| n.line_code == line_code }.sort_by(&:created_at)
- unless comments.empty?
= render "projects/notes/diff_notes_with_reply", notes: comments, line: line
= render "projects/notes/diff_notes_with_reply", notes: comments, line: line.text
- if last_line > 0
= render "projects/commits/diffs/match_line", {line: "",
= render "projects/diffs/match_line", {line: "",
line_old: last_line, line_new: last_line, bottom: true}
- if diff.diff.blank? && diff_file_mode_changed?(diff)
- if diff_file.diff.blank? && diff_file_mode_changed?(diff)
.file-mode-changed
File mode changed
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment