Changeset - 8b95d2865643
[Not reviewed]
default
0 4 0
drewp@bigasterisk.com - 12 years ago 2013-06-11 00:02:35
drewp@bigasterisk.com
subserver shows real submasters, stays live. pretty sweet
Ignore-this: 1eefab7d67bb6d8e386003a990e6f5c5
4 files changed with 67 insertions and 6 deletions:
0 comments (0 inline, 0 general)
bin/subserver
Show inline comments
 
@@ -6,12 +6,14 @@ dragging them into CC
 
from run_local import log
 
from twisted.internet import reactor
 
import twisted.internet.error
 
import sys, optparse, logging, json, os, subprocess
 
import cyclone.web, cyclone.httpclient, cyclone.websocket
 
from light9.rdfdb.syncedgraph import SyncedGraph
 
from rdflib import RDF
 
from light9.namespaces import L9
 
import pyjade.utils
 

	
 
try:
 
    import sys
 
    sys.path.append("../homeauto/lib")
 
    sys.path.append("/home/drewp/projects/homeauto/lib")
 
@@ -38,13 +40,12 @@ class Live(cyclone.websocket.WebSocketHa
 

	
 
    def messageReceived(self, message):
 
        log.info("got message %s" % message)
 
        self.sendMessage(message)
 
        
 
class Static(PrettyErrorHandler, cyclone.web.StaticFileHandler):
 
    # .xhtml pages can be get() without .xhtml on them
 
    def get(self, path, *args, **kw):
 
        if path == '':
 
            return self.respondStaticJade("light9/subserver/index.jade")
 

	
 
        if path == 'gui.js':
 
            return self.responseStaticCoffee('light9/subserver/gui.coffee')
 
@@ -76,14 +77,23 @@ if __name__ == "__main__":
 
    log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
 

	
 
    graph = SyncedGraph("subserver")
 

	
 
    d = {}
 
    def updateSubs():
 

	
 
        subs = []
 
        for sub in graph.subjects(RDF.type, L9['Submaster']):
 
            rec = {'uri' : sub}
 
            rec['isLocal'] = graph.contains((sub, RDF.type,
 
                                             L9['LocalSubmaster']))
 
            rec['label'] = graph.label(sub)
 
            subs.append(rec)
 
        
 
        d.clear()
 
        d.update({'subs':['a', 'b']})
 
        d.update({'subs': subs})
 
        sendToLiveClients(d=d)
 
    def onNewClient():
 
        sendToLiveClients(d=d)
 
        
 
    graph.addHandler(updateSubs)
 
    
light9/subserver/gui.coffee
Show inline comments
 

	
 
class Model
 
  constructor: ->
 
    @subs = ko.observable([])
 
    @showLocal = ko.observable(false)
 

	
 
model = new Model()
 

	
 
# this sort of works to stop clicks in <input> from following the
 
# submaster hyperlink, but it may make certain clicks act wrong
 
$('a').live('click', (ev) ->
 
  return false if ev.target.tagName == 'INPUT'
 
)
 

	
 
reconnectingWebSocket "ws://localhost:8052/live", (msg) ->
 
  model.subs(msg.subs) if msg.subs?
 

	
 

	
 
ko.applyBindings(model)
 
\ No newline at end of file
light9/subserver/index.jade
Show inline comments
 
doctype html
 
html
 
  head
 
    title subserver
 
    link(rel='stylesheet', href='style.css')
 
  body
 
    h1 subserver
 
    h1 Submasters
 

	
 
    div
 
      input(type='checkbox', data-bind='checked: showLocal', id='showLocal')
 
      label(for='showLocal') show local
 
    
 
    div(data-bind="foreach: subs")
 
      div(data-bind="text: JSON.stringify($data)")
 
      // ko if: $parent.showLocal() || !isLocal
 
      a(class='sub', data-bind="css: {local: isLocal},
 
                                attr: {href: uri}")
 
        div(data-bind="if: isLocal") (local)
 
        div
 
          | Label
 
          input(type="text", data-bind="value: label")
 
        div
 
          img()
 
      // /ko
 

	
 
    script(src="jquery-1.7.2.min.js")
 
    script(src="knockout-2.2.1.js")
 
    script(src="websocket.js")
 
    script(src="gui.js")
 
\ No newline at end of file
light9/subserver/style.css
Show inline comments
 
body {
 
  font-family: sans;
 
    font-family: sans;
 
    background: rgb(0, 0, 0);
 
    color: rgb(163, 163, 163);
 
}
 

	
 
a.sub {
 
    color: inherit;
 
    text-decoration: none;
 
}
 
    
 
.sub {
 
    border: 1px solid gray;
 
    border-radius: 15px;
 
    padding: 5px;
 
    margin: 5px;
 
    background: rgb(66, 66, 66);
 
    display: inline-block;
 
    vertical-align: top;
 
}
 
.sub.local {
 
    background: rgb(44, 44, 44);
 
}
 
.sub img {
 
    width: 180px;
 
    height: 90px;
 
    margin: 6px;
 
    background: -webkit-gradient(linear,right top,left bottom,color-stop(0,rgb(121, 120, 120)),color-stop(1,rgb(54, 54, 54)));
 
}
 

	
 
input[type=text] {
 
    border: 1px inset rgb(177, 177, 177);
 
    background: rgb(230, 230, 230);
 
    padding: 3px;
 
}
 
\ No newline at end of file
0 comments (0 inline, 0 general)