From 8c92646b66c8a0b0a77718567619cbf9d44467c7 Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Fri, 5 Aug 2016 14:24:27 +0100 Subject: [PATCH] Filters backlog by search query --- .../boards/components/board.js.es6 | 10 ++++++- .../boards/components/board_list.js.es6 | 30 ++----------------- .../javascripts/boards/models/list.js.es6 | 30 ++++++++++++------- .../boards/services/board_service.js.es6 | 5 ++-- .../boards/components/_board.html.haml | 1 - .../boards/components/_card.html.haml | 2 +- 6 files changed, 35 insertions(+), 43 deletions(-) diff --git a/app/assets/javascripts/boards/components/board.js.es6 b/app/assets/javascripts/boards/components/board.js.es6 index cee169b45e6..67b630d7750 100644 --- a/app/assets/javascripts/boards/components/board.js.es6 +++ b/app/assets/javascripts/boards/components/board.js.es6 @@ -3,11 +3,19 @@ props: { board: Object }, - data: () => { + data: function () { return { filters: BoardsStore.state.filters }; }, + watch: { + 'query': function () { + if (this.board.canSearch()) { + const data = _.extend(this.filters, { search: this.query }); + this.board.getIssues(data); + } + } + }, methods: { clearSearch: function () { this.query = ''; diff --git a/app/assets/javascripts/boards/components/board_list.js.es6 b/app/assets/javascripts/boards/components/board_list.js.es6 index a468eb36cbf..7a00f090ade 100644 --- a/app/assets/javascripts/boards/components/board_list.js.es6 +++ b/app/assets/javascripts/boards/components/board_list.js.es6 @@ -5,11 +5,10 @@ boardId: [Number, String], filters: Object, issues: Array, - query: String, loading: Boolean, issueLinkBase: String }, - data: () => { + data: function () { return { scrollOffset: 20, loadMore: false @@ -26,33 +25,8 @@ return this.$els.list.scrollTop + this.listHeight(); }, loadFromLastId: function () { - this.loadMore = true; - setTimeout(() => { - this.loadMore = false; - }, 2000); + }, - customFilter: function (issue) { - let returnIssue = issue; - if (this.filters.author && this.filters.author.id) { - if (!issue.author || issue.author.id !== this.filters.author.id) { - returnIssue = null; - } - } - - if (this.filters.assignee && this.filters.assignee.id) { - if (!issue.assignee || issue.assignee.id !== this.filters.assignee.id) { - returnIssue = null; - } - } - - if (this.filters.milestone && this.filters.milestone.id) { - if (!issue.milestone || issue.milestone.id !== this.filters.milestone.id) { - returnIssue = null; - } - } - - return returnIssue; - } }, ready: function () { this.sortable = Sortable.create(this.$els.list, { diff --git a/app/assets/javascripts/boards/models/list.js.es6 b/app/assets/javascripts/boards/models/list.js.es6 index 0e62987dbb8..fc63da5429a 100644 --- a/app/assets/javascripts/boards/models/list.js.es6 +++ b/app/assets/javascripts/boards/models/list.js.es6 @@ -11,16 +11,7 @@ class List { } if (this.type !== 'blank') { - this.loading = true; - gl.boardService.getIssuesForList(this.id) - .then((resp) => { - const data = resp.json(); - this.loading = false; - - data.forEach((issue) => { - this.issues.push(new Issue(issue)); - }); - }); + this.getIssues(); } } @@ -49,6 +40,25 @@ class List { return this.type === 'backlog'; } + getIssues (filter = {}) { + this.loading = true; + + gl.boardService.getIssuesForList(this.id, filter) + .then((resp) => { + const data = resp.json(); + this.loading = false; + + this.issues = []; + this.createIssues(data); + }); + } + + createIssues (data) { + data.forEach((issue) => { + this.issues.push(new Issue(issue)); + }); + } + addIssue (issue, listFrom) { this.issues.push(issue); diff --git a/app/assets/javascripts/boards/services/board_service.js.es6 b/app/assets/javascripts/boards/services/board_service.js.es6 index 39229f65ad2..c8a3b4f3dd6 100644 --- a/app/assets/javascripts/boards/services/board_service.js.es6 +++ b/app/assets/javascripts/boards/services/board_service.js.es6 @@ -43,10 +43,11 @@ class BoardService { return this.list.delete({ id }); } - getIssuesForList (id) { + getIssuesForList (id, filter = {}) { + const data = _.extend({ id }, filter) this.setCSRF(); - return this.issues.get({ id }); + return this.issues.get(data); } moveIssue (id, from, to) { diff --git a/app/views/projects/boards/components/_board.html.haml b/app/views/projects/boards/components/_board.html.haml index 318050d5850..b4d4ca4df06 100644 --- a/app/views/projects/boards/components/_board.html.haml +++ b/app/views/projects/boards/components/_board.html.haml @@ -19,7 +19,6 @@ ":board-id" => "board.id", ":issues" => "board.issues", ":disabled" => "#{current_user.nil?}", - ":query" => "query", ":filters" => "filters", ":loading" => "board.loading", ":issue-link-base" => "'#{namespace_project_issues_path(@project.namespace, @project)}'" } diff --git a/app/views/projects/boards/components/_card.html.haml b/app/views/projects/boards/components/_card.html.haml index 043a046701d..8b5da818856 100644 --- a/app/views/projects/boards/components/_card.html.haml +++ b/app/views/projects/boards/components/_card.html.haml @@ -1,4 +1,4 @@ -%li.card{ ":data-issue" => "issue.id", "v-for" => "issue in issues | filterBy query in 'title' | filterBy customFilter", "track-by" => "id" } +%li.card{ ":data-issue" => "issue.id", "v-for" => "issue in issues | orderBy 'id' -1", "track-by" => "id" } %h4.card-title %a{ ":href" => "issueLinkBase + '/' + issue.id", ":title" => "issue.title" } {{ issue.title }}