Im not very familiar with Dashboard 2 developments regarding this.
But from what i understand in Colin's post is to create a watch
on the msg
so when the ui-template component loads and its value "restored", to execute any reassignment of Vue data values.
...
mounted() {
// listen for msg events
// this.$socket.on('msg-input:' + this.id, (msg) => {
// this.value = msg.value
// this.svgStyle = msg.style
// })
},
watch: {
msg: function() {
// log what is stored in msg after reload
console.log("Msg stored", this.msg)
this.value = this.msg.value
this.svgStyle = this.msg.style
}
}
...
Now that i think of it .. this way (with watch
) you dont even need the this.$socket.on
listener because simply watching the msg
for changes should trigger on receiving a new msg also.
Test Flow :
[{"id":"b7af0e79e864239a","type":"ui-template","z":"54efb553244c241f","group":"fb2e77ec2c2a5dd1","page":"","ui":"","name":"","order":0,"width":"0","height":"0","head":"","format":"<template>\n <svg :class=\"[ svgStyle ]\" xmlns=\"http://www.w3.org/2000/svg\" height=\"32\" viewBox=\"0 -960 960 960\" width=\"32\">\n <path :d=\"msg.path\" />\n </svg>\n <v-slider thumb-label=\"always\" v-model=\"value\" max=\"100\" min=\"0\" step=\"1\" @end=\"end(value)\">\n <template v-slot:thumb-label=\"{ modelValue }\">\n {{modelValue}}%\n </template>\n </v-slider>\n</template>\n<style scoped>\n .WhiteFill {\n fill: white;\n background-color: black;\n }\n\n .YellowFill {\n fill: #FEA500;\n }\n</style>\n<script>\n export default {\n data () {\n return {\n value: 0,\n svgStyle: \"\"\n }\n },\n methods: {\n // expose a method to our <template> and Vue Application\n end: function (value) {\n this.send({payload: value})\n }\n },\n mounted() {\n // listen for msg events\n // this.$socket.on('msg-input:' + this.id, (msg) => {\n \n // this.value = msg.value\n // this.svgStyle = msg.style\n \n // })\n\n },\n watch: { \n msg: function() {\n // log what is stored in msg after reload\n console.log(\"Msg stored\", this.msg)\n this.value = this.msg.value\n this.svgStyle = this.msg.style\n }\n }\n }\n</script>","storeOutMessages":true,"passthru":false,"resendOnRefresh":true,"templateScope":"local","className":"","x":570,"y":2820,"wires":[["69e07ba9cdb95f42"]]},{"id":"202d0b41f2f8b4b5","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":210,"y":2880,"wires":[["b467592ba9d3e2b5"]]},{"id":"b467592ba9d3e2b5","type":"function","z":"54efb553244c241f","name":"42 YellowFill","func":"msg = {\n \"path\": \"M480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-80q-100 0-170-70t-70-170q0-100 70-170t170-70q100 0 170 70t70 170q0 100-70 170t-170 70Zm0-80q66 0 113-47t47-113q0-66-47-113t-113-47q-66 0-113 47t-47 113q0 66 47 113t113 47Zm0-80q-33 0-56.5-23.5T400-480q0-33 23.5-56.5T480-560q33 0 56.5 23.5T560-480q0 33-23.5 56.5T480-400Z\",\n \"style\": \"YellowFill\",\n \"value\": 42\n}\n\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":2880,"wires":[["b7af0e79e864239a"]]},{"id":"69e07ba9cdb95f42","type":"debug","z":"54efb553244c241f","name":"debug 75","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":2820,"wires":[]},{"id":"940768c83c1f77d8","type":"inject","z":"54efb553244c241f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":210,"y":2760,"wires":[["588a6ee4a6c87b43"]]},{"id":"588a6ee4a6c87b43","type":"function","z":"54efb553244c241f","name":"10 WhiteFill","func":"msg = {\n \"path\": \"M480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-80q-100 0-170-70t-70-170q0-100 70-170t170-70q100 0 170 70t70 170q0 100-70 170t-170 70Zm0-80q66 0 113-47t47-113q0-66-47-113t-113-47q-66 0-113 47t-47 113q0 66 47 113t113 47Zm0-80q-33 0-56.5-23.5T400-480q0-33 23.5-56.5T480-560q33 0 56.5 23.5T560-480q0 33-23.5 56.5T480-400Z\",\n \"style\": \"WhiteFill\",\n \"value\": 10\n}\n\nreturn msg","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":2760,"wires":[["b7af0e79e864239a"]]},{"id":"fb2e77ec2c2a5dd1","type":"ui-group","name":"SVG","page":"c466b7e4bb472f99","width":"25","height":"1","order":-1,"showTitle":false,"className":"","visible":"true","disabled":"false"},{"id":"c466b7e4bb472f99","type":"ui-page","name":"SVG","ui":"957559fb8731ef90","path":"/tables","icon":"table","layout":"grid","theme":"0d92c765bfad87e6","order":-1,"className":"","visible":"true","disabled":"false"},{"id":"957559fb8731ef90","type":"ui-base","name":"My Dashboard","path":"/dashboard","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false,"navigationStyle":"default"},{"id":"0d92c765bfad87e6","type":"ui-theme","name":"Basic Blue Theme","colors":{"surface":"#0080c0","primary":"#0094ce","bgPage":"#eeeeee","groupBg":"#ffffff","groupOutline":"#cccccc"},"sizes":{"pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]