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
 
@@ -9,6 +9,8 @@ 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:
 
@@ -41,7 +43,6 @@ class Live(cyclone.websocket.WebSocketHa
 
        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")
 
@@ -79,8 +80,17 @@ if __name__ == "__main__":
 

	
 
    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)
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?
 

	
light9/subserver/index.jade
Show inline comments
 
@@ -4,10 +4,23 @@ html
 
    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")
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)