feat: active toggle for web socket protocols

This commit is contained in:
liyasthomas
2021-06-18 10:45:48 +05:30
parent 3559d98df1
commit 6a6754c7da

View File

@@ -41,8 +41,8 @@
</li> </li>
</ul> </ul>
<ul <ul
v-for="(input, index) of protocols" v-for="(protocol, index) of protocols"
:key="`input-${index}`" :key="`protocol-${index}`"
:class="{ 'border-t': index == 0 }" :class="{ 'border-t': index == 0 }"
class=" class="
border-b border-dashed border-b border-dashed
@@ -55,12 +55,41 @@
> >
<li> <li>
<input <input
v-model="protocols[index]" v-model="protocol.value"
:placeholder="$t('protocol_count', { count: index + 1 })" :placeholder="$t('protocol_count', { count: index + 1 })"
name="message" name="message"
type="text" type="text"
/> />
</li> </li>
<div>
<li>
<button
v-tooltip.bottom="{
content: protocol.hasOwnProperty('active')
? protocol.active
? $t('turn_off')
: $t('turn_on')
: $t('turn_off'),
}"
class="icon"
@click="
protocol.active = protocol.hasOwnProperty('active')
? !protocol.active
: false
"
>
<i class="material-icons">
{{
protocol.hasOwnProperty("active")
? protocol.active
? "check_box"
: "check_box_outline_blank"
: "check_box"
}}
</i>
</button>
</li>
</div>
<div> <div>
<li> <li>
<button <button
@@ -142,6 +171,7 @@ export default {
}, },
currentIndex: -1, // index of the message log array to put in input box currentIndex: -1, // index of the message log array to put in input box
protocols: [], protocols: [],
activeProtocols: [],
} }
}, },
computed: { computed: {
@@ -153,6 +183,18 @@ export default {
url() { url() {
this.debouncer() this.debouncer()
}, },
protocols: {
handler(newVal) {
this.activeProtocols = newVal
.filter((item) =>
Object.prototype.hasOwnProperty.call(item, "active")
? item.active === true
: true
)
.map(({ value }) => value)
},
deep: true,
},
}, },
mounted() { mounted() {
if (process.browser) { if (process.browser) {
@@ -185,7 +227,7 @@ export default {
}, },
] ]
try { try {
this.socket = new WebSocket(this.url, this.protocols) this.socket = new WebSocket(this.url, this.activeProtocols)
this.socket.onopen = () => { this.socket.onopen = () => {
this.connectionState = true this.connectionState = true
this.communication.log = [ this.communication.log = [
@@ -298,10 +340,22 @@ export default {
} }
}, },
addProtocol() { addProtocol() {
this.protocols.push("") this.protocols.push({ value: "", active: true })
}, },
deleteProtocol({ index }) { deleteProtocol({ index }) {
const oldProtocols = this.protocols.slice()
this.$delete(this.protocols, index) this.$delete(this.protocols, index)
this.$toast.error(this.$t("deleted"), {
icon: "delete",
action: {
text: this.$t("undo"),
duration: 4000,
onClick: (_, toastObject) => {
this.protocols = oldProtocols
toastObject.remove()
},
},
})
}, },
}, },
} }