diff options
author | Jacob Schatz <jschatz@gitlab.com> | 2016-04-26 19:52:25 +0000 |
---|---|---|
committer | Jacob Schatz <jschatz@gitlab.com> | 2016-04-26 19:52:25 +0000 |
commit | c01ff1f54b55a60f7c7473d0d8a429d5cf9c1609 (patch) | |
tree | 824c837ece1cc0b12d4140689d81a94e4523845c /app | |
parent | dfe0ec8f72a13da2b45c52761a846204c2e66326 (diff) | |
parent | 19d8f6731a3e3912d880cfeacf0a82f5aea65f34 (diff) | |
download | gitlab-ce-c01ff1f54b55a60f7c7473d0d8a429d5cf9c1609.tar.gz |
Merge branch 'issue_4271' into 'master'
Add button to toggle whitespace changes
Closes #4271
**Merge Request**
<img src="/uploads/ea857269faed38a25b63b768d7f3a85b/Screen_Shot_2016-03-23_at_11.32.41_AM.png" width="1157" />
**Diff view**
<img src="/uploads/bc2ac3e4855584f9214c8f3ddf325b06/Screen_Shot_2016-03-23_at_11.32.53_AM.png" width="1211" />
See merge request !3367
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/diff_helper.rb | 29 | ||||
-rw-r--r-- | app/views/projects/diffs/_diffs.html.haml | 6 | ||||
-rw-r--r-- | app/views/projects/merge_requests/_new_submit.html.haml | 2 |
3 files changed, 35 insertions, 2 deletions
diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb index 97466d532f4..9f73edb4553 100644 --- a/app/helpers/diff_helper.rb +++ b/app/helpers/diff_helper.rb @@ -23,7 +23,7 @@ module DiffHelper end def diff_options - options = { ignore_whitespace_change: params[:w] == '1' } + options = { ignore_whitespace_change: hide_whitespace? } if diff_hard_limit_enabled? options.merge!(Commit.max_diff_options) end @@ -128,4 +128,31 @@ module DiffHelper title end end + + def commit_diff_whitespace_link(project, commit, options) + url = namespace_project_commit_path(project.namespace, project, commit.id, params_with_whitespace) + toggle_whitespace_link(url, options) + end + + def diff_merge_request_whitespace_link(project, merge_request, options) + url = diffs_namespace_project_merge_request_path(project.namespace, project, merge_request, params_with_whitespace) + toggle_whitespace_link(url, options) + end + + private + + def hide_whitespace? + params[:w] == '1' + end + + def params_with_whitespace + hide_whitespace? ? request.query_parameters.except(:w) : request.query_parameters.merge(w: 1) + end + + def toggle_whitespace_link(url, options) + options[:class] ||= '' + options[:class] << ' btn btn-default' + + link_to "#{hide_whitespace? ? 'Show' : 'Hide'} whitespace changes", url, class: options[:class] + end end diff --git a/app/views/projects/diffs/_diffs.html.haml b/app/views/projects/diffs/_diffs.html.haml index eaab99973a4..d9c4b410d32 100644 --- a/app/views/projects/diffs/_diffs.html.haml +++ b/app/views/projects/diffs/_diffs.html.haml @@ -1,3 +1,4 @@ +- show_whitespace_toggle = local_assigns.fetch(:show_whitespace_toggle, true) - if diff_view == 'parallel' - fluid_layout true @@ -5,6 +6,11 @@ .content-block.oneline-block.files-changed .inline-parallel-buttons + - if show_whitespace_toggle + - if current_controller?(:commit) + = commit_diff_whitespace_link(@project, @commit, class: 'hidden-xs') + - elsif current_controller?(:merge_requests) + = diff_merge_request_whitespace_link(@project, @merge_request, class: 'hidden-xs') .btn-group = inline_diff_btn = parallel_diff_btn diff --git a/app/views/projects/merge_requests/_new_submit.html.haml b/app/views/projects/merge_requests/_new_submit.html.haml index 2f14a91e64f..18b3f9e1549 100644 --- a/app/views/projects/merge_requests/_new_submit.html.haml +++ b/app/views/projects/merge_requests/_new_submit.html.haml @@ -42,7 +42,7 @@ %h4 This comparison includes more than #{MergeRequestDiff::COMMITS_SAFE_SIZE} commits. %p To preserve performance the line changes are not shown. - else - = render "projects/diffs/diffs", diffs: @diffs, project: @project, diff_refs: @merge_request.diff_refs + = render "projects/diffs/diffs", diffs: @diffs, project: @project, diff_refs: @merge_request.diff_refs, show_whitespace_toggle: false - if @ci_commit #builds.builds.tab-pane = render "projects/merge_requests/show/builds" |