Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorskv <skv-headless@yandex.ru>2014-08-02 19:12:01 +0400
committerskv <skv-headless@yandex.ru>2014-08-14 15:48:14 +0400
commit4e4080016604e2c7ca9a5e75d6dd37d34b99cb09 (patch)
tree1a443fc6b7a16828c8a4b92d1724c2f72a4024f4 /app
parentfdd8e4507527badd875a40a0ab8a3ed47a03c764 (diff)
diff unfold
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/diff.js.coffee46
-rw-r--r--app/assets/javascripts/dispatcher.js.coffee10
-rw-r--r--app/assets/stylesheets/sections/diff.scss3
-rw-r--r--app/controllers/projects/blob_controller.rb15
-rw-r--r--app/helpers/commits_helper.rb12
-rw-r--r--app/views/projects/blob/diff.html.haml19
-rw-r--r--app/views/projects/commits/_diff_file.html.haml13
-rw-r--r--app/views/projects/commits/_text_file.html.haml14
-rw-r--r--app/views/projects/commits/diffs/_match_line.html.haml7
9 files changed, 126 insertions, 13 deletions
diff --git a/app/assets/javascripts/diff.js.coffee b/app/assets/javascripts/diff.js.coffee
new file mode 100644
index 00000000000..dbe00c487dc
--- /dev/null
+++ b/app/assets/javascripts/diff.js.coffee
@@ -0,0 +1,46 @@
+class Diff
+ UNFOLD_COUNT = 20
+ constructor: ->
+ $(document).on('click', '.js-unfold', (event) =>
+ target = $(event.target)
+ unfoldBottom = target.hasClass('js-unfold-bottom')
+ unfold = true
+
+ [old_line, line_number] = @lineNumbers(target.parent())
+ offset = line_number - old_line
+
+ if unfoldBottom
+ line_number += 1
+ since = line_number
+ to = line_number + UNFOLD_COUNT
+ else
+ [prev_old_line, prev_new_line] = @lineNumbers(target.parent().prev())
+ line_number -= 1
+ to = line_number
+ if line_number - UNFOLD_COUNT > prev_new_line + 1
+ since = line_number - UNFOLD_COUNT
+ else
+ since = prev_new_line + 1
+ unfold = false
+
+ link = target.parents('.diff-file').attr('data-blob-diff-path')
+ params =
+ since: since
+ to: to
+ bottom: unfoldBottom
+ offset: offset
+ unfold: unfold
+
+ $.get(link, params, (response) =>
+ target.parent().replaceWith(response)
+ )
+ )
+
+ lineNumbers: (line) ->
+ return ([0, 0]) unless line.children().length
+ lines = line.children().slice(0, 2)
+ line_numbers = ($(l).attr('data-linenumber') for l in lines)
+ (parseInt(line_number) for line_number in line_numbers)
+
+
+@Diff = Diff
diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee
index ff68b520ad6..89bb475a8a6 100644
--- a/app/assets/javascripts/dispatcher.js.coffee
+++ b/app/assets/javascripts/dispatcher.js.coffee
@@ -23,13 +23,21 @@ class Dispatcher
new Issue()
when 'projects:milestones:show'
new Milestone()
- when 'projects:issues:new', 'projects:merge_requests:new'
+ when 'projects:issues:new'
GitLab.GfmAutoComplete.setup()
+ when 'projects:merge_requests:new'
+ GitLab.GfmAutoComplete.setup()
+ new Diff()
+ when 'projects:merge_requests:show'
+ new Diff()
+ when "projects:merge_requests:diffs"
+ new Diff()
when 'dashboard:show'
new Dashboard()
new Activities()
when 'projects:commit:show'
new Commit()
+ new Diff()
when 'groups:show', 'projects:show'
new Activities()
when 'projects:new', 'projects:edit'
diff --git a/app/assets/stylesheets/sections/diff.scss b/app/assets/stylesheets/sections/diff.scss
index 88b188dbe8d..488d06919b0 100644
--- a/app/assets/stylesheets/sections/diff.scss
+++ b/app/assets/stylesheets/sections/diff.scss
@@ -48,6 +48,9 @@
background-color: #8F8;
}
}
+ .unfold {
+ cursor: pointer;
+ }
.file-mode-changed {
padding: 10px;
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb
index db3d173b98d..7009e3b1bc8 100644
--- a/app/controllers/projects/blob_controller.rb
+++ b/app/controllers/projects/blob_controller.rb
@@ -25,6 +25,21 @@ class Projects::BlobController < Projects::ApplicationController
end
end
+ def diff
+ @form = UnfoldForm.new(params)
+ @lines = @blob.data.lines[@form.since - 1..@form.to - 1]
+
+ if @form.bottom?
+ @match_line = ''
+ else
+ lines_length = @lines.length - 1
+ line = [@form.since, lines_length].join(',')
+ @match_line = "@@ -#{line}+#{line} @@"
+ end
+
+ render layout: false
+ end
+
private
def blob
diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb
index 9a8b3928bf4..f61aa259154 100644
--- a/app/helpers/commits_helper.rb
+++ b/app/helpers/commits_helper.rb
@@ -232,4 +232,16 @@ module CommitsHelper
def diff_file_mode_changed?(diff)
diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode
end
+
+ def unfold_bottom_class(bottom)
+ (bottom) ? 'js-unfold-bottom' : ''
+ end
+
+ def view_file_btn(commit_sha, diff, project)
+ link_to project_blob_path(project, tree_join(commit_sha, diff.new_path)),
+ class: 'btn btn-small view-file js-view-file' do
+ raw('View file @') + content_tag(:span, commit_sha[0..6],
+ class: 'commit-short-id')
+ end
+ end
end
diff --git a/app/views/projects/blob/diff.html.haml b/app/views/projects/blob/diff.html.haml
new file mode 100644
index 00000000000..cfb91d6568a
--- /dev/null
+++ b/app/views/projects/blob/diff.html.haml
@@ -0,0 +1,19 @@
+- if @lines.present?
+ - if @form.unfold? && @form.since != 1 && !@form.bottom?
+ %tr.line_holder{ id: @form.since }
+ = render "projects/commits/diffs/match_line", {line: @match_line,
+ line_old: @form.since, line_new: @form.since, bottom: false}
+
+ - @lines.each_with_index do |line, index|
+ - line_new = index + @form.since
+ - line_old = line_new - @form.offset
+ %tr.line_holder
+ %td.old_line.diff-line-num{data: {linenumber: line_old}}
+ = link_to raw(line_old), "#"
+ %td.new_line= link_to raw(line_new) , "#"
+ %td.line_content.noteable_line= line
+
+ - if @form.unfold? && @form.bottom? && @form.to < @blob.loc
+ %tr.line_holder{ id: @form.to }
+ = render "projects/commits/diffs/match_line", {line: @match_line,
+ line_old: @form.to, line_new: @form.to, bottom: true}
diff --git a/app/views/projects/commits/_diff_file.html.haml b/app/views/projects/commits/_diff_file.html.haml
index 9cbcb84aead..6e6107c8849 100644
--- a/app/views/projects/commits/_diff_file.html.haml
+++ b/app/views/projects/commits/_diff_file.html.haml
@@ -1,15 +1,15 @@
- file = project.repository.blob_for_diff(@commit, diff)
- return unless file
-.diff-file{id: "diff-#{i}"}
+- blob_diff_path = diff_project_blob_path(project,
+ tree_join(@commit.id, diff.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-btn-group
- if @commit.parent_ids.present?
- = link_to project_blob_path(project, tree_join(@commit.parent_id, diff.new_path)), { class: 'btn btn-small view-file' } do
- View file @
- %span.commit-short-id= @commit.short_id(6)
+ = view_file_btn(@commit.parent_id, diff, project)
- else
%span= diff.new_path
- if diff_file_mode_changed?(diff)
@@ -26,10 +26,7 @@
Edit
&nbsp;
- = link_to project_blob_path(project, tree_join(@commit.id, diff.new_path)), { class: 'btn btn-small view-file' } do
- View file @
- %span.commit-short-id= @commit.short_id(6)
-
+ = view_file_btn(@commit.id, diff, project)
.diff-content
-# Skipp all non non-supported blobs
diff --git a/app/views/projects/commits/_text_file.html.haml b/app/views/projects/commits/_text_file.html.haml
index f5b0d711416..756481c1b21 100644
--- a/app/views/projects/commits/_text_file.html.haml
+++ b/app/views/projects/commits/_text_file.html.haml
@@ -3,18 +3,20 @@
%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
%tr.line_holder{ id: line_code, class: "#{type}" }
- if type == "match"
- %td.old_line= "..."
- %td.new_line= "..."
- %td.line_content.matched= line
+ = render "projects/commits/diffs/match_line", {line: line,
+ line_old: line_old, line_new: line_new, 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= link_to raw(type == "old" ? "&nbsp;" : line_new) , "##{line_code}", id: 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)
- if @reply_allowed
@@ -22,6 +24,10 @@
- unless comments.empty?
= render "projects/notes/diff_notes_with_reply", notes: comments, line: line
+ - if last_line > 0
+ = render "projects/commits/diffs/match_line", {line: "",
+ line_old: last_line, line_new: last_line, bottom: true}
+
- if diff.diff.blank? && diff_file_mode_changed?(diff)
.file-mode-changed
File mode changed
diff --git a/app/views/projects/commits/diffs/_match_line.html.haml b/app/views/projects/commits/diffs/_match_line.html.haml
new file mode 100644
index 00000000000..4ebe3379733
--- /dev/null
+++ b/app/views/projects/commits/diffs/_match_line.html.haml
@@ -0,0 +1,7 @@
+%td.old_line.diff-line-num.unfold.js-unfold{data: {linenumber: line_old},
+ class: unfold_bottom_class(bottom)}
+ \...
+%td.new_line.diff-line-num.unfold.js-unfold{data: {linenumber: line_new},
+ class: unfold_bottom_class(bottom)}
+ \...
+%td.line_content.matched= line