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 },