diff options
Diffstat (limited to 'app/assets/javascripts/milestones/stores/actions.js')
-rw-r--r-- | app/assets/javascripts/milestones/stores/actions.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/app/assets/javascripts/milestones/stores/actions.js b/app/assets/javascripts/milestones/stores/actions.js new file mode 100644 index 00000000000..3859771aeba --- /dev/null +++ b/app/assets/javascripts/milestones/stores/actions.js @@ -0,0 +1,58 @@ +import Api from '~/api'; +import * as types from './mutation_types'; + +export const setProjectId = ({ commit }, projectId) => commit(types.SET_PROJECT_ID, projectId); + +export const setSelectedMilestones = ({ commit }, selectedMilestones) => + commit(types.SET_SELECTED_MILESTONES, selectedMilestones); + +export const toggleMilestones = ({ commit, state }, selectedMilestone) => { + const removeMilestone = state.selectedMilestones.includes(selectedMilestone); + + if (removeMilestone) { + commit(types.REMOVE_SELECTED_MILESTONE, selectedMilestone); + } else { + commit(types.ADD_SELECTED_MILESTONE, selectedMilestone); + } +}; + +export const search = ({ dispatch, commit }, query) => { + commit(types.SET_QUERY, query); + + dispatch('searchMilestones'); +}; + +export const fetchMilestones = ({ commit, state }) => { + commit(types.REQUEST_START); + + Api.projectMilestones(state.projectId) + .then(response => { + commit(types.RECEIVE_PROJECT_MILESTONES_SUCCESS, response); + }) + .catch(error => { + commit(types.RECEIVE_PROJECT_MILESTONES_ERROR, error); + }) + .finally(() => { + commit(types.REQUEST_FINISH); + }); +}; + +export const searchMilestones = ({ commit, state }) => { + commit(types.REQUEST_START); + + const options = { + search: state.query, + scope: 'milestones', + }; + + Api.projectSearch(state.projectId, options) + .then(response => { + commit(types.RECEIVE_PROJECT_MILESTONES_SUCCESS, response); + }) + .catch(error => { + commit(types.RECEIVE_PROJECT_MILESTONES_ERROR, error); + }) + .finally(() => { + commit(types.REQUEST_FINISH); + }); +}; |