disable ui_worldmap if Node-RED Dashboard not installed (#113)

This commit is contained in:
Hiroyasu Nishiyama 2019-09-05 06:13:01 +09:00 committed by Dave Conway-Jones
parent f8a4f4207e
commit 76423e11cd
2 changed files with 125 additions and 108 deletions

View File

@ -359,6 +359,8 @@ then by default <code>⌘⇧m</code> - <code>ctrl-shift-m</code> will load the m
}
});
$.get('/.ui-worldmap', function (data) {
if (data === "true") {
RED.nodes.registerType('ui_worldmap',{
category: 'dashboard',
color: 'rgb( 63, 173, 181)',
@ -430,6 +432,11 @@ then by default <code>⌘⇧m</code> - <code>ctrl-shift-m</code> will load the m
$("#node-input-cluster").spinner({min:0, max:19});
}
});
}
else {
console.log("ui_worldmap: Node-RED not found.");
}
});
</script>
<script type="text/x-red" data-template-name="worldmap in">

View File

@ -152,13 +152,13 @@ module.exports = function(RED) {
}
var ui = undefined;
try {
ui = RED.require("node-red-dashboard")(RED);
if(ui) {
function UIWorldMap(config) {
try {
var node = this;
if(ui === undefined) {
ui = RED.require("node-red-dashboard")(RED);
}
worldMap(node, config);
var done = null;
if (checkConfig(node, config)) {
@ -198,6 +198,12 @@ module.exports = function(RED) {
});
}
RED.nodes.registerType("ui_worldmap", UIWorldMap);
}
}
catch(e) {
RED.log.info("Node-RED Dashboard not found.");
RED.log.info("ui_worldmap not installed.");
}
var WorldMapIn = function(n) {
RED.nodes.createNode(this,n);
@ -341,4 +347,8 @@ module.exports = function(RED) {
});
}
RED.nodes.registerType("worldmap-tracks",WorldMapTracks);
RED.httpNode.get("/.ui-worldmap", function(req, res) {
res.send(ui ? "true": "false");
});
}