From 032573bd69bb95103966a83baa7479e98b1cce10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20R=C3=B6hrl?= Date: Thu, 30 Jan 2020 11:54:53 +0100 Subject: [PATCH 1/2] serach cards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakob Röhrl --- src/main.js | 13 +++++++++++++ src/store/card.js | 8 ++++++-- src/store/main.js | 7 +++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index 8869424d9..b50a5b73b 100644 --- a/src/main.js +++ b/src/main.js @@ -44,6 +44,8 @@ Vue.mixin({ }, }) +Vue.prototype.$OC = OC + Vue.directive('tooltip', Tooltip) Vue.directive('click-outside', ClickOutside) @@ -58,5 +60,16 @@ new Vue({ el: '#content', router, store, + mounted: function() { + this.$OC.Search = new OCA.Search(this.filter, this.cleanSearch) + }, + methods: { + filter(query) { + this.$store.commit('setSearchQuery', query) + }, + cleanSearch() { + this.$store.commit('setSearchQuery', '') + }, + }, render: h => h(App), }) diff --git a/src/store/card.js b/src/store/card.js index 512f582a0..56ab80ec2 100644 --- a/src/store/card.js +++ b/src/store/card.js @@ -30,8 +30,12 @@ export default { cards: [], }, getters: { - cardsByStack: state => (id) => { - return state.cards.filter((card) => card.stackId === id).sort((a, b) => a.order - b.order) + cardsByStack: (state, getters) => (id) => { + return state.cards.filter( + (card) => card.stackId === id + && (card.title.includes(getters.getSearchQuery) || card.description.includes(getters.getSearchQuery)) + ) + .sort((a, b) => a.order - b.order) }, cardById: state => (id) => { return state.cards.find((card) => card.id === id) diff --git a/src/store/main.js b/src/store/main.js index fc0f27804..6cddad9a7 100644 --- a/src/store/main.js +++ b/src/store/main.js @@ -61,8 +61,12 @@ export default new Vuex.Store({ boardFilter: BOARD_FILTERS.ALL, activity: [], activityLoadMore: true, + searchQuery: '', }, getters: { + getSearchQuery: state => { + return state.searchQuery + }, boards: state => { return state.boards }, @@ -107,6 +111,9 @@ export default new Vuex.Store({ }, }, mutations: { + setSearchQuery(state, searchQuery) { + state.searchQuery = searchQuery + }, toggleShowArchived(state) { state.showArchived = !state.showArchived }, From b567a744a6ed979a1d52dee6688e9a8407b83a04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20R=C3=B6hrl?= Date: Fri, 31 Jan 2020 08:13:20 +0100 Subject: [PATCH 2/2] :case insensitive and litte changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakob Röhrl --- src/main.js | 5 ++--- src/store/card.js | 7 ++----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main.js b/src/main.js index b50a5b73b..fe5864211 100644 --- a/src/main.js +++ b/src/main.js @@ -44,8 +44,6 @@ Vue.mixin({ }, }) -Vue.prototype.$OC = OC - Vue.directive('tooltip', Tooltip) Vue.directive('click-outside', ClickOutside) @@ -61,7 +59,8 @@ new Vue({ router, store, mounted: function() { - this.$OC.Search = new OCA.Search(this.filter, this.cleanSearch) + // eslint-disable-next-line + new OCA.Search(this.filter, this.cleanSearch) }, methods: { filter(query) { diff --git a/src/store/card.js b/src/store/card.js index 56ab80ec2..dc3b29878 100644 --- a/src/store/card.js +++ b/src/store/card.js @@ -31,11 +31,8 @@ export default { }, getters: { cardsByStack: (state, getters) => (id) => { - return state.cards.filter( - (card) => card.stackId === id - && (card.title.includes(getters.getSearchQuery) || card.description.includes(getters.getSearchQuery)) - ) - .sort((a, b) => a.order - b.order) + return state.cards.filter((card) => card.stackId === id && (getters.getSearchQuery === '' || (card.title.toLowerCase().includes(getters.getSearchQuery.toLowerCase()) || card.description.toLowerCase().includes(getters.getSearchQuery.toLowerCase()))) + ).sort((a, b) => a.order - b.order) }, cardById: state => (id) => { return state.cards.find((card) => card.id === id)