-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflexdash-tab.js
55 lines (49 loc) · 1.59 KB
/
flexdash-tab.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// FlexDash tab node for Node-RED
// Copyright ©2021-2022 by Thorsten von Eicken, see LICENSE
module.exports = function (RED) {
// configuration node
class flexdashTab {
// config: name, icon, fd_children, fd
constructor(config) {
try {
// use try-catch to get stack backtrace of any error
//this.log("config=" + JSON.stringify(config))
RED.nodes.createNode(this, config)
this.config = config
this.plugin = RED.plugins.get("flexdash")
// register as container with flexdash dashboard node
if (!config.fd) return // nothing we can really do here
this.fd = RED.nodes.getNode(config.fd)
if (!this.fd) return
this.storeTab()
} catch (e) {
console.error(e.stack)
throw e
}
this.on("close", () => {
try {
// use try-catch to get stack backtrace of any error
this.removeTab()
} catch (e) {
console.error(e.stack)
throw e
}
})
}
storeTab() {
const c = this.config
this.fd_id = "t" + this.id
// construct the tab data to put into the store
const fd_config = { id: this.fd_id, title: c.title, icon: c.icon }
this.plugin._newNode(this.id, this, fd_config)
}
removeTab() {
if (this.fd) {
this.fd.store.deleteTab(this.fd_id)
this.plugin._delNode(this.id)
}
}
}
RED.nodes.registerType("flexdash tab", flexdashTab)
RED.plugins.get("node-red-vue").createVueTemplate("flexdash tab", __filename)
}