summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2017-03-09 12:32:43 +0000
committerPhil Hughes <me@iamphill.com>2017-03-09 12:32:43 +0000
commit7eabb7a9641481d89ccb52b421dcbd8cd63c3bb6 (patch)
tree2618dea650afc6bb1c238efdb8dffc64b1f84f15
parent236d6595edd2393f4ba4faadd39529fcabe48aec (diff)
downloadgitlab-ce-7eabb7a9641481d89ccb52b421dcbd8cd63c3bb6.tar.gz
Use reduce instead of a forEach
Changed an isArray check to use -1 Added comment to boards search manager to explain behaviour
-rw-r--r--app/assets/javascripts/boards/boards_bundle.js15
-rw-r--r--app/assets/javascripts/boards/components/board_card.js3
-rw-r--r--app/assets/javascripts/boards/components/issue_card_inner.js10
-rw-r--r--app/assets/javascripts/boards/filtered_search_boards.js3
-rw-r--r--app/assets/javascripts/boards/models/list.js14
5 files changed, 34 insertions, 11 deletions
diff --git a/app/assets/javascripts/boards/boards_bundle.js b/app/assets/javascripts/boards/boards_bundle.js
index 2fd1f43f02c..4d60fedaeb8 100644
--- a/app/assets/javascripts/boards/boards_bundle.js
+++ b/app/assets/javascripts/boards/boards_bundle.js
@@ -62,7 +62,13 @@ $(() => {
created () {
gl.boardService = new BoardService(this.endpoint, this.bulkUpdatePath, this.boardId);
- gl.boardsFilterManager = new FilteredSearchBoards(Store.filter, true);
+ this.filterManager = new FilteredSearchBoards(Store.filter, true);
+
+ // Listen for updateTokens event
+ this.$on('updateTokens', this.updateTokens);
+ },
+ beforeDestroy() {
+ this.$off('updateTokens', this.updateTokens);
},
mounted () {
Store.disabled = this.disabled;
@@ -81,7 +87,12 @@ $(() => {
Store.addBlankState();
this.loading = false;
});
- }
+ },
+ methods: {
+ updateTokens() {
+ this.filterManager.updateTokens();
+ }
+ },
});
gl.IssueBoardsSearch = new Vue({
diff --git a/app/assets/javascripts/boards/components/board_card.js b/app/assets/javascripts/boards/components/board_card.js
index 795b3cf2ec0..4b72090df31 100644
--- a/app/assets/javascripts/boards/components/board_card.js
+++ b/app/assets/javascripts/boards/components/board_card.js
@@ -17,7 +17,8 @@ export default {
:list="list"
:issue="issue"
:issue-link-base="issueLinkBase"
- :root-path="rootPath" />
+ :root-path="rootPath"
+ :update-filters="true" />
</li>
`,
components: {
diff --git a/app/assets/javascripts/boards/components/issue_card_inner.js b/app/assets/javascripts/boards/components/issue_card_inner.js
index dce573ed6ca..3d57ec429c6 100644
--- a/app/assets/javascripts/boards/components/issue_card_inner.js
+++ b/app/assets/javascripts/boards/components/issue_card_inner.js
@@ -23,6 +23,11 @@
type: String,
required: true,
},
+ updateFilters: {
+ type: Boolean,
+ required: false,
+ default: false,
+ },
},
methods: {
showLabel(label) {
@@ -31,6 +36,8 @@
return !this.list.label || label.id !== this.list.label.id;
},
filterByLabel(label, e) {
+ if (!this.updateFilters) return;
+
const filterPath = gl.issueBoards.BoardsStore.filter.path.split('&');
const labelTitle = encodeURIComponent(label.title);
const param = `label_name[]=${labelTitle}`;
@@ -46,7 +53,8 @@
gl.issueBoards.BoardsStore.filter.path = filterPath.join('&');
Store.updateFiltersUrl();
- gl.boardsFilterManager.updateTokens();
+
+ gl.IssueBoardsApp.$emit('updateTokens');
},
labelStyle(label) {
return {
diff --git a/app/assets/javascripts/boards/filtered_search_boards.js b/app/assets/javascripts/boards/filtered_search_boards.js
index 3014557c440..47448b02bdd 100644
--- a/app/assets/javascripts/boards/filtered_search_boards.js
+++ b/app/assets/javascripts/boards/filtered_search_boards.js
@@ -4,6 +4,9 @@ export default class FilteredSearchBoards extends gl.FilteredSearchManager {
this.store = store;
this.updateUrl = updateUrl;
+
+ // Issue boards is slightly different, we handle all the requests async
+ // instead or reloading the page, we just re-fire the list ajax requests
this.isHandledAsync = true;
}
diff --git a/app/assets/javascripts/boards/models/list.js b/app/assets/javascripts/boards/models/list.js
index ad968d2120f..3251ca76b26 100644
--- a/app/assets/javascripts/boards/models/list.js
+++ b/app/assets/javascripts/boards/models/list.js
@@ -64,16 +64,14 @@ class List {
}
getIssues (emptyIssues = true) {
- const data = { page: this.page };
- gl.issueBoards.BoardsStore.filter.path.split('&').forEach((filterParam) => {
- if (filterParam === '') return;
+ const data = gl.issueBoards.BoardsStore.filter.path.split('&').reduce((data, filterParam) => {
+ if (filterParam === '') return data;
const paramSplit = filterParam.split('=');
const paramKeyNormalized = paramSplit[0].replace('[]', '');
const isArray = paramSplit[0].indexOf('[]');
- let value = decodeURIComponent(paramSplit[1]);
- value = value.replace(/\+/g, ' ');
+ const value = decodeURIComponent(paramSplit[1]).replace(/\+/g, ' ');
- if (isArray >= 0) {
+ if (isArray !== -1) {
if (!data[paramKeyNormalized]) {
data[paramKeyNormalized] = [];
}
@@ -82,7 +80,9 @@ class List {
} else {
data[paramKeyNormalized] = value;
}
- });
+
+ return data;
+ }, { page: this.page });
if (this.label && data.label_name) {
data.label_name = data.label_name.filter(label => label !== this.label.title);