Commit 77a074a7 authored by Phil Hughes's avatar Phil Hughes

Code improvements

parent 94f5d8a9
...@@ -31,29 +31,23 @@ $(() => { ...@@ -31,29 +31,23 @@ $(() => {
disabled: $boardApp.dataset.disabled === 'true', disabled: $boardApp.dataset.disabled === 'true',
issueLinkBase: $boardApp.dataset.issueLinkBase issueLinkBase: $boardApp.dataset.issueLinkBase
}, },
init () { init: Store.create.bind(Store),
gl.issueBoards.BoardsStore.create();
},
created () { created () {
this.loading = true;
gl.boardService = new BoardService(this.endpoint); gl.boardService = new BoardService(this.endpoint);
}, },
ready () { ready () {
Store.disabled = this.disabled; Store.disabled = this.disabled;
gl.boardService.all() gl.boardService.all()
.then((resp) => { .then((resp) => {
const boards = resp.json(); resp.json().forEach((board) => {
const list = Store.addList(board);
for (let i = 0, boardsLength = boards.length; i < boardsLength; i++) {
const board = boards[i],
list = Store.addList(board);
if (list.type === 'done') { if (list.type === 'done') {
list.position = Infinity; list.position = Infinity;
} else if (list.type === 'backlog') { } else if (list.type === 'backlog') {
list.position = -1; list.position = -1;
} }
} });
Store.addBlankState(); Store.addBlankState();
this.loading = false; this.loading = false;
......
...@@ -29,7 +29,9 @@ class ListIssue { ...@@ -29,7 +29,9 @@ class ListIssue {
} }
removeLabel (removeLabel) { removeLabel (removeLabel) {
this.labels = this.labels.filter( label => removeLabel.title !== label.title ); if (removeLabel) {
this.labels = this.labels.filter( label => removeLabel.title !== label.title );
}
} }
removeLabels (labels) { removeLabels (labels) {
......
...@@ -33,10 +33,7 @@ ...@@ -33,10 +33,7 @@
.then(() => { .then(() => {
// Remove any new issues from the backlog // Remove any new issues from the backlog
// as they will be visible in the new list // as they will be visible in the new list
for (let i = 0, issuesLength = list.issues.length; i < issuesLength; i++) { list.issues.forEach(backlogList.removeIssue.bind(backlogList));
const issue = list.issues[i];
backlogList.removeIssue(issue);
}
}); });
this.removeBlankState(); this.removeBlankState();
}, },
...@@ -45,21 +42,17 @@ ...@@ -45,21 +42,17 @@
}, },
shouldAddBlankState () { shouldAddBlankState () {
// Decide whether to add the blank state // Decide whether to add the blank state
return !(this.state.lists.filter((list) => { return !(this.state.lists.filter( list => list.type !== 'backlog' && list.type !== 'done' )[0]);
return list.type !== 'backlog' && list.type !== 'done';
})[0]);
}, },
addBlankState () { addBlankState () {
if (this.welcomeIsHidden() || this.disabled) return; if (!this.shouldAddBlankState() || this.welcomeIsHidden() || this.disabled) return;
if (this.shouldAddBlankState()) { this.addList({
this.addList({ id: 'blank',
id: 'blank', list_type: 'blank',
list_type: 'blank', title: 'Welcome to your Issue Board!',
title: 'Welcome to your Issue Board!', position: 0
position: 0 });
});
}
}, },
removeBlankState () { removeBlankState () {
this.removeList('blank'); this.removeList('blank');
...@@ -76,25 +69,20 @@ ...@@ -76,25 +69,20 @@
if (!list) return; if (!list) return;
this.state.lists = this.state.lists.filter((list) => { this.state.lists = this.state.lists.filter( list => list.id !== id );
return list.id !== id;
});
}, },
moveList (listFrom, orderLists) { moveList (listFrom, orderLists) {
for (let i = 0, orderLength = orderLists.length; i < orderLength; i++) { orderLists.forEach((id, i) => {
const id = parseInt(orderLists[i]), const list = this.findList('id', id);
list = this.findList('id', id);
list.position = i; list.position = i;
} });
listFrom.update(); listFrom.update();
}, },
moveIssueToList (listFrom, listTo, issue) { moveIssueToList (listFrom, listTo, issue) {
const issueTo = listTo.findIssue(issue.id), const issueTo = listTo.findIssue(issue.id),
issueLists = issue.getLists(), issueLists = issue.getLists(),
listLabels = issueLists.map((listIssue) => { listLabels = issueLists.map( listIssue => listIssue.label );
return listIssue.label;
});
// Add to new lists issues if it doesn't already exist // Add to new lists issues if it doesn't already exist
if (!issueTo) { if (!issueTo) {
...@@ -102,10 +90,9 @@ ...@@ -102,10 +90,9 @@
} }
if (listTo.type === 'done' && listFrom.type !== 'backlog') { if (listTo.type === 'done' && listFrom.type !== 'backlog') {
for (let i = 0, listsLength = issueLists.length; i < listsLength; i++) { issueLists.forEach((list) => {
const list = issueLists[i];
list.removeIssue(issue); list.removeIssue(issue);
} })
issue.removeLabels(listLabels); issue.removeLabels(listLabels);
} else { } else {
listFrom.removeIssue(issue); listFrom.removeIssue(issue);
......
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