padavanfirmware / rt-n56u

Padavan Firmware
http://padavanfw.net/
6 stars 4 forks source link

Feature request (patch available): Sortable List of Manually Assigned IPs in Advanced_DHCP_Content.asp #1421

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We have a long list of manually assigned IPs for dhcpd. The patch inlined below 
makes this list sortable by IP, MAC, Name or ID, all client-side, in js 
(Advanced_DHCP_Content.asp). If you think this might be useful I would be happy 
if you included it in future releases.
What's missing is internationalization of the "sort" link. And maybe 
statefulness, i.e. a permanent setting how to sort the list, as right now it 
jumps back into its default, unsorted (sorted by "ID") state as soon as you 
make any changes/reload the page.

Here's the patch against your current trunk:

diff --git a/trunk/user/www/n56u_ribbon_fixed/Advanced_DHCP_Content.asp 
b/trunk/user/www/n56u_ribbon_fixed/Advanced_DHCP_Content.asp
index db97bfc..7a59fc9 100644
--- a/trunk/user/www/n56u_ribbon_fixed/Advanced_DHCP_Content.asp
+++ b/trunk/user/www/n56u_ribbon_fixed/Advanced_DHCP_Content.asp
@@ -38,6 +38,14 @@ var ipmonitor = [<% get_static_client(); %>];
 var wireless = [<% wl_auth_list(); %>];
 var m_dhcp = [<% get_nvram_list("LANHostConfig", "ManualDHCPList"); %>];

+var mdhcp_ifield = 3;
+if(m_dhcp.length > 0){
+   var m_dhcp_ifield = m_dhcp[0].length;
+   for (var i = 0; i < m_dhcp.length; i++) {
+       m_dhcp[i][mdhcp_ifield] = i;
+   }
+}
+
 var clients_info = getclients(1,0);

 var isMenuopen = 0;
@@ -153,6 +161,41 @@ function validForm(){
    return true;
 }

+function sortMDHCPbyIP(){
+        m_dhcp.sort(function(a,b){
+     var aa = a[1].split(".");
+     var bb = b[1].split(".");
+   
+          var resulta = aa[0]*0x1000000 + aa[1]*0x10000 + aa[2]*0x100 + 
aa[3]*1;
+          var resultb = bb[0]*0x1000000 + bb[1]*0x10000 + bb[2]*0x100 + 
bb[3]*1;
+   
+     return resulta-resultb;
+   });
+}
+
+function sortMDHCPbyMAC(){
+        m_dhcp.sort(function(a,b){
+     return parseInt(a[0])-parseInt(b[0]);
+   });
+}
+
+function sortMDHCPbyName(){
+        m_dhcp.sort(function(a,b){
+     var aa = a[2].toLowerCase();
+     var bb = b[2].toLowerCase();
+     if (aa < bb) return -1;
+     if (aa > bb) return 1;    
+     return 0;
+   });
+}
+
+function sortMDHCPbyID(){
+        m_dhcp.sort(function(a,b){
+     return a[mdhcp_ifield] - b[mdhcp_ifield]; 
+   });
+}
+
+
 function setClientMAC(num){
    document.form.dhcp_staticmac_x_0.value = clients_info[num][2];
    document.form.dhcp_staticip_x_0.value = clients_info[num][1];
@@ -266,7 +309,7 @@ function showMDHCPList(){
        code +='<td width="25%">' + m_dhcp[i][0] + '</td>';
        code +='<td width="25%">' + m_dhcp[i][1] + '</td>';
        code +='<td width="45%">' + m_dhcp[i][2] + '</td>';
-       code +='<td width="5%" style="text-align: center;"><input type="checkbox" 
name="ManualDHCPList_s" value="' + i + '" onClick="changeBgColor(this,' + i + 
');" id="check' + i + '"></td>';
+       code +='<td width="5%" style="text-align: center;"><input type="checkbox" 
name="ManualDHCPList_s" value="' + m_dhcp[i][mdhcp_ifield] + '" 
onClick="changeBgColor(this,' + i + ');" id="check' + m_dhcp[i][mdhcp_ifield] + 
'"></td>';
        code +='</tr>';
        }

@@ -508,10 +551,26 @@ function changeBgColor(obj, num){
                                             </td>
                                         </tr>
                                         <tr id="row_static_caption" style="display:none">
-                                            <th 
width="25%"><#LANHostConfig_ManualMac_itemname#></th>
-                                            <th 
width="25%"><#LANHostConfig_ManualIP_itemname#></th>
-                                            <th 
width="45%"><#LANHostConfig_ManualName_itemname#></th>
-                                            <th width="5%">&nbsp;</th>
+                                            <th 
width="25%"><#LANHostConfig_ManualMac_itemname#>
+                           <a href="javascript:sortMDHCPbyMAC();showMDHCPList()">
+                         (sort)
+                       </a>
+                       </th>
+                                            <th 
width="25%"><#LANHostConfig_ManualIP_itemname#>
+                           <a href="javascript:sortMDHCPbyIP();showMDHCPList()">
+                         (sort)
+                       </a>
+                       </th>
+                                            <th 
width="45%"><#LANHostConfig_ManualName_itemname#>
+                           <a href="javascript:sortMDHCPbyName();showMDHCPList()">
+                         (sort)
+                       </a>
+                       </th>
+                                            <th width="5%">
+                           <a href="javascript:sortMDHCPbyID();showMDHCPList()">
+                         unsort
+                       </a>
+                       </th>
                                         </tr>
                                         <tr id="row_static_header" style="display:none">
                                             <td width="25%">

Original issue reported on code.google.com by dr.chris...@gmail.com on 10 Feb 2015 at 11:29

GoogleCodeExporter commented 9 years ago
Applied, thanks. 
http://code.google.com/p/rt-n56u/source/detail?r=abd411ce46e87a8794d2632537c2751
6e6c98499

Original comment by andy.pad...@gmail.com on 22 Feb 2015 at 12:55

GoogleCodeExporter commented 9 years ago
I would love for this feature also

Original comment by xfiles4...@gmail.com on 7 Mar 2015 at 4:37

GoogleCodeExporter commented 9 years ago

Original comment by andy.pad...@gmail.com on 1 Jun 2015 at 2:33