diff options
Diffstat (limited to 'app/assets/javascripts/milestones/stores/actions.js')
-rw-r--r-- | app/assets/javascripts/milestones/stores/actions.js | 61 |
1 files changed, 55 insertions, 6 deletions
diff --git a/app/assets/javascripts/milestones/stores/actions.js b/app/assets/javascripts/milestones/stores/actions.js index 3859771aeba..df45c7156ad 100644 --- a/app/assets/javascripts/milestones/stores/actions.js +++ b/app/assets/javascripts/milestones/stores/actions.js @@ -2,10 +2,15 @@ import Api from '~/api'; import * as types from './mutation_types'; export const setProjectId = ({ commit }, projectId) => commit(types.SET_PROJECT_ID, projectId); +export const setGroupId = ({ commit }, groupId) => commit(types.SET_GROUP_ID, groupId); +export const setGroupMilestonesAvailable = ({ commit }, groupMilestonesAvailable) => + commit(types.SET_GROUP_MILESTONES_AVAILABLE, groupMilestonesAvailable); export const setSelectedMilestones = ({ commit }, selectedMilestones) => commit(types.SET_SELECTED_MILESTONES, selectedMilestones); +export const clearSelectedMilestones = ({ commit }) => commit(types.CLEAR_SELECTED_MILESTONES); + export const toggleMilestones = ({ commit, state }, selectedMilestone) => { const removeMilestone = state.selectedMilestones.includes(selectedMilestone); @@ -16,13 +21,23 @@ export const toggleMilestones = ({ commit, state }, selectedMilestone) => { } }; -export const search = ({ dispatch, commit }, query) => { - commit(types.SET_QUERY, query); +export const search = ({ dispatch, commit, getters }, searchQuery) => { + commit(types.SET_SEARCH_QUERY, searchQuery); + + dispatch('searchProjectMilestones'); + if (getters.groupMilestonesEnabled) { + dispatch('searchGroupMilestones'); + } +}; - dispatch('searchMilestones'); +export const fetchMilestones = ({ dispatch, getters }) => { + dispatch('fetchProjectMilestones'); + if (getters.groupMilestonesEnabled) { + dispatch('fetchGroupMilestones'); + } }; -export const fetchMilestones = ({ commit, state }) => { +export const fetchProjectMilestones = ({ commit, state }) => { commit(types.REQUEST_START); Api.projectMilestones(state.projectId) @@ -37,14 +52,29 @@ export const fetchMilestones = ({ commit, state }) => { }); }; -export const searchMilestones = ({ commit, state }) => { +export const fetchGroupMilestones = ({ commit, state }) => { commit(types.REQUEST_START); + Api.groupMilestones(state.groupId) + .then(response => { + commit(types.RECEIVE_GROUP_MILESTONES_SUCCESS, response); + }) + .catch(error => { + commit(types.RECEIVE_GROUP_MILESTONES_ERROR, error); + }) + .finally(() => { + commit(types.REQUEST_FINISH); + }); +}; + +export const searchProjectMilestones = ({ commit, state }) => { const options = { - search: state.query, + search: state.searchQuery, scope: 'milestones', }; + commit(types.REQUEST_START); + Api.projectSearch(state.projectId, options) .then(response => { commit(types.RECEIVE_PROJECT_MILESTONES_SUCCESS, response); @@ -56,3 +86,22 @@ export const searchMilestones = ({ commit, state }) => { commit(types.REQUEST_FINISH); }); }; + +export const searchGroupMilestones = ({ commit, state }) => { + const options = { + search: state.searchQuery, + }; + + commit(types.REQUEST_START); + + Api.groupMilestones(state.groupId, options) + .then(response => { + commit(types.RECEIVE_GROUP_MILESTONES_SUCCESS, response); + }) + .catch(error => { + commit(types.RECEIVE_GROUP_MILESTONES_ERROR, error); + }) + .finally(() => { + commit(types.REQUEST_FINISH); + }); +}; |