api-client/components/environments/Edit.vue

169 lines
4.3 KiB
Vue
Raw Normal View History

2020-02-23 16:38:15 +00:00
<template>
<SmartModal v-if="show" @close="hideModal">
<template #header>
<h3 class="heading">{{ $t("edit_environment") }}</h3>
<div>
<button class="icon button" @click="hideModal">
<i class="material-icons">close</i>
</button>
2020-12-11 10:29:03 +00:00
</div>
</template>
<template #body>
2020-12-11 10:29:03 +00:00
<label for="selectLabel">{{ $t("label") }}</label>
<input
id="selectLabel"
v-model="name"
class="input"
2021-05-18 06:26:59 +00:00
type="text"
2020-12-11 10:29:03 +00:00
:placeholder="editingEnvironment.name"
@keyup.enter="saveEnvironment"
/>
<div class="row-wrapper">
<label for="variableList">{{ $t("env_variable_list") }}</label>
<div>
2021-05-18 06:26:59 +00:00
<button
v-tooltip.bottom="$t('clear')"
class="icon button"
2021-05-18 06:26:59 +00:00
@click="clearContent($event)"
>
2021-06-29 11:34:02 +00:00
<i class="material-icons">{{ clearIcon }}</i>
2020-12-11 10:29:03 +00:00
</button>
</div>
</div>
2020-12-12 03:03:29 +00:00
<ul
v-for="(variable, index) in vars"
2020-12-12 03:03:29 +00:00
:key="index"
2021-05-15 12:43:31 +00:00
class="
border-b border-dashed
divide-y
md:divide-x
2021-06-12 16:46:17 +00:00
border-divider
divide-dashed divide-divider
2021-05-15 12:43:31 +00:00
md:divide-y-0
"
2020-12-12 03:03:29 +00:00
:class="{ 'border-t': index == 0 }"
>
2020-02-23 16:38:15 +00:00
<li>
<input
v-model="variable.key"
class="input"
2021-01-23 14:13:11 +00:00
:placeholder="$t('variable_count', { count: index + 1 })"
2020-02-23 16:38:15 +00:00
:name="'param' + index"
/>
</li>
<li>
<input
v-model="variable.value"
class="input"
2020-02-23 16:38:15 +00:00
:placeholder="$t('value_count', { count: index + 1 })"
:name="'value' + index"
/>
</li>
<div>
<li>
<button
2021-05-18 06:26:59 +00:00
id="variable"
v-tooltip.bottom="$t('delete')"
class="icon button"
2020-02-23 16:38:15 +00:00
@click="removeEnvironmentVariable(index)"
>
2020-12-07 15:07:13 +00:00
<i class="material-icons">delete</i>
2020-02-23 16:38:15 +00:00
</button>
</li>
</div>
</ul>
<ul>
<li>
<button class="icon button" @click="addEnvironmentVariable">
2020-02-23 16:38:15 +00:00
<i class="material-icons">add</i>
<span>{{ $t("add_new") }}</span>
2020-02-23 16:38:15 +00:00
</button>
</li>
</ul>
</template>
<template #footer>
<span></span>
<span>
<button class="icon button" @click="hideModal">
{{ $t("cancel") }}
</button>
<button class="icon button primary" @click="saveEnvironment">
{{ $t("save") }}
</button>
</span>
</template>
</SmartModal>
2020-02-23 16:38:15 +00:00
</template>
<script lang="ts">
import Vue, { PropType } from "vue"
import clone from "lodash/clone"
import type { Environment } from "~/newstore/environments"
import { updateEnvironment } from "~/newstore/environments"
2020-02-23 16:38:15 +00:00
export default Vue.extend({
2020-02-23 16:38:15 +00:00
props: {
show: Boolean,
editingEnvironment: {
type: Object as PropType<Environment | null>,
default: null,
},
2021-05-18 06:26:59 +00:00
editingEnvironmentIndex: { type: Number, default: null },
2020-02-23 16:38:15 +00:00
},
data() {
return {
name: null as string | null,
vars: [] as { key: string; value: string }[],
2021-06-29 11:34:02 +00:00
clearIcon: "clear_all",
2020-02-24 18:44:50 +00:00
}
2020-02-23 16:38:15 +00:00
},
2021-05-18 06:26:59 +00:00
watch: {
editingEnvironment() {
this.name = this.editingEnvironment?.name ?? null
this.vars = clone(this.editingEnvironment?.variables ?? [])
},
show() {
this.name = this.editingEnvironment?.name ?? null
this.vars = clone(this.editingEnvironment?.variables ?? [])
2021-05-18 06:26:59 +00:00
},
},
2020-02-23 16:38:15 +00:00
methods: {
2021-06-29 11:34:02 +00:00
clearContent() {
this.vars = []
2021-06-29 11:34:02 +00:00
this.clearIcon = "done"
this.$toast.info(this.$t("cleared").toString(), {
icon: "clear_all",
2020-02-24 18:44:50 +00:00
})
2021-06-29 11:34:02 +00:00
setTimeout(() => (this.clearIcon = "clear_all"), 1000)
2020-02-23 16:38:15 +00:00
},
addEnvironmentVariable() {
this.vars.push({
key: "",
value: "",
2020-02-24 18:44:50 +00:00
})
},
removeEnvironmentVariable(index: number) {
this.vars.splice(index, 1)
2020-02-23 16:38:15 +00:00
},
saveEnvironment() {
if (!this.name) {
this.$toast.info(this.$t("invalid_environment_name").toString())
2020-02-24 18:44:50 +00:00
return
2020-02-23 16:38:15 +00:00
}
const environmentUpdated: Environment = {
name: this.name,
variables: this.vars,
2020-02-24 18:44:50 +00:00
}
updateEnvironment(this.editingEnvironmentIndex, environmentUpdated)
this.hideModal()
2020-02-23 16:38:15 +00:00
},
hideModal() {
this.name = null
this.$emit("hide-modal")
2020-02-24 18:44:50 +00:00
},
},
})
2020-02-23 16:38:15 +00:00
</script>