modules/admin-full: properly handle disabled radios in live overview
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 8 Nov 2010 22:40:04 +0000 (22:40 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 8 Nov 2010 22:40:04 +0000 (22:40 +0000)
modules/admin-full/luasrc/controller/admin/network.lua
modules/admin-full/luasrc/view/admin_network/wifi_overview.htm

index b9d9d845ef5920739fdff6d4bf704d99bc4d0dca..b271e20d248df7752a32dc494ffcdf9ffcdf77af 100644 (file)
@@ -224,14 +224,15 @@ end
 
 function wifi_status()
        local path = luci.dispatcher.context.requestpath
+       local arp  = luci.sys.net.arptable()
        local rv   = { }
 
        local dev
        for dev in path[#path]:gmatch("[%w%.%-]+") do
+               local j = { id = dev }
                local iw = luci.sys.wifi.getiwinfo(dev)
                if iw then
                        local f
-                       local j = { id = dev }
                        for _, f in ipairs({
                                "channel", "frequency", "txpower", "bitrate", "signal", "noise",
                                "quality", "quality_max", "mode", "ssid", "bssid", "country",
@@ -239,9 +240,8 @@ function wifi_status()
                        }) do
                                j[f] = iw[f]
                        end
-
-                       rv[#rv+1] = j
                end
+               rv[#rv+1] = j
        end
 
        if #rv > 0 then
index 20f0e8d6ec16f1a46424369d896bb49e012b469d..218e47bb2c9daf1cb03bcc0691081e5cea6bf057 100644 (file)
@@ -109,11 +109,14 @@ $Id$
                                                while (assoctable.rows.length > 1)
                                                        assoctable.rows[1].parentNode.removeChild(assoctable.rows[1]);
 
+                                       var devup = { };
+
                                        for( var i = 0; i < st.length; i++ )
                                        {
                                                var iw = st[i];
+                                               var is_assoc = (iw.bssid && iw.channel);
                                                var p = (100 / iw.quality_max * iw.quality);
-                                               var q = (iw.bssid && iw.channel) ? p : -1;
+                                               var q = is_assoc ? p : -1;
 
                                                var icon;
                                                if (q < 0)
@@ -129,6 +132,9 @@ $Id$
                                                else
                                                        icon = "<%=resource%>/icons/signal-75-100.png";
 
+                                               if (!devup[wifidevs[iw.id]])
+                                                       devup[wifidevs[iw.id]] = is_assoc;
+
                                                var sig = document.getElementById(iw.id + '-iw-signal');
                                                if (sig)
                                                        sig.innerHTML = String.format(
@@ -138,24 +144,34 @@ $Id$
 
                                                var info = document.getElementById(iw.id + '-iw-status');
                                                if (info)
-                                                       info.innerHTML = String.format(
-                                                               '<strong><%:SSID%>:</strong> %s | ' +
-                                                               '<strong><%:Mode%>:</strong> %s<br />' +
-                                                               '<strong><%:BSSID%>:</strong> %s | ' +
-                                                               '<strong><%:Encryption%>:</strong> %s',
-                                                                       iw.ssid, iw.mode, iw.bssid,
-                                                                       iw.encryption ? iw.encryption.description : '<%:None%>'
-                                                       );
+                                               {
+                                                       if (is_assoc)
+                                                               info.innerHTML = String.format(
+                                                                       '<strong><%:SSID%>:</strong> %s | ' +
+                                                                       '<strong><%:Mode%>:</strong> %s<br />' +
+                                                                       '<strong><%:BSSID%>:</strong> %s | ' +
+                                                                       '<strong><%:Encryption%>:</strong> %s',
+                                                                               iw.ssid, iw.mode, iw.bssid,
+                                                                               iw.encryption ? iw.encryption.description : '<%:None%>'
+                                                               );
+                                                       else
+                                                               info.innerHTML = '<em><%:Wireless is disabled or not associated%></em>';
+                                               }
 
                                                var dev = document.getElementById(wifidevs[iw.id] + '-iw-devinfo');
                                                if (dev)
-                                                       dev.innerHTML = String.format(
-                                                               '<strong><%:Channel%>:</strong> %s (%s GHz) | ' +
-                                                               '<strong><%:Bitrate%>:</strong> %s Mb/s',
-                                                                       iw.channel ? iw.channel : '?',
-                                                                       iw.frequency ? iw.frequency / 1000 : '?',
-                                                                       iw.bitrate ? iw.bitrate / 1000 : '?'
-                                                       );
+                                               {
+                                                       if (is_assoc)
+                                                               dev.innerHTML = String.format(
+                                                                       '<strong><%:Channel%>:</strong> %s (%s GHz) | ' +
+                                                                       '<strong><%:Bitrate%>:</strong> %s Mb/s',
+                                                                               iw.channel ? iw.channel : '?',
+                                                                               iw.frequency ? iw.frequency / 1000 : '?',
+                                                                               iw.bitrate ? iw.bitrate / 1000 : '?'
+                                                               );
+                                                       else
+                                                               dev.innerHTML = '';
+                                               }
 
                                                if (assoctable)
                                                {
@@ -218,6 +234,13 @@ $Id$
 
                                                assoctable.rows[0].parentNode.appendChild(tr);
                                        }
+
+                                       for (var dev in devup)
+                                       {
+                                               var img = document.getElementById(dev + '-iw-upstate');
+                                               if (img)
+                                                       img.src = '<%=resource%>/icons/wifi' + (devup[dev] ? '' : '_disabled') + '.png';
+                                       }
                                }
                        }
                )
@@ -236,7 +259,7 @@ $Id$
                <table class="cbi-section-table" style="margin:10px; empty-cells:hide">
                        <!-- physical device -->
                        <tr>
-                               <td style="width:34px"><img src="<%=resource%>/icons/wifi<%=dev:is_up() and "" or "_disabled"%>.png" style="float:left; margin-right:10px" /></td>
+                               <td style="width:34px"><img src="<%=resource%>/icons/wifi_disabled.png" style="float:left; margin-right:10px" id="<%=dev:name()%>-iw-upstate" /></td>
                                <td colspan="2" style="text-align:left">
                                        <big><strong><%=guess_wifi_hw(dev:name())%> (<%=dev:name()%>)</strong></big><br />
                                        <span id="<%=dev:name()%>-iw-devinfo"></span>