Commit ff5fd4eb authored by Phil Hughes's avatar Phil Hughes

Moved some code over to underscorejs

parent 1de64675
...@@ -35,10 +35,11 @@ ...@@ -35,10 +35,11 @@
}, },
}, },
ready: function () { ready: function () {
const list = this.list;
const options = _.extend({ const options = _.extend({
group: 'issues', group: 'issues',
disabled: this.disabled, disabled: this.disabled,
onAdd: function (e) { onAdd: (e) => {
const fromListId = parseInt(e.from.getAttribute('data-board')), const fromListId = parseInt(e.from.getAttribute('data-board')),
toListId = parseInt(e.to.getAttribute('data-board')), toListId = parseInt(e.to.getAttribute('data-board')),
issueId = parseInt(e.item.getAttribute('data-issue')); issueId = parseInt(e.item.getAttribute('data-issue'));
......
...@@ -39,9 +39,7 @@ class Issue { ...@@ -39,9 +39,7 @@ class Issue {
} }
removeLabels (labels) { removeLabels (labels) {
labels.forEach((label) => { _.each(labels, this.removeLabel.bind(this));
this.removeLabel(label);
});
} }
getLists () { getLists () {
......
...@@ -19,7 +19,7 @@ class List { ...@@ -19,7 +19,7 @@ class List {
} }
save () { save () {
gl.boardService.createList(this.label.id) return gl.boardService.createList(this.label.id)
.then((resp) => { .then((resp) => {
const data = resp.json(); const data = resp.json();
...@@ -27,7 +27,7 @@ class List { ...@@ -27,7 +27,7 @@ class List {
this.type = data.list_type; this.type = data.list_type;
this.position = data.position; this.position = data.position;
this.getIssues(); return this.getIssues();
}); });
} }
...@@ -80,7 +80,7 @@ class List { ...@@ -80,7 +80,7 @@ class List {
} }
createIssues (data) { createIssues (data) {
data.forEach((issue) => { _.each(data, (issue) => {
this.issues.push(new Issue(issue)); this.issues.push(new Issue(issue));
}); });
} }
......
...@@ -12,12 +12,19 @@ ...@@ -12,12 +12,19 @@
}; };
}, },
new: function (board, persist = true) { new: function (board, persist = true) {
const doneList = this.getDoneList(), const doneList = this.findList('type', 'done'),
backlogList = this.findList('type', 'backlog'),
list = new List(board); list = new List(board);
this.state.lists.push(list); this.state.lists.push(list);
if (persist) { if (persist) {
list.save(); list
.save()
.then(function () {
// Remove any new issues from the backlog
// as they will be visible in the new list
_.each(list.issues, backlogList.removeIssue.bind(backlogList));
});
this.removeBlankState(); this.removeBlankState();
} }
...@@ -29,15 +36,10 @@ ...@@ -29,15 +36,10 @@
}, },
shouldAddBlankState: function () { shouldAddBlankState: function () {
// Decide whether to add the blank state // Decide whether to add the blank state
let addBlankState = true; let addBlankState = _.find(this.state.lists, function (list) {
return list.type === 'backlog' || list.type === 'done';
this.state.lists.forEach(function (list) {
if (list.type !== 'backlog' && list.type !== 'done') {
addBlankState = false;
return;
}
}); });
return addBlankState; return !addBlankState;
}, },
addBlankState: function () { addBlankState: function () {
const addBlankState = this.shouldAddBlankState(); const addBlankState = this.shouldAddBlankState();
...@@ -65,9 +67,6 @@ ...@@ -65,9 +67,6 @@
welcomeIsHidden: function () { welcomeIsHidden: function () {
return $.cookie('issue_board_welcome_hidden') === 'true'; return $.cookie('issue_board_welcome_hidden') === 'true';
}, },
getDoneList: function () {
return this.findList('type', 'done');
},
removeList: function (id) { removeList: function (id) {
const list = this.findList('id', id); const list = this.findList('id', id);
...@@ -75,7 +74,7 @@ ...@@ -75,7 +74,7 @@
list.destroy(); list.destroy();
this.state.lists = _.reject(this.state.lists, (list) => { this.state.lists = _.reject(this.state.lists, function (list) {
return list.id === id; return list.id === id;
}); });
...@@ -83,7 +82,7 @@ ...@@ -83,7 +82,7 @@
}, },
moveList: function (oldIndex, newIndex) { moveList: function (oldIndex, newIndex) {
if (oldIndex === newIndex) return; if (oldIndex === newIndex) return;
const listFrom = this.findList('position', oldIndex), const listFrom = this.findList('position', oldIndex),
listTo = this.findList('position', newIndex); listTo = this.findList('position', newIndex);
...@@ -101,9 +100,9 @@ ...@@ -101,9 +100,9 @@
moveCardToList: function (listFromId, listToId, issueId) { moveCardToList: function (listFromId, listToId, issueId) {
const listFrom = this.findList('id', listFromId), const listFrom = this.findList('id', listFromId),
listTo = this.findList('id', listToId), listTo = this.findList('id', listToId),
issueTo = listTo.findIssue(issueId); issueTo = listTo.findIssue(issueId),
let issue = listFrom.findIssue(issueId); issue = listFrom.findIssue(issueId),
const issueLists = issue.getLists(), issueLists = issue.getLists(),
listLabels = issueLists.map(function (issue) { listLabels = issueLists.map(function (issue) {
return issue.label; return issue.label;
}); });
...@@ -114,9 +113,7 @@ ...@@ -114,9 +113,7 @@
} }
if (listTo.type === 'done' && listFrom.type !== 'backlog') { if (listTo.type === 'done' && listFrom.type !== 'backlog') {
issueLists.forEach((list) => { _.each(issueLists, list.removeIssue.bind(list));
list.removeIssue(issue);
});
issue.removeLabels(listLabels); issue.removeLabels(listLabels);
} else { } else {
listFrom.removeIssue(issue); listFrom.removeIssue(issue);
......
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
overflow-x: scroll; overflow-x: scroll;
@media (min-width: $screen-sm-min) { @media (min-width: $screen-sm-min) {
min-height: 470px; min-height: 475px;
max-height: 470px; max-height: 475px;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment