From c5920f4b70da0a0f648e97323227e918f8ec4856 Mon Sep 17 00:00:00 2001 From: fenn-cs Date: Fri, 9 Feb 2024 02:07:18 +0100 Subject: [PATCH] WIP 2, fixup Signed-off-by: fenn-cs --- core/src/store/index.js | 11 ++ .../store/unified-search-external-filters.js | 43 ++++++ core/src/unified-search.js | 14 ++ core/src/views/UnifiedSearchModal.vue | 131 ++++++++---------- 4 files changed, 126 insertions(+), 73 deletions(-) create mode 100644 core/src/store/index.js create mode 100644 core/src/store/unified-search-external-filters.js diff --git a/core/src/store/index.js b/core/src/store/index.js new file mode 100644 index 0000000000000..d263a5dc40740 --- /dev/null +++ b/core/src/store/index.js @@ -0,0 +1,11 @@ +import Vue from 'vue'; +import Vuex from 'vuex'; +import search from './unified-search-external-filters'; + +Vue.use(Vuex); + +export default new Vuex.Store({ + modules: { + search, + }, +}); diff --git a/core/src/store/unified-search-external-filters.js b/core/src/store/unified-search-external-filters.js new file mode 100644 index 0000000000000..9b37e4b1d8a3c --- /dev/null +++ b/core/src/store/unified-search-external-filters.js @@ -0,0 +1,43 @@ +/* + * @copyright Copyright (c) 2021 Fon E. Noel NFEBE + * + * @author Fon E. Noel NFEBE + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ +const state = { + externalFilters: [], + }; + + const mutations = { + registerExternalFilter(state, { label, callback, icon }) { + state.externalFilters.push({ label, callback, icon }); + }, + }; + + const actions = { + registerExternalFilter({ commit }, { label, callback, icon }) { + commit('registerExternalFilter', { label, callback, icon }); + }, + }; + + export default { + state, + mutations, + actions, + }; + \ No newline at end of file diff --git a/core/src/unified-search.js b/core/src/unified-search.js index f9bddff4c6837..efbe69524c637 100644 --- a/core/src/unified-search.js +++ b/core/src/unified-search.js @@ -26,6 +26,7 @@ import { translate as t, translatePlural as n } from '@nextcloud/l10n' import Vue from 'vue' import UnifiedSearch from './views/UnifiedSearch.vue' +import store from '../src/store/index.js' // eslint-disable-next-line camelcase __webpack_nonce__ = btoa(getRequestToken()) @@ -47,9 +48,22 @@ Vue.mixin({ }, }) +// Register the add/register filter action API globally +window.OCA.Core = window.OCA.Core || {} +window.OCA.Core.UnifiedSearch = { + registerFilterAction: ({ label, callback, icon }) => { + store.dispatch('search/registerExternalFilter', { + label, + icon, + callback, + }) + }, +} + export default new Vue({ el: '#unified-search', // eslint-disable-next-line vue/match-component-file-name name: 'UnifiedSearchRoot', + store, render: h => h(UnifiedSearch), }) diff --git a/core/src/views/UnifiedSearchModal.vue b/core/src/views/UnifiedSearchModal.vue index 410b8e058ed9b..14f7ca555fa49 100644 --- a/core/src/views/UnifiedSearchModal.vue +++ b/core/src/views/UnifiedSearchModal.vue @@ -1,33 +1,22 @@