mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.6 KiB
158 lines
4.6 KiB
3 years ago
|
import Vue from 'vue'
|
||
4 years ago
|
|
||
|
export const state = () => ({
|
||
|
projectApiFilePaths: {},
|
||
|
activeEnvironment: {},
|
||
|
currentProjectKey: ''
|
||
|
|
||
3 years ago
|
})
|
||
4 years ago
|
|
||
|
export const mutations = {
|
||
|
|
||
3 years ago
|
MutApiFilePathsAdd(state, args) {
|
||
4 years ago
|
state.projectApiFilePaths = {
|
||
|
...state.projectApiFilePaths,
|
||
|
[state.currentProjectKey]: [...state.projectApiFilePaths[state.currentProjectKey], args]
|
||
|
}
|
||
|
},
|
||
|
|
||
3 years ago
|
MutApiFilePathsRemove(state, index) {
|
||
3 years ago
|
state.projectApiFilePaths[state.currentProjectKey].splice(index, 1)
|
||
|
state.projectApiFilePaths[state.currentProjectKey] = [...state.projectApiFilePaths[state.currentProjectKey]]
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
MutListAdd(state, args) {
|
||
3 years ago
|
state.list.unshift(args)
|
||
|
if (state.list.length > 500) { state.list.pop() }
|
||
4 years ago
|
},
|
||
|
|
||
3 years ago
|
MutListRemove(state, index) {
|
||
4 years ago
|
// find index and set status
|
||
3 years ago
|
state.list.splice(index, 1)
|
||
|
// state.list = [...state.list]
|
||
4 years ago
|
},
|
||
3 years ago
|
MutList(state, list) {
|
||
3 years ago
|
state.projectApiFilePaths[state.currentProjectKey] = list
|
||
4 years ago
|
},
|
||
3 years ago
|
MutCurrentProjectKey(state, currentProjectKey) {
|
||
3 years ago
|
state.currentProjectKey = currentProjectKey
|
||
4 years ago
|
},
|
||
3 years ago
|
MutActiveEnvironment(state, { env }) {
|
||
3 years ago
|
Vue.set(state.activeEnvironment, state.currentProjectKey, env)
|
||
4 years ago
|
}
|
||
|
|
||
3 years ago
|
}
|
||
4 years ago
|
|
||
|
export const getters = {
|
||
3 years ago
|
GtrCurrentApiFilePaths(state) {
|
||
3 years ago
|
return state.projectApiFilePaths[state.currentProjectKey]
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|
||
4 years ago
|
|
||
|
export const actions = {
|
||
|
|
||
3 years ago
|
async send({ commit, state, rootGetters }, { apiDecoded, api }) {
|
||
3 years ago
|
const apiMeta = { ...apiDecoded }
|
||
|
// let t, t1, t2
|
||
4 years ago
|
|
||
|
// return (await rootGetters['sqlMgr/sqlMgr'].sqlOp(null, 'handleApiCall', apiMeta));
|
||
|
|
||
3 years ago
|
return (await this.dispatch('sqlMgr/ActSqlOp', [null, 'handleApiCall', apiMeta]))
|
||
4 years ago
|
//
|
||
|
// try {
|
||
|
// commit('notification/MutToggleProgressBar', true, {root: true});
|
||
|
// const req = XcApiHelp.axiosRequestMake(apiMeta);
|
||
|
// console.log(req);
|
||
|
//
|
||
|
//
|
||
|
// if (Object.values(apiMeta.perf).every(v => !v)) {
|
||
|
//
|
||
|
// // t = process.hrtime();
|
||
|
// let data = await axios(req);
|
||
|
//
|
||
|
// // t1 = process.hrtime(t);
|
||
|
// // t2 = (t1[0] + t1[1] / 1000000000).toFixed(2);
|
||
|
//
|
||
|
// apiMeta.response.status = data.status;
|
||
|
// apiMeta.response.headers = data.headers;
|
||
|
// apiMeta.response.data = data.data;
|
||
|
// console.log(data);
|
||
|
// } else {
|
||
|
// this.$toast.info('Starting performance test').goAway(3000);
|
||
|
// try {
|
||
|
// const res = await autocannon({
|
||
|
// ...req,`
|
||
|
// ...apiMeta.perf,
|
||
|
// body: req.data
|
||
|
// });
|
||
|
// console.log('perf result', res)
|
||
|
//
|
||
|
// apiMeta.response.status = 200;
|
||
|
// apiMeta.response.headers = [];
|
||
|
// apiMeta.response.data = res;
|
||
|
//
|
||
|
// this.$toast.info('Finished performance test').goAway(3000);
|
||
|
//
|
||
|
// } catch (e) {
|
||
|
// console.log(e)
|
||
|
// apiMeta.response.status = 400;
|
||
|
// apiMeta.response.data = e;
|
||
|
// }
|
||
|
//
|
||
|
// }
|
||
|
// } catch (e) {
|
||
|
// // t1 = process.hrtime(t);
|
||
|
// // t2 = (t1[0] + t1[1] / 1000000000).toFixed(2);
|
||
|
//
|
||
|
// console.log(e, Object.keys(e), Object.entries(e));
|
||
|
// apiMeta.response = e.response;
|
||
|
// if (apiMeta.response)
|
||
|
// delete apiMeta.response.request
|
||
|
// //throw e;
|
||
|
// } finally {
|
||
|
// commit('notification/MutToggleProgressBar', false, {root: true});
|
||
|
// }
|
||
|
// return {
|
||
|
// ...apiMeta,
|
||
|
// body: JSON.stringify(apiMeta.body, 0, 2),
|
||
|
// response: {
|
||
|
// ...apiMeta.response,
|
||
|
// timeTaken: t2,
|
||
|
// createdAt: Date.now()
|
||
|
// }
|
||
|
// };
|
||
|
},
|
||
|
|
||
3 years ago
|
async loadApiCollectionForProject({ commit, state }, { projectName = '__default', projectId = '__id' }) {
|
||
3 years ago
|
const key = projectName + '__' + projectId
|
||
4 years ago
|
commit('MutCurrentProjectKey', key)
|
||
|
if (!(key in state.projectApiFilePaths)) {
|
||
3 years ago
|
commit('MutList', [])
|
||
4 years ago
|
}
|
||
3 years ago
|
}
|
||
4 years ago
|
|
||
3 years ago
|
}
|
||
4 years ago
|
|
||
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
|
*/
|