Commit a13b59c2 authored by Безуглый Андрей's avatar Безуглый Андрей
Browse files

Added i18n strings, fixed bug with ub connection using https.

parent 4329843a
{
"ub": {
"label": {
"server": "Server"
}
}
}
{
"ub": {
"errors": {
"missing-config": "Missing configuration"
},
"label": {
"host": "Host",
"method": "Method",
"password": "Password",
"port": "Port",
"user": "User",
"use-tls": "Use TLS"
},
"state": {
"connect-failed": "Connection failed",
"connected": "Connected"
},
"tabs-label": {
"server": "Server",
"authentication": "Authentication"
}
}
}
......@@ -5,8 +5,8 @@
defaults: {
name: {value: ''},
server: {type: 'ub-server', required: true},
entity: {value: '', type: 'text'},
method: {value: '', type: 'text'}
entity: {value: ''},
method: {value: ''}
},
inputs: 1,
outputs: 1,
......@@ -34,11 +34,9 @@
<label for="node-input-name"><i class="fa fa-tasks"></i> Method</label>
<input type="text" id="node-input-method" placeholder="select">
</div>
</script>
<script type="text/x-red" data-help-name="ub-call">
<p>Call a UnityBase entity method.</p>
<p></p>
</script>
......@@ -30,13 +30,13 @@ module.exports = function (RED) {
method: node.method,
execParams: msg.payload
});
// TODO: connect to ub, make a call
// TODO: implement returning result from UB
// msg.payload = msg.payload.toLowerCase();
// node.send(msg);
});
} else {
this.error(RED._('mqtt.errors.missing-config'));
this.error(RED._('ub.errors.missing-config'));
}
}
......
......@@ -3,35 +3,32 @@
<ul style="background: #fff; min-width: 600px; margin-bottom: 20px;" id="node-config-ub-server-tabs"></ul>
</div>
<div id="node-config-ub-server-tabs-content" style="min-height: 170px;">
<div id="ub-server-tab-connection">
<div id="ub-server-tab-server">
<div class="form-row node-input-server">
<label for="node-config-input-server"><i class="fa fa-globe"></i> Server</label>
<label for="node-config-input-server"><i class="fa fa-globe"></i> <span data-i18n="ub.label.host"></span></label>
<input class="input-append-left" type="text" id="node-config-input-server" placeholder="e.g. localhost" style="width: 40%;" >
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; " placeholder="888"> Port</label>
<input type="text" id="node-config-input-port" data-i18n="[placeholder]mqtt.label.port" style="width:45px">
<label for="node-config-input-port" style="margin-left: 10px; width: 35px; " placeholder="888"> <span data-i18n="ub.label.port"></span></label>
<input type="text" id="node-config-input-port" data-i18n="[placeholder]ub.label.port" style="width:45px">
</div>
<div class="form-row">
<input type="checkbox" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-usetls" style="width: auto" data-i18n="mqtt.label.use-tls"></label>
<div id="node-config-row-tls" class="hide">
<label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-config-input-tls"><span data-i18n="mqtt.label.tls-config"></span></label><input style="width: 300px;" type="text" id="node-config-input-tls">
</div>
<input type="checkbox" id="node-config-input-useTls" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-useTls" style="width: auto" data-i18n="ub.label.use-tls"></label>
</div>
</div>
<div id="ub-server-tab-authentication" style="display:none">
<div class="form-row">
<label for="node-config-input-authMethod"><i class="fa fa-user"></i> Method</label>
<label for="node-config-input-authMethod"><i class="fa fa-user"></i> <span data-i18n="ub.label.method"></span></label>
<select id="node-config-input-authMethod" style="width:125px !important">
<option value="UB">UB</option>
<option value="UBIP">UBIP</option>
</select>
</div>
<div class="form-row">
<label for="node-config-input-user"><i class="fa fa-user"></i> <span data-i18n="common.label.username"></span></label>
<label for="node-config-input-user"><i class="fa fa-user"></i> <span data-i18n="ub.label.user"></span></label>
<input type="text" id="node-config-input-user">
</div>
<div class="form-row" id="node-config-row-password">
<label for="node-config-input-password"><i class="fa fa-lock"></i> <span data-i18n="common.label.password"></span></label>
<label for="node-config-input-password"><i class="fa fa-lock"></i> <span data-i18n="ub.label.password"></span></label>
<input type="password" id="node-config-input-password">
</div>
</div>
......@@ -50,9 +47,10 @@
defaults: {
server: {value: 'localhost', required: true},
port: {value: 888, required: true, validate: RED.validators.number()},
authMethod: {value: 'UB', type: 'text', validate: v => v === 'UB' || v === 'UBIP'},
user: {value: 'admin', type: 'text'},
password: {value: 'admin', type: 'text'}
useTls: {value: false},
authMethod: {value: 'UB', validate: v => v === 'UB' || v === 'UBIP'},
user: {value: 'admin'},
password: {value: 'admin'}
},
label: function () {
var b = this.server;
......@@ -70,12 +68,12 @@
}
});
tabs.addTab({
id: 'ub-server-tab-connection',
label: this._('mqtt.tabs-label.connection')
id: 'ub-server-tab-server',
label: this._('ub.tabs-label.server')
});
tabs.addTab({
id: 'ub-server-tab-authentication',
label: this._('mqtt.tabs-label.security')
label: this._('ub.tabs-label.authentication')
});
setTimeout(function () {
......
......@@ -7,6 +7,7 @@ module.exports = function (RED) {
RED.nodes.createNode(this, n);
this.server = n.server;
this.port = n.port;
this.useTls = n.useTls;
this.authMethod = n.authMethod;
this.user = n.user;
this.password = n.password;
......@@ -42,7 +43,7 @@ module.exports = function (RED) {
node.connecting = true;
const host = 'http://' + node.server + ':' + node.port;
const host = (node.useTls ? 'https' : 'http') + '://' + node.server + ':' + node.port;
node.log(`Connecting to UnityBase server: ${host}...`);
ub.connect({
host,
......@@ -55,7 +56,7 @@ module.exports = function (RED) {
});
},
onAuthorizationFail: function (reason) {
node.log(RED._('mqtt.state.connect-failed', {server: (node.clientid ? node.clientid + '@' : '') + node.brokerurl}));
node.log(RED._('ub.state.connect-failed', {server: (node.clientid ? node.clientid + '@' : '') + node.brokerurl}));
node.connecting = false;
}
}).then(
......@@ -65,7 +66,7 @@ module.exports = function (RED) {
node.connecting = false;
node.log(`Connected to UnityBase`);
node.log(RED._('mqtt.state.connected', {broker: (node.clientid ? node.clientid + '@' : '') + node.brokerurl}));
node.log(RED._('ub.state.connected', {broker: (node.clientid ? node.clientid + '@' : '') + node.brokerurl}));
for (let id in node.users) {
if (node.users.hasOwnProperty(id)) {
node.users[id].status({
......@@ -83,9 +84,5 @@ module.exports = function (RED) {
}
}
RED.nodes.registerType('ub-server', UbServerNode, {
authMethod: {type: 'text'},
user: {type: 'text'},
password: {type: 'password'}
});
RED.nodes.registerType('ub-server', UbServerNode);
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment