2018-06-03 23:45:01 +01:00
|
|
|
import route from '../../../../../vendor/tightenco/ziggy/src/js/route';
|
2018-07-19 06:48:19 +01:00
|
|
|
import Server from '../../models/server';
|
2018-06-03 23:45:01 +01:00
|
|
|
|
2018-07-16 00:57:00 +01:00
|
|
|
export default {
|
2018-07-19 06:48:19 +01:00
|
|
|
namespaced: true,
|
2018-06-03 23:45:01 +01:00
|
|
|
state: {
|
2018-07-19 06:48:19 +01:00
|
|
|
server: {},
|
2018-06-03 23:45:01 +01:00
|
|
|
},
|
2018-07-19 06:48:19 +01:00
|
|
|
getters: {
|
2018-06-03 23:45:01 +01:00
|
|
|
},
|
|
|
|
actions: {
|
2018-07-19 06:48:19 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param commit
|
|
|
|
* @param {String} server
|
|
|
|
* @returns {Promise<any>}
|
|
|
|
*/
|
|
|
|
getServer: ({commit}, {server}) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
window.axios.get(route('api.client.servers.view', { server }))
|
|
|
|
.then(response => {
|
|
|
|
// If there is a 302 redirect or some other odd behavior (basically, response that isnt
|
|
|
|
// in JSON format) throw an error and don't try to continue with the login.
|
|
|
|
if (!(response.data instanceof Object)) {
|
|
|
|
return reject(new Error('An error was encountered while processing this request.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (response.data.object === 'server' && response.data.attributes) {
|
|
|
|
commit('SERVER_DATA', response.data.attributes)
|
|
|
|
}
|
|
|
|
|
|
|
|
return resolve();
|
|
|
|
})
|
|
|
|
.catch(reject);
|
|
|
|
});
|
2018-06-03 23:45:01 +01:00
|
|
|
},
|
|
|
|
},
|
2018-07-19 06:48:19 +01:00
|
|
|
mutations: {
|
|
|
|
SERVER_DATA: function (state, data) {
|
|
|
|
state.server = data;
|
2018-06-03 23:45:01 +01:00
|
|
|
}
|
2018-07-19 06:48:19 +01:00
|
|
|
},
|
|
|
|
}
|