diff --git a/Gemfile b/Gemfile
index 24640164f..fdffdb31c 100644
--- a/Gemfile
+++ b/Gemfile
@@ -29,7 +29,7 @@ gem 'state_machines-activerecord'
gem 'redis-rails'
gem 'grack', git: 'git://github.com/rosa-abf/grack.git', require: 'git_http'
-gem 'grit', git: 'git://github.com/rosa-abf/grit.git', tag: '2.6.16'
+gem 'grit', git: 'git://github.com/rosa-abf/grit.git', tag: '2.6.17'
gem 'charlock_holmes'
gem 'github-linguist', '3.1.5', require: 'linguist'
gem 'diff-display'
diff --git a/Gemfile.lock b/Gemfile.lock
index 4dbc5f2cf..52a43a070 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -34,8 +34,8 @@ GIT
GIT
remote: git://github.com/rosa-abf/grit.git
- revision: a9548c92188cc307e7af1dd41a733e7000a783a9
- tag: 2.6.16
+ revision: b733f0ceefb44b18a9dec8f509ba5493dab59e4e
+ tag: 2.6.17
specs:
grit (2.5.0)
diff-lcs (~> 1.1)
diff --git a/app/assets/javascripts/angularjs/comments/comments_controller.js.coffee b/app/assets/javascripts/angularjs/comments/comments_controller.js.coffee
index 2cce12bb0..d5fb3380d 100644
--- a/app/assets/javascripts/angularjs/comments/comments_controller.js.coffee
+++ b/app/assets/javascripts/angularjs/comments/comments_controller.js.coffee
@@ -75,15 +75,22 @@ CommentsController = (Comment, Preview, confirmMessage, $scope, compileHTML, $ro
else
false
- vm.add = ->
+ vm.add = ($event)->
+ $event.preventDefault()
+ $event.stopPropagation()
+
vm.processing = true
- promise = Comment.add(vm.project, vm.commentable, vm.new_body)
- promise.then (response) ->
- element = compileHTML.run($scope, response.data.html)
+ Comment.add(vm.project, vm.commentable, vm.new_body)
+ .success (data) ->
+ element = compileHTML.run($scope, data.html)
list.append(element)
vm.new_body = ''
- location.hash = "#comment" + response.data.id;
+ location.hash = "#comment" + data.id;
+ vm.processing = false
+ $.notify(data.message, 'success')
+ .error (data) ->
+ $.notify(data.message, 'error')
vm.processing = false
false
@@ -91,8 +98,8 @@ CommentsController = (Comment, Preview, confirmMessage, $scope, compileHTML, $ro
vm.remove = (id) ->
return false unless confirmMessage.show()
vm.processing = true
- promise = Comment.remove(vm.project, vm.commentable, id)
- promise.then () ->
+ Comment.remove(vm.project, vm.commentable, id)
+ .success (data)->
parent = $('#comment'+id+',#diff-comment'+id).parents('tr.line-comments')
if parent.find('.line-comment').length is 1
# there is only one line comment, remove all line
@@ -100,16 +107,21 @@ CommentsController = (Comment, Preview, confirmMessage, $scope, compileHTML, $ro
else
$('#comment'+id+',#diff-comment'+id+',#update-comment'+id).remove()
+ $.notify(data.message, 'success')
+ vm.processing = false
+ .error (data)->
+ $.notify(data.message, 'error')
vm.processing = false
false
vm.update = (id) ->
vm.processing = true
- promise = Comment.update(vm.project, vm.commentable, id)
- promise.then (response) ->
- form = $('#comment'+id+ ' .md_and_cm.cm-s-default').html(response.data.body)
+ Comment.update(vm.project, vm.commentable, id)
+ .success (data) ->
+ form = $('#comment'+id+ ' .md_and_cm.cm-s-default').html(data.body)
+ $.notify(data.message, 'success')
vm.processing = false
form = $('.open-comment.comment-'+id)
if form.length is 1
@@ -117,6 +129,9 @@ CommentsController = (Comment, Preview, confirmMessage, $scope, compileHTML, $ro
return true
else
return false
+ .error (data) ->
+ $.notify(data.message, 'error')
+ vm.processing = false
vm.showInlineForm = ($event, params = {}) ->
line_comments = findInlineComments($event, params)
diff --git a/app/assets/javascripts/angularjs/pull_requests/pull_request_controller.js.coffee b/app/assets/javascripts/angularjs/pull_requests/pull_request_controller.js.coffee
index 97772a8e4..b72a85eb3 100644
--- a/app/assets/javascripts/angularjs/pull_requests/pull_request_controller.js.coffee
+++ b/app/assets/javascripts/angularjs/pull_requests/pull_request_controller.js.coffee
@@ -108,9 +108,8 @@ PullRequestController = (dataservice, $http, ApiPullRequest, ApiProject, DateTim
promise = ApiPullRequest.get_diff(vm.pull_params)
promise.then (response) ->
diff.html(null)
- #html = compileHTML.run($scope, response.data)
- #diff.html(html)
$rootScope.$broadcast('compile_html', { element: diff, html: response.data })
+ $('[data-toggle="tooltip"]').tooltip()
vm.processing = false
vm.is_diff_updated = true
false
diff --git a/app/assets/javascripts/extra/diff.js.coffee b/app/assets/javascripts/extra/diff.js.coffee
index 77b3e59cd..dc811ae69 100644
--- a/app/assets/javascripts/extra/diff.js.coffee
+++ b/app/assets/javascripts/extra/diff.js.coffee
@@ -1,5 +1,5 @@
$(document).ready ->
- $(document).on 'click', '#diff_header .panel-body table a', ->
+ $(document).on 'click', '#diff_header .panel-body li.list-group-item a', ->
href = $(this).attr('href')
$(".diff_data.collapse#"+href.slice(1)+"_content").collapse('show')
diff --git a/app/assets/stylesheets/views/diff.sass b/app/assets/stylesheets/views/diff.sass
index 9d32cfe4a..5e6448143 100644
--- a/app/assets/stylesheets/views/diff.sass
+++ b/app/assets/stylesheets/views/diff.sass
@@ -3,7 +3,7 @@
overflow-x: auto
table.table.diff.inline
- //border: 1px solid #DDD
+ margin-bottom: 0
tr.changes
pre
@@ -66,17 +66,6 @@ table.table.diff.inline
.line-comment, #new_inline_comment
max-width: 700px
- td.diff-image
- text-align: center
-
- span.diff-image
- text-align: center
- margin: 0
- padding: 0
-
- img
- margin-top: 5px
-
div.file div.top
min-height: 28px
background: #ededed
diff --git a/app/controllers/projects/comments_controller.rb b/app/controllers/projects/comments_controller.rb
index dc6a31cd6..d90cd05a6 100644
--- a/app/controllers/projects/comments_controller.rb
+++ b/app/controllers/projects/comments_controller.rb
@@ -6,15 +6,19 @@ class Projects::CommentsController < Projects::BaseController
include CommentsHelper
def create
- if !@comment.set_additional_data params
- render json: {
- error: I18n.t("flash.comment.save_error"),
- message: @comment.errors.full_messages
- }
- elsif @comment.save
- render :create
- else
- render json: { error: I18n.t("flash.comment.save_error") }, status: 422
+ respond_to do |format|
+ if !@comment.set_additional_data params
+ format.json {
+ render json: {
+ message: I18n.t("flash.comment.save_error"),
+ error: @comment.errors.full_messages
+ }
+ }
+ elsif @comment.save
+ format.json {}
+ else
+ format.json { render json: { message: I18n.t("flash.comment.save_error") }, status: 422 }
+ end
end
end
@@ -22,17 +26,24 @@ class Projects::CommentsController < Projects::BaseController
end
def update
- status, message = if @comment.update_attributes(params[:comment])
- [200, view_context.markdown(@comment.body)]
- else
- [422, 'error']
+ respond_to do |format|
+ if @comment.update_attributes(params[:comment])
+ format.json { render json: {message:t('flash.comment.updated'), body: view_context.markdown(@comment.body)} }
+ else
+ format.json { render json: {message:t('flash.comment.error_in_updating')}, status: 422 }
+ end
end
- render json: {body: message}, status: status
end
def destroy
- @comment.destroy
- render json: nil
+ respond_to do |format|
+ if @comment.present? && @comment.destroy
+ format.json { render json: {message: I18n.t('flash.comment.destroyed')} }
+ else
+ format.json {
+ render json: {message: t('flash.comment.error_in_deleting')}, status: 422 }
+ end
+ end
end
protected
diff --git a/app/controllers/projects/git/commits_controller.rb b/app/controllers/projects/git/commits_controller.rb
index 3dd5b5295..5072521dd 100644
--- a/app/controllers/projects/git/commits_controller.rb
+++ b/app/controllers/projects/git/commits_controller.rb
@@ -14,7 +14,7 @@ class Projects::Git::CommitsController < Projects::Git::BaseController
respond_to do |format|
format.html
- format.diff { render text: (@commit.diffs.map(&:diff).join("\n") rescue ''), content_type: "text/plain" }
+ format.diff { render text: (@commit.show.map(&:diff).join("\n") rescue ''), content_type: "text/plain" }
format.patch { render text: (@commit.to_patch rescue ''), content_type: "text/plain" }
end
end
diff --git a/app/helpers/commit_helper.rb b/app/helpers/commit_helper.rb
index f3282580b..a031fc950 100644
--- a/app/helpers/commit_helper.rb
+++ b/app/helpers/commit_helper.rb
@@ -1,23 +1,31 @@
module CommitHelper
MAX_FILES_WITHOUT_COLLAPSE = 25
- def render_commit_stats(stats)
- res = ["
"]
+ def render_commit_stats(options = {})
+ stats = options[:stats]
+ diff = options[:diff]
+ repo = options[:repo]
+ commit = options[:commit]
+ parent_commit = commit.parents.try(:first)
+
+ res = [""]
ind=0
stats.files.each do |filename, adds, deletes, total|
- res << ""
- res << "#{h(filename.rtruncate 120)} | "
- res << ""
- res << I18n.t("layout.projects.inline_changes_count", count: total).strip +
- " (" +
- I18n.t("layout.projects.inline_additions_count", count: adds).strip +
- ", " +
- I18n.t("layout.projects.inline_deletions_count", count: deletes).strip +
- ")"
- res << " | "
+ file_name = get_filename_in_diff(diff[ind], filename)
+ file_status = t "layout.projects.diff.#{get_file_status_in_diff(diff[ind])}"
+ res << "- "
+ res << "
"
+ res << "
"
+ res << render_file_changes(diff: diff[ind], adds: adds, deletes: deletes, total: total,
+ repo: repo, commit: commit, parent_commit: parent_commit, file_status: file_status)
+ res << "
"
ind +=1
end
- res << "
"
+ res << ""
wrap_commit_header_list(stats, res)
end
@@ -73,9 +81,116 @@ module CommitHelper
Russian.p(commits_count, *commits_pluralization_arr)
end
+ def is_file_open_in_diff(blob, diff)
+ return true if blob.binary? && blob.render_as == :image
+ return true if diff.diff.blank? && diff.a_mode != diff.b_mode
+ diff.diff.present? && diff.diff.split("\n").count <= DiffHelper::MAX_LINES_WITHOUT_COLLAPSE
+ end
+
+ def file_blob_in_diff(repo, commit_id, diff)
+ return if repo.nil? || commit_id.nil? || diff.nil?
+ tree = repo.tree(commit_id)
+ blob = diff.renamed_file ? (tree / diff.b_path) : (tree / (diff.a_path || diff.b_path))
+ blob || diff.a_blob || diff.b_blob
+ end
+
+ def get_commit_id_for_file(diff, commit, parent_commit)
+ diff.deleted_file ? parent_commit.id : commit.id
+ end
+
+ def get_file_status_in_diff(diff)
+ if diff.renamed_file
+ :renamed_file
+ elsif diff.new_file
+ :new_file
+ elsif diff.deleted_file
+ :deleted_file
+ else
+ :changed_file
+ end
+ end
+
+ def get_filename_in_diff(diff, filename)
+ if diff.renamed_file
+ "#{diff.a_path.rtruncate 50} => #{diff.b_path.rtruncate 50}"
+ else
+ filename.rtruncate(100)
+ end
+ end
+
protected
def commits_pluralization_arr
pluralize ||= t('layout.commits.pluralize').map {|base, title| title.to_s}
end
+
+ def render_file_changes(options = {})
+ diff = options[:diff]
+ adds = options[:adds]
+ deletes = options[:deletes]
+ total = options[:total]
+ repo = options[:repo]
+ file_status = options[:file_status]
+ commit_id = get_commit_id_for_file(diff, options[:commit], options[:parent_commit])
+ blob = file_blob_in_diff(repo, commit_id, diff)
+
+ res = ''
+ res << ""
+ res << "
"
+ if blob.binary?
+ res << "#{t 'layout.projects.diff.binary'} #{file_status}"
+ elsif total > 0
+ res << "+#{adds} -#{deletes}"
+ else # total == 0
+ res << "#{t 'layout.projects.diff.without_changes'}"
+ end
+ res << "
"
+ res << "
"
+
+ res << ""
+ res << render_progress_bar(adds, deletes, total, blob)
+ res << "
"
+
+ end
+
+ def render_progress_bar(adds, deletes, total, blob)
+ res = ''
+ pluses = 0
+ minuses = 0
+
+ if total > 0
+ pluses = ((adds/(adds+deletes).to_f)*100).round
+ minuses = 100 - pluses
+ end
+
+ title = if total >0
+ t 'layout.projects.inline_changes_count', count: total
+ elsif !blob.binary?
+ t 'layout.projects.diff.without_changes'
+ else
+ 'BIN'
+ end
+
+ res << ""
+ res << "
"
+ res << "
"
+ res << "
"
+ res
+ end
+
+ def diff_file_icon(diff)
+ icon = case get_file_status_in_diff(diff)
+ when :renamed_file
+ 'fa-caret-square-o-right text-info'
+ when :new_file
+ 'fa-plus-square text-success'
+ when :deleted_file
+ 'fa-minus-square text-danger'
+ when :changed_file
+ 'fa-pencil-square text-primary'
+ else
+ 'fa-exclamation-circle text-danger'
+ end
+ ""
+ end
end
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb
index afa4b193a..f698214ce 100644
--- a/app/helpers/diff_helper.rb
+++ b/app/helpers/diff_helper.rb
@@ -1,26 +1,41 @@
module DiffHelper
- MAX_FILES_WITHOUT_COLLAPSE = 25
+ include CommitHelper
+
MAX_LINES_WITHOUT_COLLAPSE = 50
- def render_diff_stats(stats)
- res = [""]
+ def render_diff_stats(options = {})
+ stats = options[:stats]
+ diff = options[:diff]
+ repo = options[:repo]
+ commit = options[:commit]
+ parent_commit = options[:common_ancestor]
+
+ res = [""]
stats.each_with_index do |stat, ind|
- res << ""
- res << "#{link_to stat.filename.rtruncate(120), "#diff-#{ind}"} | "
- res << ""
- res << I18n.t("layout.projects.inline_changes_count", count: stat.additions + stat.deletions).strip +
- " (" +
- I18n.t("layout.projects.inline_additions_count", count: stat.additions).strip +
- ", " +
- I18n.t("layout.projects.inline_deletions_count", count: stat.deletions).strip +
- ")"
- res << " | "
+ adds = stat.additions
+ deletes = stat.deletions
+ total = adds + deletes
+ file_name = get_filename_in_diff(diff[ind], stat.filename)
+ file_status = t "layout.projects.diff.#{get_file_status_in_diff(diff[ind])}"
+
+ res << "- "
+ res << "
"
+ res << "
"
+ res << render_file_changes(diff: diff[ind], adds: adds, deletes: deletes, total: total,
+ repo: repo, commit: commit, parent_commit: parent_commit, file_status: file_status)
+ res << "
"
+ ind +=1
end
- res << '
'
- wrap_header_list(stats, res)
+ res << ""
+
+ wrap_diff_header_list(stats, res)
end
- def wrap_header_list(stats, list)
+ def wrap_diff_header_list(stats, list)
is_stats_open = stats.count <= MAX_FILES_WITHOUT_COLLAPSE ? 'in' : ''
res = ["