2019-06-04 17:55:52 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { __ } from '~/locale';
|
2020-08-20 09:09:55 +00:00
|
|
|
import { deprecatedCreateFlash as createFlash } from '~/flash';
|
2019-06-04 17:55:52 +00:00
|
|
|
import { refreshCurrentPage } from '~/lib/utils/url_utility';
|
|
|
|
import * as mutationTypes from './mutation_types';
|
|
|
|
|
|
|
|
export const setExternalDashboardUrl = ({ commit }, url) =>
|
|
|
|
commit(mutationTypes.SET_EXTERNAL_DASHBOARD_URL, url);
|
|
|
|
|
2020-06-12 03:08:22 +00:00
|
|
|
export const setDashboardTimezone = ({ commit }, selected) =>
|
|
|
|
commit(mutationTypes.SET_DASHBOARD_TIMEZONE, selected);
|
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
export const saveChanges = ({ state, dispatch }) =>
|
2019-06-04 17:55:52 +00:00
|
|
|
axios
|
|
|
|
.patch(state.operationsSettingsEndpoint, {
|
|
|
|
project: {
|
|
|
|
metrics_setting_attributes: {
|
2020-06-12 03:08:22 +00:00
|
|
|
dashboard_timezone: state.dashboardTimezone.selected,
|
2020-05-28 18:08:37 +00:00
|
|
|
external_dashboard_url: state.externalDashboard.url,
|
2019-06-04 17:55:52 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2020-05-28 18:08:37 +00:00
|
|
|
.then(() => dispatch('receiveSaveChangesSuccess'))
|
2020-12-23 21:10:24 +00:00
|
|
|
.catch((error) => dispatch('receiveSaveChangesError', error));
|
2019-06-04 17:55:52 +00:00
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
export const receiveSaveChangesSuccess = () => {
|
2019-06-04 17:55:52 +00:00
|
|
|
/**
|
|
|
|
* The operations_controller currently handles successful requests
|
|
|
|
* by creating a flash banner messsage to notify the user.
|
|
|
|
*/
|
|
|
|
refreshCurrentPage();
|
|
|
|
};
|
|
|
|
|
2020-05-28 18:08:37 +00:00
|
|
|
export const receiveSaveChangesError = (_, error) => {
|
|
|
|
const { response = {} } = error;
|
2019-06-04 17:55:52 +00:00
|
|
|
const message = response.data && response.data.message ? response.data.message : '';
|
|
|
|
|
|
|
|
createFlash(`${__('There was an error saving your changes.')} ${message}`, 'alert');
|
|
|
|
};
|