Compare commits
5 Commits
fbfb09a545
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7827cc6cd4 | |||
| 179480f628 | |||
| 134d759bf6 | |||
| b91c3be0b4 | |||
| 3f95905578 |
+53
-16
@@ -1,5 +1,8 @@
|
|||||||
module.exports = function (RED) {
|
module.exports = function (RED) {
|
||||||
|
var counter = 0;
|
||||||
|
|
||||||
function ButtonGroupNode(config) {
|
function ButtonGroupNode(config) {
|
||||||
|
const iid = ++counter;
|
||||||
var ui = undefined;
|
var ui = undefined;
|
||||||
try {
|
try {
|
||||||
var node = this;
|
var node = this;
|
||||||
@@ -8,15 +11,9 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
RED.nodes.createNode(this, config);
|
RED.nodes.createNode(this, config);
|
||||||
|
|
||||||
var sizes = ui.getSizes();
|
var html = `
|
||||||
|
<div id="buttons-${iid}" style="width=100%; height=100%; display: flex; flex-wrap: wrap; justify-content: center;"></div>
|
||||||
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; background-color: {{button.color}}; white-space: pre-wrap; word-break: break-word;" ng-click="buttonClick($event)" ng-repeat="button in msg.buttons">{{button.label}}</md-button>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
var done = ui.addWidget({
|
var done = ui.addWidget({
|
||||||
node: node,
|
node: node,
|
||||||
@@ -33,7 +30,7 @@ module.exports = function (RED) {
|
|||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
beforeEmit: function (msg, value) {
|
beforeEmit: function (msg, value) {
|
||||||
return { msg: { buttons: value, socketid: msg.socketid } };
|
return { msg: { iid: iid, width: config.buttonwidth, height: config.buttonheight, sizes: ui.getSizes(), buttons: value, socketid: msg.socketid } };
|
||||||
},
|
},
|
||||||
beforeSend: function (msg, orig) {
|
beforeSend: function (msg, orig) {
|
||||||
if (orig) {
|
if (orig) {
|
||||||
@@ -42,13 +39,53 @@ module.exports = function (RED) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
initController: function ($scope, events) {
|
initController: function ($scope, events) {
|
||||||
$scope.buttonClick = function (e) {
|
$scope.$watch('msg', function (msg) {
|
||||||
e.preventDefault();
|
if (!msg) {
|
||||||
var buttonId = e.target.id;
|
return;
|
||||||
if ($scope.msg.buttons[buttonId].payload) {
|
|
||||||
$scope.send({ "payload": $scope.msg.buttons[buttonId].payload });
|
|
||||||
}
|
}
|
||||||
};
|
const iid = msg.iid;
|
||||||
|
|
||||||
|
|
||||||
|
var root = $(`#buttons-${iid}`);
|
||||||
|
|
||||||
|
root.children().remove();
|
||||||
|
|
||||||
|
const widthPx = (msg.width * msg.sizes.sx) - (msg.sizes.gx * 2);
|
||||||
|
const heightPx = (msg.height * msg.sizes.sy) - (msg.sizes.gy * 2);
|
||||||
|
|
||||||
|
console.log(root, widthPx, heightPx);
|
||||||
|
|
||||||
|
for (const button of msg.buttons) {
|
||||||
|
const buttonElement = $(`<button class="md-raised md-button md-ink-ripple" type="button" style="white-space: pre-wrap; word-break: break-word;"></button>`);
|
||||||
|
|
||||||
|
buttonElement.css("width", `${widthPx}px`);
|
||||||
|
buttonElement.css("height", `${heightPx}px`);
|
||||||
|
buttonElement.css("margin", `${sizes.gx}px ${sizes.gy}px`);
|
||||||
|
buttonElement.css("background-color", button.color ? button.color : "");
|
||||||
|
|
||||||
|
buttonElement.text(button.label);
|
||||||
|
|
||||||
|
if (button.click) {
|
||||||
|
buttonElement.on('click', function (e) {
|
||||||
|
$scope.send(button.click);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button.down) {
|
||||||
|
buttonElement.on('touchstart mousedown', function (e) {
|
||||||
|
$scope.send(button.down);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button.up) {
|
||||||
|
buttonElement.on('touchend mouseup', function (e) {
|
||||||
|
$scope.send(button.up);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
root.append(buttonElement);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ module.exports = function (RED) {
|
|||||||
|
|
||||||
var html = `
|
var html = `
|
||||||
<script type='text/javascript' src='ui-gauge-group/gauge.min.js'></script>
|
<script type='text/javascript' src='ui-gauge-group/gauge.min.js'></script>
|
||||||
<div id="gauge-${iid}" style="width=100%; height=100%; display: flex; flex-wrap: wrap"></div>
|
<div id="gauge-${iid}" style="width=100%; height=100%; display: flex; flex-wrap: wrap; justify-content: center;"></div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
var done = ui.addWidget({
|
var done = ui.addWidget({
|
||||||
|
|||||||
+2
-2
@@ -15,7 +15,7 @@ module.exports = function (RED) {
|
|||||||
|
|
||||||
var html = `
|
var html = `
|
||||||
<script type='text/javascript' src='ui-gauge-group/gauge.min.js'></script>
|
<script type='text/javascript' src='ui-gauge-group/gauge.min.js'></script>
|
||||||
<div id="multi-${iid}" style="width=100%; height=100%; display: flex; flex-wrap: wrap; justify-content: center;"></div>
|
<div id="multi-${iid}" style="width=100%; height=100%; display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start;"></div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
var done = ui.addWidget({
|
var done = ui.addWidget({
|
||||||
@@ -173,7 +173,7 @@ module.exports = function (RED) {
|
|||||||
const widthPx = widthToPx(config.width, includeMargin);
|
const widthPx = widthToPx(config.width, includeMargin);
|
||||||
const heightPx = heightToPx(config.height, includeMargin);
|
const heightPx = heightToPx(config.height, includeMargin);
|
||||||
|
|
||||||
const container = $(`<div id=${containerId} style="display: flex; flex-wrap: wrap; justify-content: center" />`);
|
const container = $(`<div id=${containerId} style="display: flex; flex-wrap: wrap; justify-content: center; align-content: flex-start;" />`);
|
||||||
|
|
||||||
container.css("width", `${widthPx}px`);
|
container.css("width", `${widthPx}px`);
|
||||||
container.css("height", `${heightPx}px`);
|
container.css("height", `${heightPx}px`);
|
||||||
|
|||||||
Reference in New Issue
Block a user