Angular in Dashboard - repeating buttons

I have this template node, where the table rows repeat with the number of parameters in msg.Notify.

I'd also like to include a button for each row, that simply sends a message out that can be used to update the object in context, or whatever.

I've studied @TotallyInformation's excellent primer but can't quite work out how to do it.

<h1>Notification List</h1>
<tr style="font-weight:800;"><td>ID</td><td>Start</td><td>Title</td><td>Text</td></tr>
<tr ng-repeat="(key, value) in msg.Notify">

Are you able to share some data? With the example you've given, msg.notify would need to be an object:

msg.notify = { 
    key1: { Starttime: ....., Title: ......, Message: ..... },
    key2: { ..... }

Hi, yes it is.

I have loaded it from global context into the message object, and here's what the message object looks like (debug from the output):

{"_msgid":"cee7f04b.6a931","topic":"","payload":1569872000671,"Notify":{"RearPumpFail":{"Title":"REAR SUMP ALARM","Message":"The rear sump says it's flooding","Priority":5,"Recipient":[],"Validity":"Start","ID":"RearPumpFail","Acknowledged":false}}}

The display of existing data in rows works, but I'd just like to work out how to post data out using a button for each row

Ah, I must be tired as I completely skipped over the button part! :tired_face:

Something like:

<button ng-click="node.send({payload:'plink', topic: key})">

within the tr tags?

I rarely use Anglular these days.

Ahh, I didn't realise you could insert node.send like that.

I've tried it though, and unticked the option in template node to "pass messages through" (so I don't get stuff that is sent to the input of the template) but nothing comes out when I click it. Any ideas? Thanks

I didn't remember the syntax correctly. Actually the answer is in my article:

<md-button ng-click="send({payload: 'Hello World'})">
    Click me to send a hello world

