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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
f6624b5c
Commit
f6624b5c
authored
Oct 27, 2016
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix eslint failures on Diff and MergeRequestTabs
parent
825fea63
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
119 additions
and
117 deletions
+119
-117
app/assets/javascripts/diff.js.es6
app/assets/javascripts/diff.js.es6
+8
-11
app/assets/javascripts/merge_request_tabs.js.es6
app/assets/javascripts/merge_request_tabs.js.es6
+55
-53
spec/javascripts/merge_request_tabs_spec.js
spec/javascripts/merge_request_tabs_spec.js
+56
-53
No files found.
app/assets/javascripts/diff.js.es6
View file @
f6624b5c
/* eslint-disable */
/* eslint-disable
class-methods-use-this, no-param-reassign
*/
((global) => {
const UNFOLD_COUNT = 20;
...
...
@@ -29,7 +29,8 @@
const newLineNumber = ref[1];
const offset = newLineNumber - oldLineNumber;
const bottom = $target.hasClass('js-unfold-bottom');
let since, to;
let since;
let to;
let unfold = true;
if (bottom) {
...
...
@@ -54,19 +55,19 @@
const view = file.data('view');
const params = { since, to, bottom, offset, unfold, view };
$.get(link, params,
(response)
=> $target.parent().replaceWith(response));
$.get(link, params,
response
=> $target.parent().replaceWith(response));
}
handleClickLineNum(event) {
const hash = $(event.currentTarget).attr('href');
event.preventDefault();
if (history.pushState) {
history.pushState(null, null, hash);
if (
window.
history.pushState) {
window.
history.pushState(null, null, hash);
} else {
window.location.hash = hash;
}
this.highlighSelectedLine();
}
;
}
diffViewType() {
return $('.inline-parallel-buttons a.active').data('view-type');
...
...
@@ -76,10 +77,7 @@
if (!line.children().length) {
return [0, 0];
}
return line.find('.diff-line-num').map(function() {
return parseInt($(this).data('linenumber'));
});
return line.find('.diff-line-num').map((i, elm) => parseInt($(elm).data('linenumber'), 10));
}
highlighSelectedLine() {
...
...
@@ -96,5 +94,4 @@
}
global.Diff = Diff;
})(window.gl || (window.gl = {}));
app/assets/javascripts/merge_request_tabs.js.es6
View file @
f6624b5c
/* eslint-disable max-len, func-names, space-before-function-paren, no-var, space-before-blocks, prefer-rest-params, wrap-iife, no-use-before-define, no-underscore-dangle, no-undef, one-var, one-var-declaration-per-line, quotes, comma-dangle, consistent-return, prefer-template, no-param-reassign, camelcase, vars-on-top, space-in-parens, curly, prefer-arrow-callback, no-unused-vars, no-return-assign, semi, object-shorthand, operator-assignment, padded-blocks, max-len */
/* eslint-disable no-new, no-param-reassign, class-methods-use-this */
/* global Breakpoints, Cookies, DiffNotesApp */
/*= require js.cookie */
/*= require breakpoints */
/* eslint-disable max-len */
// MergeRequestTabs
//
// Handles persisting and restoring the current tab selection and lazily-loading
// content on the MergeRequests#show page.
//
/*= require js.cookie */
//
// ### Example Markup
//
...
...
@@ -45,11 +48,15 @@
// </div>
// </div>
//
/* eslint-enable max-len */
((global) => {
// Store the `location` object, allowing for easier stubbing in tests
let location = window.location;
class MergeRequestTabs {
constructor({ action, setUrl, buildsLoaded } = {}) {
constructor({ action, setUrl, buildsLoaded
, stubLocation
} = {}) {
this.diffsLoaded = false;
this.buildsLoaded = false;
this.pipelinesLoaded = false;
...
...
@@ -63,8 +70,10 @@
this.tabShown = this.tabShown.bind(this);
this.showTab = this.showTab.bind(this);
// Store the `location` object, allowing for easier stubbing in tests
this._location = window.location;
if (stubLocation) {
location = stubLocation;
}
this.bindEvents();
this.activateTab(action);
this.initAffix();
...
...
@@ -97,15 +106,15 @@
this.resetViewContainer();
} else if (this.isDiffAction(action)) {
this.loadDiff($target.attr('href'));
if (
(typeof bp !== "undefined" && bp !== null) && bp
.getBreakpointSize() !== 'lg') {
if (
Breakpoints.get()
.getBreakpointSize() !== 'lg') {
this.shrinkView();
}
if (this.diffViewType() === 'parallel') {
this.expandViewContainer();
}
const navBarHeight = $('.navbar-gitlab').outerHeight();
$.scrollTo(
".merge-request-details .merge-request-tabs"
, {
offset: -navBarHeight
$.scrollTo(
'.merge-request-details .merge-request-tabs'
, {
offset: -navBarHeight
,
});
} else if (action === 'builds') {
this.loadBuilds($target.attr('href'));
...
...
@@ -125,13 +134,12 @@
}
scrollToElement(container) {
if (
window.
location.hash) {
if (location.hash) {
const navBarHeight = $('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight() + document.querySelector('.js-tabs-affix').offsetHeight;
const navBarHeight = $('.navbar-gitlab').outerHeight() + $('.layout-nav').outerHeight();
const $el = $(`${container} ${window.location.hash}:not(.match)`);
const $el = $(`${container} ${location.hash}:not(.match)`);
if ($el.length) {
$.scrollTo($el[0], {
offset: -navBarHeight
offset: -navBarHeight
,
});
}
}
...
...
@@ -139,11 +147,9 @@
// Activate a tab based on the current action
activateTab(action) {
if (action === 'show') {
action = 'notes';
}
const activate = action === 'show' ? 'notes' : action;
// important note: the .tab('show') method triggers 'shown.bs.tab' event itself
$(`.merge-request-tabs a[data-action='${acti
on
}']`).tab('show');
$(`.merge-request-tabs a[data-action='${acti
vate
}']`).tab('show');
}
// Replaces the current Merge Request-specific action in the URL with a new one
...
...
@@ -167,33 +173,29 @@
//
// Returns the new URL String
setCurrentAction(action) {
// Normalize action, just to be safe
if (action === 'show') {
action = 'notes';
}
this.currentAction = action;
this.currentAction = action === 'show' ? 'notes' : action;
// Remove a trailing '/commits' '/diffs' '/builds' '/pipelines' '/new' '/new/diffs'
let new
_state = this._
location.pathname.replace(/\/(commits|diffs|builds|pipelines|new|new\/diffs)(\.html)?\/?$/, '');
let new
State =
location.pathname.replace(/\/(commits|diffs|builds|pipelines|new|new\/diffs)(\.html)?\/?$/, '');
// Append the new action if we're on a tab other than 'notes'
if (
a
ction !== 'notes') {
new
_state += `/${a
ction}`;
if (
this.currentA
ction !== 'notes') {
new
State += `/${this.currentA
ction}`;
}
// Ensure parameters and hash come along for the ride
new
_state += this._location.search + this._
location.hash;
new
State += location.search +
location.hash;
// Replace the current history state with the new one without breaking
// Turbolinks' history.
//
// See https://github.com/rails/turbolinks/issues/363
history.replaceState({
window.
history.replaceState({
turbolinks: true,
url: new
_state
}, document.title, new
_s
tate);
url: new
State,
}, document.title, new
S
tate);
return new
_s
tate;
return new
S
tate;
}
loadCommits(source) {
...
...
@@ -203,11 +205,11 @@
this.ajaxGet({
url: `${source}.json`,
success: (data) => {
document.querySelector(
"div#commits"
).innerHTML = data.html;
document.querySelector(
'div#commits'
).innerHTML = data.html;
gl.utils.localTimeAgo($('.js-timeago', 'div#commits'));
this.commitsLoaded = true;
this.scrollToElement(
"#commits"
);
}
this.scrollToElement(
'#commits'
);
}
,
});
}
...
...
@@ -222,7 +224,7 @@
url.href = source;
this.ajaxGet({
url: `${url.pathname}.json${
this._
location.search}`,
url: `${url.pathname}.json${location.search}`,
success: (data) => {
$('#diffs').html(data.html);
...
...
@@ -233,14 +235,14 @@
gl.utils.localTimeAgo($('.js-timeago', 'div#diffs'));
$('#diffs .js-syntax-highlight').syntaxHighlight();
if (this.diffViewType() === 'parallel' && this.isDiffAction(this.currentAction)
) {
if (this.diffViewType() === 'parallel' && this.isDiffAction(this.currentAction)) {
this.expandViewContainer();
}
this.diffsLoaded = true;
this.scrollToElement(
"#diffs"
);
this.scrollToElement(
'#diffs'
);
new gl.Diff();
}
}
,
});
}
...
...
@@ -251,12 +253,12 @@
this.ajaxGet({
url: `${source}.json`,
success: (data) => {
document.querySelector(
"div#builds"
).innerHTML = data.html;
document.querySelector(
'div#builds'
).innerHTML = data.html;
gl.utils.localTimeAgo($('.js-timeago', 'div#builds'));
this.buildsLoaded = true;
new gl.Pipelines();
this.scrollToElement(
"#builds"
);
}
this.scrollToElement(
'#builds'
);
}
,
});
}
...
...
@@ -270,8 +272,8 @@
$('#pipelines').html(data.html);
gl.utils.localTimeAgo($('.js-timeago', '#pipelines'));
this.pipelinesLoaded = true;
this.scrollToElement(
"#pipelines"
);
}
this.scrollToElement(
'#pipelines'
);
}
,
});
}
...
...
@@ -287,10 +289,9 @@
beforeSend: () => this.toggleLoading(true),
complete: () => this.toggleLoading(false),
dataType: 'json',
type: 'GET'
type: 'GET'
,
};
options = $.extend({}, defaults, options);
$.ajax(options);
$.ajax($.extend({}, defaults, options));
}
diffViewType() {
...
...
@@ -298,7 +299,7 @@
}
isDiffAction(action) {
return action === 'diffs' || action === 'new/diffs'
return action === 'diffs' || action === 'new/diffs'
;
}
expandViewContainer() {
...
...
@@ -356,11 +357,13 @@
const $layoutNav = $('.layout-nav');
$tabs.off('affix.bs.affix affix-top.bs.affix')
.affix({ offset: {
.affix({
offset: {
top: () => (
$diffTabs.offset().top - $tabs.height() - $fixedNav.height() - $layoutNav.height()
)
}})
),
},
})
.on('affix.bs.affix', () => $diffTabs.css({ marginTop: $tabs.height() }))
.on('affix-top.bs.affix', () => $diffTabs.css({ marginTop: '' }));
...
...
@@ -372,5 +375,4 @@
}
global.MergeRequestTabs = MergeRequestTabs;
})(window.gl || (window.gl = {}));
spec/javascripts/merge_request_tabs_spec.js
View file @
f6624b5c
/* eslint-disable
space-before-function-paren, no-var, comma-dangle, dot-notation, quotes, no-undef, no-return-assign, no-underscore-dangle, camelcase, padded-blocks, max-len
*/
/* eslint-disable
no-var, comma-dangle, object-shorthand
*/
/*= require merge_request_tabs */
//= require breakpoints
(
function
()
{
describe
(
'
MergeRequestTabs
'
,
function
()
{
var
stubLocation
;
stubLocation
=
function
(
stubs
)
{
var
defaults
;
defaults
=
{
(
function
()
{
describe
(
'
MergeRequestTabs
'
,
function
()
{
var
stubLocation
=
{};
var
setLocation
=
function
(
stubs
)
{
var
defaults
=
{
pathname
:
''
,
search
:
''
,
hash
:
''
};
return
$
.
extend
(
defaults
,
stubs
);
$
.
extend
(
stubLocation
,
defaults
,
stubs
||
{}
);
};
fixture
.
preload
(
'
merge_request_tabs.html
'
);
beforeEach
(
function
()
{
this
[
"
class
"
]
=
new
gl
.
MergeRequestTabs
();
return
this
.
spies
=
{
ajax
:
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(
function
()
{}),
history
:
spyOn
(
history
,
'
replaceState
'
).
and
.
callFake
(
function
()
{})
beforeEach
(
function
()
{
this
.
class
=
new
gl
.
MergeRequestTabs
({
stubLocation
:
stubLocation
});
setLocation
();
this
.
spies
=
{
ajax
:
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(
function
()
{}),
history
:
spyOn
(
window
.
history
,
'
replaceState
'
).
and
.
callFake
(
function
()
{})
};
});
describe
(
'
#activateTab
'
,
function
()
{
beforeEach
(
function
()
{
describe
(
'
#activateTab
'
,
function
()
{
beforeEach
(
function
()
{
fixture
.
load
(
'
merge_request_tabs.html
'
);
return
this
.
subject
=
this
[
"
class
"
]
.
activateTab
;
this
.
subject
=
this
.
class
.
activateTab
;
});
it
(
'
shows the first tab when action is show
'
,
function
()
{
it
(
'
shows the first tab when action is show
'
,
function
()
{
this
.
subject
(
'
show
'
);
return
expect
(
$
(
'
#notes
'
)).
toHaveClass
(
'
active
'
);
expect
(
$
(
'
#notes
'
)).
toHaveClass
(
'
active
'
);
});
it
(
'
shows the notes tab when action is notes
'
,
function
()
{
it
(
'
shows the notes tab when action is notes
'
,
function
()
{
this
.
subject
(
'
notes
'
);
return
expect
(
$
(
'
#notes
'
)).
toHaveClass
(
'
active
'
);
expect
(
$
(
'
#notes
'
)).
toHaveClass
(
'
active
'
);
});
it
(
'
shows the commits tab when action is commits
'
,
function
()
{
it
(
'
shows the commits tab when action is commits
'
,
function
()
{
this
.
subject
(
'
commits
'
);
return
expect
(
$
(
'
#commits
'
)).
toHaveClass
(
'
active
'
);
expect
(
$
(
'
#commits
'
)).
toHaveClass
(
'
active
'
);
});
return
it
(
'
shows the diffs tab when action is diffs
'
,
function
()
{
it
(
'
shows the diffs tab when action is diffs
'
,
function
()
{
this
.
subject
(
'
diffs
'
);
return
expect
(
$
(
'
#diffs
'
)).
toHaveClass
(
'
active
'
);
expect
(
$
(
'
#diffs
'
)).
toHaveClass
(
'
active
'
);
});
});
return
describe
(
'
#setCurrentAction
'
,
function
()
{
beforeEach
(
function
()
{
return
this
.
subject
=
this
[
"
class
"
].
setCurrentAction
;
describe
(
'
#setCurrentAction
'
,
function
()
{
beforeEach
(
function
()
{
this
.
subject
=
this
.
class
.
setCurrentAction
;
});
it
(
'
changes from commits
'
,
function
()
{
this
[
"
class
"
].
_location
=
stub
Location
({
it
(
'
changes from commits
'
,
function
()
{
set
Location
({
pathname
:
'
/foo/bar/merge_requests/1/commits
'
});
expect
(
this
.
subject
(
'
notes
'
)).
toBe
(
'
/foo/bar/merge_requests/1
'
);
return
expect
(
this
.
subject
(
'
diffs
'
)).
toBe
(
'
/foo/bar/merge_requests/1/diffs
'
);
expect
(
this
.
subject
(
'
diffs
'
)).
toBe
(
'
/foo/bar/merge_requests/1/diffs
'
);
});
it
(
'
changes from diffs
'
,
function
()
{
this
[
"
class
"
].
_location
=
stub
Location
({
it
(
'
changes from diffs
'
,
function
()
{
set
Location
({
pathname
:
'
/foo/bar/merge_requests/1/diffs
'
});
expect
(
this
.
subject
(
'
notes
'
)).
toBe
(
'
/foo/bar/merge_requests/1
'
);
return
expect
(
this
.
subject
(
'
commits
'
)).
toBe
(
'
/foo/bar/merge_requests/1/commits
'
);
expect
(
this
.
subject
(
'
commits
'
)).
toBe
(
'
/foo/bar/merge_requests/1/commits
'
);
});
it
(
'
changes from diffs.html
'
,
function
()
{
this
[
"
class
"
].
_location
=
stub
Location
({
it
(
'
changes from diffs.html
'
,
function
()
{
set
Location
({
pathname
:
'
/foo/bar/merge_requests/1/diffs.html
'
});
expect
(
this
.
subject
(
'
notes
'
)).
toBe
(
'
/foo/bar/merge_requests/1
'
);
return
expect
(
this
.
subject
(
'
commits
'
)).
toBe
(
'
/foo/bar/merge_requests/1/commits
'
);
expect
(
this
.
subject
(
'
commits
'
)).
toBe
(
'
/foo/bar/merge_requests/1/commits
'
);
});
it
(
'
changes from notes
'
,
function
()
{
this
[
"
class
"
].
_location
=
stub
Location
({
it
(
'
changes from notes
'
,
function
()
{
set
Location
({
pathname
:
'
/foo/bar/merge_requests/1
'
});
expect
(
this
.
subject
(
'
diffs
'
)).
toBe
(
'
/foo/bar/merge_requests/1/diffs
'
);
return
expect
(
this
.
subject
(
'
commits
'
)).
toBe
(
'
/foo/bar/merge_requests/1/commits
'
);
expect
(
this
.
subject
(
'
commits
'
)).
toBe
(
'
/foo/bar/merge_requests/1/commits
'
);
});
it
(
'
includes search parameters and hash string
'
,
function
()
{
this
[
"
class
"
].
_location
=
stub
Location
({
it
(
'
includes search parameters and hash string
'
,
function
()
{
set
Location
({
pathname
:
'
/foo/bar/merge_requests/1/diffs
'
,
search
:
'
?view=parallel
'
,
hash
:
'
#L15-35
'
});
return
expect
(
this
.
subject
(
'
show
'
)).
toBe
(
'
/foo/bar/merge_requests/1?view=parallel#L15-35
'
);
expect
(
this
.
subject
(
'
show
'
)).
toBe
(
'
/foo/bar/merge_requests/1?view=parallel#L15-35
'
);
});
it
(
'
replaces the current history state
'
,
function
()
{
var
new
_s
tate
;
this
[
"
class
"
].
_location
=
stub
Location
({
it
(
'
replaces the current history state
'
,
function
()
{
var
new
S
tate
;
set
Location
({
pathname
:
'
/foo/bar/merge_requests/1
'
});
new
_s
tate
=
this
.
subject
(
'
commits
'
);
return
expect
(
this
.
spies
.
history
).
toHaveBeenCalledWith
({
new
S
tate
=
this
.
subject
(
'
commits
'
);
expect
(
this
.
spies
.
history
).
toHaveBeenCalledWith
({
turbolinks
:
true
,
url
:
new
_s
tate
},
document
.
title
,
new
_s
tate
);
url
:
new
S
tate
},
document
.
title
,
new
S
tate
);
});
return
it
(
'
treats "show" like "notes"
'
,
function
()
{
this
[
"
class
"
].
_location
=
stub
Location
({
it
(
'
treats "show" like "notes"
'
,
function
()
{
set
Location
({
pathname
:
'
/foo/bar/merge_requests/1/commits
'
});
return
expect
(
this
.
subject
(
'
show
'
)).
toBe
(
'
/foo/bar/merge_requests/1
'
);
expect
(
this
.
subject
(
'
show
'
)).
toBe
(
'
/foo/bar/merge_requests/1
'
);
});
});
});
}).
call
(
this
);
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