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

47 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-02-15 15:39:39 +05:30
import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
2018-03-17 18:26:18 +05:30
import * as types from './mutation_types';
2019-02-15 15:39:39 +05:30
import { errorMessages, errorMessagesTypes } from '../constants';
2018-03-17 18:26:18 +05:30
export const fetchRepos = ({ commit, state }) => {
commit(types.TOGGLE_MAIN_LOADING);
2019-02-15 15:39:39 +05:30
return axios
2018-11-08 19:23:39 +05:30
.get(state.endpoint)
2019-02-15 15:39:39 +05:30
.then(({ data }) => {
commit(types.TOGGLE_MAIN_LOADING);
commit(types.SET_REPOS_LIST, data);
})
.catch(() => {
2018-03-17 18:26:18 +05:30
commit(types.TOGGLE_MAIN_LOADING);
2019-02-15 15:39:39 +05:30
createFlash(errorMessages[errorMessagesTypes.FETCH_REPOS]);
2018-03-17 18:26:18 +05:30
});
};
export const fetchList = ({ commit }, { repo, page }) => {
commit(types.TOGGLE_REGISTRY_LIST_LOADING, repo);
2019-02-15 15:39:39 +05:30
return axios
.get(repo.tagsPath, { params: { page } })
.then(response => {
const { headers, data } = response;
2018-03-17 18:26:18 +05:30
2018-11-08 19:23:39 +05:30
commit(types.TOGGLE_REGISTRY_LIST_LOADING, repo);
2019-02-15 15:39:39 +05:30
commit(types.SET_REGISTRY_LIST, { repo, resp: data, headers });
})
.catch(() => {
commit(types.TOGGLE_REGISTRY_LIST_LOADING, repo);
createFlash(errorMessages[errorMessagesTypes.FETCH_REGISTRY]);
2018-03-17 18:26:18 +05:30
});
};
2019-09-30 21:07:59 +05:30
export const deleteItem = (_, item) => axios.delete(item.destroyPath);
2019-10-12 21:52:04 +05:30
export const multiDeleteItems = (_, { path, items }) =>
axios.delete(path, { params: { ids: items } });
2018-03-17 18:26:18 +05:30
export const setMainEndpoint = ({ commit }, data) => commit(types.SET_MAIN_ENDPOINT, data);
2019-12-21 20:55:43 +05:30
export const setIsDeleteDisabled = ({ commit }, data) => commit(types.SET_IS_DELETE_DISABLED, data);
2018-03-17 18:26:18 +05:30
export const toggleLoading = ({ commit }) => commit(types.TOGGLE_MAIN_LOADING);
2018-10-15 14:42:47 +05:30
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};