diff options
author | Phil Hughes <me@iamphill.com> | 2016-08-17 13:57:36 +0100 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2016-08-17 17:17:39 +0100 |
commit | 77a074a7201cf934fc255f9fcd59f9fd2d01ad57 (patch) | |
tree | aa3246cdc0004af17ff971955c0fe76296f57f12 /app/assets/javascripts/boards | |
parent | 94f5d8a98c40975dbcf39e8c116cfeea5bf3719d (diff) | |
download | gitlab-ce-77a074a7201cf934fc255f9fcd59f9fd2d01ad57.tar.gz |
Code improvements
Diffstat (limited to 'app/assets/javascripts/boards')
-rw-r--r-- | app/assets/javascripts/boards/boards_bundle.js.es6 | 16 | ||||
-rw-r--r-- | app/assets/javascripts/boards/models/issue.js.es6 | 4 | ||||
-rw-r--r-- | app/assets/javascripts/boards/stores/boards_store.js.es6 | 45 |
3 files changed, 24 insertions, 41 deletions
diff --git a/app/assets/javascripts/boards/boards_bundle.js.es6 b/app/assets/javascripts/boards/boards_bundle.js.es6 index fbb05534ef6..2c65d4427be 100644 --- a/app/assets/javascripts/boards/boards_bundle.js.es6 +++ b/app/assets/javascripts/boards/boards_bundle.js.es6 @@ -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; diff --git a/app/assets/javascripts/boards/models/issue.js.es6 b/app/assets/javascripts/boards/models/issue.js.es6 index 28fad539f2f..eb082103de9 100644 --- a/app/assets/javascripts/boards/models/issue.js.es6 +++ b/app/assets/javascripts/boards/models/issue.js.es6 @@ -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) { diff --git a/app/assets/javascripts/boards/stores/boards_store.js.es6 b/app/assets/javascripts/boards/stores/boards_store.js.es6 index e55941cd5bd..36201008ddf 100644 --- a/app/assets/javascripts/boards/stores/boards_store.js.es6 +++ b/app/assets/javascripts/boards/stores/boards_store.js.es6 @@ -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); |