summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base/htdocs/luci-static
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-10-18 11:49:13 +0200
committerJo-Philipp Wich <jo@mein.io>2019-10-18 11:49:13 +0200
commitd5ffab23b65fc37719752d122e0d37b38f471870 (patch)
tree5cc72e674eabde0462a769ba841fcae55bb1e726 /modules/luci-base/htdocs/luci-static
parent45e57cf1db2212af033b19d1912f364e6857d068 (diff)
luci-base: network.js: simplify rpc error handling
Use L.resolveDefault() catch unexpected RPC replies and rename declared rpc functions in a consistent manner. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base/htdocs/luci-static')
-rw-r--r--modules/luci-base/htdocs/luci-static/resources/network.js110
1 files changed, 21 insertions, 89 deletions
diff --git a/modules/luci-base/htdocs/luci-static/resources/network.js b/modules/luci-base/htdocs/luci-static/resources/network.js
index 30d508df2..c5b0c3027 100644
--- a/modules/luci-base/htdocs/luci-static/resources/network.js
+++ b/modules/luci-base/htdocs/luci-static/resources/network.js
@@ -44,13 +44,13 @@ var iface_patterns_wireless = [
var iface_patterns_virtual = [ ];
-var callLuciNetdevs = rpc.declare({
+var callLuciNetworkDevices = rpc.declare({
object: 'luci',
method: 'getNetworkDevices',
expect: { '': {} }
});
-var callLuciWifidevs = rpc.declare({
+var callLuciWirelessDevices = rpc.declare({
object: 'luci',
method: 'getWirelessDevices',
expect: { '': {} }
@@ -62,11 +62,17 @@ var callLuciIfaddrs = rpc.declare({
expect: { result: [] }
});
-var callLuciBoardjson = rpc.declare({
+var callLuciBoardJSON = rpc.declare({
object: 'luci',
method: 'getBoardJSON'
});
+var callLuciHostHints = rpc.declare({
+ object: 'luci',
+ method: 'getHostHints',
+ expect: { '': {} }
+});
+
var callIwinfoAssoclist = rpc.declare({
object: 'iwinfo',
method: 'assoclist',
@@ -82,7 +88,7 @@ var callIwinfoScan = rpc.declare({
expect: { results: [] }
});
-var callNetworkInterfaceStatus = rpc.declare({
+var callNetworkInterfaceDump = rpc.declare({
object: 'network.interface',
method: 'dump',
expect: { 'interface': [] }
@@ -94,88 +100,19 @@ var callNetworkDeviceStatus = rpc.declare({
expect: { '': {} }
});
-var callGetProtoHandlers = rpc.declare({
+var callNetworkProtoHandlers = rpc.declare({
object: 'network',
method: 'get_proto_handlers',
expect: { '': {} }
});
-var callGetHostHints = rpc.declare({
- object: 'luci',
- method: 'getHostHints',
- expect: { '': {} }
-});
-
var _init = null,
_state = null,
_protocols = {},
_protospecs = {};
-function getInterfaceState(cache) {
- return callNetworkInterfaceStatus().then(function(state) {
- if (!Array.isArray(state))
- throw !1;
- return state;
- }).catch(function() {
- return [];
- });
-}
-
-function getDeviceState(cache) {
- return callNetworkDeviceStatus().then(function(state) {
- if (!L.isObject(state))
- throw !1;
- return state;
- }).catch(function() {
- return {};
- });
-}
-
-function getIfaddrState(cache) {
- return callLuciIfaddrs().then(function(addrs) {
- if (!Array.isArray(addrs))
- throw !1;
- return addrs;
- }).catch(function() {
- return [];
- });
-}
-
-function getNetdevState(cache) {
- return callLuciNetdevs().then(function(state) {
- if (!L.isObject(state))
- throw !1;
- return state;
- }).catch(function() {
- return {};
- });
-}
-
-function getWifidevState(cache) {
- return callLuciWifidevs().then(function(state) {
- if (!L.isObject(state))
- throw !1;
- return state;
- }).catch(function() {
- return {};
- });
-}
-
-function getBoardState(cache) {
- return callLuciBoardjson().then(function(state) {
- if (!L.isObject(state))
- throw !1;
- return state;
- }).catch(function() {
- return {};
- });
-}
-
function getProtocolHandlers(cache) {
- return callGetProtoHandlers().then(function(protos) {
- if (!L.isObject(protos))
- throw !1;
-
+ return callNetworkProtoHandlers().then(function(protos) {
/* Register "none" protocol */
if (!protos.hasOwnProperty('none'))
Object.assign(protos, { none: { no_device: false } });
@@ -199,16 +136,6 @@ function getProtocolHandlers(cache) {
});
}
-function getHostHints(cache) {
- return callGetHostHints().then(function(hosts) {
- if (!L.isObject(hosts))
- throw !1;
- return hosts;
- }).catch(function() {
- return {};
- });
-}
-
function getWifiStateBySid(sid) {
var s = uci.get('wireless', sid);
@@ -433,10 +360,15 @@ function maskToPrefix(mask, v6) {
function initNetworkState(refresh) {
if (_state == null || refresh) {
_init = _init || Promise.all([
- getInterfaceState(), getDeviceState(), getBoardState(),
- getIfaddrState(), getNetdevState(), getWifidevState(),
- getHostHints(), getProtocolHandlers(),
- uci.load('network'), uci.load('wireless'), uci.load('luci')
+ L.resolveDefault(callNetworkInterfaceDump(), []),
+ L.resolveDefault(callNetworkDeviceStatus(), {}),
+ L.resolveDefault(callLuciBoardJSON(), {}),
+ L.resolveDefault(callLuciIfaddrs(), []),
+ L.resolveDefault(callLuciNetworkDevices(), {}),
+ L.resolveDefault(callLuciWirelessDevices(), {}),
+ L.resolveDefault(callLuciHostHints(), {}),
+ getProtocolHandlers(),
+ uci.load(['network', 'wireless', 'luci'])
]).then(function(data) {
var netifd_ifaces = data[0],
netifd_devs = data[1],