Lint + few best practices

This commit is contained in:
Liyas Thomas
2020-02-23 22:43:12 +05:30
parent 59ca8cb2c6
commit 010be95ed5
5 changed files with 63 additions and 46 deletions

View File

@@ -43,7 +43,6 @@
</template> </template>
<script> <script>
export default { export default {
props: { props: {
show: Boolean show: Boolean
@@ -62,10 +61,12 @@ export default {
this.$toast.info($t("invalid_environment_name")); this.$toast.info($t("invalid_environment_name"));
return; return;
} }
let newEnvironment = [{ let newEnvironment = [
name: this.$data.name, {
variables: [] name: this.$data.name,
}] variables: []
}
];
this.$store.commit("postwoman/importAddEnvironments", newEnvironment); this.$store.commit("postwoman/importAddEnvironments", newEnvironment);
this.$emit("hide-modal"); this.$emit("hide-modal");
}, },

View File

@@ -49,18 +49,21 @@
></textarea> ></textarea>
</li> </li>
</ul> </ul>
<ul v-for="(variable, index) in this.editingEnvCopy.variables" :key="index"> <ul
v-for="(variable, index) in this.editingEnvCopy.variables"
:key="index"
>
<li> <li>
<input <input
:placeholder="$t('parameter_count', { count: index + 1 })" :placeholder="$t('parameter_count', { count: index + 1 })"
:name="'param' + index" :name="'param' + index"
:value="variable.key" :value="variable.key"
@change=" @change="
$store.commit('postwoman/setVariableKey', { $store.commit('postwoman/setVariableKey', {
index, index,
value: $event.target.value value: $event.target.value
}) })
" "
autofocus autofocus
/> />
</li> </li>
@@ -70,11 +73,11 @@
:name="'value' + index" :name="'value' + index"
:value="variable.value" :value="variable.value"
@change=" @change="
$store.commit('postwoman/setVariableValue', { $store.commit('postwoman/setVariableValue', {
index, index,
value: $event.target.value value: $event.target.value
}) })
" "
/> />
</li> </li>
<div> <div>
@@ -137,21 +140,24 @@ export default {
}, },
watch: { watch: {
editingEnvironment: function(update) { editingEnvironment: function(update) {
this.$store.commit("postwoman/setEditingEnvironment", this.$props.editingEnvironment); this.$store.commit(
"postwoman/setEditingEnvironment",
this.$props.editingEnvironment
);
} }
}, },
computed: { computed: {
editingEnvCopy() { editingEnvCopy() {
return this.$store.state.postwoman.editingEnvironment return this.$store.state.postwoman.editingEnvironment;
}, },
variableString() { variableString() {
const result = this.editingEnvCopy.variables const result = this.editingEnvCopy.variables;
return result === "" ? "" : JSON.stringify(result); return result === "" ? "" : JSON.stringify(result);
} }
}, },
methods: { methods: {
clearContent(e) { clearContent(e) {
this.$store.commit("postwoman/removeVariables", []) this.$store.commit("postwoman/removeVariables", []);
e.target.innerHTML = this.doneButton; e.target.innerHTML = this.doneButton;
this.$toast.info(this.$t("cleared"), { this.$toast.info(this.$t("cleared"), {
icon: "clear_all" icon: "clear_all"
@@ -162,15 +168,17 @@ export default {
); );
}, },
addEnvironmentVariable() { addEnvironmentVariable() {
let value = { key: "", value: "" } let value = { key: "", value: "" };
this.$store.commit("postwoman/addVariable", value); this.$store.commit("postwoman/addVariable", value);
}, },
removeEnvironmentVariable(index) { removeEnvironmentVariable(index) {
let variableIndex = index let variableIndex = index;
const oldVariables = this.editingEnvCopy.variables.slice() const oldVariables = this.editingEnvCopy.variables.slice();
const newVariables = this.editingEnvCopy.variables.filter((variable, index) => variableIndex !== index) const newVariables = this.editingEnvCopy.variables.filter(
(variable, index) => variableIndex !== index
);
this.$store.commit("postwoman/removeVariable", newVariables) this.$store.commit("postwoman/removeVariable", newVariables);
this.$toast.error(this.$t("deleted"), { this.$toast.error(this.$t("deleted"), {
icon: "delete", icon: "delete",
action: { action: {
@@ -198,7 +206,7 @@ export default {
this.$emit("hide-modal"); this.$emit("hide-modal");
}, },
hideModal() { hideModal() {
this.$data.name = undefined this.$data.name = undefined;
this.$emit("hide-modal"); this.$emit("hide-modal");
} }
} }

View File

@@ -23,11 +23,7 @@
: $t('replace_current') : $t('replace_current')
}" }"
> >
<button <button :disabled="true" class="icon" @click="syncEnvironments">
:disabled="true"
class="icon"
@click="syncEnvironments"
>
<i class="material-icons">folder_shared</i> <i class="material-icons">folder_shared</i>
<span>{{ $t("import_from_sync") }}</span> <span>{{ $t("import_from_sync") }}</span>
</button> </button>

View File

@@ -1,5 +1,10 @@
<template> <template>
<pw-section class="green" icon="history" :label="$t('environment')" ref="environment"> <pw-section
class="green"
icon="history"
:label="$t('environment')"
ref="environment"
>
<addEnvironment :show="showModalAdd" @hide-modal="displayModalAdd(false)" /> <addEnvironment :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
<editEnvironment <editEnvironment
:show="showModalEdit" :show="showModalEdit"
@@ -11,7 +16,6 @@
:show="showModalImportExport" :show="showModalImportExport"
@hide-modal="displayModalImportExport(false)" @hide-modal="displayModalImportExport(false)"
/> />
<div class="flex-wrap"> <div class="flex-wrap">
<div> <div>
<button class="icon" @click="displayModalAdd(true)"> <button class="icon" @click="displayModalAdd(true)">
@@ -35,7 +39,10 @@
:remain="Math.min(5, environments.length)" :remain="Math.min(5, environments.length)"
> >
<ul> <ul>
<li v-for="(environment, index) in environments" :key="environment.name"> <li
v-for="(environment, index) in environments"
:key="environment.name"
>
<environment <environment
:environmentIndex="index" :environmentIndex="index"
:environment="environment" :environment="environment"
@@ -84,7 +91,7 @@ export default {
showModalAdd: false, showModalAdd: false,
showModalEdit: false, showModalEdit: false,
editingEnvironment: undefined, editingEnvironment: undefined,
editingEnvironmentIndex: undefined, editingEnvironmentIndex: undefined
}; };
}, },
computed: { computed: {
@@ -125,9 +132,9 @@ export default {
syncEnvironments() { syncEnvironments() {
// TODO // TODO
}, },
beforeDestroy() { beforeDestroy() {
document.removeEventListener("keydown", this._keyListener); document.removeEventListener("keydown", this._keyListener);
}
} }
} };
}
</script> </script>

View File

@@ -110,11 +110,11 @@ export const mutations = {
}, },
removeVariables({ editingEnvironment }, value) { removeVariables({ editingEnvironment }, value) {
editingEnvironment.variables = value editingEnvironment.variables = value;
}, },
setEditingEnvironment(state, value ) { setEditingEnvironment(state, value) {
state.editingEnvironment = {...value} state.editingEnvironment = { ...value };
}, },
setVariableKey({ editingEnvironment }, { index, value }) { setVariableKey({ editingEnvironment }, { index, value }) {
@@ -154,9 +154,11 @@ 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(item => { const duplicateEnvironment = environments.some(
return item.environmentIndex !== environmentIndex && item.name.toLowerCase() === name.toLowerCase() item =>
}); item.environmentIndex !== environmentIndex &&
item.name.toLowerCase() === name.toLowerCase()
);
if (duplicateEnvironment) { if (duplicateEnvironment) {
this.$toast.info("Duplicate environment"); this.$toast.info("Duplicate environment");
return; return;
@@ -201,7 +203,10 @@ export const mutations = {
}, },
editCollection({ collections }, payload) { editCollection({ collections }, payload) {
const { collection: { name }, collectionIndex } = payload; const {
collection: { name },
collectionIndex
} = payload;
const duplicateCollection = collections.some( const duplicateCollection = collections.some(
item => item.name.toLowerCase() === name.toLowerCase() item => item.name.toLowerCase() === name.toLowerCase()
); );