forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.js
More file actions
63 lines (58 loc) · 2.02 KB
/
dashboard.js
File metadata and controls
63 lines (58 loc) · 2.02 KB
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
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;
},
},
};