From 2c369cb86de4d92a2b37ab65f0e7a420e928dfdf Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 22 Aug 2018 19:50:30 +0200 Subject: [PATCH] Added web interface for gpio plugin --- platypush/backend/http/static/css/gpio.css | 29 +++++++ platypush/backend/http/static/js/gpio.js | 78 +++++++++++++++++++ .../backend/http/templates/plugins/gpio.html | 5 ++ 3 files changed, 112 insertions(+) create mode 100644 platypush/backend/http/static/css/gpio.css create mode 100644 platypush/backend/http/static/js/gpio.js create mode 100644 platypush/backend/http/templates/plugins/gpio.html diff --git a/platypush/backend/http/static/css/gpio.css b/platypush/backend/http/static/css/gpio.css new file mode 100644 index 0000000000..9a62c13bd2 --- /dev/null +++ b/platypush/backend/http/static/css/gpio.css @@ -0,0 +1,29 @@ +#gpio-container { + background-color: #f8f8f8; + padding: 12px; + border: 1px solid #ddd; + border-radius: 10px; + font-family: "Raleway", "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: 400; + line-height: 38px; + letter-spacing: .1rem; +} + +.gpio-pin { + padding: 1.5em 1em .2em .5em; + border-radius: 10px; +} + + .gpio-pin:nth-of-type(odd) { + background-color: #ececec; + } + + .gpio-pin:hover { + background-color: #daf8e2 !important; + } + +.toggle-container { + text-align: right; + padding-right: 1em; +} + diff --git a/platypush/backend/http/static/js/gpio.js b/platypush/backend/http/static/js/gpio.js new file mode 100644 index 0000000000..42facfb48c --- /dev/null +++ b/platypush/backend/http/static/js/gpio.js @@ -0,0 +1,78 @@ +$(document).ready(function() { + var $container = $('#sensors-container'); + + var createPowerToggleElement = function(pin) { + var $powerToggle = $('
').addClass('toggle toggle--push pin-ctrl-container'); + var $input = $('').attr('type', 'checkbox') + .data('number', pin.pin).attr('name', pin.name).addClass('toggle--checkbox pin-ctrl'); + + var $label = $('').attr('for', pin.name).addClass('toggle--btn'); + + $input.appendTo($powerToggle); + $label.appendTo($powerToggle); + + if (pin.value > 0) { + $input.prop('checked', true); + } + + return $powerToggle; + }; + + var initElements = function() { + execute({ type: 'request', action: 'gpio.read_all' }, function(data) { + var response = data.response.output; + + for (var pin of response) { + var $pin = $('
') + .addClass('row gpio-pin') + .attr('data-pin-number', pin.pin); + + var $name = $('
') + .addClass('pin-name ten columns') + .text(pin.name); + + var $value = $('
') + .addClass('pin-value two columns'); + + var $toggle = createPowerToggleElement(pin); + + $toggle.appendTo($value); + $name.appendTo($pin); + $value.appendTo($pin); + $pin.appendTo($container); + } + }); + }; + + var initBindings = function() { + $container.on('click touch', '.pin-ctrl-container', function() { + var $input = $(this).find('.pin-ctrl'); + var pinNumber = $input.data('number'); + var val = $input.prop('checked') ? 0 : 1; + + execute( + { + type: 'request', + action: 'gpio.write', + args: { + pin: pinNumber, + val: val, + } + }, + + onSuccess = function(response) { + var val = response.response.output.val; + $input.prop('checked', val == 0 ? false : true); + } + ); + }); + }; + + var init = function() { + initElements(); + initBindings(); + }; + + init(); +}); + diff --git a/platypush/backend/http/templates/plugins/gpio.html b/platypush/backend/http/templates/plugins/gpio.html new file mode 100644 index 0000000000..ac652297dc --- /dev/null +++ b/platypush/backend/http/templates/plugins/gpio.html @@ -0,0 +1,5 @@ + + + +
+