debian-mirror-gitlab/app/assets/javascripts/milestones/stores/actions.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
3 KiB
JavaScript
Raw Normal View History

2021-01-03 14:25:43 +05:30
import Api from '~/api';
import * as types from './mutation_types';
export const setProjectId = ({ commit }, projectId) => commit(types.SET_PROJECT_ID, projectId);
2021-01-29 00:20:46 +05:30
export const setGroupId = ({ commit }, groupId) => commit(types.SET_GROUP_ID, groupId);
export const setGroupMilestonesAvailable = ({ commit }, groupMilestonesAvailable) =>
commit(types.SET_GROUP_MILESTONES_AVAILABLE, groupMilestonesAvailable);
2021-01-03 14:25:43 +05:30
export const setSelectedMilestones = ({ commit }, selectedMilestones) =>
commit(types.SET_SELECTED_MILESTONES, selectedMilestones);
2021-01-29 00:20:46 +05:30
export const clearSelectedMilestones = ({ commit }) => commit(types.CLEAR_SELECTED_MILESTONES);
2021-01-03 14:25:43 +05:30
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);
}
};
2021-01-29 00:20:46 +05:30
export const search = ({ dispatch, commit, getters }, searchQuery) => {
commit(types.SET_SEARCH_QUERY, searchQuery);
dispatch('searchProjectMilestones');
if (getters.groupMilestonesEnabled) {
dispatch('searchGroupMilestones');
}
};
2021-01-03 14:25:43 +05:30
2021-01-29 00:20:46 +05:30
export const fetchMilestones = ({ dispatch, getters }) => {
dispatch('fetchProjectMilestones');
if (getters.groupMilestonesEnabled) {
dispatch('fetchGroupMilestones');
}
2021-01-03 14:25:43 +05:30
};
2021-01-29 00:20:46 +05:30
export const fetchProjectMilestones = ({ commit, state }) => {
2021-01-03 14:25:43 +05:30
commit(types.REQUEST_START);
Api.projectMilestones(state.projectId)
2021-03-08 18:12:59 +05:30
.then((response) => {
2021-01-03 14:25:43 +05:30
commit(types.RECEIVE_PROJECT_MILESTONES_SUCCESS, response);
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2021-01-03 14:25:43 +05:30
commit(types.RECEIVE_PROJECT_MILESTONES_ERROR, error);
})
.finally(() => {
commit(types.REQUEST_FINISH);
});
};
2021-01-29 00:20:46 +05:30
export const fetchGroupMilestones = ({ commit, state }) => {
2021-01-03 14:25:43 +05:30
commit(types.REQUEST_START);
2021-01-29 00:20:46 +05:30
Api.groupMilestones(state.groupId)
2021-03-08 18:12:59 +05:30
.then((response) => {
2021-01-29 00:20:46 +05:30
commit(types.RECEIVE_GROUP_MILESTONES_SUCCESS, response);
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2021-01-29 00:20:46 +05:30
commit(types.RECEIVE_GROUP_MILESTONES_ERROR, error);
})
.finally(() => {
commit(types.REQUEST_FINISH);
});
};
export const searchProjectMilestones = ({ commit, state }) => {
2021-01-03 14:25:43 +05:30
const options = {
2021-01-29 00:20:46 +05:30
search: state.searchQuery,
2021-01-03 14:25:43 +05:30
scope: 'milestones',
};
2021-01-29 00:20:46 +05:30
commit(types.REQUEST_START);
2021-01-03 14:25:43 +05:30
Api.projectSearch(state.projectId, options)
2021-03-08 18:12:59 +05:30
.then((response) => {
2021-01-03 14:25:43 +05:30
commit(types.RECEIVE_PROJECT_MILESTONES_SUCCESS, response);
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2021-01-03 14:25:43 +05:30
commit(types.RECEIVE_PROJECT_MILESTONES_ERROR, error);
})
.finally(() => {
commit(types.REQUEST_FINISH);
});
};
2021-01-29 00:20:46 +05:30
export const searchGroupMilestones = ({ commit, state }) => {
const options = {
search: state.searchQuery,
};
commit(types.REQUEST_START);
Api.groupMilestones(state.groupId, options)
2021-03-08 18:12:59 +05:30
.then((response) => {
2021-01-29 00:20:46 +05:30
commit(types.RECEIVE_GROUP_MILESTONES_SUCCESS, response);
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2021-01-29 00:20:46 +05:30
commit(types.RECEIVE_GROUP_MILESTONES_ERROR, error);
})
.finally(() => {
commit(types.REQUEST_FINISH);
});
};