debian-mirror-gitlab/app/assets/javascripts/deploy_freeze/store/actions.js

107 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-10-24 23:57:45 +05:30
import Api from '~/api';
2021-09-04 01:27:46 +05:30
import createFlash from '~/flash';
2021-11-11 11:23:49 +05:30
import { logError } from '~/lib/logger';
2020-10-24 23:57:45 +05:30
import { __ } from '~/locale';
2021-03-11 19:13:27 +05:30
import * as types from './mutation_types';
2020-10-24 23:57:45 +05:30
2021-04-29 21:17:54 +05:30
export const requestFreezePeriod = ({ commit }) => {
2020-10-24 23:57:45 +05:30
commit(types.REQUEST_ADD_FREEZE_PERIOD);
};
2021-04-29 21:17:54 +05:30
export const receiveFreezePeriodSuccess = ({ commit }) => {
2020-10-24 23:57:45 +05:30
commit(types.RECEIVE_ADD_FREEZE_PERIOD_SUCCESS);
};
2021-04-29 21:17:54 +05:30
export const receiveFreezePeriodError = ({ commit }, error) => {
2020-10-24 23:57:45 +05:30
commit(types.RECEIVE_ADD_FREEZE_PERIOD_ERROR, error);
};
2021-04-29 21:17:54 +05:30
const receiveFreezePeriod = (store, request) => {
const { dispatch, commit } = store;
dispatch('requestFreezePeriod');
2020-10-24 23:57:45 +05:30
2021-04-29 21:17:54 +05:30
request(store)
2020-10-24 23:57:45 +05:30
.then(() => {
2021-04-29 21:17:54 +05:30
dispatch('receiveFreezePeriodSuccess');
2020-10-24 23:57:45 +05:30
commit(types.RESET_MODAL);
dispatch('fetchFreezePeriods');
})
2021-03-08 18:12:59 +05:30
.catch((error) => {
2021-09-04 01:27:46 +05:30
createFlash({
message: __('Error: Unable to create deploy freeze'),
});
2021-04-29 21:17:54 +05:30
dispatch('receiveFreezePeriodError', error);
2020-10-24 23:57:45 +05:30
});
};
2021-04-29 21:17:54 +05:30
export const addFreezePeriod = (store) =>
receiveFreezePeriod(store, ({ state }) =>
Api.createFreezePeriod(state.projectId, {
freeze_start: state.freezeStartCron,
freeze_end: state.freezeEndCron,
cron_timezone: state.selectedTimezoneIdentifier,
}),
);
export const updateFreezePeriod = (store) =>
receiveFreezePeriod(store, ({ state }) =>
Api.updateFreezePeriod(state.projectId, {
id: state.selectedId,
freeze_start: state.freezeStartCron,
freeze_end: state.freezeEndCron,
cron_timezone: state.selectedTimezoneIdentifier,
}),
);
2021-11-11 11:23:49 +05:30
export const deleteFreezePeriod = ({ state, commit }, { id }) => {
commit(types.REQUEST_DELETE_FREEZE_PERIOD, id);
return Api.deleteFreezePeriod(state.projectId, id)
.then(() => commit(types.RECEIVE_DELETE_FREEZE_PERIOD_SUCCESS, id))
.catch((e) => {
createFlash({
message: __('Error: Unable to delete deploy freeze'),
});
commit(types.RECEIVE_DELETE_FREEZE_PERIOD_ERROR, id);
logError(`Unable to delete deploy freeze`, e);
});
};
2020-10-24 23:57:45 +05:30
export const fetchFreezePeriods = ({ commit, state }) => {
commit(types.REQUEST_FREEZE_PERIODS);
return Api.freezePeriods(state.projectId)
.then(({ data }) => {
commit(types.RECEIVE_FREEZE_PERIODS_SUCCESS, data);
})
.catch(() => {
2021-09-04 01:27:46 +05:30
createFlash({
message: __('There was an error fetching the deploy freezes.'),
});
2020-10-24 23:57:45 +05:30
});
};
2021-04-29 21:17:54 +05:30
export const setFreezePeriod = ({ commit }, freezePeriod) => {
commit(types.SET_SELECTED_ID, freezePeriod.id);
commit(types.SET_SELECTED_TIMEZONE, freezePeriod.cronTimezone);
commit(types.SET_FREEZE_START_CRON, freezePeriod.freezeStart);
commit(types.SET_FREEZE_END_CRON, freezePeriod.freezeEnd);
};
2020-10-24 23:57:45 +05:30
export const setSelectedTimezone = ({ commit }, timezone) => {
commit(types.SET_SELECTED_TIMEZONE, timezone);
};
export const setFreezeStartCron = ({ commit }, { freezeStartCron }) => {
commit(types.SET_FREEZE_START_CRON, freezeStartCron);
};
export const setFreezeEndCron = ({ commit }, { freezeEndCron }) => {
commit(types.SET_FREEZE_END_CRON, freezeEndCron);
};
export const resetModal = ({ commit }) => {
commit(types.RESET_MODAL);
};