api-client/components/environments/Edit.vue

190 lines
5.3 KiB
Vue
Raw Normal View History

2020-02-23 16:38:15 +00:00
<template>
<SmartModal v-if="show" :title="$t('edit_environment')" @close="hideModal">
<template #body>
2021-07-17 17:40:28 +00:00
<div class="flex flex-col px-2">
2021-08-08 06:31:36 +00:00
<div class="flex relative">
<input
id="selectLabelEnvEdit"
v-model="name"
v-focus
2021-08-08 06:31:36 +00:00
class="input floating-input"
placeholder=" "
type="text"
@keyup.enter="saveEnvironment"
/>
<label for="selectLabelEnvEdit">
{{ $t("label") }}
</label>
</div>
2021-07-17 17:40:28 +00:00
<div class="flex flex-1 justify-between items-center">
<label for="variableList" class="font-semibold p-4">
2021-07-09 17:19:45 +00:00
{{ $t("env_variable_list") }}
</label>
2021-08-07 03:37:26 +00:00
<div class="flex">
2021-07-09 17:19:45 +00:00
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
:title="$t('clear')"
:icon="clearIcon"
2021-08-08 06:31:36 +00:00
@click.native="clearContent()"
2021-07-09 17:19:45 +00:00
/>
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
icon="add"
2021-08-02 15:27:18 +00:00
:title="$t('add.new')"
@click.native="addEnvironmentVariable"
/>
2021-07-09 17:19:45 +00:00
</div>
2020-12-11 10:29:03 +00:00
</div>
<div class="divide-y divide-dividerLight border-divider border rounded">
<div
v-for="(variable, index) in vars"
2021-07-13 23:49:08 +00:00
:key="`variable-${index}`"
class="divide-x divide-dividerLight flex"
>
2021-07-09 17:19:45 +00:00
<input
v-model="variable.key"
class="
bg-primaryLight
2021-07-17 17:40:28 +00:00
flex
2021-07-23 19:12:31 +00:00
font-semibold font-mono
2021-07-17 17:40:28 +00:00
flex-1
py-2
2021-07-17 17:40:28 +00:00
px-4
truncate
focus:outline-none
"
2021-08-02 15:27:18 +00:00
:placeholder="$t('count.variable', { count: index + 1 })"
2021-07-09 17:19:45 +00:00
:name="'param' + index"
/>
<input
v-model="variable.value"
class="
bg-primaryLight
2021-07-17 17:40:28 +00:00
flex
2021-07-23 19:12:31 +00:00
font-semibold font-mono
2021-07-17 17:40:28 +00:00
flex-1
2021-07-23 19:12:31 +00:00
py-2
2021-07-17 17:40:28 +00:00
px-4
truncate
focus:outline-none
"
2021-08-02 15:27:18 +00:00
:placeholder="$t('count.value', { count: index + 1 })"
2021-07-09 17:19:45 +00:00
:name="'value' + index"
/>
2021-08-07 03:37:26 +00:00
<div class="flex">
2021-07-09 17:19:45 +00:00
<ButtonSecondary
id="variable"
v-tippy="{ theme: 'tooltip' }"
:title="$t('delete')"
icon="delete"
color="red"
2021-07-09 17:19:45 +00:00
@click.native="removeEnvironmentVariable(index)"
/>
</div>
2021-07-09 17:19:45 +00:00
</div>
<div
v-if="vars.length === 0"
class="
flex flex-col
text-secondaryLight
p-4
items-center
justify-center
"
>
<i class="opacity-75 pb-2 material-icons">layers</i>
<span class="text-center pb-4">
2021-08-02 15:27:18 +00:00
{{ $t("empty.environments") }}
</span>
<ButtonSecondary
2021-08-02 15:27:18 +00:00
:label="$t('add.new')"
outline
@click.native="addEnvironmentVariable"
/>
</div>
</div>
2021-07-09 17:19:45 +00:00
</div>
</template>
<template #footer>
<span>
2021-07-03 13:14:58 +00:00
<ButtonPrimary :label="$t('save')" @click.native="saveEnvironment" />
2021-07-09 17:19:45 +00:00
<ButtonSecondary :label="$t('cancel')" @click.native="hideModal" />
</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(), {
icon: "info",
})
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>