diff options
Diffstat (limited to 'app/assets/javascripts/search/store')
-rw-r--r-- | app/assets/javascripts/search/store/actions.js | 29 | ||||
-rw-r--r-- | app/assets/javascripts/search/store/index.js | 4 | ||||
-rw-r--r-- | app/assets/javascripts/search/store/mutation_types.js | 5 | ||||
-rw-r--r-- | app/assets/javascripts/search/store/mutations.js | 18 | ||||
-rw-r--r-- | app/assets/javascripts/search/store/state.js | 2 |
5 files changed, 58 insertions, 0 deletions
diff --git a/app/assets/javascripts/search/store/actions.js b/app/assets/javascripts/search/store/actions.js new file mode 100644 index 00000000000..447278aa223 --- /dev/null +++ b/app/assets/javascripts/search/store/actions.js @@ -0,0 +1,29 @@ +import Api from '~/api'; +import createFlash from '~/flash'; +import { __ } from '~/locale'; +import { visitUrl, setUrlParams } from '~/lib/utils/url_utility'; +import * as types from './mutation_types'; + +export const fetchGroups = ({ commit }, search) => { + commit(types.REQUEST_GROUPS); + Api.groups(search) + .then(data => { + commit(types.RECEIVE_GROUPS_SUCCESS, data); + }) + .catch(() => { + createFlash({ message: __('There was a problem fetching groups.') }); + commit(types.RECEIVE_GROUPS_ERROR); + }); +}; + +export const setQuery = ({ commit }, { key, value }) => { + commit(types.SET_QUERY, { key, value }); +}; + +export const applyQuery = ({ state }) => { + visitUrl(setUrlParams({ ...state.query, page: null })); +}; + +export const resetQuery = ({ state }) => { + visitUrl(setUrlParams({ ...state.query, page: null, state: null, confidential: null })); +}; diff --git a/app/assets/javascripts/search/store/index.js b/app/assets/javascripts/search/store/index.js index 10cfb647a92..e0a7e488f9f 100644 --- a/app/assets/javascripts/search/store/index.js +++ b/app/assets/javascripts/search/store/index.js @@ -1,10 +1,14 @@ import Vue from 'vue'; import Vuex from 'vuex'; +import * as actions from './actions'; +import mutations from './mutations'; import createState from './state'; Vue.use(Vuex); export const getStoreConfig = ({ query }) => ({ + actions, + mutations, state: createState({ query }), }); diff --git a/app/assets/javascripts/search/store/mutation_types.js b/app/assets/javascripts/search/store/mutation_types.js new file mode 100644 index 00000000000..2482621d4d7 --- /dev/null +++ b/app/assets/javascripts/search/store/mutation_types.js @@ -0,0 +1,5 @@ +export const REQUEST_GROUPS = 'REQUEST_GROUPS'; +export const RECEIVE_GROUPS_SUCCESS = 'RECEIVE_GROUPS_SUCCESS'; +export const RECEIVE_GROUPS_ERROR = 'RECEIVE_GROUPS_ERROR'; + +export const SET_QUERY = 'SET_QUERY'; diff --git a/app/assets/javascripts/search/store/mutations.js b/app/assets/javascripts/search/store/mutations.js new file mode 100644 index 00000000000..e57850b870e --- /dev/null +++ b/app/assets/javascripts/search/store/mutations.js @@ -0,0 +1,18 @@ +import * as types from './mutation_types'; + +export default { + [types.REQUEST_GROUPS](state) { + state.fetchingGroups = true; + }, + [types.RECEIVE_GROUPS_SUCCESS](state, data) { + state.fetchingGroups = false; + state.groups = data; + }, + [types.RECEIVE_GROUPS_ERROR](state) { + state.fetchingGroups = false; + state.groups = []; + }, + [types.SET_QUERY](state, { key, value }) { + state.query[key] = value; + }, +}; diff --git a/app/assets/javascripts/search/store/state.js b/app/assets/javascripts/search/store/state.js index 9115a613767..70a8aab9998 100644 --- a/app/assets/javascripts/search/store/state.js +++ b/app/assets/javascripts/search/store/state.js @@ -1,4 +1,6 @@ const createState = ({ query }) => ({ query, + groups: [], + fetchingGroups: false, }); export default createState; |