That works, thanks so much. Also thank you for that article you wrote. Over the last 3 months I have returned to view a number of times (although clearly most of it hasn't sunk in to my brain yet!)

Really looking forward to getting in to uibuilder, once I can get my head around it :slight_smile:

Any idea how I would go about getting the output to relate to the row in question?

e.g. something like

<td><md-button ng-click="send({payload: '{{key}}=hello'})">Ack</md-button></td></tr>

(my addition of {{key}} results in getting this output:
payload: "{{key}}=hello"

as opposed to
payload: "RearSumpFail=hello" (or whatever the key in question was)

EDIT: just worked that out. I inserted key without the moustache syntax like so:

<td><md-button ng-click="send({payload: key+'=hello'})">Ack</md-button></td></tr>

No problem, glad it has helped. I often write those because I know that I won't remember next time I need to do something.

Just install it, add a node to a flow with an inject and a debug - the "vue" example even does that for you, use the examples section of the import menu. Then open the resulting page. Then work step-by-step through the front-end javascript - it is nowhere near as complex as it looks.

Or try this nice little example:

[{"id":"ece9345a.f21808","type":"debug","z":"18cb249f.38bafb","name":"simple-debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":640,"y":1720,"wires":[]},{"id":"bad4b165.e6a08","type":"uibuilder","z":"18cb249f.38bafb","name":"Simple Example","topic":"","url":"uib_simple","fwdInMessages":false,"allowScripts":false,"allowStyles":false,"copyIndex":true,"showfolder":false,"x":450,"y":1740,"wires":[["ece9345a.f21808"],["bf35e77f.4a7978","6eb39afc.539d54"]]},{"id":"ba6581d8.f5fa2","type":"inject","z":"18cb249f.38bafb","name":"Manual Start","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"*/30 9-22 * * *","once":true,"onceDelay":"","x":155,"y":1740,"wires":[["eb406f24.13a48"]],"l":false},{"id":"bf35e77f.4a7978","type":"debug","z":"18cb249f.38bafb","name":"uib controls","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":690,"y":1760,"wires":[]},{"id":"5b8a68be.588ec8","type":"comment","z":"18cb249f.38bafb","name":"uibuilder/Simple Example","info":"[Front-End](/uib_simple)\n\nThis flow gets a \"quote of the day\" from the Internet and passes it\nto uibuilder. It caches the result so that if you reload the page,\nyou get the last result back. The quote is updated every 30 minutes\nduring the day and evening.\n\n\"Simple\" refers to the front-end code. While the flow looks a little\ncomplex, it really isn't. A trigger (repeating), an Internet request,\na cache and uibuilder. The link nodes loop the control output from\nuibuilder back to the cache.\n\n## Configuration\n\nUpdate the files:\n\n* `index.html`\n* `index.js`\n* `index.css`\n\nAccording to the example(s) in the 3 other comment nodes in this example.\n\nPress the button on the trigger to start the flow.","x":230,"y":1680,"wires":[]},{"id":"4a7cc95e.3becd8","type":"comment","z":"18cb249f.38bafb","name":"index.html","info":"<!doctype html>\n<html lang=\"en\"><head>\n    <meta charset=\"utf-8\">\n    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n    <meta name=\"viewport\" content=\"width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes\">\n\n    <title>uibuilder simple example</title>\n    <meta name=\"description\" content=\"Node-RED uibuilder - Simple example using VueJS\">\n\n    <link rel=\"icon\" href=\"./images/node-blue.ico\">\n\n    <!-- Put your own custom styles in here -->\n    <link rel=\"stylesheet\" href=\"./index.css\" media=\"all\">\n\n</head><body>\n    <!-- The \"app\" element is where the code for dynamic updates is attached -->\n\t<div id=\"app\">\n\t    <h1>A simple uibuilder page</h1>\n\t    <p>\n\t        The elements below are dynamically updated when you send\n\t        a msg to your uibuilder node.\n\t    </p>\n\t    \n\t    <div v-if=\"msg.payload\">\n\t        <h2>Quote of the Day</h2>\n\t        <blockquote>\n\t            <i>{{ msg.payload.quote.body }}</i>\n    \t        <div>{{ }}</div>\n\t        </blockquote>\n\t    </div>\n\t    \n\t    <h2>The full msg object</h2>\n\t\t<code>{{ msg }}</code>\n\t\t\n\t</div>\n\n    <!-- Vendor Libraries - Load in the right order -->\n    <script src=\"../uibuilder/vendor/\"></script>\n    <script src=\"../uibuilder/vendor/vue/dist/vue.min.js\"></script>\n\n    <!-- REQUIRED: Sets up Socket listeners, the uibuilder and msg objects -->\n    <script src=\"./uibuilderfe.min.js\"></script>\n\n    <!-- Put your own custom code in here -->\n    <script src=\"./index.js\"></script>\n\n</body></html>","x":420,"y":1680,"wires":[],"icon":"node-red/parser-html.svg"},{"id":"1a004a18.d3c5e6","type":"comment","z":"18cb249f.38bafb","name":"index.js","info":"/* jshint browser: true, esversion: 5, asi: true */\n/*globals uibuilder, Vue */\n// @ts-nocheck\n/*\n  Copyright (c) 2019 Julian Knight (Totally Information)\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\n'use strict'\n\n/** @see */\n\nvar app1 = new Vue({\n    // The HTML element to attach to\n\tel: '#app',\n\t/** Pre-defined data\n\t *  Anything defined here can be used in the HTML\n\t *  if you update it, the HTML will automatically update\n\t */\n\tdata: {\n\t\tmsg: '[Nothing Recieved Yet]',\n\t},\n\n    // This is called when Vue is fully loaded\n\tmounted: function() {\n\t    // Start up uibuilder\n\t\tuibuilder.start()\n\t\t\n\t\t// Keep a convenient reference to the Vue app\n\t\tvar vueApp = this\n\n        /** Triggered when the node on the Node-RED server\n         *  recieves a (non-control) msg\n         */\n\t\tuibuilder.onChange('msg', function(msg) {\n\t\t\tvueApp.msg = msg\n\t\t})\n\n\t\t// Send message back to node-red\n\t\t// uibuilder.send({payload:'some message'})\n\n\t\t// Triggered on reciept of a control message from node-red\n\t\t//uibuilder.onChange('ctrlMsg', function(msg) {\n\t\t//    console.log(msg)\n\t\t//})\n\t},\n\t\n}) // --- End of the Vue app definition --- //\n\n// EOF","x":550,"y":1680,"wires":[],"icon":"font-awesome/fa-code"},{"id":"ddf41d65.687","type":"debug","z":"18cb249f.38bafb","name":"qod-debug","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":410,"y":1800,"wires":[]},{"id":"eb406f24.13a48","type":"http request","z":"18cb249f.38bafb","name":"GET","method":"GET","ret":"obj","paytoqs":false,"url":"","tls":"","persist":false,"proxy":"","authType":"","x":250,"y":1740,"wires":[["ddf41d65.687","8cfb4d87.519ba","bad4b165.e6a08"]]},{"id":"fa66e5de.8a81e8","type":"comment","z":"18cb249f.38bafb","name":"index.css","info":"body {font-family: sans-serif; font-size: 120%;}\ndiv, p, code { margin:0.3em; padding: 0.3em;}\n\nblockquote i {\n    font-size: 1.5em; color:grey; font-style: italic;\n}","x":680,"y":1680,"wires":[],"icon":"node-red/hash.svg"},{"id":"83b1be67.1e3d3","type":"link out","z":"18cb249f.38bafb","name":"uib_simple_ctrl_out","links":["c65760d4.37dac"],"x":815,"y":1800,"wires":[]},{"id":"c65760d4.37dac","type":"link in","z":"18cb249f.38bafb","name":"uib_simple_ctrl_in","links":["83b1be67.1e3d3"],"x":155,"y":1780,"wires":[["eb406f24.13a48"]]},{"id":"a7683dd2.9a4e5","type":"file","z":"18cb249f.38bafb","name":"","filename":"","appendNewline":true,"createDir":false,"overwriteFile":"false","encoding":"none","x":630,"y":1620,"wires":[[]]},{"id":"8cfb4d87.519ba","type":"change","z":"18cb249f.38bafb","name":"","rules":[{"t":"set","p":"filename","pt":"msg","to":"\"./quotes/\" & & \".json\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":1620,"wires":[["a7683dd2.9a4e5"]]},{"id":"6eb39afc.539d54","type":"switch","z":"18cb249f.38bafb","name":"client","property":"from","propertyType":"msg","rules":[{"t":"eq","v":"client","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":610,"y":1800,"wires":[["1d092359.465b4d"]]},{"id":"1d092359.465b4d","type":"change","z":"18cb249f.38bafb","name":"delete","rules":[{"t":"delete","p":"cacheControl","pt":"msg"},{"t":"delete","p":"uibuilderCtrl","pt":"msg"},{"t":"delete","p":"from","pt":"msg"},{"t":"delete","p":"_socketId","pt":"msg"},{"t":"delete","p":"_msgid","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":1800,"wires":[["83b1be67.1e3d3"]]},{"id":"8ed2c6e8.a5e258","type":"comment","z":"18cb249f.38bafb","name":"Saves copies of all quotes ==>","info":"To a `quotes` folder.","x":210,"y":1620,"wires":[]},{"id":"c0567834.0593b8","type":"comment","z":"18cb249f.38bafb","name":"Shows a new quote if the page is reloaded","info":"","x":720,"y":1840,"wires":[]}]

Which produces a really simple page that shows a quote taken from a quote API. I must remember to put this into the examples for the next release.

It really is amazing what you can build really simply with VueJS and bootstrap-vue:

1 Like

Ohh my, @TotallyInformation this is beautiful, could you point us to any code stubs that we can get a fast start - specially on the buttons?

Hi. The node's WIKI page contains loads of examples, there are also some in the flows library.

The buttons are bog-standard bootstrap-vue, you can change the colour dynamically, in the image, I use green and amber which are both standard colours in bootstrap. The flame icon is an SVG version of a Font Awesome icon if I remember correctly, you can download that from their website. The nav header and tab bar are all standard bootstrap-vue.

All very easy to do thanks to VueJS and bootstrap-vue - and Node-RED of course :slight_smile:

Thank you