luci-mod-status: use progressbar widgets on main status page
authorJo-Philipp Wich <jo@mein.io>
Tue, 13 Nov 2018 17:42:56 +0000 (18:42 +0100)
committerJo-Philipp Wich <jo@mein.io>
Wed, 14 Nov 2018 19:46:04 +0000 (20:46 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-mod-status/luasrc/view/admin_status/index.htm

index 54e35b82a06a97d57a32175a4790cd1c5c25a8a9..b98ba76f899f620d971d208ef24014d4d4f22b4d 100644 (file)
 <%+header%>
 
 <script type="text/javascript">//<![CDATA[
-       function progressbar(v, m)
+       function progressbar(q, v, m)
        {
-               var vn = parseInt(v) || 0;
-               var mn = parseInt(m) || 100;
-               var pc = Math.floor((100 / mn) * vn);
-
-               return String.format(
-                       '<div style="width:100%%; max-width:200px; position:relative; border:1px solid #999999">' +
-                               '<div style="background-color:#CCCCCC; width:%d%%; height:15px">' +
-                                       '<div style="position:absolute; left:0; top:0; text-align:center; width:100%%; color:#000000">' +
-                                               '<small>%s / %s (%d%%)</small>' +
-                                       '</div>' +
-                               '</div>' +
-                       '</div>', pc, v, m, pc
-               );
+               var pg = document.querySelector(q),
+                   vn = parseInt(v) || 0,
+                   mn = parseInt(m) || 100,
+                   pc = Math.floor((100 / mn) * vn);
+
+               if (pg) {
+                       pg.firstElementChild.style.width = pc + '%';
+                       pg.setAttribute('title', '%s / %s (%d%%)'.format(v, m, pc));
+               }
        }
 
        function labelList(items, offset) {
                                        info.loadavg[2] / 65535.0
                                );
 
-                       if (e = document.getElementById('memtotal'))
-                               e.innerHTML = progressbar(
-                                       ((info.memory.free + info.memory.buffered) / 1024) + " <%:kB%>",
-                                       (info.memory.total / 1024) + " <%:kB%>"
-                               );
+                       progressbar('#memtotal',
+                               ((info.memory.free + info.memory.buffered) / 1024) + " <%:kB%>",
+                               (info.memory.total / 1024) + " <%:kB%>");
 
-                       if (e = document.getElementById('memfree'))
-                               e.innerHTML = progressbar(
-                                       (info.memory.free / 1024) + " <%:kB%>",
-                                       (info.memory.total / 1024) + " <%:kB%>"
-                               );
+                       progressbar('#memfree',
+                               (info.memory.free / 1024) + " <%:kB%>",
+                               (info.memory.total / 1024) + " <%:kB%>");
 
-                       if (e = document.getElementById('membuff'))
-                               e.innerHTML = progressbar(
-                                       (info.memory.buffered / 1024) + " <%:kB%>",
-                                       (info.memory.total / 1024) + " <%:kB%>"
-                               );
+                       progressbar('#membuff',
+                               (info.memory.buffered / 1024) + " <%:kB%>",
+                               (info.memory.total / 1024) + " <%:kB%>");
 
-                       if (e = document.getElementById('swaptotal'))
-                               e.innerHTML = progressbar(
-                                       (info.swap.free / 1024) + " <%:kB%>",
-                                       (info.swap.total / 1024) + " <%:kB%>"
-                               );
+                       progressbar('#swaptotal',
+                               (info.swap.free / 1024) + " <%:kB%>",
+                               (info.swap.total / 1024) + " <%:kB%>");
 
-                       if (e = document.getElementById('swapfree'))
-                               e.innerHTML = progressbar(
-                                       (info.swap.free / 1024) + " <%:kB%>",
-                                       (info.swap.total / 1024) + " <%:kB%>"
-                               );
+                       progressbar('#swapfree',
+                               (info.swap.free / 1024) + " <%:kB%>",
+                               (info.swap.total / 1024) + " <%:kB%>");
 
-                       if (e = document.getElementById('conns'))
-                               e.innerHTML = progressbar(info.conncount, info.connmax);
+                       progressbar('#conns',
+                               info.conncount, info.connmax);
 
                }
        );
        <h3><%:Memory%></h3>
 
        <div class="table" width="100%">
-               <div class="tr"><div class="td left" width="33%"><%:Total Available%></div><div class="td left" id="memtotal">-</div></div>
-               <div class="tr"><div class="td left" width="33%"><%:Free%></div><div class="td left" id="memfree">-</div></div>
-               <div class="tr"><div class="td left" width="33%"><%:Buffered%></div><div class="td left" id="membuff">-</div></div>
+               <div class="tr"><div class="td left" width="33%"><%:Total Available%></div><div class="td left"><div id="memtotal" class="cbi-progressbar" title="-"><div></div></div></div></div>
+               <div class="tr"><div class="td left" width="33%"><%:Free%></div><div class="td left"><div id="memfree" class="cbi-progressbar" title="-"><div></div></div></div></div>
+               <div class="tr"><div class="td left" width="33%"><%:Buffered%></div><div class="td left"><div id="membuff" class="cbi-progressbar" title="-"><div></div></div></div></div>
        </div>
 </div>
 
        <h3><%:Swap%></h3>
 
        <div class="table" width="100%">
-               <div class="tr"><div class="td left" width="33%"><%:Total Available%></div><div class="td left" id="swaptotal">-</div></div>
-               <div class="tr"><div class="td left" width="33%"><%:Free%></div><div class="td left" id="swapfree">-</div></div>
+               <div class="tr"><div class="td left" width="33%"><%:Total Available%></div><div class="td left"><div id="swaptotal" class="cbi-progressbar" title="-"><div></div></div></div></div>
+               <div class="tr"><div class="td left" width="33%"><%:Free%></div><div class="td left"><div id="swapfree" class="cbi-progressbar" title="-"><div></div></div></div></div>
        </div>
 </div>
 <% end %>
        </div>
 
        <div class="table" width="100%">
-               <div class="tr"><div class="td left" width="33%"><%:Active Connections%></div><div class="td left" id="conns">-</div></div>
+               <div class="tr"><div class="td left" width="33%"><%:Active Connections%></div><div class="td left"><div id="conns" class="cbi-progressbar" title="-"><div></div></div></div></div>
        </div>
 </div>