From ea8c0aa2a1a1ff9f29ffd452049a7b749298ed17 Mon Sep 17 00:00:00 2001 From: Daniel Vijge Date: Thu, 26 Oct 2023 22:58:03 +0200 Subject: luci-app-dawn: Implement in JavaScript This commit re-implements luci-app-dawn in JavaScript, removing the older lua implementation. Besides a 1-to-1 port, there are some changes/improvements: * In both the network overview and the hearing map, replace MAC addresses by host name if known. * In the hearing map, the table is sortable. If the same client is connected to multiple access points/frequencies the MAC/host name is listed twice, whereas in the lua implementation the second MAC address was empty to show it was referring to the same client. This means the table can be sorted on any column, and the information remains correct. * The view in the network overview is a bit different. This table is not sortable, because LuCi doesn't seem to like a table inside a table for sorting. * Align the column names between the network overview and the hearing table. * Add tooltips for abbreviations in column names. Signed-off-by: Daniel Vijge --- .../luci-static/resources/dawn/dawn-common.js | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 applications/luci-app-dawn/htdocs/luci-static/resources/dawn/dawn-common.js (limited to 'applications/luci-app-dawn/htdocs/luci-static/resources/dawn') diff --git a/applications/luci-app-dawn/htdocs/luci-static/resources/dawn/dawn-common.js b/applications/luci-app-dawn/htdocs/luci-static/resources/dawn/dawn-common.js new file mode 100644 index 0000000000..5d002d9b7f --- /dev/null +++ b/applications/luci-app-dawn/htdocs/luci-static/resources/dawn/dawn-common.js @@ -0,0 +1,69 @@ +'use strict'; +'require baseclass'; +'require rpc'; + +let callDawnGetNetwork, callDawnGetHearingMap, callHostHints; + +callDawnGetNetwork = rpc.declare({ + object: 'dawn', + method: 'get_network', + expect: { } +}); + +callDawnGetHearingMap = rpc.declare({ + object: 'dawn', + method: 'get_hearing_map', + expect: { } +}); + +callHostHints = rpc.declare({ + object: 'luci-rpc', + method: 'getHostHints', + expect: { } +}); + +function getAvailableText(available) { + return ( available ? _('Available') : _('Not available') ); +} + +function getChannelFromFrequency(freq) { + if (freq <= 2400) { + return 0; + } + else if (freq == 2484) { + return 14; + } + else if (freq < 2484) { + return (freq - 2407) / 5; + } + else if (freq >= 4910 && freq <= 4980) { + return (freq - 4000) / 5; + } + else if (freq <= 45000) { + return (freq - 5000) / 5; + } + else if (freq >= 58320 && freq <= 64800) { + return (freq - 56160) / 2160; + } + else { + return 0; + } +} + +function getFormattedNumber(num, decimals, divider = 1) { + return (num/divider).toFixed(decimals); +} + +function getHostnameFromMAC(hosthints, mac) { + return ( hosthints[mac] && hosthints[mac].name ? hosthints[mac].name : mac); +} + +return L.Class.extend({ + callDawnGetNetwork: callDawnGetNetwork, + callDawnGetHearingMap: callDawnGetHearingMap, + callHostHints: callHostHints, + getAvailableText: getAvailableText, + getChannelFromFrequency: getChannelFromFrequency, + getFormattedNumber: getFormattedNumber, + getHostnameFromMAC: getHostnameFromMAC +}); -- cgit v1.2.3