1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

mqtt: Add 'name' to mqtt-broker node, and label it by this if it is set. (#1364)

This allows you to easily distinguish between broker nodes which are talking to the same server but with different credentials.
This commit is contained in:
btsimonh 2017-08-09 22:22:40 +01:00 committed by Dave Conway-Jones
parent 96a0dbea2d
commit e09efba313

View File

@ -165,6 +165,10 @@
</script> </script>
<script type="text/x-red" data-template-name="mqtt-broker"> <script type="text/x-red" data-template-name="mqtt-broker">
<div class="form-row">
<label for="node-config-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
<input type="text" id="node-config-input-name" data-i18n="[placeholder]common.label.name">
</div>
<div class="form-row"> <div class="form-row">
<ul style="background: #fff; min-width: 600px; margin-bottom: 20px;" id="node-config-mqtt-broker-tabs"></ul> <ul style="background: #fff; min-width: 600px; margin-bottom: 20px;" id="node-config-mqtt-broker-tabs"></ul>
</div> </div>
@ -266,6 +270,7 @@
RED.nodes.registerType('mqtt-broker',{ RED.nodes.registerType('mqtt-broker',{
category: 'config', category: 'config',
defaults: { defaults: {
name: {value:""},
broker: {value:"",required:true}, broker: {value:"",required:true},
port: {value:1883,required:true,validate:RED.validators.number()}, port: {value:1883,required:true,validate:RED.validators.number()},
tls: {type:"tls-config",required: false}, tls: {type:"tls-config",required: false},
@ -296,9 +301,15 @@
password: {type: "password"} password: {type: "password"}
}, },
label: function() { label: function() {
var lab = this.name;
if ((lab === undefined) || (lab ==="")) {
var b = this.broker; var b = this.broker;
if (b === "") { b = "undefined"; } if (b === "") { b = "undefined"; }
return (this.clientid?this.clientid+"@":"")+b+":"+this.port; lab = (this.clientid?this.clientid+"@":"")+b+":"+this.port;
}
return lab;
}, },
oneditprepare: function () { oneditprepare: function () {
var tabs = RED.tabs.create({ var tabs = RED.tabs.create({