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

49 lines
1.6 KiB
JavaScript
Raw Normal View History

2019-02-13 22:33:31 +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-13 22:33:31 +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-13 22:33:31 +05:30
return axios
2018-11-08 19:23:39 +05:30
.get(state.endpoint)
2019-02-13 22:33:31 +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-13 22:33:31 +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-13 22:33:31 +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-13 22:33:31 +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
});
};
2018-11-08 19:23:39 +05:30
// eslint-disable-next-line no-unused-vars
2019-02-13 22:33:31 +05:30
export const deleteRepo = ({ commit }, repo) => axios.delete(repo.destroyPath);
2018-03-17 18:26:18 +05:30
2018-11-08 19:23:39 +05:30
// eslint-disable-next-line no-unused-vars
2019-02-13 22:33:31 +05:30
export const deleteRegistry = ({ commit }, image) => axios.delete(image.destroyPath);
2018-03-17 18:26:18 +05:30
export const setMainEndpoint = ({ commit }, data) => commit(types.SET_MAIN_ENDPOINT, data);
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 () => {};