Changeset - 891f2d75c686
[Not reviewed]
default
0 3 2
drewp@bigasterisk.com - 12 years ago 2013-06-14 05:30:45
drewp@bigasterisk.com
subserver now also serves some premade subterms with the defined chases
Ignore-this: dbf877dc234795252e5c913d7489aa11
5 files changed with 92 insertions and 11 deletions:
0 comments (0 inline, 0 general)
bin/subserver
Show inline comments
 
@@ -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)
light9/subserver/chases.coffee
Show inline comments
 
new file 100644
 
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 <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.chases(msg.chases) if msg.chases?
 

	
 

	
 
ko.applyBindings(model)
 
\ No newline at end of file
light9/subserver/chases.jade
Show inline comments
 
new file 100644
 
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
light9/subserver/index.jade
Show inline comments
 
@@ -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
light9/subserver/style.css
Show inline comments
 
@@ -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;
 
}
 
@@ -37,4 +53,7 @@ input[type=text] {
 
position: fixed;
 
bottom: 10px;
 
right: 10px;
 
}
 
.chase {
 
    background: rgb(75, 57, 72);
 
    }
 
\ No newline at end of file
0 comments (0 inline, 0 general)