2018-12-04 08:20:43 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2018-12-05 04:27:29 -05:00
|
|
|
import createFlash from '~/flash';
|
2017-09-15 09:10:08 -04:00
|
|
|
import * as types from './mutation_types';
|
2018-12-05 04:27:29 -05:00
|
|
|
import { errorMessages, errorMessagesTypes } from '../constants';
|
2017-09-15 09:10:08 -04:00
|
|
|
|
|
|
|
export const fetchRepos = ({ commit, state }) => {
|
|
|
|
commit(types.TOGGLE_MAIN_LOADING);
|
|
|
|
|
2018-12-04 08:20:43 -05:00
|
|
|
return axios
|
2018-05-28 05:47:59 -04:00
|
|
|
.get(state.endpoint)
|
2018-12-04 08:20:43 -05:00
|
|
|
.then(({ data }) => {
|
2017-09-15 09:10:08 -04:00
|
|
|
commit(types.TOGGLE_MAIN_LOADING);
|
2018-12-04 08:20:43 -05:00
|
|
|
commit(types.SET_REPOS_LIST, data);
|
2018-12-05 04:27:29 -05:00
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
commit(types.TOGGLE_MAIN_LOADING);
|
|
|
|
createFlash(errorMessages[errorMessagesTypes.FETCH_REPOS]);
|
2017-09-15 09:10:08 -04:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-09-22 06:46:55 -04:00
|
|
|
export const fetchList = ({ commit }, { repo, page }) => {
|
|
|
|
commit(types.TOGGLE_REGISTRY_LIST_LOADING, repo);
|
2017-09-15 09:10:08 -04:00
|
|
|
|
2018-12-05 04:27:29 -05:00
|
|
|
return axios
|
|
|
|
.get(repo.tagsPath, { params: { page } })
|
|
|
|
.then(response => {
|
|
|
|
const { headers, data } = response;
|
|
|
|
|
|
|
|
commit(types.TOGGLE_REGISTRY_LIST_LOADING, repo);
|
|
|
|
commit(types.SET_REGISTRY_LIST, { repo, resp: data, headers });
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
commit(types.TOGGLE_REGISTRY_LIST_LOADING, repo);
|
|
|
|
createFlash(errorMessages[errorMessagesTypes.FETCH_REGISTRY]);
|
|
|
|
});
|
2017-09-15 09:10:08 -04:00
|
|
|
};
|
|
|
|
|
2018-05-28 05:53:00 -04:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2018-12-04 08:20:43 -05:00
|
|
|
export const deleteRepo = ({ commit }, repo) => axios.delete(repo.destroyPath);
|
2017-09-15 09:10:08 -04:00
|
|
|
|
2018-05-28 05:53:00 -04:00
|
|
|
// eslint-disable-next-line no-unused-vars
|
2018-12-04 08:20:43 -05:00
|
|
|
export const deleteRegistry = ({ commit }, image) => axios.delete(image.destroyPath);
|
2017-09-19 11:38:55 -04:00
|
|
|
|
|
|
|
export const setMainEndpoint = ({ commit }, data) => commit(types.SET_MAIN_ENDPOINT, data);
|
2017-09-20 14:03:53 -04:00
|
|
|
export const toggleLoading = ({ commit }) => commit(types.TOGGLE_MAIN_LOADING);
|
2018-04-13 19:27:16 -04:00
|
|
|
|
|
|
|
// prevent babel-plugin-rewire from generating an invalid default during karma tests
|
|
|
|
export default () => {};
|