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
251240c0
Commit
251240c0
authored
Mar 28, 2016
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refresh page according remaining todos
parent
a5fb9980
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
app/assets/javascripts/todos.js.coffee
app/assets/javascripts/todos.js.coffee
+43
-0
No files found.
app/assets/javascripts/todos.js.coffee
View file @
251240c0
class
@
Todos
PER_PAGE
=
20
constructor
:
(
@
name
)
->
@
clearListeners
()
@
initBtnListeners
()
...
...
@@ -24,6 +26,7 @@ class @Todos
dataType
:
'json'
data
:
'_method'
:
'delete'
success
:
(
data
)
=>
@
redirectIfNeeded
data
.
count
@
clearDone
$this
.
closest
(
'li'
)
@
updateBadges
data
...
...
@@ -54,3 +57,43 @@ class @Todos
updateBadges
:
(
data
)
->
$
(
'.todos-pending .badge, .todos-pending-count'
).
text
data
.
count
$
(
'.todos-done .badge'
).
text
data
.
done_count
getRenderedPages
:
->
$
(
'.gl-pagination .page'
).
length
getCurrentPage
:
->
parseInt
(
$
.
trim
(
$
(
'.gl-pagination .page.active'
).
text
()))
redirectIfNeeded
:
(
total
)
->
currPages
=
@
getRenderedPages
()
currPage
=
@
getCurrentPage
()
newPages
=
Math
.
ceil
(
total
/
PER_PAGE
)
url
=
location
.
href
# Includes query strings
# Refresh if no remaining Todos
if
!
total
location
.
reload
()
return
# Do nothing if no pagination
return
if
!
currPages
# If new total of pages if different than we have now
if
newPages
isnt
currPages
# Redirect to previous page if there´s one available
if
currPages
>
1
and
currPage
is
currPages
url
=
@
updateQueryStringParameter
(
url
,
'page'
,
currPages
-
1
)
location
.
replace
url
updateQueryStringParameter
:
(
uri
,
key
,
value
)
->
separator
=
if
uri
.
indexOf
(
'?'
)
isnt
-
1
then
"&"
else
"?"
# Matches key and value
regex
=
new
RegExp
(
"([?&])"
+
key
+
"=.*?(&|#|$)"
,
"i"
)
if
uri
.
match
(
regex
)
return
uri
.
replace
(
regex
,
'$1'
+
key
+
"="
+
value
+
'$2'
)
uri
+
separator
+
key
+
"="
+
value
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