Node-Red configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UILed.vue 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <div class="nrdb-ui-led" :style="`--ui-led-shadow-width: ${size * 0.1}px; --ui-led-border-width: ${size * 0.15}px; --ui-led-color: ${color}; flex-direction: ${flexDirection}`">
  3. <label v-if="props.label" class="nrdb-ui-led-label v-label" :style="`justify-content: ${labelAlignment}`">{{ props.label }}</label>
  4. <span ref="led" class="nrdb-ui-led-bulb" :class="`${hasValue ? 'nrdb-ui-led-bulb-on' : ''} nrdb-ui-led-bulb--${props.shape} ${props.showGlow && hasValue ? 'nrdb-ui-led-bulb--glow' : ''} ${props.showBorder ? 'nrdb-ui-led-bulb--border' : ''}`">{{ value !== null ? value : 'No Message Received' }}</span>
  5. </div>
  6. </template>
  7. <script>
  8. import { mapState } from 'vuex'
  9. export default {
  10. name: 'UILed',
  11. inject: ['$socket'],
  12. props: {
  13. id: { type: String, required: true },
  14. props: { type: Object, default: () => ({}) },
  15. state: { type: Object, default: () => ({ enabled: false, visible: false }) }
  16. },
  17. data () {
  18. return {
  19. size: 24
  20. }
  21. },
  22. computed: {
  23. ...mapState('data', ['messages']),
  24. hasValue: function () {
  25. return this.messages[this.id] !== undefined
  26. },
  27. flexDirection: function () {
  28. return this.props.labelPlacement === 'left' ? 'row' : 'row-reverse'
  29. },
  30. labelAlignment: function () {
  31. return this.props.labelAlignment
  32. },
  33. color: function () {
  34. if (this.hasValue && this.props.evaluated) {
  35. const msg = this.messages[this.id]
  36. // check which, if any, color we should be displaying
  37. for (const i in this.props.evaluated) {
  38. const state = this.props.evaluated[i]
  39. if (typeof (state.value) === 'object') {
  40. if (JSON.stringify(state.value) === JSON.stringify(msg.payload)) {
  41. return state.color
  42. }
  43. } else if (state.value === msg.payload) {
  44. return state.color
  45. }
  46. }
  47. }
  48. return 'gray'
  49. }
  50. },
  51. mounted () {
  52. this.$socket.on('widget-load:' + this.id, (msg) => {
  53. // load the latest message from the Node-RED datastore when this widget is loaded
  54. // storing it in our vuex store so that we have it saved as we navigate around
  55. this.$store.commit('data/bind', {
  56. widgetId: this.id,
  57. msg
  58. })
  59. })
  60. this.$socket.on('msg-input:' + this.id, (msg) => {
  61. // store the latest message in our client-side vuex store when we receive a new message
  62. this.$store.commit('data/bind', {
  63. widgetId: this.id,
  64. msg
  65. })
  66. })
  67. // tell Node-RED that we're loading a new instance of this widget
  68. this.$socket.emit('widget-load', this.id)
  69. this.$nextTick(() => {
  70. this.size = this.$refs.led.clientWidth
  71. })
  72. },
  73. unmounted () {
  74. /* Make sure, any events you subscribe to on SocketIO are unsubscribed to here */
  75. this.$socket?.off('widget-load' + this.id)
  76. this.$socket?.off('msg-input:' + this.id)
  77. }
  78. }
  79. </script>
  80. <style scoped>
  81. .nrdb-ui-led {
  82. --ui-led-border-width: 12px;
  83. --ui-led-shadow-width: 12px;
  84. display: flex;
  85. align-items: center;
  86. justify-content: space-between;
  87. gap: 16px;
  88. }
  89. .nrdb-ui-led-label {
  90. flex-grow: 1;
  91. }
  92. .nrdb-ui-led-bulb {
  93. display: block;
  94. height: 65%;
  95. aspect-ratio: 1 / 1;
  96. background-color: var(--ui-led-color);
  97. box-shadow: inset #4413138a 0 -1px var(--ui-led-shadow-width) var(--ui-led-shadow-width);
  98. }
  99. .nrdb-ui-led-bulb-on {
  100. background: radial-gradient(#ffffff96, #ffffff00 70%), var(--ui-led-color);
  101. }
  102. .nrdb-ui-led-bulb--square {
  103. border-radius: 25%;
  104. }
  105. .nrdb-ui-led-bulb--circle {
  106. border-radius: 50%;
  107. }
  108. .nrdb-ui-led-bulb--border {
  109. border-width: var(--ui-led-border-width);
  110. border-color: #222;
  111. border-style: solid;
  112. }
  113. .nrdb-ui-led-bulb--glow {
  114. box-shadow: 0 0 calc(1.25 * var(--ui-led-border-width)) var(--ui-led-color), inset #44131340 0 -1px var(--ui-led-shadow-width) var(--ui-led-shadow-width);
  115. }
  116. </style>