Merge pull request #591 from liyasthomas/feature/env-manager

Environment Mangement
This commit is contained in:
Liyas Thomas
2020-02-24 14:14:18 +05:30
committed by GitHub
11 changed files with 942 additions and 62 deletions

View File

@@ -121,12 +121,19 @@ export default {
let content = event.target.result;
let collections = JSON.parse(content);
if (collections[0]) {
let [ name, folders, requests ] = Object.keys(collections[0])
if (name === 'name' && folders === 'folders' && requests === 'requests') {
let [name, folders, requests] = Object.keys(collections[0]);
if (
name === "name" &&
folders === "folders" &&
requests === "requests"
) {
// Do nothing
}
} else if (collections.info && collections.info.schema.includes('v2.1.0')) {
collections = this.parsePostmanCollection(collections)
} else if (
collections.info &&
collections.info.schema.includes("v2.1.0")
) {
collections = this.parsePostmanCollection(collections);
} else {
return this.failedImport();
}
@@ -141,11 +148,18 @@ export default {
let content = event.target.result;
let collections = JSON.parse(content);
if (collections[0]) {
let [ name, folders, requests ] = Object.keys(collections[0])
if (name === 'name' && folders === 'folders' && requests === 'requests') {
let [name, folders, requests] = Object.keys(collections[0]);
if (
name === "name" &&
folders === "folders" &&
requests === "requests"
) {
// Do nothing
}
} else if (collections.info && collections.info.schema.includes('v2.1.0')) {
} else if (
collections.info &&
collections.info.schema.includes("v2.1.0")
) {
collections = this.parsePostmanCollection(collections);
} else {
return this.failedImport();
@@ -188,28 +202,38 @@ export default {
});
},
parsePostmanCollection(collection, folders = true) {
let postwomanCollection = folders ? [{
"name": "",
"folders": [],
"requests": []
}]
let postwomanCollection = folders
? [
{
name: "",
folders: [],
requests: []
}
]
: {
"name": "",
"requests": []
};
for(let collectionItem of collection.item) {
name: "",
requests: []
};
for (let collectionItem of collection.item) {
if (collectionItem.request) {
if (postwomanCollection[0]) {
postwomanCollection[0].name = collection.info ? collection.info.name : "";
postwomanCollection[0].requests.push(this.parsePostmanRequest(collectionItem));
postwomanCollection[0].name = collection.info
? collection.info.name
: "";
postwomanCollection[0].requests.push(
this.parsePostmanRequest(collectionItem)
);
} else {
postwomanCollection.name = collection.name ? collection.name
: "";
postwomanCollection.requests.push(this.parsePostmanRequest(collectionItem));
postwomanCollection.name = collection.name ? collection.name : "";
postwomanCollection.requests.push(
this.parsePostmanRequest(collectionItem)
);
}
} else if (collectionItem.item) {
if (collectionItem.item[0]) {
postwomanCollection[0].folders.push(this.parsePostmanCollection(collectionItem, false));
postwomanCollection[0].folders.push(
this.parsePostmanCollection(collectionItem, false)
);
}
}
}
@@ -217,46 +241,51 @@ export default {
},
parsePostmanRequest(requestObject) {
let pwRequest = {
"url": "",
"path": "",
"method": "",
"auth": "",
"httpUser": "",
"httpPassword": "",
"passwordFieldType": "password",
"bearerToken": "",
"headers": [],
"params": [],
"bodyParams": [],
"rawParams": "",
"rawInput": false,
"contentType": "",
"requestType": "",
"name": "",
url: "",
path: "",
method: "",
auth: "",
httpUser: "",
httpPassword: "",
passwordFieldType: "password",
bearerToken: "",
headers: [],
params: [],
bodyParams: [],
rawParams: "",
rawInput: false,
contentType: "",
requestType: "",
name: ""
};
pwRequest.name = requestObject.name;
let requestObjectUrl = requestObject.request.url.raw.match(/^(.+:\/\/[^\/]+|{[^\/]+})(\/[^\?]+|).*$/);
let requestObjectUrl = requestObject.request.url.raw.match(
/^(.+:\/\/[^\/]+|{[^\/]+})(\/[^\?]+|).*$/
);
pwRequest.url = requestObjectUrl[1];
pwRequest.path = requestObjectUrl[2] ? requestObjectUrl[2] : "";
pwRequest.method = requestObject.request.method;
let itemAuth = requestObject.request.auth ? requestObject.request.auth
: "";
let authType = itemAuth ? itemAuth.type
let itemAuth = requestObject.request.auth
? requestObject.request.auth
: "";
let authType = itemAuth ? itemAuth.type : "";
if (authType === "basic") {
pwRequest.auth = "Basic Auth";
pwRequest.httpUser = itemAuth.basic[0].key === "username"
? itemAuth.basic[0].value
: itemAuth.basic[1].value;
pwRequest.httpPassword = itemAuth.basic[0].key === "password"
? itemAuth.basic[0].value
: itemAuth.basic[1].value;
pwRequest.httpUser =
itemAuth.basic[0].key === "username"
? itemAuth.basic[0].value
: itemAuth.basic[1].value;
pwRequest.httpPassword =
itemAuth.basic[0].key === "password"
? itemAuth.basic[0].value
: itemAuth.basic[1].value;
} else if (authType === "oauth2") {
pwRequest.auth = "OAuth 2.0";
pwRequest.bearerToken = itemAuth.oauth2[0].key === "accessToken"
? itemAuth.oauth2[0].value
: itemAuth.oauth2[1].value;
pwRequest.bearerToken =
itemAuth.oauth2[0].key === "accessToken"
? itemAuth.oauth2[0].value
: itemAuth.oauth2[1].value;
} else if (authType === "bearer") {
pwRequest.auth = "Bearer Token";
pwRequest.bearerToken = itemAuth.bearer[0].value;
@@ -280,7 +309,7 @@ export default {
if (requestObject.request.body.mode === "urlencoded") {
let params = requestObject.request.body.urlencoded;
pwRequest.bodyParams = params ? params : [];
for(let param of pwRequest.bodyParams) {
for (let param of pwRequest.bodyParams) {
delete param.type;
}
} else if (requestObject.request.body.mode === "raw") {

View File

@@ -0,0 +1,94 @@
<template>
<modal v-if="show" @close="hideModal">
<div slot="header">
<ul>
<li>
<div class="flex-wrap">
<h3 class="title">{{ $t("new_environment") }}</h3>
<div>
<button class="icon" @click="hideModal">
<i class="material-icons">close</i>
</button>
</div>
</div>
</li>
</ul>
</div>
<div slot="body">
<ul>
<li>
<input
type="text"
v-model="name"
:placeholder="$t('my_new_environment')"
@keyup.enter="addNewEnvironment"
/>
</li>
</ul>
</div>
<div slot="footer">
<div class="flex-wrap">
<span></span>
<span>
<button class="icon" @click="hideModal">
{{ $t("cancel") }}
</button>
<button class="icon primary" @click="addNewEnvironment">
{{ $t("save") }}
</button>
</span>
</div>
</div>
</modal>
</template>
<script>
import { fb } from "../../functions/fb";
export default {
props: {
show: Boolean
},
components: {
modal: () => import("../../components/modal")
},
data() {
return {
name: undefined
};
},
methods: {
syncEnvironments() {
if (fb.currentUser !== null) {
if (fb.currentSettings[1].value) {
fb.writeEnvironments(
JSON.parse(JSON.stringify(this.$store.state.postwoman.environments))
);
}
}
},
addNewEnvironment() {
if (!this.$data.name) {
this.$toast.info(this.$t("invalid_environment_name"));
return;
}
let newEnvironment = [
{
name: this.$data.name,
variables: []
}
];
this.$store.commit("postwoman/importAddEnvironments", {
environments: newEnvironment,
confirmation: "Environment added"
});
this.$emit("hide-modal");
this.syncEnvironments();
},
hideModal() {
this.$data.name = undefined;
this.$emit("hide-modal");
}
}
};
</script>

View File

@@ -0,0 +1,221 @@
<template>
<modal v-if="show" @close="hideModal">
<div slot="header">
<ul>
<li>
<div class="flex-wrap">
<h3 class="title">{{ $t("edit_environment") }}</h3>
<div>
<button class="icon" @click="hideModal">
<i class="material-icons">close</i>
</button>
</div>
</div>
</li>
</ul>
</div>
<div slot="body">
<ul>
<li>
<input
type="text"
v-model="name"
:placeholder="editingEnvironment.name"
@keyup.enter="saveEnvironment"
/>
</li>
</ul>
<ul>
<li>
<div class="flex-wrap">
<label for="variableList">{{ $t("env_variable_list") }}</label>
<div>
<button
class="icon"
@click="clearContent($event)"
v-tooltip.bottom="$t('clear')"
>
<i class="material-icons">clear_all</i>
</button>
</div>
</div>
<textarea
id="variableList"
readonly
v-textarea-auto-height="variableString"
v-model="variableString"
:placeholder="$t('add_one_variable')"
rows="1"
></textarea>
</li>
</ul>
<ul
v-for="(variable, index) in this.editingEnvCopy.variables"
:key="index"
>
<li>
<input
:placeholder="$t('parameter_count', { count: index + 1 })"
:name="'param' + index"
:value="variable.key"
@change="
$store.commit('postwoman/setVariableKey', {
index,
value: $event.target.value
})
"
autofocus
/>
</li>
<li>
<input
:placeholder="$t('value_count', { count: index + 1 })"
:name="'value' + index"
:value="
typeof variable.value === 'string'
? variable.value
: JSON.stringify(variable.value)
"
@change="
$store.commit('postwoman/setVariableValue', {
index,
value: $event.target.value
})
"
/>
</li>
<div>
<li>
<button
class="icon"
@click="removeEnvironmentVariable(index)"
v-tooltip.bottom="$t('delete')"
id="variable"
>
<i class="material-icons">delete</i>
</button>
</li>
</div>
</ul>
<ul>
<li>
<button class="icon" @click="addEnvironmentVariable">
<i class="material-icons">add</i>
<span>{{ $t("add_new") }}</span>
</button>
</li>
</ul>
</div>
<div slot="footer">
<div class="flex-wrap">
<span></span>
<span>
<button class="icon" @click="hideModal">
{{ $t("cancel") }}
</button>
<button class="icon primary" @click="saveEnvironment">
{{ $t("save") }}
</button>
</span>
</div>
</div>
</modal>
</template>
<script>
import textareaAutoHeight from "../../directives/textareaAutoHeight";
export default {
directives: {
textareaAutoHeight
},
props: {
show: Boolean,
editingEnvironment: Object,
editingEnvironmentIndex: Number
},
components: {
modal: () => import("../../components/modal")
},
data() {
return {
name: undefined
};
},
watch: {
editingEnvironment: function(update) {
this.name = this.$props.editingEnvironment && this.$props.editingEnvironment.name
? this.$props.editingEnvironment.name
: undefined
this.$store.commit(
"postwoman/setEditingEnvironment",
this.$props.editingEnvironment
);
}
},
computed: {
editingEnvCopy() {
return this.$store.state.postwoman.editingEnvironment;
},
variableString() {
const result = this.editingEnvCopy.variables;
return result === "" ? "" : JSON.stringify(result);
}
},
methods: {
clearContent(e) {
this.$store.commit("postwoman/removeVariables", []);
e.target.innerHTML = this.doneButton;
this.$toast.info(this.$t("cleared"), {
icon: "clear_all"
});
setTimeout(
() => (e.target.innerHTML = '<i class="material-icons">clear_all</i>'),
1000
);
},
addEnvironmentVariable() {
let value = { key: "", value: "" };
this.$store.commit("postwoman/addVariable", value);
},
removeEnvironmentVariable(index) {
let variableIndex = index;
const oldVariables = this.editingEnvCopy.variables.slice();
const newVariables = this.editingEnvCopy.variables.filter(
(variable, index) => variableIndex !== index
);
this.$store.commit("postwoman/removeVariable", newVariables);
this.$toast.error(this.$t("deleted"), {
icon: "delete",
action: {
text: this.$t("undo"),
onClick: (e, toastObject) => {
this.$store.commit("postwoman/removeVariable", oldVariables);
toastObject.remove();
}
}
});
},
saveEnvironment() {
if (!this.$data.name) {
this.$toast.info(this.$t("invalid_environment_name"));
return;
}
const environmentUpdated = {
...this.editingEnvCopy,
name: this.$data.name
};
this.$store.commit("postwoman/saveEnvironment", {
environment: environmentUpdated,
environmentIndex: this.$props.editingEnvironmentIndex
});
this.$emit("hide-modal");
},
hideModal() {
this.$data.name = undefined;
this.$emit("hide-modal");
}
}
};
</script>

View File

@@ -0,0 +1,65 @@
<template>
<div class="flex-wrap">
<div>
<button
class="icon"
@click="$emit('select-environment')"
v-tooltip="$t('use_environment')"
>
<i class="material-icons">insert_drive_file</i>
<span>{{ environment.name }}</span>
</button>
</div>
<v-popover>
<button class="tooltip-target icon" v-tooltip="$t('more')">
<i class="material-icons">more_vert</i>
</button>
<template slot="popover">
<div>
<button
class="icon"
@click="$emit('edit-environment')"
v-close-popover
>
<i class="material-icons">create</i>
<span>{{ $t("edit") }}</span>
</button>
</div>
<div>
<button class="icon" @click="removeEnvironment" v-close-popover>
<i class="material-icons">delete</i>
<span>{{ $t("delete") }}</span>
</button>
</div>
</template>
</v-popover>
</div>
</template>
<style scoped lang="scss">
ul {
display: flex;
flex-direction: column;
}
ul li {
display: flex;
padding-left: 16px;
border-left: 1px solid var(--brd-color);
}
</style>
<script>
export default {
props: {
environment: Object,
environmentIndex: Number
},
methods: {
removeEnvironment() {
if (!confirm("Are you sure you want to remove this environment?")) return;
this.$store.commit("postwoman/removeEnvironment", this.environmentIndex);
}
}
};
</script>

View File

@@ -0,0 +1,173 @@
<template>
<modal v-if="show" @close="hideModal">
<div slot="header">
<ul>
<li>
<div class="flex-wrap">
<h3 class="title">Import / Export Environment</h3>
<div>
<button class="icon" @click="hideModal">
<i class="material-icons">close</i>
</button>
</div>
</div>
<div class="flex-wrap">
<span
v-tooltip="{
content: !fb.currentUser
? $t('login_first')
: $t('replace_current')
}"
>
<button
:disabled="!fb.currentUser"
class="icon"
@click="syncEnvironments"
>
<i class="material-icons">folder_shared</i>
<span>{{ $t("import_from_sync") }}</span>
</button>
</span>
<button
class="icon"
@click="openDialogChooseFileToReplaceWith"
v-tooltip="$t('replace_current')"
>
<i class="material-icons">create_new_folder</i>
<span>{{ $t("replace_json") }}</span>
<input
type="file"
@change="replaceWithJSON"
style="display: none;"
ref="inputChooseFileToReplaceWith"
accept="application/json"
/>
</button>
<button
class="icon"
@click="openDialogChooseFileToImportFrom"
v-tooltip="$t('preserve_current')"
>
<i class="material-icons">folder_special</i>
<span>{{ $t("import_json") }}</span>
<input
type="file"
@change="importFromJSON"
style="display: none;"
ref="inputChooseFileToImportFrom"
accept="application/json"
/>
</button>
</div>
</li>
</ul>
</div>
<div slot="body">
<textarea v-model="environmentJson" rows="8"></textarea>
</div>
<div slot="footer">
<div class="flex-wrap">
<span></span>
<span>
<button class="icon" @click="hideModal">
{{ $t("cancel") }}
</button>
<button
class="icon primary"
@click="exportJSON"
v-tooltip="$t('download_file')"
>
{{ $t("export") }}
</button>
</span>
</div>
</div>
</modal>
</template>
<script>
import { fb } from "../../functions/fb";
export default {
data() {
return {
fb
};
},
props: {
show: Boolean
},
components: {
modal: () => import("../../components/modal")
},
computed: {
environmentJson() {
return JSON.stringify(this.$store.state.postwoman.environments, null, 2);
}
},
methods: {
hideModal() {
this.$emit("hide-modal");
},
openDialogChooseFileToReplaceWith() {
this.$refs.inputChooseFileToReplaceWith.click();
},
openDialogChooseFileToImportFrom() {
this.$refs.inputChooseFileToImportFrom.click();
},
replaceWithJSON() {
let reader = new FileReader();
reader.onload = event => {
let content = event.target.result;
let environments = JSON.parse(content);
this.$store.commit("postwoman/replaceEnvironments", environments);
};
reader.readAsText(this.$refs.inputChooseFileToReplaceWith.files[0]);
this.fileImported();
},
importFromJSON() {
let reader = new FileReader();
reader.onload = event => {
let content = event.target.result;
let environments = JSON.parse(content);
let confirmation = this.$t("file_imported")
this.$store.commit("postwoman/importAddEnvironments", {
environments,
confirmation
});
};
reader.readAsText(this.$refs.inputChooseFileToImportFrom.files[0]);
},
exportJSON() {
let text = this.environmentJson;
text = text.replace(/\n/g, "\r\n");
let blob = new Blob([text], {
type: "text/json"
});
let anchor = document.createElement("a");
anchor.download = "postwoman-environment.json";
anchor.href = window.URL.createObjectURL(blob);
anchor.target = "_blank";
anchor.style.display = "none";
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
this.$toast.success(this.$t("download_started"), {
icon: "done"
});
},
syncEnvironments() {
this.$store.commit(
"postwoman/replaceEnvironments",
fb.currentEnvironments
);
this.fileImported();
},
fileImported() {
this.$toast.info(this.$t("file_imported"), {
icon: "folder_shared"
});
}
}
};
</script>

View File

@@ -0,0 +1,147 @@
<template>
<pw-section
class="green"
icon="history"
:label="$t('environment')"
ref="environment"
>
<addEnvironment :show="showModalAdd" @hide-modal="displayModalAdd(false)" />
<editEnvironment
:show="showModalEdit"
:editingEnvironment="editingEnvironment"
:editingEnvironmentIndex="editingEnvironmentIndex"
@hide-modal="displayModalEdit(false)"
/>
<importExportEnvironment
:show="showModalImportExport"
@hide-modal="displayModalImportExport(false)"
/>
<div class="flex-wrap">
<div>
<button class="icon" @click="displayModalAdd(true)">
<i class="material-icons">add</i>
<span>{{ $t("new") }}</span>
</button>
</div>
<div>
<button class="icon" @click="displayModalImportExport(true)">
{{ $t("import_export") }}
</button>
</div>
</div>
<p v-if="environments.length === 0" class="info">
Create new environment
</p>
<virtual-list
class="virtual-list"
:class="{ filled: environments.length }"
:size="152"
:remain="Math.min(5, environments.length)"
>
<ul>
<li
v-for="(environment, index) in environments"
:key="environment.name"
>
<environment
:environmentIndex="index"
:environment="environment"
@edit-environment="editEnvironment(environment, index)"
@select-environment="$emit('use-environment', environment)"
/>
</li>
<li v-if="environments.length === 0">
<label>Environments are empty</label>
</li>
</ul>
</virtual-list>
</pw-section>
</template>
<style scoped lang="scss">
.virtual-list {
max-height: calc(100vh - 276px);
}
ul {
display: flex;
flex-direction: column;
}
</style>
<script>
import environment from "./environment";
import { fb } from "../../functions/fb";
const updateOnLocalStorage = (propertyName, property) =>
window.localStorage.setItem(propertyName, JSON.stringify(property));
export default {
components: {
environment,
"pw-section": () => import("../section"),
addEnvironment: () => import("./addEnvironment"),
editEnvironment: () => import("./editEnvironment"),
importExportEnvironment: () => import("./importExportEnvironment"),
VirtualList: () => import("vue-virtual-scroll-list")
},
data() {
return {
showModalImportExport: false,
showModalAdd: false,
showModalEdit: false,
editingEnvironment: undefined,
editingEnvironmentIndex: undefined
};
},
computed: {
environments() {
return this.$store.state.postwoman.environments;
}
},
async mounted() {
this._keyListener = function(e) {
if (e.key === "Escape") {
e.preventDefault();
this.showModalImportExport = false;
}
};
document.addEventListener("keydown", this._keyListener.bind(this));
},
methods: {
displayModalAdd(shouldDisplay) {
this.showModalAdd = shouldDisplay;
},
displayModalEdit(shouldDisplay) {
this.showModalEdit = shouldDisplay;
if (!shouldDisplay) this.resetSelectedData();
},
displayModalImportExport(shouldDisplay) {
this.showModalImportExport = shouldDisplay;
},
editEnvironment(environment, environmentIndex) {
this.$data.editingEnvironment = environment;
this.$data.editingEnvironmentIndex = environmentIndex;
this.displayModalEdit(true);
this.syncEnvironments;
},
resetSelectedData() {
this.$data.editingEnvironment = undefined;
this.$data.editingEnvironmentIndex = undefined;
},
syncEnvironments() {
if (fb.currentUser !== null) {
if (fb.currentSettings[1].value) {
fb.writeEnvironments(
JSON.parse(JSON.stringify(this.$store.state.postwoman.environments))
);
}
}
}
},
beforeDestroy() {
document.removeEventListener("keydown", this._keyListener);
}
};
</script>

View File

@@ -26,6 +26,7 @@ export const fb = {
currentSettings: [],
currentHistory: [],
currentCollections: [],
currentEnvironments: [],
writeFeeds: async (message, label) => {
const dt = {
createdOn: new Date(),
@@ -112,6 +113,21 @@ export const fb = {
.doc("sync")
.set(cl)
.catch(e => console.error("error updating", cl, e));
},
writeEnvironments: async environment => {
const ev = {
updatedOn: new Date(),
author: fb.currentUser.uid,
author_name: fb.currentUser.displayName,
author_image: fb.currentUser.photoURL,
environment: environment
};
usersCollection
.doc(fb.currentUser.uid)
.collection("environments")
.doc("sync")
.set(ev)
.catch(e => console.error("error updating", ev, e));
}
};
@@ -186,6 +202,19 @@ firebase.auth().onAuthStateChanged(user => {
});
fb.currentCollections = collections[0].collection;
});
usersCollection
.doc(fb.currentUser.uid)
.collection("environments")
.onSnapshot(environmentsRef => {
const environments = [];
environmentsRef.forEach(doc => {
const environment = doc.data();
environment.id = doc.id;
environments.push(environment);
});
fb.currentEnvironments = environments[0].environment;
});
} else {
fb.currentUser = null;
}

View File

@@ -45,6 +45,14 @@ export default {
preview_html: "Preview HTML",
history: "History",
collections: "Collections",
environment: "Environment",
new_environment: "New Environment",
my_new_environment: "My New Environment",
edit_environment: "Edit Environment",
env_variable_list: "Variable List",
invalid_environment_name: "Please provide a valid name for the environment",
use_environment: "Use Environment",
add_one_variable: "(add at least one variable)",
import_curl: "Import cURL",
import: "Import",
generate_code: "Generate code",
@@ -248,7 +256,8 @@ export default {
enter_curl: "Enter cURL",
empty: "Empty",
extensions: "Extensions",
extensions_use_toggle: "Use the browser extension to send requests (if present)",
extensions_use_toggle:
"Use the browser extension to send requests (if present)",
extensions_info1: "Browser extension that simplifies access to Postwoman",
extensions_info2: "Get Postwoman browser extension!",
installed: "Installed",
@@ -259,6 +268,7 @@ export default {
sync: "Sync",
syncHistory: "History",
syncCollections: "Collections",
syncEnvironments: "Environments",
turn_on: "Turn on",
login_first: "Login first",
paste_a_note: "Paste a note",

View File

@@ -1075,13 +1075,18 @@
<div class="tab">
<collections />
</div>
<input id="environment-tab" type="radio" name="side" />
<label for="environment-tab">{{ $t("environment") }}</label>
<div class="tab">
<environments @use-environment="useSelectedEnvironment($event)" />
</div>
<input id="sync-tab" type="radio" name="side" />
<label for="sync-tab">{{ $t("notes") }}</label>
<div class="tab">
<pw-section class="pink" :label="$t('notes')" ref="sync">
<div v-if="fb.currentUser">
<inputform />
<ballsfeed />
<notes />
</div>
<div v-else>
<ul>
@@ -1452,7 +1457,8 @@ export default {
saveRequestAs: () => import("../components/collections/saveRequestAs"),
Editor: AceEditor,
inputform: () => import("../components/firebase/inputform"),
ballsfeed: () => import("../components/firebase/feeds")
notes: () => import("../components/firebase/feeds"),
environments: () => import("../components/environments")
},
data() {
return {
@@ -2044,6 +2050,16 @@ export default {
}
},
methods: {
useSelectedEnvironment(environment) {
let preRequestScriptString = "";
for (let variable of environment.variables) {
preRequestScriptString =
preRequestScriptString +
`pw.env.set('${variable.key}', '${variable.value}');\n`;
}
this.preRequestScript = preRequestScriptString;
this.showPreRequestScript = true;
},
checkCollections() {
const checkCollectionAvailability =
this.$store.state.postwoman.collections &&
@@ -2237,7 +2253,7 @@ export default {
};
this.$refs.historyComponent.addEntry(entry);
if (fb.currentUser !== null) {
if (fb.currentSettings[1].value) {
if (fb.currentSettings[2].value) {
fb.writeHistory(entry);
}
}
@@ -2274,7 +2290,7 @@ export default {
};
this.$refs.historyComponent.addEntry(entry);
if (fb.currentUser !== null) {
if (fb.currentSettings[1].value) {
if (fb.currentSettings[2].value) {
fb.writeHistory(entry);
}
}

View File

@@ -38,7 +38,7 @@
{{ setting.value ? $t("enabled") : $t("disabled") }}
</pw-toggle>
</p>
<p v-if="fb.currentSettings.length == 0">
<p v-if="fb.currentSettings.length !== 3">
<button class="" @click="initSettings">
<i class="material-icons">sync</i>
<span>{{ $t("turn_on") + " " + $t("sync") }}</span>
@@ -433,7 +433,8 @@ export default {
text: this.$t("yes"),
onClick: (e, toastObject) => {
fb.writeSettings("syncHistory", true);
fb.writeSettings("syncCollections", false);
fb.writeSettings("syncCollections", true);
fb.writeSettings("syncEnvironments", true);
this.$router.push({ path: "/settings" });
toastObject.remove();
}
@@ -462,7 +463,8 @@ export default {
text: this.$t("yes"),
onClick: (e, toastObject) => {
fb.writeSettings("syncHistory", true);
fb.writeSettings("syncCollections", false);
fb.writeSettings("syncCollections", true);
fb.writeSettings("syncEnvironments", true);
this.$router.push({ path: "/settings" });
toastObject.remove();
}
@@ -481,7 +483,8 @@ export default {
},
initSettings() {
fb.writeSettings("syncHistory", true);
fb.writeSettings("syncCollections", false);
fb.writeSettings("syncCollections", true);
fb.writeSettings("syncEnvironments", true);
},
resetProxy({ target }) {
this.settings.PROXY_URL = `https://postwoman.apollotv.xyz/`;

View File

@@ -74,6 +74,13 @@ export const state = () => ({
requests: []
}
],
environments: [
{
name: "My Environment Variables",
variables: []
}
],
editingEnvironment: {},
selectedRequest: {},
editingRequest: {}
});
@@ -102,6 +109,80 @@ 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 = testValue(value);
},
removeVariable({ editingEnvironment }, variables) {
editingEnvironment.variables = variables;
},
addVariable({ editingEnvironment }, value) {
editingEnvironment.variables.push(value);
},
replaceEnvironments(state, environments) {
state.environments = 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];
let index = 0;
for (let environment of state.environments) {
environment.environmentIndex = index;
index += 1;
}
this.$toast.info(confirmation, {
icon: "folder_shared"
});
},
removeEnvironment({ environments }, environmentIndex) {
environments.splice(environmentIndex, 1);
},
saveEnvironment({ environments }, payload) {
const { environment, environmentIndex } = payload;
const { name } = environment;
const duplicateEnvironment = environments.length === 1
? false
: environments.some(
item =>
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;
},
@@ -139,7 +220,10 @@ export const mutations = {
},
editCollection({ collections }, payload) {
const { collection: { name }, collectionIndex } = payload;
const {
collection: { name },
collectionIndex
} = payload;
const duplicateCollection = collections.some(
item => item.name.toLowerCase() === name.toLowerCase()
);
@@ -326,3 +410,12 @@ export const mutations = {
state.selectedRequest = Object.assign({}, request);
}
};
function testValue(myValue) {
try {
return JSON.parse(myValue);
} catch(ex) {
// Now we know it's a string just leave it as a string value.
return myValue;
}
}