gluon-status-page: move mesh protocol specific definitions into a separate file
This commit is contained in:
parent
3282a63ea7
commit
35ade80f1c
@ -18,6 +18,16 @@
|
||||
_('%s used')
|
||||
_('%s packets/s')
|
||||
|
||||
local function get_mesh()
|
||||
local f = loadfile('/lib/gluon/status-page/mesh.lua')
|
||||
if f then
|
||||
return f()
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
local mesh = get_mesh()
|
||||
|
||||
local function get_interfaces()
|
||||
local uconn = ubus.connect()
|
||||
if not uconn then
|
||||
@ -77,7 +87,11 @@
|
||||
|
||||
<link rel="stylesheet" href="/static/status-page.css" type="text/css" />
|
||||
</head>
|
||||
<body data-node-address="<%| http:getenv('SERVER_ADDR') %>"<%= attr('data-translations', translations) .. attr('data-node-location', nodeinfo.location) %>>
|
||||
<body data-node-address="<%| http:getenv('SERVER_ADDR') %>"<%=
|
||||
attr('data-translations', translations) ..
|
||||
attr('data-node-location', nodeinfo.location) ..
|
||||
attr('data-mesh-provider', mesh.provider)
|
||||
%>>
|
||||
<header>
|
||||
<h1><%| nodeinfo.hostname %></h1>
|
||||
</header>
|
||||
@ -139,7 +153,9 @@
|
||||
<table class="datatable">
|
||||
<tr>
|
||||
<th><%:Node%></th>
|
||||
<th>TQ</th>
|
||||
<% for i, v in ipairs(mesh.attrs or {}) do %>
|
||||
<th<%= attr('data-key', v[1]) .. attr('data-suffix', v[3]) %>><%| v[2] %></th>
|
||||
<% end %>
|
||||
<% if wireless then %>
|
||||
<th>dBm</th>
|
||||
<th><%:Distance%></th>
|
||||
|
File diff suppressed because one or more lines are too long
@ -412,6 +412,7 @@
|
||||
}
|
||||
|
||||
function Neighbour(iface, addr, color, destroy) {
|
||||
var th = iface.table.firstElementChild;
|
||||
var el = iface.table.insertRow();
|
||||
|
||||
var tdHostname = el.insertCell();
|
||||
@ -427,8 +428,26 @@
|
||||
hostname.textContent = addr;
|
||||
tdHostname.appendChild(hostname);
|
||||
|
||||
var tdTQ = el.insertCell();
|
||||
tdTQ.textContent = '-';
|
||||
var meshAttrs = {};
|
||||
|
||||
function add_attr(attr) {
|
||||
var key = attr.getAttribute('data-key');
|
||||
if (!key)
|
||||
return;
|
||||
|
||||
var suffix = attr.getAttribute('data-suffix') || '';
|
||||
|
||||
var td = el.insertCell();
|
||||
td.textContent = '-';
|
||||
|
||||
meshAttrs[key] = {
|
||||
'td': td,
|
||||
'suffix': suffix,
|
||||
};
|
||||
}
|
||||
|
||||
for (var i = 0; i < th.children.length; i++)
|
||||
add_attr(th.children[i]);
|
||||
|
||||
var tdSignal;
|
||||
var tdDistance;
|
||||
@ -585,7 +604,10 @@
|
||||
updated();
|
||||
},
|
||||
'update_mesh': function(mesh) {
|
||||
tdTQ.textContent = Math.round(mesh.tq / 2.55) + ' %';
|
||||
Object.keys(meshAttrs).forEach(function(key) {
|
||||
var attr = meshAttrs[key];
|
||||
attr.td.textContent = mesh[key] + attr.suffix;
|
||||
});
|
||||
|
||||
updated();
|
||||
},
|
||||
@ -724,7 +746,9 @@
|
||||
interfaces[ifname] = Interface(elem, ifname, wireless);
|
||||
});
|
||||
|
||||
add_event_source('/cgi-bin/dyn/neighbours-batadv', function(data) {
|
||||
var mesh_provider = document.body.getAttribute('data-mesh-provider');
|
||||
if (mesh_provider) {
|
||||
add_event_source(mesh_provider, function(data) {
|
||||
Object.keys(data).forEach(function (addr) {
|
||||
var mesh = data[addr];
|
||||
var iface = interfaces[mesh.ifname];
|
||||
@ -734,4 +758,5 @@
|
||||
iface.get_neigh(addr).update_mesh(mesh);
|
||||
});
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
@ -0,0 +1,10 @@
|
||||
return {
|
||||
provider = '/cgi-bin/dyn/neighbours-batadv',
|
||||
-- List of mesh-specific attributes, each a tuple of
|
||||
-- 1) the internal identifier (JSON key)
|
||||
-- 2) human-readable key (not translatable yet)
|
||||
-- 3) value suffix (optional)
|
||||
attrs = {
|
||||
{'tq', 'TQ', ' %'},
|
||||
},
|
||||
}
|
@ -76,7 +76,7 @@ static int parse_orig_list_netlink_cb(struct nl_msg *msg, void *arg)
|
||||
if (!neigh)
|
||||
return NL_OK;
|
||||
|
||||
json_object_object_add(neigh, "tq", json_object_new_int(tq));
|
||||
json_object_object_add(neigh, "tq", json_object_new_int(tq * 100 / 255));
|
||||
json_object_object_add(neigh, "ifname", json_object_new_string(ifname));
|
||||
|
||||
json_object_object_add(opts->obj, mac1, neigh);
|
||||
|
Loading…
Reference in New Issue
Block a user