Commit c01ff1f5 authored by Jacob Schatz's avatar Jacob Schatz

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
parents dfe0ec8f 19d8f673
...@@ -7,6 +7,7 @@ v 8.8.0 (unreleased) ...@@ -7,6 +7,7 @@ v 8.8.0 (unreleased)
- Updated search UI - Updated search UI
- Replace Devise Async with Devise ActiveJob integration. !3902 (Connor Shea) - Replace Devise Async with Devise ActiveJob integration. !3902 (Connor Shea)
- Allow "NEWS" and "CHANGES" as alternative names for CHANGELOG. !3768 (Connor Shea) - Allow "NEWS" and "CHANGES" as alternative names for CHANGELOG. !3768 (Connor Shea)
- Added button to toggle whitespaces changes on diff view
v 8.7.1 (unreleased) v 8.7.1 (unreleased)
- Throttle the update of `project.last_activity_at` to 1 minute. !3848 - Throttle the update of `project.last_activity_at` to 1 minute. !3848
......
...@@ -23,7 +23,7 @@ module DiffHelper ...@@ -23,7 +23,7 @@ module DiffHelper
end end
def diff_options def diff_options
options = { ignore_whitespace_change: params[:w] == '1' } options = { ignore_whitespace_change: hide_whitespace? }
if diff_hard_limit_enabled? if diff_hard_limit_enabled?
options.merge!(Commit.max_diff_options) options.merge!(Commit.max_diff_options)
end end
...@@ -128,4 +128,31 @@ module DiffHelper ...@@ -128,4 +128,31 @@ module DiffHelper
title title
end end
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 end
- show_whitespace_toggle = local_assigns.fetch(:show_whitespace_toggle, true)
- if diff_view == 'parallel' - if diff_view == 'parallel'
- fluid_layout true - fluid_layout true
...@@ -5,6 +6,11 @@ ...@@ -5,6 +6,11 @@
.content-block.oneline-block.files-changed .content-block.oneline-block.files-changed
.inline-parallel-buttons .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 .btn-group
= inline_diff_btn = inline_diff_btn
= parallel_diff_btn = parallel_diff_btn
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
%h4 This comparison includes more than #{MergeRequestDiff::COMMITS_SAFE_SIZE} commits. %h4 This comparison includes more than #{MergeRequestDiff::COMMITS_SAFE_SIZE} commits.
%p To preserve performance the line changes are not shown. %p To preserve performance the line changes are not shown.
- else - 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 - if @ci_commit
#builds.builds.tab-pane #builds.builds.tab-pane
= render "projects/merge_requests/show/builds" = render "projects/merge_requests/show/builds"
......
...@@ -14,7 +14,7 @@ Locate the section for your GitLab remote in the `.git/config` file. It looks li ...@@ -14,7 +14,7 @@ Locate the section for your GitLab remote in the `.git/config` file. It looks li
Now add the line `fetch = +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*` to this section. Now add the line `fetch = +refs/merge-requests/*/head:refs/remotes/origin/merge-requests/*` to this section.
It should looks like this: It should look like this:
``` ```
[remote "origin"] [remote "origin"]
...@@ -43,7 +43,7 @@ $ git checkout origin/merge-requests/1 ...@@ -43,7 +43,7 @@ $ git checkout origin/merge-requests/1
![MR diff](merge_requests/merge_request_diff.png) ![MR diff](merge_requests/merge_request_diff.png)
It you add `w=1` option to URL, you can see diff without whitespace changes. If you click the "Hide whitespace changes" button, you can see the diff without whitespace changes.
![MR diff without whitespace](merge_requests/merge_request_diff_without_whitespace.png) ![MR diff without whitespace](merge_requests/merge_request_diff_without_whitespace.png)
......
require 'spec_helper'
feature 'Toggle Whitespace Changes', js: true, feature: true do
before do
login_as :admin
merge_request = create(:merge_request)
project = merge_request.source_project
visit diffs_namespace_project_merge_request_path(project.namespace, project, merge_request)
end
it 'has a button to toggle whitespace changes' do
expect(page).to have_content 'Hide whitespace changes'
end
describe 'clicking "Hide whitespace changes" button' do
it 'toggles the "Hide whitespace changes" button' do
click_link 'Hide whitespace changes'
expect(page).to have_content 'Show whitespace changes'
end
end
end
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