Env management

This commit is contained in:
Jacob Anavisca
2020-02-23 11:38:15 -05:00
parent 112c140ce7
commit 15dc0ad9ac
8 changed files with 742 additions and 1 deletions

View File

@@ -74,6 +74,13 @@ export const state = () => ({
requests: []
}
],
environments: [
{
name: "My Env Variables",
variables: []
}
],
editingEnvironment: {},
selectedRequest: {},
editingRequest: {}
});
@@ -102,6 +109,61 @@ export const mutations = {
settings[key] = value;
},
removeVariables({ editingEnvironment }, value) {
editingEnvironment.variables = value
},
setEditingEnvironment(state, value ) {
state.editingEnvironment = {...value}
},
setVariableKey({ editingEnvironment }, { index, value }) {
editingEnvironment.variables[index].key = value;
},
setVariableValue({ editingEnvironment }, { index, value }) {
editingEnvironment.variables[index].value = value;
},
removeVariable({ editingEnvironment }, variables) {
editingEnvironment.variables = variables;
},
addVariable({ editingEnvironment }, value) {
editingEnvironment.variables.push(value);
},
replaceEnvironments(state, environments) {
state.environments = environments;
},
importAddEnvironments(state, environments) {
state.environments = [...state.environments, ...environments];
let index = 0;
for (let environment of state.environments) {
environment.environmentIndex = index;
index += 1;
}
},
removeEnvironment({ environments }, environmentIndex) {
environments.splice(environmentIndex, 1);
},
saveEnvironment({ environments }, payload) {
const { environment, environmentIndex } = payload;
const { name } = environment;
const duplicateEnvironment = environments.some(item => {
return item.environmentIndex !== environmentIndex && item.name.toLowerCase() === name.toLowerCase()
});
if (duplicateEnvironment) {
this.$toast.info("Duplicate environment");
return;
}
environments[environmentIndex] = environment;
},
replaceCollections(state, collections) {
state.collections = collections;
},
@@ -323,3 +385,9 @@ export const mutations = {
state.selectedRequest = Object.assign({}, request);
}
};
// export const getters = {
// getEditingEnvironment: state => {
// return state.editingEnvironment
// }
// }