Fix dashboard to track server state
This commit is contained in:
parent
8b3713e3ff
commit
7f5485d648
5 changed files with 95 additions and 31 deletions
|
@ -1,22 +1,22 @@
|
|||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
import server from "./modules/server";
|
||||
import auth from "./modules/auth";
|
||||
import auth from './modules/auth';
|
||||
import dashboard from './modules/dashboard';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
const store = new Vuex.Store({
|
||||
strict: process.env.NODE_ENV !== 'production',
|
||||
modules: { auth },
|
||||
modules: { auth, dashboard },
|
||||
});
|
||||
|
||||
if (module.hot) {
|
||||
module.hot.accept(['./modules/auth'], () => {
|
||||
const newAuthModule = require('./modules/auth').default;
|
||||
// const newServerModule = require('./modules/server').default;
|
||||
const newDashboardModule = require('./modules/dashboard').default;
|
||||
|
||||
store.hotUpdate({
|
||||
modules: { newAuthModule },
|
||||
modules: { newAuthModule, newDashboardModule },
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
63
resources/assets/scripts/store/modules/dashboard.js
Normal file
63
resources/assets/scripts/store/modules/dashboard.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
import Server from './../../models/server';
|
||||
const route = require('./../../../../../vendor/tightenco/ziggy/src/js/route').default;
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
servers: [],
|
||||
searchTerm: '',
|
||||
},
|
||||
getters: {
|
||||
getSearchTerm: function (state) {
|
||||
return state.searchTerm;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
/**
|
||||
* Retrieve all of the servers for a user matching the query.
|
||||
*
|
||||
* @param commit
|
||||
* @param {String} query
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
loadServers: ({commit, state}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.axios.get(route('api.client.index'), {
|
||||
params: { query: state.searchTerm },
|
||||
})
|
||||
.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 request processing.
|
||||
if (!(response.data instanceof Object)) {
|
||||
return reject(new Error('An error was encountered while processing this request.'));
|
||||
}
|
||||
|
||||
// Remove all of the existing servers.
|
||||
commit('clearServers');
|
||||
|
||||
response.data.data.forEach(obj => {
|
||||
commit('addServer', obj.attributes);
|
||||
});
|
||||
|
||||
resolve();
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
},
|
||||
|
||||
setSearchTerm: ({commit}, term) => {
|
||||
commit('setSearchTerm', term);
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
addServer: function (state, data) {
|
||||
state.servers.push(new Server(data));
|
||||
},
|
||||
clearServers: function (state) {
|
||||
state.servers = [];
|
||||
},
|
||||
setSearchTerm: function (state, term) {
|
||||
state.searchTerm = term;
|
||||
},
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue