Add Hide/show whitespace changes button on diff and commit view

This commit is contained in:
Alfredo Sumaran 2016-03-23 11:10:17 -05:00
parent 18e00e3ba3
commit d8d00b5bc2
2 changed files with 26 additions and 0 deletions

View file

@ -128,4 +128,26 @@ module DiffHelper
title
end
end
def hide_whitespaces?
params[:w] == '1'
end
def params_with_whitespace
hide_whitespaces? ? request.query_parameters.except(:w) : request.query_parameters.merge(w: 1)
end
def toggle_whitespace_link(url)
link_to "#{hide_whitespaces? ? 'Show' : 'Hide'} whitespace changes", url, class: "btn btn-default"
end
def commit_diff_whitespace_link(project, commit)
url = namespace_project_commit_path(project.namespace, project, commit.id, params_with_whitespace)
toggle_whitespace_link(url)
end
def diff_merge_request_whitespace_link(project, merge_request)
url = diffs_namespace_project_merge_request_path(project.namespace, project, merge_request, params_with_whitespace)
toggle_whitespace_link(url)
end
end

View file

@ -5,6 +5,10 @@
.content-block.oneline-block.files-changed
.inline-parallel-buttons
- if current_controller?(:commit)
= commit_diff_whitespace_link(@project, @commit)
- if current_controller?(:merge_requests)
= diff_merge_request_whitespace_link(@project, @merge_request)
.btn-group
= inline_diff_btn
= parallel_diff_btn