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
Léo-Paul Géneau
gitlab-ce
Commits
2597d8d2
Commit
2597d8d2
authored
Oct 09, 2017
by
Filipa Lacerda
Committed by
Phil Hughes
Oct 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removes CommitsList from global namespace
parent
8af29c21
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
82 deletions
+79
-82
app/assets/javascripts/commits.js
app/assets/javascripts/commits.js
+26
-25
app/assets/javascripts/dispatcher.js
app/assets/javascripts/dispatcher.js
+1
-1
spec/javascripts/commits_spec.js
spec/javascripts/commits_spec.js
+52
-56
No files found.
app/assets/javascripts/commits.js
View file @
2597d8d2
/* eslint-disable func-names, space-before-function-paren, wrap-iife, quotes, consistent-return, no-return-assign, no-param-reassign, one-var, no-var, one-var-declaration-per-line, no-unused-vars, prefer-template, object-shorthand, comma-dangle, max-len, prefer-arrow-callback */
/* 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 */
/* global Pager */
window
.
CommitsList
=
(
function
()
{
var
CommitsList
=
{};
export
default
(
function
()
{
const
CommitsList
=
{};
CommitsList
.
timer
=
null
;
CommitsList
.
init
=
function
(
limit
)
{
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
"
);
$
(
'
body
'
).
on
(
'
click
'
,
'
.day-commits-table li.commit
'
,
function
(
e
)
{
if
(
e
.
target
.
nodeName
!==
'
A
'
)
{
location
.
href
=
$
(
this
).
attr
(
'
url
'
);
e
.
stopPropagation
();
return
false
;
}
...
...
@@ -19,48 +21,47 @@ window.CommitsList = (function() {
Pager
.
init
(
parseInt
(
limit
,
10
),
false
,
false
,
this
.
processCommits
);
this
.
content
=
$
(
"
#commits-list
"
);
this
.
searchField
=
$
(
"
#commits-search
"
);
this
.
content
=
$
(
'
#commits-list
'
);
this
.
searchField
=
$
(
'
#commits-search
'
);
this
.
lastSearch
=
this
.
searchField
.
val
();
return
this
.
initSearch
();
};
CommitsList
.
initSearch
=
function
()
{
CommitsList
.
initSearch
=
function
()
{
this
.
timer
=
null
;
return
this
.
searchField
.
keyup
((
function
(
_this
)
{
return
function
()
{
return
this
.
searchField
.
keyup
((
function
(
_this
)
{
return
function
()
{
clearTimeout
(
_this
.
timer
);
return
_this
.
timer
=
setTimeout
(
_this
.
filterResults
,
500
);
};
})(
this
));
};
CommitsList
.
filterResults
=
function
()
{
var
commitsUrl
,
form
,
search
;
form
=
$
(
"
.commits-search-form
"
);
search
=
CommitsList
.
searchField
.
val
();
CommitsList
.
filterResults
=
function
()
{
const
form
=
$
(
'
.commits-search-form
'
);
const
search
=
CommitsList
.
searchField
.
val
();
if
(
search
===
CommitsList
.
lastSearch
)
return
;
co
mmitsUrl
=
form
.
attr
(
"
action
"
)
+
'
?
'
+
form
.
serialize
();
co
nst
commitsUrl
=
form
.
attr
(
'
action
'
)
+
'
?
'
+
form
.
serialize
();
CommitsList
.
content
.
fadeTo
(
'
fast
'
,
0.5
);
return
$
.
ajax
({
type
:
"
GET
"
,
url
:
form
.
attr
(
"
action
"
),
type
:
'
GET
'
,
url
:
form
.
attr
(
'
action
'
),
data
:
form
.
serialize
(),
complete
:
function
()
{
complete
:
function
()
{
return
CommitsList
.
content
.
fadeTo
(
'
fast
'
,
1.0
);
},
success
:
function
(
data
)
{
success
:
function
(
data
)
{
CommitsList
.
lastSearch
=
search
;
CommitsList
.
content
.
html
(
data
.
html
);
return
history
.
replaceState
({
page
:
commitsUrl
page
:
commitsUrl
,
// Change url so if user reload a page - search results are saved
},
document
.
title
,
commitsUrl
);
},
error
:
function
()
{
error
:
function
()
{
CommitsList
.
lastSearch
=
null
;
},
dataType
:
"
json
"
dataType
:
'
json
'
,
});
};
...
...
@@ -81,7 +82,7 @@ window.CommitsList = (function() {
commitsCount
=
$commitsHeadersLast
.
nextUntil
(
'
li.js-commit-header
'
).
find
(
'
li.commit
'
).
length
;
// Remove duplicate of commits header.
processedData
=
$processedData
.
not
(
`li.js-commit-header[data-day=
"
${
loadedShownDayFirst
}
"
]`
);
processedData
=
$processedData
.
not
(
`li.js-commit-header[data-day=
'
${
loadedShownDayFirst
}
'
]`
);
// Update commits count in the previous commits header.
commitsCount
+=
Number
(
$
(
processedData
).
nextUntil
(
'
li.js-commit-header
'
).
first
().
find
(
'
li.commit
'
).
length
);
...
...
app/assets/javascripts/dispatcher.js
View file @
2597d8d2
...
...
@@ -7,7 +7,6 @@
/* global IssuableForm */
/* global LabelsSelect */
/* global MilestoneSelect */
/* global CommitsList */
/* global NewBranchForm */
/* global NotificationsForm */
/* global NotificationsDropdown */
...
...
@@ -35,6 +34,7 @@
/* global Sidebar */
/* global ShortcutsWiki */
import
CommitsList
from
'
./commits
'
;
import
Issue
from
'
./issue
'
;
import
BindInOut
from
'
./behaviors/bind_in_out
'
;
import
DeleteModal
from
'
./branches/branches_delete_modal
'
;
...
...
spec/javascripts/commits_spec.js
View file @
2597d8d2
/* global CommitsList */
import
'
vendor/jquery.endless-scroll
'
;
import
'
~/pager
'
;
import
'
~/commits
'
;
(()
=>
{
describe
(
'
Commits List
'
,
()
=>
{
beforeEach
(()
=>
{
setFixtures
(
`
<form class="commits-search-form" action="/h5bp/html5-boilerplate/commits/master">
<input id="commits-search">
</form>
<ol id="commits-list"></ol>
`
);
});
import
CommitsList
from
'
~/commits
'
;
it
(
'
should be defined
'
,
()
=>
{
expect
(
CommitsList
).
toBeDefined
();
});
describe
(
'
Commits List
'
,
()
=>
{
beforeEach
(()
=>
{
setFixtures
(
`
<form class="commits-search-form" action="/h5bp/html5-boilerplate/commits/master">
<input id="commits-search">
</form>
<ol id="commits-list"></ol>
`
);
});
describe
(
'
processCommits
'
,
()
=>
{
it
(
'
should join commit headers
'
,
()
=>
{
CommitsList
.
$contentList
=
$
(
`
<div>
<li class="commit-header" data-day="2016-09-20">
<span class="day">20 Sep, 2016</span>
<span class="commits-count">1 commit</span>
</li>
<li class="commit"></li>
</div>
`
);
it
(
'
should be defined
'
,
()
=>
{
expect
(
CommitsList
).
toBeDefined
();
});
const
data
=
`
describe
(
'
processCommits
'
,
()
=>
{
it
(
'
should join commit headers
'
,
()
=>
{
CommitsList
.
$contentList
=
$
(
`
<div>
<li class="commit-header" data-day="2016-09-20">
<span class="day">20 Sep, 2016</span>
<span class="commits-count">1 commit</span>
</li>
<li class="commit"></li>
`
;
</div>
`
);
// The last commit header should be removed
// since the previous one has the same data-day value.
expect
(
CommitsList
.
processCommits
(
data
).
find
(
'
li.commit-header
'
).
length
).
toBe
(
0
);
});
const
data
=
`
<li class="commit-header" data-day="2016-09-20">
<span class="day">20 Sep, 2016</span>
<span class="commits-count">1 commit</span>
</li>
<li class="commit"></li>
`
;
// The last commit header should be removed
// since the previous one has the same data-day value.
expect
(
CommitsList
.
processCommits
(
data
).
find
(
'
li.commit-header
'
).
length
).
toBe
(
0
);
});
});
describe
(
'
on entering input
'
,
()
=>
{
let
ajaxSpy
;
describe
(
'
on entering input
'
,
()
=>
{
let
ajaxSpy
;
beforeEach
(()
=>
{
CommitsList
.
init
(
25
);
CommitsList
.
searchField
.
val
(
''
);
beforeEach
(()
=>
{
CommitsList
.
init
(
25
);
CommitsList
.
searchField
.
val
(
''
);
spyOn
(
history
,
'
replaceState
'
).
and
.
stub
();
ajaxSpy
=
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
req
)
=>
{
req
.
success
({
data
:
'
<li>Result</li>
'
,
});
spyOn
(
history
,
'
replaceState
'
).
and
.
stub
();
ajaxSpy
=
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
((
req
)
=>
{
req
.
success
({
data
:
'
<li>Result</li>
'
,
});
});
});
it
(
'
should save the last search string
'
,
()
=>
{
CommitsList
.
searchField
.
val
(
'
GitLab
'
);
CommitsList
.
filterResults
();
expect
(
ajaxSpy
).
toHaveBeenCalled
();
expect
(
CommitsList
.
lastSearch
).
toEqual
(
'
GitLab
'
);
});
it
(
'
should save the last search string
'
,
()
=>
{
CommitsList
.
searchField
.
val
(
'
GitLab
'
);
CommitsList
.
filterResults
();
expect
(
ajaxSpy
).
toHaveBeenCalled
();
expect
(
CommitsList
.
lastSearch
).
toEqual
(
'
GitLab
'
);
});
it
(
'
should not make ajax call if the input does not change
'
,
()
=>
{
CommitsList
.
filterResults
();
expect
(
ajaxSpy
).
not
.
toHaveBeenCalled
();
expect
(
CommitsList
.
lastSearch
).
toEqual
(
''
);
});
it
(
'
should not make ajax call if the input does not change
'
,
()
=>
{
CommitsList
.
filterResults
();
expect
(
ajaxSpy
).
not
.
toHaveBeenCalled
();
expect
(
CommitsList
.
lastSearch
).
toEqual
(
''
);
});
});
})
()
;
});
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