diff --git a/bin/subserver b/bin/subserver --- a/bin/subserver +++ b/bin/subserver @@ -45,11 +45,9 @@ class Live(cyclone.websocket.WebSocketHa class Static(PrettyErrorHandler, cyclone.web.StaticFileHandler): 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') + if path in ['', 'chases']: + return self.respondStaticJade("light9/subserver/%s.jade" % + (path or 'index')) oddlyPlaced = { "websocket.js": "light9/rdfdb/web/websocket.js", @@ -59,6 +57,11 @@ class Static(PrettyErrorHandler, cyclone self.write(open(oddlyPlaced[path]).read()) return + if path.endswith(".js") and path not in ['knockout-2.2.1.js']: + return self.responseStaticCoffee( + 'light9/subserver/%s' % + path.replace(".js", ".coffee")) # potential security hole + cyclone.web.StaticFileHandler.get(self, path, *args, **kw) def respondStaticJade(self, src): @@ -121,6 +124,15 @@ if __name__ == "__main__": d.clear() d.update({'subs': subs}) + + d['chases'] = [] + for chase in sorted(graph.subjects(RDF.type, L9['Chase'])): + fakeLabel = chase.rsplit('/', 1)[-1] + d['chases'].append({ + 'uri': chase, + 'label': fakeLabel, + }) + sendToLiveClients(d=d) def onNewClient(): sendToLiveClients(d=d) diff --git a/light9/subserver/chases.coffee b/light9/subserver/chases.coffee new file mode 100644 --- /dev/null +++ b/light9/subserver/chases.coffee @@ -0,0 +1,29 @@ +class Model + constructor: -> + @chases = ko.observable([]) + + subtermLink: (label, expr) => + "http://chase?"+$.param({ + subtermName: label + subtermExpr: expr + curve: label + }) + subtermExprs: (chase) => + [ + 'LABEL(t) * chase(t, names=LABEL, ontime=0.5, offset=0.2)'.replace(/LABEL/g, chase.label) + ] + + +model = new Model() + +# this sort of works to stop clicks in 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.chases(msg.chases) if msg.chases? + + +ko.applyBindings(model) \ No newline at end of file diff --git a/light9/subserver/chases.jade b/light9/subserver/chases.jade new file mode 100644 --- /dev/null +++ b/light9/subserver/chases.jade @@ -0,0 +1,22 @@ +doctype html +html + head + title subserver + link(rel='stylesheet', href='style.css') + body + h1 Chases + + div(data-bind="foreach: chases") + div.resource.chase + | Chase + a(data-bind="attr: {href: uri}, text: label") + h2 Subterms + ul(data-bind="foreach: $parent.subtermExprs($data)") + li: a.resource(data-bind="attr: {href: $root.subtermLink($parent.label, $data)}, text: $data") + + #status + + script(src="jquery-1.7.2.min.js") + script(src="knockout-2.2.1.js") + script(src="websocket.js") + script(src="chases.js") \ No newline at end of file diff --git a/light9/subserver/index.jade b/light9/subserver/index.jade --- a/light9/subserver/index.jade +++ b/light9/subserver/index.jade @@ -12,8 +12,7 @@ html div(data-bind="foreach: subs") // ko if: $parent.showLocal() || !isLocal - a(class='sub', data-bind="css: {local: isLocal}, - attr: {href: uri}") + a.resource.sub(data-bind="css: {local: isLocal}, attr: {href: uri}") div(data-bind="if: isLocal") (local) div | Label diff --git a/light9/subserver/style.css b/light9/subserver/style.css --- a/light9/subserver/style.css +++ b/light9/subserver/style.css @@ -3,18 +3,34 @@ body { background: rgb(0, 0, 0); color: rgb(163, 163, 163); } - -a.sub { +h2 { + margin: 0; + padding: 0; + font-size: 100%; +} +ul { + margin: 0; +} +.vari { + color: white; +} +a.resource { color: inherit; text-decoration: none; } - -.sub { + +.resource { border: 1px solid gray; - border-radius: 15px; + border-radius: 5px; padding: 5px; margin: 5px; background: rgb(66, 66, 66); + display: block; +} +.resource a { + color: rgb(150, 150, 255); +} +.sub { display: inline-block; vertical-align: top; } @@ -34,7 +50,10 @@ input[type=text] { padding: 3px; } #status { -position: fixed; -bottom: 10px; -right: 10px; - } \ No newline at end of file + position: fixed; + bottom: 10px; + right: 10px; +} +.chase { + background: rgb(75, 57, 72); +} \ No newline at end of file