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

Code improvements

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