Review Updates

This commit is contained in:
Jacob Anavisca
2020-02-23 22:21:10 -05:00
parent 54d590765f
commit 00fa17b31f
4 changed files with 50 additions and 16 deletions

View File

@@ -69,7 +69,7 @@ export default {
}, },
addNewEnvironment() { addNewEnvironment() {
if (!this.$data.name) { if (!this.$data.name) {
this.$toast.info($t("invalid_environment_name")); this.$toast.info(this.$t("invalid_environment_name"));
return; return;
} }
let newEnvironment = [ let newEnvironment = [
@@ -78,11 +78,15 @@ export default {
variables: [] variables: []
} }
]; ];
this.$store.commit("postwoman/importAddEnvironments", newEnvironment); this.$store.commit("postwoman/importAddEnvironments", {
environments: newEnvironment,
confirmation: "Environment added"
});
this.$emit("hide-modal"); this.$emit("hide-modal");
this.syncEnvironments(); this.syncEnvironments();
}, },
hideModal() { hideModal() {
this.$data.name = undefined;
this.$emit("hide-modal"); this.$emit("hide-modal");
} }
} }

View File

@@ -71,7 +71,11 @@
<input <input
:placeholder="$t('value_count', { count: index + 1 })" :placeholder="$t('value_count', { count: index + 1 })"
:name="'value' + index" :name="'value' + index"
:value="variable.value" :value="
typeof variable.value === 'string'
? variable.value
: JSON.stringify(variable.value)
"
@change=" @change="
$store.commit('postwoman/setVariableValue', { $store.commit('postwoman/setVariableValue', {
index, index,
@@ -140,6 +144,9 @@ export default {
}, },
watch: { watch: {
editingEnvironment: function(update) { editingEnvironment: function(update) {
this.name = this.$props.editingEnvironment && this.$props.editingEnvironment.name
? this.$props.editingEnvironment.name
: undefined
this.$store.commit( this.$store.commit(
"postwoman/setEditingEnvironment", "postwoman/setEditingEnvironment",
this.$props.editingEnvironment this.$props.editingEnvironment

View File

@@ -119,8 +119,8 @@ export default {
let reader = new FileReader(); let reader = new FileReader();
reader.onload = event => { reader.onload = event => {
let content = event.target.result; let content = event.target.result;
let environment = JSON.parse(content); let environments = JSON.parse(content);
this.$store.commit("postwoman/replaceEnvironments", environment); this.$store.commit("postwoman/replaceEnvironments", environments);
}; };
reader.readAsText(this.$refs.inputChooseFileToReplaceWith.files[0]); reader.readAsText(this.$refs.inputChooseFileToReplaceWith.files[0]);
this.fileImported(); this.fileImported();
@@ -129,11 +129,14 @@ export default {
let reader = new FileReader(); let reader = new FileReader();
reader.onload = event => { reader.onload = event => {
let content = event.target.result; let content = event.target.result;
let environment = JSON.parse(content); let environments = JSON.parse(content);
this.$store.commit("postwoman/importAddEnvironments", environment); let confirmation = this.$t("file_imported")
this.$store.commit("postwoman/importAddEnvironments", {
environments,
confirmation
});
}; };
reader.readAsText(this.$refs.inputChooseFileToImportFrom.files[0]); reader.readAsText(this.$refs.inputChooseFileToImportFrom.files[0]);
this.fileImported();
}, },
exportJSON() { exportJSON() {
let text = this.environmentJson; let text = this.environmentJson;

View File

@@ -122,7 +122,7 @@ export const mutations = {
}, },
setVariableValue({ editingEnvironment }, { index, value }) { setVariableValue({ editingEnvironment }, { index, value }) {
editingEnvironment.variables[index].value = value; editingEnvironment.variables[index].value = testValue(value);
}, },
removeVariable({ editingEnvironment }, variables) { removeVariable({ editingEnvironment }, variables) {
@@ -137,7 +137,19 @@ export const mutations = {
state.environments = environments; state.environments = environments;
}, },
importAddEnvironments(state, environments) { importAddEnvironments(state, { environments, confirmation }) {
const duplicateEnvironment = environments.some(
item => {
return state.environments.some(
item2 => {
return item.name.toLowerCase() === item2.name.toLowerCase();
});
}
);
if (duplicateEnvironment) {
this.$toast.info("Duplicate environment");
return;
};
state.environments = [...state.environments, ...environments]; state.environments = [...state.environments, ...environments];
let index = 0; let index = 0;
@@ -145,6 +157,9 @@ export const mutations = {
environment.environmentIndex = index; environment.environmentIndex = index;
index += 1; index += 1;
} }
this.$toast.info(confirmation, {
icon: "folder_shared"
});
}, },
removeEnvironment({ environments }, environmentIndex) { removeEnvironment({ environments }, environmentIndex) {
@@ -154,7 +169,9 @@ export const mutations = {
saveEnvironment({ environments }, payload) { saveEnvironment({ environments }, payload) {
const { environment, environmentIndex } = payload; const { environment, environmentIndex } = payload;
const { name } = environment; const { name } = environment;
const duplicateEnvironment = environments.some( const duplicateEnvironment = environments.length === 1
? false
: environments.some(
item => item =>
item.environmentIndex !== environmentIndex && item.environmentIndex !== environmentIndex &&
item.name.toLowerCase() === name.toLowerCase() item.name.toLowerCase() === name.toLowerCase()
@@ -394,8 +411,11 @@ export const mutations = {
} }
}; };
// export const getters = { function testValue(myValue) {
// getEditingEnvironment: state => { try {
// return state.editingEnvironment return JSON.parse(myValue);
// } } catch(ex) {
// } // Now we know it's a string just leave it as a string value.
return myValue;
}
}