diff options
Diffstat (limited to 'applications/luci-app-ledtrig-usbport')
-rw-r--r-- | applications/luci-app-ledtrig-usbport/Makefile | 16 | ||||
-rw-r--r-- | applications/luci-app-ledtrig-usbport/htdocs/luci-static/resources/view/system/led-trigger/usbport.js | 46 |
2 files changed, 62 insertions, 0 deletions
diff --git a/applications/luci-app-ledtrig-usbport/Makefile b/applications/luci-app-ledtrig-usbport/Makefile new file mode 100644 index 000000000..1a176676f --- /dev/null +++ b/applications/luci-app-ledtrig-usbport/Makefile @@ -0,0 +1,16 @@ +# +# Copyright (C) 2020 TDT AG <development@tdt.de> +# +# This is free software, licensed under the Apache License Version 2.0. +# See https://www.apache.org/licenses/LICENSE-2.0 for more information. +# + +include $(TOPDIR)/rules.mk + +LUCI_TITLE:= LuCI Support for ledtrigger usbport +LUCI_DEPENDS:=+kmod-usb-ledtrig-usbport +LUCI_PKGARCH:=all + +include ../../luci.mk + +# call BuildPackage - OpenWrt buildroot signature diff --git a/applications/luci-app-ledtrig-usbport/htdocs/luci-static/resources/view/system/led-trigger/usbport.js b/applications/luci-app-ledtrig-usbport/htdocs/luci-static/resources/view/system/led-trigger/usbport.js new file mode 100644 index 000000000..970016c42 --- /dev/null +++ b/applications/luci-app-ledtrig-usbport/htdocs/luci-static/resources/view/system/led-trigger/usbport.js @@ -0,0 +1,46 @@ +'use strict'; +'require rpc'; +'require uci'; +'require form'; + +var callUSB = rpc.declare({ + object: 'luci', + method: 'getUSBDevices', + expect: { 'ports': [] } +}); + +return L.Class.extend({ + trigger: _('usbport (kernel)'), + kernel: true, + addFormOptions(s){ + var o; + + o = s.option(form.Value, 'port', _('USB Ports')); + o.depends('trigger', 'usbport'); + o.rmempty = true; + o.modalonly = true; + o.load = function(s) { + return Promise.all([ + callUSB() + ]).then(L.bind(function(usbport){ + for (var i = 0; i < usbport[0].length; i++) + o.value(usbport[0][i].port, _('Port %s').format(usbport[0][i].port)); + },this)); + }; + o.cfgvalue = function(section_id) { + var ports = [], + value = uci.get('system', section_id, 'port'); + + if (!Array.isArray(value)) + value = String(value || '').split(/\s+/); + + for (var i = 0; i < value.length; i++) + if (value[i].match(/^(\d+)-(\d+)$/)) + ports.push('usb%d-port%d'.format(Regexp.$1, Regexp.$2)); + else + ports.push(value[i]); + + return ports; + }; + } +}); |