Add button group ui node
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('ui_button_group', {
|
||||
category: 'dashboard',
|
||||
color: 'rgb(63, 173, 181)',
|
||||
defaults: {
|
||||
name: { value: '' },
|
||||
group: { type: 'ui_group', required: true },
|
||||
order: { value: 0 },
|
||||
width: {
|
||||
value: 0, validate: function (v) {
|
||||
var width = v || 0;
|
||||
var currentGroup = $('#node-input-group').val() || this.group;
|
||||
var groupNode = RED.nodes.node(currentGroup);
|
||||
var valid = !groupNode || +width <= +groupNode.width;
|
||||
$("#node-input-size").toggleClass("input-error", !valid);
|
||||
return valid;
|
||||
}
|
||||
},
|
||||
height: { value: 0 },
|
||||
buttonwidth: {
|
||||
value: 0, validate: function (v) {
|
||||
var btnWidth = Number(v || 0);
|
||||
var valid = btnWidth <= Number(this.width) && btnWidth > 0;
|
||||
console.log(`valid: ${valid}; btnWidth: ${btnWidth}; this.width: ${this.width}; v: ${v}`);
|
||||
$("#node-input-buttonwidth").toggleClass("input-error", !valid);
|
||||
return valid;
|
||||
}
|
||||
},
|
||||
buttonheight: {
|
||||
value: 0, validate: function (v) {
|
||||
var btnHeight = Number(v || 0);
|
||||
var valid = btnHeight <= Number(this.height) && btnHeight > 0;
|
||||
$("#node-input-buttonheight").toggleClass("input-error", !valid);
|
||||
return valid;
|
||||
},
|
||||
},
|
||||
},
|
||||
inputs: 1,
|
||||
outputs: 1,
|
||||
icon: 'font-awesome/fa-th-large',
|
||||
paletteLabel: 'button group',
|
||||
label: function () {
|
||||
return this.name || 'Buttons';
|
||||
},
|
||||
oneditprepare: function () {
|
||||
$("#node-input-size").elementSizer({
|
||||
width: "#node-input-width",
|
||||
height: "#node-input-height",
|
||||
group: "#node-input-group"
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-template-name="ui_button_group">
|
||||
<div class='form-row' id='template-row-group'>
|
||||
<label for='node-input-group'><i class='fa fa-table'></i> Group</label>
|
||||
<input type='text' id='node-input-group'>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label><i class="fa fa-object-group"></i> Size</label>
|
||||
<input type="hidden" id="node-input-width">
|
||||
<input type="hidden" id="node-input-height">
|
||||
<button class="editor-button" id="node-input-size"></button>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-buttonwidth"><i class="fa fa-tag"></i> Button Width</label>
|
||||
<input type="number" id="node-input-buttonwidth" placeholder="1">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-buttonheight"><i class="fa fa-tag"></i> Button Height</label>
|
||||
<input type="number" id="node-input-buttonheight" placeholder="1">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
</script>
|
||||
|
||||
<script type="text/html" data-help-name="ui_button_group">
|
||||
<p>A simple button group node</p>
|
||||
</script>
|
||||
@@ -0,0 +1,58 @@
|
||||
module.exports = function (RED) {
|
||||
function ButtonGroupNode(config) {
|
||||
var ui = undefined;
|
||||
try {
|
||||
var node = this;
|
||||
if (ui === undefined) {
|
||||
ui = RED.require("node-red-dashboard")(RED);
|
||||
}
|
||||
RED.nodes.createNode(this, config);
|
||||
|
||||
var sizes = ui.getSizes();
|
||||
|
||||
var widthPx = config.buttonwidth * sizes.sx - sizes.gx;
|
||||
|
||||
var heightPx = config.buttonheight * sizes.sy - sizes.gy;
|
||||
|
||||
var html = `<div style="width=100%; height=100%">
|
||||
<md-button id="{{$index}}" style="width:${widthPx}px; height:${heightPx}px; margin: ${sizes.gx}px ${sizes.gy}px;" ng-click="buttonClick($event)" ng-repeat="button in msg.buttons">{{button.label}}</md-button>
|
||||
</div>`;
|
||||
|
||||
var done = ui.addWidget({
|
||||
node: node,
|
||||
order: config.order,
|
||||
group: config.group,
|
||||
width: config.width,
|
||||
height: config.height,
|
||||
format: html,
|
||||
templateScope: 'local',
|
||||
emitOnlyNewValues: false,
|
||||
forwardInputMessages: false,
|
||||
storeFrontEndInputAsState: false,
|
||||
convertBack: function (value) {
|
||||
return value;
|
||||
},
|
||||
beforeEmit: function (msg, value) {
|
||||
return { msg: { buttons: value, socketid: msg.socketid } };
|
||||
},
|
||||
beforeSend: function (msg, orig) {
|
||||
if (orig) {
|
||||
orig.msg.topic = config.topic;
|
||||
return orig.msg;
|
||||
}
|
||||
},
|
||||
initController: function ($scope, events) {
|
||||
$scope.buttonClick = function (e) {
|
||||
e.preventDefault();
|
||||
var buttonId = e.target.id;
|
||||
$scope.send({ "payload": $scope.msg.buttons[buttonId].payload });
|
||||
};
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
node.on('close', done);
|
||||
}
|
||||
RED.nodes.registerType("ui_button_group", ButtonGroupNode);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "node-red-contrib-ui-cocktail",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Jendrik Jäger",
|
||||
"license": "ISC",
|
||||
"node-red": {
|
||||
"nodes": {
|
||||
"ui_button_group": "button-group.js"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user