diff options
author | Jo-Philipp Wich <jo@mein.io> | 2019-07-07 20:11:35 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2019-07-07 20:11:35 +0200 |
commit | f970c485cfb2571dd6d4ee6a1ad36958f1410b6a (patch) | |
tree | bac0cd8c4d8fa60c11ac4db804074b2548c020cc /applications/luci-app-firewall/htdocs/luci-static/resources/view | |
parent | 37ca6fe6d63f748904a18ee5213f52e642980ab5 (diff) |
treewide: switch to shared isObject(), toArray() and sortedKeys() helpers
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'applications/luci-app-firewall/htdocs/luci-static/resources/view')
-rw-r--r-- | applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js | 36 | ||||
-rw-r--r-- | applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js | 34 |
2 files changed, 7 insertions, 63 deletions
diff --git a/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js b/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js index 743d115e88..93bfc29188 100644 --- a/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js +++ b/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/forwards.js @@ -6,34 +6,6 @@ 'require tools.firewall as fwtool'; 'require tools.widgets as widgets'; -function skeys(obj, key, mode) { - if (obj == null || typeof(obj) != 'object') - return []; - - return Object.keys(obj).map(function(e) { - var v = (key != null) ? obj[e][key] : e; - - switch (mode) { - case 'addr': - v = (v != null) ? v.replace(/(?:^|[.:])([0-9a-fA-F]{1,4})/g, - function(m0, m1) { return ('000' + m1.toLowerCase()).substr(-4) }) : null; - break; - - case 'num': - v = (v != null) ? +v : null; - break; - } - - return [ e, v ]; - }).filter(function(e) { - return (e[1] != null); - }).sort(function(a, b) { - return (a[1] > b[1]); - }).map(function(e) { - return e[0]; - }); -} - function fmt(fmt /*, ...*/) { var repl = [], wrap = false; @@ -192,7 +164,7 @@ return L.view.extend({ o.rmempty = true; o.datatype = 'neg(macaddr)'; o.placeholder = E('em', _('any')); - skeys(hosts).forEach(function(mac) { + L.sortedKeys(hosts).forEach(function(mac) { o.value(mac, '%s (%s)'.format( mac, hosts[mac].name || hosts[mac].ipv4 || hosts[mac].ipv6 || '?' @@ -205,7 +177,7 @@ return L.view.extend({ o.rmempty = true; o.datatype = 'neg(ipmask4)'; o.placeholder = E('em', _('any')); - skeys(hosts, 'ipv4', 'addr').forEach(function(mac) { + L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) { o.value(hosts[mac].ipv4, '%s (%s)'.format( hosts[mac].ipv4, hosts[mac].name || mac @@ -229,7 +201,7 @@ return L.view.extend({ o.rmempty = true; o.datatype = 'neg(ipmask4)'; o.placeholder = E('em', _('any')); - skeys(hosts, 'ipv4', 'addr').forEach(function(mac) { + L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) { o.value(hosts[mac].ipv4, '%s (%s)'.format( hosts[mac].ipv4, hosts[mac].name || mac @@ -257,7 +229,7 @@ return L.view.extend({ o.modalonly = true; o.rmempty = true; o.datatype = 'ipmask4'; - skeys(hosts, 'ipv4', 'addr').forEach(function(mac) { + L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) { o.value(hosts[mac].ipv4, '%s (%s)'.format( hosts[mac].ipv4, hosts[mac].name || mac diff --git a/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js b/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js index 9fa1aa252d..d2d1916322 100644 --- a/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js +++ b/applications/luci-app-firewall/htdocs/luci-static/resources/view/firewall/rules.js @@ -6,34 +6,6 @@ 'require tools.firewall as fwtool'; 'require tools.widgets as widgets'; -function skeys(obj, key, mode) { - if (obj == null || typeof(obj) != 'object') - return []; - - return Object.keys(obj).map(function(e) { - var v = (key != null) ? obj[e][key] : e; - - switch (mode) { - case 'addr': - v = (v != null) ? v.replace(/(?:^|[.:])([0-9a-fA-F]{1,4})/g, - function(m0, m1) { return ('000' + m1.toLowerCase()).substr(-4) }) : null; - break; - - case 'num': - v = (v != null) ? +v : null; - break; - } - - return [ e, v ]; - }).filter(function(e) { - return (e[1] != null); - }).sort(function(a, b) { - return (a[1] > b[1]); - }).map(function(e) { - return e[0]; - }); -} - function fmt(fmt /*, ...*/) { var repl = [], wrap = false; @@ -276,7 +248,7 @@ return L.view.extend({ o.modalonly = true; o.datatype = 'list(macaddr)'; o.placeholder = _('any'); - skeys(hosts).forEach(function(mac) { + L.sortedKeys(hosts).forEach(function(mac) { o.value(mac, '%s (%s)'.format( mac, hosts[mac].name || hosts[mac].ipv4 || hosts[mac].ipv6 || '?' @@ -287,7 +259,7 @@ return L.view.extend({ o.modalonly = true; o.datatype = 'list(neg(ipmask))'; o.placeholder = _('any'); - skeys(hosts, 'ipv4', 'addr').forEach(function(mac) { + L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) { o.value(hosts[mac].ipv4, '%s (%s)'.format( hosts[mac].ipv4, hosts[mac].name || mac @@ -324,7 +296,7 @@ return L.view.extend({ o.modalonly = true; o.datatype = 'list(neg(ipmask))'; o.placeholder = _('any'); - skeys(hosts, 'ipv4', 'addr').forEach(function(mac) { + L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) { o.value(hosts[mac].ipv4, '%s (%s)'.format( hosts[mac].ipv4, hosts[mac].name || mac |