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
8377c2fb
Commit
8377c2fb
authored
Sep 08, 2016
by
Bryce Johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Todos to ES6.
parent
45ae34f8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
79 deletions
+64
-79
app/assets/javascripts/dispatcher.js
app/assets/javascripts/dispatcher.js
+1
-1
app/assets/javascripts/todos.js.es6
app/assets/javascripts/todos.js.es6
+63
-78
No files found.
app/assets/javascripts/dispatcher.js
View file @
8377c2fb
...
@@ -40,7 +40,7 @@
...
@@ -40,7 +40,7 @@
new
Milestone
();
new
Milestone
();
break
;
break
;
case
'
dashboard:todos:index
'
:
case
'
dashboard:todos:index
'
:
new
Todos
();
new
gl
.
Todos
();
break
;
break
;
case
'
projects:milestones:new
'
:
case
'
projects:milestones:new
'
:
case
'
projects:milestones:edit
'
:
case
'
projects:milestones:edit
'
:
...
...
app/assets/javascripts/todos.js
→
app/assets/javascripts/todos.js
.es6
View file @
8377c2fb
(
function
()
{
(global => {
var
bind
=
function
(
fn
,
me
){
return
function
(){
return
fn
.
apply
(
me
,
arguments
);
};
};
class Todos {
this
.
Todos
=
(
function
()
{
constructor(opts = {}) {
function
Todos
(
opts
)
{
this.allDoneClicked = this.allDoneClicked.bind(this);
var
ref
;
this.doneClicked = this.doneClicked.bind(this);
if
(
opts
==
null
)
{
this.el = opts.el || $('.js-todos-options');
opts
=
{};
}
this
.
allDoneClicked
=
bind
(
this
.
allDoneClicked
,
this
);
this
.
doneClicked
=
bind
(
this
.
doneClicked
,
this
);
this
.
el
=
(
ref
=
opts
.
el
)
!=
null
?
ref
:
$
(
'
.js-todos-options
'
);
this.perPage = this.el.data('perPage');
this.perPage = this.el.data('perPage');
this.clearListeners();
this.clearListeners();
this.initBtnListeners();
this.initBtnListeners();
this.initFilters();
this.initFilters();
}
}
Todos
.
prototype
.
clearListeners
=
function
()
{
clearListeners
() {
$('.done-todo').off('click');
$('.done-todo').off('click');
$('.js-todos-mark-all').off('click');
$('.js-todos-mark-all').off('click');
return $('.todo').off('click');
return $('.todo').off('click');
}
;
}
Todos
.
prototype
.
initBtnListeners
=
function
()
{
initBtnListeners
() {
$('.done-todo').on('click', this.doneClicked);
$('.done-todo').on('click', this.doneClicked);
$('.js-todos-mark-all').on('click', this.allDoneClicked);
$('.js-todos-mark-all').on('click', this.allDoneClicked);
return $('.todo').on('click', this.goToTodoUrl);
return $('.todo').on('click', this.goToTodoUrl);
}
;
}
Todos
.
prototype
.
initFilters
=
function
()
{
initFilters
() {
new UsersSelect();
new UsersSelect();
this.initFilterDropdown($('.js-project-search'), 'project_id', ['text']);
this.initFilterDropdown($('.js-project-search'), 'project_id', ['text']);
this.initFilterDropdown($('.js-type-search'), 'type');
this.initFilterDropdown($('.js-type-search'), 'type');
...
@@ -38,125 +33,117 @@
...
@@ -38,125 +33,117 @@
event.preventDefault();
event.preventDefault();
Turbolinks.visit(this.action + '&' + $(this).serialize());
Turbolinks.visit(this.action + '&' + $(this).serialize());
});
});
}
;
}
Todos
.
prototype
.
initFilterDropdown
=
functio
n
(
$dropdown
,
fieldName
,
searchFields
)
{
initFilterDropdow
n($dropdown, fieldName, searchFields) {
$dropdown.glDropdown({
$dropdown.glDropdown({
fieldName,
selectable: true,
selectable: true,
filterable: searchFields ? true : false,
filterable: searchFields ? true : false,
fieldName
:
fieldName
,
search: { fields: searchFields },
search: { fields: searchFields },
data: $dropdown.data('data'),
data: $dropdown.data('data'),
clicked: function() {
clicked: function() {
return $dropdown.closest('form.filter-form').submit();
return $dropdown.closest('form.filter-form').submit();
}
}
})
})
}
;
}
Todos
.
prototype
.
doneClicked
=
function
(
e
)
{
doneClicked(e) {
var
$this
;
e.preventDefault();
e.preventDefault();
e.stopImmediatePropagation();
e.stopImmediatePropagation();
$this
=
$
(
e
.
currentTarget
);
const $target
= $(e.currentTarget);
$t
his
.
disable
();
$t
arget
.disable();
return $.ajax({
return $.ajax({
type: 'POST',
type: 'POST',
url
:
$t
his
.
attr
(
'
href
'
),
url: $t
arget
.attr('href'),
dataType: 'json',
dataType: 'json',
data: {
data: {
'_method': 'delete'
'_method': 'delete'
},
},
success
:
(
function
(
_this
)
{
success: data => {
return
function
(
data
)
{
this.redirectIfNeeded(data.count);
_this
.
redirectIfNeeded
(
data
.
count
);
this.clearDone($target.closest('li'));
_this
.
clearDone
(
$this
.
closest
(
'
li
'
));
return this.updateBadges(data);
return
_this
.
updateBadges
(
data
);
}
};
})(
this
)
});
});
}
;
}
Todos
.
prototype
.
allDoneClicked
=
function
(
e
)
{
allDoneClicked(e) {
var
$this
;
e.preventDefault();
e.preventDefault();
e.stopImmediatePropagation();
e.stopImmediatePropagation();
$t
his
=
$
(
e
.
currentTarget
);
$t
arget
= $(e.currentTarget);
$t
his
.
disable
();
$t
arget
.disable();
return $.ajax({
return $.ajax({
type: 'POST',
type: 'POST',
url
:
$t
his
.
attr
(
'
href
'
),
url: $t
arget
.attr('href'),
dataType: 'json',
dataType: 'json',
data: {
data: {
'_method': 'delete'
'_method': 'delete'
},
},
success
:
(
function
(
_this
)
{
success: data => {
return
function
(
data
)
{
$target.remove();
$this
.
remove
();
$('.prepend-top-default').html('<div class="nothing-here-block">You\'re all done!</div>');
$('.prepend-top-default').html('<div class="nothing-here-block">You\'re all done!</div>');
return
_this
.
updateBadges
(
data
);
return this.updateBadges(data);
};
}
})(
this
)
});
});
}
;
}
Todos
.
prototype
.
clearDone
=
function
(
$row
)
{
clearDone($row) {
var
$ul
;
const $ul = $row.closest('ul');
$ul
=
$row
.
closest
(
'
ul
'
);
$row.remove();
$row.remove();
if (!$ul.find('li').length) {
if (!$ul.find('li').length) {
return $ul.parents('.panel').remove();
return $ul.parents('.panel').remove();
}
}
}
;
}
Todos
.
prototype
.
updateBadges
=
function
(
data
)
{
updateBadges
(data) {
$('.todos-pending .badge, .todos-pending-count').text(data.count);
$('.todos-pending .badge, .todos-pending-count').text(data.count);
return $('.todos-done .badge').text(data.done_count);
return $('.todos-done .badge').text(data.done_count);
}
;
}
Todos
.
prototype
.
getTotalPages
=
function
()
{
getTotalPages
() {
return this.el.data('totalPages');
return this.el.data('totalPages');
}
;
}
Todos
.
prototype
.
getCurrentPage
=
function
()
{
getCurrentPage
() {
return this.el.data('currentPage');
return this.el.data('currentPage');
}
;
}
Todos
.
prototype
.
getTodosPerPage
=
function
()
{
getTodosPerPage
() {
return this.el.data('perPage');
return this.el.data('perPage');
}
;
}
Todos
.
prototype
.
redirectIfNeeded
=
function
(
total
)
{
redirectIfNeeded(total) {
var
currPage
,
currPages
,
newPages
,
pageParams
,
url
;
let currPages = this.getTotalPages();
currPages
=
this
.
getTotalPages
();
currPage = this.getCurrentPage();
currPage = this.getCurrentPage();
// Refresh if no remaining Todos
// Refresh if no remaining Todos
if (!total) {
if (!total) {
location
.
reload
();
window.
location.reload();
return;
return;
}
}
// Do nothing if no pagination
// Do nothing if no pagination
if (!currPages) {
if (!currPages) {
return;
return;
}
}
newPages
=
Math
.
ceil
(
total
/
this
.
getTodosPerPage
());
// Includes query strings
const newPages = Math.ceil(total / this.getTodosPerPage());
url
=
location
.
href
;
let
url = location.href;
// If new total of pages is different than we have now
if (newPages !== currPages) {
if (newPages !== currPages) {
// Redirect to previous page if there's one available
// Redirect to previous page if there's one available
if (currPages > 1 && currPage === currPages) {
if (currPages > 1 && currPage === currPages) {
pageParams
=
{
const
pageParams = {
page: currPages - 1
page: currPages - 1
};
};
url = gl.utils.mergeUrlParams(pageParams, url);
url = gl.utils.mergeUrlParams(pageParams, url);
}
}
return Turbolinks.visit(url);
return Turbolinks.visit(url);
}
}
}
;
}
Todos
.
prototype
.
goToTodoUrl
=
function
(
e
)
{
goToTodoUrl(e) {
var
todoLink
;
const todoLink = $(this).data('url');
todoLink
=
$
(
this
).
data
(
'
url
'
);
if (!todoLink) {
if (!todoLink) {
return;
return;
}
}
...
@@ -167,10 +154,8 @@
...
@@ -167,10 +154,8 @@
} else {
} else {
return Turbolinks.visit(todoLink);
return Turbolinks.visit(todoLink);
}
}
};
}
}
return
Todos
;
})();
}).
call
(
this
);
global.Todos = Todos;
})(window.gl || (window.gl = {}));
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