applications/luci-olsr: Update all statuspages; use json reloading on overview, neigh...
[project/luci.git] / applications / luci-olsr / luasrc / view / status-olsr / routes.htm
1 <%#
2 LuCI - Lua Configuration Interface
3 Copyright 2008 Steven Barth <steven@midlink.org>
4 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5 Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12 -%>
13
14 <%
15
16 local olsrtools = require "luci.tools.olsr"
17 local i = 1
18
19 if luci.http.formvalue("status") == "1" then
20         local rv = {}
21         for k, route in ipairs(routes) do
22                 rv[#rv+1] = {
23                         hostname = route.Hostname,
24                         dest = route.Destination,
25                         gw = route["Gateway IP"],
26                         interface = route.Interface,
27                         metric = route.Metric,
28                         etx = tonumber(route.ETX),
29                         color = olsrtools.etx_color(tonumber(route.ETX)),
30                         rs = i
31                 }
32                 if i == 1 then i = 0 elseif i == 0 then i = 1 end       
33         end
34         luci.http.prepare_content("application/json")
35         luci.http.write_json(rv)
36         return
37 end
38
39 %>
40
41 <%+header%>
42
43 <script type="text/javascript" src="<%=resource%>/cbi.js"></script>
44 <script type="text/javascript">//<![CDATA[  
45
46 XHR.poll(20, '<%=REQUEST_URI%>', { status: 1 },
47                 function(x, info)
48                 {
49
50                 var rt = document.getElementById('olsrd_routes');
51                         if (rt)
52                         {
53                                 var s = '';
54                                 for (var idx = 0; idx < info.length; idx++)
55                                 {
56                                         var route = info[idx];
57
58                                         s += String.format(
59                                                 '<tr class="cbi-section-table-row cbi-rowstyle-%s">' +
60                                                         '<td class="cbi-section-table-cell">%s</td>' +
61                                                         '<td class="cbi-section-table-cell">' +
62                                                                 '<a href="http://%s/cgi-bin-status.html">%s</a>',
63                                                                 route.rs, route.dest, route.gw, route.gw
64                                                 )
65
66                                         if (route.hostname)
67                                                 {
68                                                 s += String.format(
69                                                                 ' / <a href="http://%s/cgi-bin-status.html">%s</a>',
70                                                                 route.hostname, route.hostname || '?'
71                                                                 );
72                                                 }
73                                         s += String.format(
74                                                         '</td>' +
75                                                         '<td class="cbi-section-table-cell">%s</td>' +
76                                                         '<td class="cbi-section-table-cell">%s</td>' +
77                                                         '<td class="cbi-section-table-cell" style="background-color:%s">%s</td>' +
78                                                 '</tr>',
79                                                 route.interface, route.metric, route.color, route.etx || '?'
80                                         );
81                                 }
82                         }
83                          rt.innerHTML = s;
84
85                 }
86         );
87 //]]></script>
88
89
90
91 <h2><a id="content" name="content"><%:Known OLSR routes%></a></h2>
92
93 <fieldset class="cbi-section">
94 <legend><%:Overview of currently known routes to other OLSR nodes%></legend>
95
96 <table class="cbi-section-table">
97         <tr class="cbi-section-table-titles">
98                 <th class="cbi-section-table-cell"><%:Announced network%></th>
99                 <th class="cbi-section-table-cell"><%:OLSR gateway%></th>
100                 <th class="cbi-section-table-cell"><%:Interface%></th>
101                 <th class="cbi-section-table-cell"><%:Metric%></th>
102                 <th class="cbi-section-table-cell">ETX</th>
103         </tr>
104
105         <tbody id="olsrd_routes">
106
107         <% for k, route in ipairs(routes) do
108                 color = olsrtools.etx_color(tonumber(route.ETX))
109         %>
110
111                 <tr class="cbi-section-table-row cbi-rowstyle-<%=i%>">
112                         <td class="cbi-section-table-cell"><%=route.Destination%></td>
113                         <td class="cbi-section-table-cell">
114                                 <a href="http://<%=route["Gateway IP"]%>/cgi-bin-status.html"><%=route["Gateway IP"]%></a>
115                                 <% if route.Hostname then %>
116                                         / <a href="http://<%=route.Hostname%>/cgi-bin-status.html"><%=route.Hostname%></a>  
117                                 <% end %>
118                         </td>
119                         <td class="cbi-section-table-cell"><%=route.Interface%></td>
120                         <td class="cbi-section-table-cell"><%=route.Metric%></td>
121                         <td class="cbi-section-table-cell" style="background-color:<%=color%>"><%=string.format("%.3f", tonumber(route.ETX) or 0)%></td>
122                 </tr>
123         <% 
124         if i == 1 then i = 0 elseif i == 0 then i = 1 end
125         end %>
126         </tbody>
127 </table>
128
129 </fieldset>
130 <%+footer%>