All files / app/assets/javascripts/milestones/stores actions.js

100% Statements 50/50
100% Branches 6/6
100% Functions 24/24
100% Lines 47/47

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108      50x 50x 3x 50x   3x 5x   3x   3x 2x   2x 1x   1x       3x 3x   3x 3x 2x       3x 51x 51x 50x       3x 51x   51x   49x     30x     51x       3x 51x   51x   21x     30x     51x       3x 3x         3x   3x   2x     1x     3x       3x 3x       3x   3x   2x     1x     3x      
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);
 
  if (removeMilestone) {
    commit(types.REMOVE_SELECTED_MILESTONE, selectedMilestone);
  } else {
    commit(types.ADD_SELECTED_MILESTONE, selectedMilestone);
  }
};
 
export const search = ({ dispatch, commit, getters }, searchQuery) => {
  commit(types.SET_SEARCH_QUERY, searchQuery);
 
  dispatch('searchProjectMilestones');
  if (getters.groupMilestonesEnabled) {
    dispatch('searchGroupMilestones');
  }
};
 
export const fetchMilestones = ({ dispatch, getters }) => {
  dispatch('fetchProjectMilestones');
  if (getters.groupMilestonesEnabled) {
    dispatch('fetchGroupMilestones');
  }
};
 
export const fetchProjectMilestones = ({ 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 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.searchQuery,
    scope: 'milestones',
  };
 
  commit(types.REQUEST_START);
 
  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);
    });
};
 
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);
    });
};