api-client/components/http/Parameters.vue

180 lines
3.9 KiB
Vue
Raw Normal View History

<template>
<AppSection label="parameters">
2021-07-13 07:18:57 +00:00
<div
class="
sticky
top-110px
z-10
bg-primary
flex flex-1
items-center
justify-between
pl-4
border-b border-dividerLight
2021-07-13 07:18:57 +00:00
"
>
2021-07-10 13:15:39 +00:00
<label for="paramList" class="font-semibold text-xs">
{{ $t("parameter_list") }}
</label>
2021-07-12 03:41:55 +00:00
<div>
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
:title="$t('clear_all')"
icon="clear_all"
@click.native="clearContent"
/>
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
:title="$t('add_new')"
icon="add"
@click.native="addParam"
/>
</div>
2021-07-10 13:15:39 +00:00
</div>
<div
2021-07-12 03:41:55 +00:00
v-for="(param, index) in params$"
2021-07-13 23:49:08 +00:00
:key="`param-${index}`"
2021-05-15 12:43:31 +00:00
class="
2021-07-10 13:15:39 +00:00
flex
2021-05-15 12:43:31 +00:00
border-b border-dashed
2021-07-10 18:08:35 +00:00
divide-x
2021-06-12 16:46:17 +00:00
border-divider
divide-dashed divide-divider
2021-05-15 12:43:31 +00:00
"
2020-12-12 03:03:29 +00:00
:class="{ 'border-t': index == 0 }"
>
2021-07-10 13:15:39 +00:00
<input
class="
px-4
py-3
text-xs
flex flex-1
font-semibold
bg-primaryLight
focus:outline-none
"
:placeholder="$t('parameter_count', { count: index + 1 })"
:name="'param' + index"
:value="param.key"
autofocus
@change="
2021-07-12 03:41:55 +00:00
updateParam(index, {
key: $event.target.value,
value: param.value,
active: param.active,
2021-07-10 13:15:39 +00:00
})
"
/>
<input
class="
px-4
py-3
text-xs
flex flex-1
font-semibold
bg-primaryLight
focus:outline-none
"
:placeholder="$t('value_count', { count: index + 1 })"
:name="'value' + index"
:value="param.value"
@change="
2021-07-12 03:41:55 +00:00
updateParam(index, {
key: param.key,
2021-07-10 13:15:39 +00:00
value: $event.target.value,
2021-07-12 03:41:55 +00:00
active: param.active,
2021-07-10 13:15:39 +00:00
})
"
/>
<div>
2021-07-10 13:15:39 +00:00
<ButtonSecondary
v-tippy="{ theme: 'tooltip' }"
:title="
param.hasOwnProperty('active')
? param.active
? $t('turn_off')
: $t('turn_on')
: $t('turn_off')
"
:icon="
param.hasOwnProperty('active')
? param.active
? 'check_box'
: 'check_box_outline_blank'
: 'check_box'
"
@click.native="
2021-07-12 03:41:55 +00:00
updateParam(index, {
key: param.key,
value: param.value,
active: param.hasOwnProperty('active') ? !param.active : false,
2021-07-10 13:15:39 +00:00
})
"
/>
</div>
2021-07-10 13:15:39 +00:00
<div>
2021-07-05 12:56:00 +00:00
<ButtonSecondary
2021-07-10 13:15:39 +00:00
v-tippy="{ theme: 'tooltip' }"
:title="$t('delete')"
icon="delete"
2021-07-12 03:41:55 +00:00
@click.native="deleteParam(index)"
2021-07-05 12:56:00 +00:00
/>
2021-07-10 13:15:39 +00:00
</div>
</div>
</AppSection>
</template>
<script>
2021-07-12 03:41:55 +00:00
import {
restParams$,
addRESTParam,
updateRESTParam,
deleteRESTParam,
deleteAllRESTParams,
} from "~/newstore/RESTSession"
export default {
2021-07-12 03:41:55 +00:00
data() {
return {
params$: [],
}
},
2021-07-12 03:41:55 +00:00
subscriptions() {
return {
params$: restParams$,
}
2021-07-10 18:08:35 +00:00
},
2021-07-12 03:41:55 +00:00
// watch: {
// params$: {
// handler(newValue) {
// if (
// newValue[newValue.length - 1]?.key !== "" ||
// newValue[newValue.length - 1]?.value !== ""
// )
// this.addParam()
// },
// deep: true,
// },
// },
2021-07-10 18:08:35 +00:00
mounted() {
2021-07-12 03:41:55 +00:00
if (!this.params$?.length) {
this.addParam()
2021-07-10 18:08:35 +00:00
}
},
methods: {
2021-07-12 03:41:55 +00:00
addParam() {
addRESTParam({ key: "", value: "", active: true })
},
updateParam(index, item) {
updateRESTParam(index, item)
},
2021-07-12 03:41:55 +00:00
deleteParam(index) {
deleteRESTParam(index)
},
2021-07-12 03:41:55 +00:00
clearContent() {
deleteAllRESTParams()
},
},
}
</script>