pvl/verkko/hosts.py
changeset 26 589249097230
parent 25 47faf2ac32d0
child 27 38d050c657da
--- a/pvl/verkko/hosts.py	Wed Oct 24 18:13:14 2012 +0300
+++ b/pvl/verkko/hosts.py	Wed Oct 24 19:42:16 2012 +0300
@@ -87,7 +87,7 @@
         else :
             return self.state
 
-    def when (self) :
+    def seen (self) :
         return (
                 html.span(title=self.first_seen)(self.first_seen.strftime(self.DATE_FMT)),
                 '-',
@@ -120,6 +120,9 @@
     #state   = db.dhcp_hosts.c.,
 ))
 
+
+   
+ 
 class BaseHandler (web.Handler) :
     HOST_ATTRS = {
         'id':       Host.id,
@@ -254,7 +257,7 @@
                     render_cell('name', host.name, htmlvalue=host.render_name()),
                     render_cell('gw', host.gw),
 
-                    html.td(host.when()),
+                    html.td(host.seen()),
                     html.td(class_=host.state_class(), title=host.state_title())(host.state),
                 ) for i, host in enumerate(hosts)
             ),
@@ -465,6 +468,7 @@
     JS = (
         #"/static/jquery/jquery.js",
         'http://code.jquery.com/jquery-1.8.2.js',
+        '/static/js/spin.js',
         '/static/hosts.js',
     )
 
@@ -482,7 +486,18 @@
             
             if hosts :
                 t = hosts[-1].last_seen
-                hosts = [{'id': host.id, 't': dt2ts(host.last_seen), 'ip': host.ip, 'mac': host.mac} for host in hosts]
+                hosts = [dict(
+                    id      = host.id, 
+                    ip      = host.ip, 
+                    mac     = host.mac,
+                    name    = host.name,
+                    gw      = host.gw,
+                    seen    = unicode(html.div(host.seen())),
+                    state       = host.state,
+                    state_class = host.state_class(),
+
+                    t       = dt2ts(host.last_seen), 
+                ) for host in hosts]
             
             else :
                 hosts = []
@@ -506,13 +521,33 @@
         params = dict(
             url     = self.url(),
             t       = dt2ts(self.t),
+            host    = self.url(ItemHandler, id='0'),
         )
         params = json.dumps(params)
+        
+        COLUMNS = (
+            '#', 'IP', 'MAC', 'Hostname', 'Network', 'Seen', 'State'
+        )
 
-        return (
-            html.input(type='submit', id='refresh', value="Refresh", _selfclosing=False),
-            html.ul(id='hosts')(
-                html.li(id=host.id)("{host.ip} / {host.mac}".format(host=host)) for host in self.hosts
+        return html.div(id='wrapper')(
+            html.input(type='submit', id='refresh', value="Refresh"),
+            html.table(id='hosts')(
+                html.thead(
+                    html.tr(
+                        html.th(title) for title in COLUMNS
+                    ),
+                ),
+                html.tbody(
+                    html.tr(id=host.id)(
+                        html.td(html.a(href=self.url(ItemHandler, id=host.id))('#')),
+                        (
+                            html.td(value) for value in (
+                                host.ip, host.mac, host.name, host.gw, host.seen(),
+                            )
+                        ),
+                        html.td(class_=host.state_class())(host.state),
+                    ) for host in self.hosts
+                )
             ),
             html.script(type='text/javascript')("""
 $(document).ready(hosts_realtime({params}));