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
65e761e6
Commit
65e761e6
authored
Feb 15, 2018
by
André Luís
Committed by
Clement Ho
Feb 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-enable eslint in `commits.js` file
parent
ee2313f6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
55 deletions
+39
-55
app/assets/javascripts/commits.js
app/assets/javascripts/commits.js
+27
-45
app/assets/javascripts/pages/projects/commits/show/index.js
app/assets/javascripts/pages/projects/commits/show/index.js
+1
-1
spec/javascripts/commits_spec.js
spec/javascripts/commits_spec.js
+11
-9
No files found.
app/assets/javascripts/commits.js
View file @
65e761e6
/* eslint-disable func-names, wrap-iife, consistent-return,
no-return-assign, no-param-reassign, one-var-declaration-per-line, no-unused-vars,
prefer-template, object-shorthand, prefer-arrow-callback */
import
{
pluralize
}
from
'
./lib/utils/text_utility
'
;
import
{
localTimeAgo
}
from
'
./lib/utils/datetime_utility
'
;
import
Pager
from
'
./pager
'
;
import
axios
from
'
./lib/utils/axios_utils
'
;
export
default
(
function
()
{
const
CommitsList
=
{};
CommitsList
.
timer
=
null
;
export
default
class
CommitsList
{
constructor
(
limit
=
0
)
{
this
.
timer
=
null
;
CommitsList
.
init
=
function
(
limit
)
{
this
.
$contentList
=
$
(
'
.content_list
'
);
$
(
'
body
'
).
on
(
'
click
'
,
'
.day-commits-table li.commit
'
,
function
(
e
)
{
if
(
e
.
target
.
nodeName
!==
'
A
'
)
{
location
.
href
=
$
(
this
).
attr
(
'
url
'
);
e
.
stopPropagation
();
return
false
;
}
});
Pager
.
init
(
parseInt
(
limit
,
10
),
false
,
false
,
this
.
processCommits
);
Pager
.
init
(
parseInt
(
limit
,
10
),
false
,
false
,
this
.
processCommits
.
bind
(
this
));
this
.
content
=
$
(
'
#commits-list
'
);
this
.
searchField
=
$
(
'
#commits-search
'
);
this
.
lastSearch
=
this
.
searchField
.
val
();
return
this
.
initSearch
();
}
;
this
.
initSearch
();
}
CommitsList
.
initSearch
=
function
()
{
initSearch
()
{
this
.
timer
=
null
;
return
this
.
searchField
.
keyup
((
function
(
_this
)
{
return
function
()
{
clearTimeout
(
_this
.
timer
);
return
_this
.
timer
=
setTimeout
(
_this
.
filterResults
,
500
);
};
})(
this
));
};
this
.
searchField
.
on
(
'
keyup
'
,
()
=>
{
clearTimeout
(
this
.
timer
);
this
.
timer
=
setTimeout
(
this
.
filterResults
.
bind
(
this
),
500
);
});
}
CommitsList
.
filterResults
=
function
()
{
filterResults
()
{
const
form
=
$
(
'
.commits-search-form
'
);
const
search
=
CommitsList
.
searchField
.
val
();
if
(
search
===
CommitsList
.
lastSearch
)
return
Promise
.
resolve
();
const
commitsUrl
=
form
.
attr
(
'
action
'
)
+
'
?
'
+
form
.
serialize
()
;
CommitsList
.
content
.
fadeTo
(
'
fast
'
,
0.5
);
const
search
=
this
.
searchField
.
val
();
if
(
search
===
this
.
lastSearch
)
return
Promise
.
resolve
();
const
commitsUrl
=
`
${
form
.
attr
(
'
action
'
)}
?
${
form
.
serialize
()}
`
;
this
.
content
.
fadeTo
(
'
fast
'
,
0.5
);
const
params
=
form
.
serializeArray
().
reduce
((
acc
,
obj
)
=>
Object
.
assign
(
acc
,
{
[
obj
.
name
]:
obj
.
value
,
}),
{});
...
...
@@ -55,9 +39,9 @@ export default (function () {
params
,
})
.
then
(({
data
})
=>
{
CommitsList
.
lastSearch
=
search
;
CommitsList
.
content
.
html
(
data
.
html
);
CommitsList
.
content
.
fadeTo
(
'
fast
'
,
1.0
);
this
.
lastSearch
=
search
;
this
.
content
.
html
(
data
.
html
);
this
.
content
.
fadeTo
(
'
fast
'
,
1.0
);
// Change url so if user reload a page - search results are saved
history
.
replaceState
({
...
...
@@ -65,16 +49,16 @@ export default (function () {
},
document
.
title
,
commitsUrl
);
})
.
catch
(()
=>
{
CommitsList
.
content
.
fadeTo
(
'
fast
'
,
1.0
);
CommitsList
.
lastSearch
=
null
;
this
.
content
.
fadeTo
(
'
fast
'
,
1.0
);
this
.
lastSearch
=
null
;
});
}
;
}
// Prepare loaded data.
CommitsList
.
processCommits
=
(
data
)
=>
{
processCommits
(
data
)
{
let
processedData
=
data
;
const
$processedData
=
$
(
processedData
);
const
$commitsHeadersLast
=
CommitsList
.
$contentList
.
find
(
'
li.js-commit-header
'
).
last
();
const
$commitsHeadersLast
=
this
.
$contentList
.
find
(
'
li.js-commit-header
'
).
last
();
const
lastShownDay
=
$commitsHeadersLast
.
data
(
'
day
'
);
const
$loadedCommitsHeadersFirst
=
$processedData
.
filter
(
'
li.js-commit-header
'
).
first
();
const
loadedShownDayFirst
=
$loadedCommitsHeadersFirst
.
data
(
'
day
'
);
...
...
@@ -97,7 +81,5 @@ export default (function () {
localTimeAgo
(
$processedData
.
find
(
'
.js-timeago
'
));
return
processedData
;
};
return
CommitsList
;
})();
}
}
app/assets/javascripts/pages/projects/commits/show/index.js
View file @
65e761e6
...
...
@@ -3,7 +3,7 @@ import GpgBadges from '~/gpg_badges';
import
ShortcutsNavigation
from
'
~/shortcuts_navigation
'
;
export
default
()
=>
{
CommitsList
.
init
(
document
.
querySelector
(
'
.js-project-commits-show
'
).
dataset
.
commitsLimit
);
new
CommitsList
(
document
.
querySelector
(
'
.js-project-commits-show
'
).
dataset
.
commitsLimit
);
// eslint-disable-line no-new
new
ShortcutsNavigation
();
// eslint-disable-line no-new
GpgBadges
.
fetch
();
};
spec/javascripts/commits_spec.js
View file @
65e761e6
...
...
@@ -4,6 +4,8 @@ import axios from '~/lib/utils/axios_utils';
import
CommitsList
from
'
~/commits
'
;
describe
(
'
Commits List
'
,
()
=>
{
let
commitsList
;
beforeEach
(()
=>
{
setFixtures
(
`
<form class="commits-search-form" action="/h5bp/html5-boilerplate/commits/master">
...
...
@@ -11,6 +13,7 @@ describe('Commits List', () => {
</form>
<ol id="commits-list"></ol>
`
);
commitsList
=
new
CommitsList
(
25
);
});
it
(
'
should be defined
'
,
()
=>
{
...
...
@@ -19,7 +22,7 @@ describe('Commits List', () => {
describe
(
'
processCommits
'
,
()
=>
{
it
(
'
should join commit headers
'
,
()
=>
{
C
ommitsList
.
$contentList
=
$
(
`
c
ommitsList
.
$contentList
=
$
(
`
<div>
<li class="commit-header" data-day="2016-09-20">
<span class="day">20 Sep, 2016</span>
...
...
@@ -39,7 +42,7 @@ describe('Commits List', () => {
// The last commit header should be removed
// since the previous one has the same data-day value.
expect
(
C
ommitsList
.
processCommits
(
data
).
find
(
'
li.commit-header
'
).
length
).
toBe
(
0
);
expect
(
c
ommitsList
.
processCommits
(
data
).
find
(
'
li.commit-header
'
).
length
).
toBe
(
0
);
});
});
...
...
@@ -48,8 +51,7 @@ describe('Commits List', () => {
let
mock
;
beforeEach
(()
=>
{
CommitsList
.
init
(
25
);
CommitsList
.
searchField
.
val
(
''
);
commitsList
.
searchField
.
val
(
''
);
spyOn
(
history
,
'
replaceState
'
).
and
.
stub
();
mock
=
new
MockAdapter
(
axios
);
...
...
@@ -66,11 +68,11 @@ describe('Commits List', () => {
});
it
(
'
should save the last search string
'
,
(
done
)
=>
{
C
ommitsList
.
searchField
.
val
(
'
GitLab
'
);
C
ommitsList
.
filterResults
()
c
ommitsList
.
searchField
.
val
(
'
GitLab
'
);
c
ommitsList
.
filterResults
()
.
then
(()
=>
{
expect
(
ajaxSpy
).
toHaveBeenCalled
();
expect
(
C
ommitsList
.
lastSearch
).
toEqual
(
'
GitLab
'
);
expect
(
c
ommitsList
.
lastSearch
).
toEqual
(
'
GitLab
'
);
done
();
})
...
...
@@ -78,10 +80,10 @@ describe('Commits List', () => {
});
it
(
'
should not make ajax call if the input does not change
'
,
(
done
)
=>
{
C
ommitsList
.
filterResults
()
c
ommitsList
.
filterResults
()
.
then
(()
=>
{
expect
(
ajaxSpy
).
not
.
toHaveBeenCalled
();
expect
(
C
ommitsList
.
lastSearch
).
toEqual
(
''
);
expect
(
c
ommitsList
.
lastSearch
).
toEqual
(
''
);
done
();
})
...
...
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