Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
faa53a8a
Commit
faa53a8a
authored
Jan 16, 2017
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix/diff-title' into 'master'
Fix issue with diff comments path See merge request !7819
parents
1028b111
c1dd08e1
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
26 deletions
+55
-26
app/assets/javascripts/diff.js.es6
app/assets/javascripts/diff.js.es6
+14
-5
app/assets/javascripts/merge_request_tabs.js.es6
app/assets/javascripts/merge_request_tabs.js.es6
+2
-7
app/assets/javascripts/single_file_diff.js
app/assets/javascripts/single_file_diff.js
+10
-12
app/views/projects/diffs/_file.html.haml
app/views/projects/diffs/_file.html.haml
+1
-1
spec/features/expand_collapse_diffs_spec.rb
spec/features/expand_collapse_diffs_spec.rb
+28
-1
No files found.
app/assets/javascripts/diff.js.es6
View file @
faa53a8a
...
...
@@ -20,7 +20,7 @@
.on('click', '.js-unfold', this.handleClickUnfold.bind(this))
.on('click', '.diff-line-num a', this.handleClickLineNum.bind(this));
this.
highlighSelectedLine
();
this.
openAnchoredDiff
();
}
handleClickUnfold(e) {
...
...
@@ -61,13 +61,22 @@
$.get(link, params, response => $target.parent().replaceWith(response));
}
openAnchoredDiff(anchoredDiff, cb) {
const diffTitle = $(`#file-path-${anchoredDiff}`);
openAnchoredDiff(cb) {
const locationHash = gl.utils.getLocationHash();
const anchoredDiff = locationHash && locationHash.split('_')[0];
if (!anchoredDiff) return;
const diffTitle = $(`#${anchoredDiff}`);
const diffFile = diffTitle.closest('.diff-file');
const nothingHereBlock = $('.nothing-here-block:visible', diffFile);
if (nothingHereBlock.length) {
diffFile.singleFileDiff(true, cb);
} else {
const clickTarget = $('.file-title, .click-to-expand', diffFile);
diffFile.data('singleFileDiff').toggleDiff(clickTarget, () => {
this.highlighSelectedLine();
if (cb) cb();
});
} else if (cb) {
cb();
}
}
...
...
app/assets/javascripts/merge_request_tabs.js.es6
View file @
faa53a8a
...
...
@@ -237,13 +237,8 @@
}
this.diffsLoaded = true;
const diffPage = new gl.Diff();
const locationHash = gl.utils.getLocationHash();
const anchoredDiff = locationHash && locationHash.split('_')[0];
if (anchoredDiff) {
diffPage.openAnchoredDiff(anchoredDiff, () => this.scrollToElement('#diffs'));
}
new gl.Diff();
this.scrollToElement('#diffs');
},
});
}
...
...
app/assets/javascripts/single_file_diff.js
View file @
faa53a8a
/* eslint-disable func-names, space-before-function-paren, no-var, space-before-blocks, prefer-rest-params, wrap-iife, one-var, one-var-declaration-per-line, consistent-return, no-param-reassign, padded-blocks, max-len */
/* eslint-disable func-names,
prefer-arrow-callback,
space-before-function-paren, no-var, space-before-blocks, prefer-rest-params, wrap-iife, one-var, one-var-declaration-per-line, consistent-return, no-param-reassign, padded-blocks, max-len */
(
function
()
{
var
bind
=
function
(
fn
,
me
){
return
function
(){
return
fn
.
apply
(
me
,
arguments
);
};
};
...
...
@@ -14,8 +14,7 @@
COLLAPSED_HTML
=
'
<div class="nothing-here-block diff-collapsed">This diff is collapsed. <a class="click-to-expand">Click to expand it.</a></div>
'
;
function
SingleFileDiff
(
file
,
forceLoad
,
cb
)
{
var
clickTarget
;
function
SingleFileDiff
(
file
)
{
this
.
file
=
file
;
this
.
toggleDiff
=
bind
(
this
.
toggleDiff
,
this
);
this
.
content
=
$
(
'
.diff-content
'
,
this
.
file
);
...
...
@@ -33,14 +32,13 @@
this
.
content
.
after
(
this
.
collapsedContent
);
this
.
$toggleIcon
.
addClass
(
'
fa-caret-down
'
);
}
clickTarget
=
$
(
'
.file-title, .click-to-expand
'
,
this
.
file
).
on
(
'
click
'
,
this
.
toggleDiff
);
if
(
forceLoad
)
{
this
.
toggleDiff
(
{
target
:
clickTarget
},
cb
);
}
$
(
'
.file-title, .click-to-expand
'
,
this
.
file
).
on
(
'
click
'
,
(
function
(
e
)
{
this
.
toggleDiff
(
$
(
e
.
target
)
);
}
).
bind
(
this
));
}
SingleFileDiff
.
prototype
.
toggleDiff
=
function
(
e
,
cb
)
{
var
$target
=
$
(
e
.
target
);
SingleFileDiff
.
prototype
.
toggleDiff
=
function
(
$target
,
cb
)
{
if
(
!
$target
.
hasClass
(
'
file-title
'
)
&&
!
$target
.
hasClass
(
'
click-to-expand
'
)
&&
!
$target
.
hasClass
(
'
diff-toggle-caret
'
))
return
;
this
.
isOpen
=
!
this
.
isOpen
;
if
(
!
this
.
isOpen
&&
!
this
.
hasError
)
{
...
...
@@ -91,10 +89,10 @@
})();
$
.
fn
.
singleFileDiff
=
function
(
forceLoad
,
cb
)
{
$
.
fn
.
singleFileDiff
=
function
()
{
return
this
.
each
(
function
()
{
if
(
!
$
.
data
(
this
,
'
singleFileDiff
'
)
||
forceLoad
)
{
return
$
.
data
(
this
,
'
singleFileDiff
'
,
new
window
.
SingleFileDiff
(
this
,
forceLoad
,
cb
));
if
(
!
$
.
data
(
this
,
'
singleFileDiff
'
))
{
return
$
.
data
(
this
,
'
singleFileDiff
'
,
new
window
.
SingleFileDiff
(
this
));
}
});
};
...
...
app/views/projects/diffs/_file.html.haml
View file @
faa53a8a
.diff-file.file-holder
{
id:
file_hash
,
data:
diff_file_html_data
(
project
,
diff_file
.
file_path
,
diff_commit
.
id
)
}
.file-title
{
id:
"file-path-#{hexdigest(diff_file.file_path)}"
}
.file-title
=
render
"projects/diffs/file_header"
,
diff_file:
diff_file
,
blob:
blob
,
diff_commit:
diff_commit
,
project:
project
,
url:
"#
#{
file_hash
}
"
-
unless
diff_file
.
submodule?
...
...
spec/features/expand_collapse_diffs_spec.rb
View file @
faa53a8a
...
...
@@ -4,10 +4,10 @@ feature 'Expand and collapse diffs', js: true, feature: true do
include
WaitForAjax
let
(
:branch
)
{
'expand-collapse-diffs'
}
let
(
:project
)
{
create
(
:project
)
}
before
do
login_as
:admin
project
=
create
(
:project
)
# Ensure that undiffable.md is in .gitattributes
project
.
repository
.
copy_gitattributes
(
branch
)
...
...
@@ -31,6 +31,33 @@ feature 'Expand and collapse diffs', js: true, feature: true do
define_method
(
file
.
split
(
'.'
).
first
)
{
file_container
(
file
)
}
end
it
'should show the diff content with a highlighted line when linking to line'
do
expect
(
large_diff
).
not_to
have_selector
(
'.code'
)
expect
(
large_diff
).
to
have_selector
(
'.nothing-here-block'
)
visit
namespace_project_commit_path
(
project
.
namespace
,
project
,
project
.
commit
(
branch
),
anchor:
"
#{
large_diff
[
:id
]
}
_0_1"
)
execute_script
(
'window.location.reload()'
)
wait_for_ajax
expect
(
large_diff
).
to
have_selector
(
'.code'
)
expect
(
large_diff
).
not_to
have_selector
(
'.nothing-here-block'
)
expect
(
large_diff
).
to
have_selector
(
'.hll'
)
end
it
'should show the diff content when linking to file'
do
expect
(
large_diff
).
not_to
have_selector
(
'.code'
)
expect
(
large_diff
).
to
have_selector
(
'.nothing-here-block'
)
visit
namespace_project_commit_path
(
project
.
namespace
,
project
,
project
.
commit
(
branch
),
anchor:
large_diff
[
:id
])
execute_script
(
'window.location.reload()'
)
wait_for_ajax
expect
(
large_diff
).
to
have_selector
(
'.code'
)
expect
(
large_diff
).
not_to
have_selector
(
'.nothing-here-block'
)
end
context
'visiting a commit with collapsed diffs'
do
it
'shows small diffs immediately'
do
expect
(
small_diff
).
to
have_selector
(
'.code'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment