Welcome to mirror list, hosted at ThFree Co, Russian Federation.

actions.js « stores « explorer « registry « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 25ff105ac538f7c831ecd880da372c6575d37d35 (plain)
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
109
110
111
112
113
114
115
import axios from '~/lib/utils/axios_utils';
import createFlash from '~/flash';
import * as types from './mutation_types';
import {
  FETCH_IMAGES_LIST_ERROR_MESSAGE,
  DEFAULT_PAGE,
  DEFAULT_PAGE_SIZE,
  FETCH_TAGS_LIST_ERROR_MESSAGE,
  DELETE_TAG_SUCCESS_MESSAGE,
  DELETE_TAG_ERROR_MESSAGE,
  DELETE_TAGS_SUCCESS_MESSAGE,
  DELETE_TAGS_ERROR_MESSAGE,
  DELETE_IMAGE_ERROR_MESSAGE,
  DELETE_IMAGE_SUCCESS_MESSAGE,
} from '../constants';

export const setInitialState = ({ commit }, data) => commit(types.SET_INITIAL_STATE, data);

export const receiveImagesListSuccess = ({ commit }, { data, headers }) => {
  commit(types.SET_IMAGES_LIST_SUCCESS, data);
  commit(types.SET_PAGINATION, headers);
};

export const receiveTagsListSuccess = ({ commit }, { data, headers }) => {
  commit(types.SET_TAGS_LIST_SUCCESS, data);
  commit(types.SET_TAGS_PAGINATION, headers);
};

export const requestImagesList = ({ commit, dispatch, state }, pagination = {}) => {
  commit(types.SET_MAIN_LOADING, true);
  const { page = DEFAULT_PAGE, perPage = DEFAULT_PAGE_SIZE } = pagination;

  return axios
    .get(state.config.endpoint, { params: { page, per_page: perPage } })
    .then(({ data, headers }) => {
      dispatch('receiveImagesListSuccess', { data, headers });
    })
    .catch(() => {
      createFlash(FETCH_IMAGES_LIST_ERROR_MESSAGE);
    })
    .finally(() => {
      commit(types.SET_MAIN_LOADING, false);
    });
};

export const requestTagsList = ({ commit, dispatch }, { pagination = {}, id }) => {
  commit(types.SET_MAIN_LOADING, true);
  const { tags_path } = JSON.parse(window.atob(id));

  const { page = DEFAULT_PAGE, perPage = DEFAULT_PAGE_SIZE } = pagination;
  return axios
    .get(tags_path, { params: { page, per_page: perPage } })
    .then(({ data, headers }) => {
      dispatch('receiveTagsListSuccess', { data, headers });
    })
    .catch(() => {
      createFlash(FETCH_TAGS_LIST_ERROR_MESSAGE);
    })
    .finally(() => {
      commit(types.SET_MAIN_LOADING, false);
    });
};

export const requestDeleteTag = ({ commit, dispatch, state }, { tag, imageId }) => {
  commit(types.SET_MAIN_LOADING, true);
  return axios
    .delete(tag.destroy_path)
    .then(() => {
      createFlash(DELETE_TAG_SUCCESS_MESSAGE, 'success');
      dispatch('requestTagsList', { pagination: state.tagsPagination, id: imageId });
    })
    .catch(() => {
      createFlash(DELETE_TAG_ERROR_MESSAGE);
    })
    .finally(() => {
      commit(types.SET_MAIN_LOADING, false);
    });
};

export const requestDeleteTags = ({ commit, dispatch, state }, { ids, imageId }) => {
  commit(types.SET_MAIN_LOADING, true);
  const url = `/${state.config.projectPath}/registry/repository/${imageId}/tags/bulk_destroy`;

  return axios
    .delete(url, { params: { ids } })
    .then(() => {
      createFlash(DELETE_TAGS_SUCCESS_MESSAGE, 'success');
      dispatch('requestTagsList', { pagination: state.tagsPagination, id: imageId });
    })
    .catch(() => {
      createFlash(DELETE_TAGS_ERROR_MESSAGE);
    })
    .finally(() => {
      commit(types.SET_MAIN_LOADING, false);
    });
};

export const requestDeleteImage = ({ commit, dispatch, state }, destroyPath) => {
  commit(types.SET_MAIN_LOADING, true);

  return axios
    .delete(destroyPath)
    .then(() => {
      dispatch('requestImagesList', { pagination: state.pagination });
      createFlash(DELETE_IMAGE_SUCCESS_MESSAGE, 'success');
    })
    .catch(() => {
      createFlash(DELETE_IMAGE_ERROR_MESSAGE);
    })
    .finally(() => {
      commit(types.SET_MAIN_LOADING, false);
    });
};

export default () => {};