Mercurial > code > home > repos > homeauto
changeset 136:2200d6530a5d
testing rdfs:comment display on enironment's graph viewer
Ignore-this: d25c57b80a1dc4180b348d64f1546cd6
author | drewp@bigasterisk.com |
---|---|
date | Sun, 13 Oct 2013 12:03:26 -0700 |
parents | 88e7dd767550 |
children | 1952788e5299 |
files | service/environment/environment.py service/environment/index.html service/environment/rdfdoc.py |
diffstat | 3 files changed, 39 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/service/environment/environment.py Sun Oct 13 00:25:03 2013 -0700 +++ b/service/environment/environment.py Sun Oct 13 12:03:26 2013 -0700 @@ -41,6 +41,8 @@ self.set_header('Content-type', 'application/x-trig') self.write(g.asTrig()) + +from rdfdoc import Doc class Application(cyclone.web.Application): def __init__(self): @@ -48,6 +50,7 @@ (r"/()", cyclone.web.StaticFileHandler, {"path": ".", "default_filename": "index.html"}), (r'/graph', GraphHandler), + (r'/doc', Doc), # to be shared ] cyclone.web.Application.__init__(self, handlers)
--- a/service/environment/index.html Sun Oct 13 00:25:03 2013 -0700 +++ b/service/environment/index.html Sun Oct 13 12:03:26 2013 -0700 @@ -15,12 +15,13 @@ .literalType { vertical-align: super; font-size: 80%; } .literal { display: inline-block; border: 1px solid gray; background: white; } .resource { display: inline-block; background: lightblue; border-radius: 6px; padding: 1px 6px; margin: 2px; } - + .comment { color: green; } </style> <script type="text/html" id="node"> <!-- ko if: typeof($data) == 'string' --> - <span class="node resource" data-bind="html: $root.createCurie($data)"></span> <span data-bind="html: $root.docLink($data)"></span> + <span class="node resource" data-bind="html: $root.createCurie($data)"></span> + <span class="comment" data-bind="html: $root.docLink($data)"></span> <!-- /ko --> <!-- ko if: typeof($data) != 'string' --> <!-- ko if: type == 'literal' --> @@ -28,7 +29,8 @@ <span class="literalType" data-bind="html: $root.createCurie($data['datatype'] || '')"></span> <!-- /ko --> <!-- ko if: type == 'uri' --> - <span class="resource" data-bind="html: $root.createCurie(value)"></span> <span data-bind="html: $root.docLink($data)"></span> + <span class="resource" data-bind="html: $root.createCurie(value)"></span> + <span class="comment" data-bind="html: $root.docLink($data)"></span> <!-- /ko --> <!-- ko if: type == 'bnode' --> <span class="resource bnode" data-bind="text: value"></span> @@ -93,10 +95,18 @@ var short = tryCurie(uri); return '<a href="' + _.escape(uri) + '">' + _.escape(short) + '</a>'; }; + var docs = {}; // uri : observable(doc) model.docLink = function(uri) { - var result = ko.observable("..."); - setTimeout(function() { result('hey'); }, 1000); - return result; + if (uri.type == 'uri') { + uri = uri.value; + } + if (_.isUndefined(docs[uri])) { + docs[uri] = ko.observable("..."); + $.getJSON("doc", {uri: uri}, function(data) { + docs[uri](data.comment); // might be undefined + }); + } + return docs[uri]; }; model.refresh = function() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/service/environment/rdfdoc.py Sun Oct 13 12:03:26 2013 -0700 @@ -0,0 +1,20 @@ +# to be shared somewhere +import json, cyclone.web +from cycloneerr import PrettyErrorHandler +from rdflib import Graph, RDFS, URIRef + +graph = Graph() +graph.parse("docs.n3", format="n3") + +# maybe the web page could just query sesame over http and we drop this server +class Doc(PrettyErrorHandler, cyclone.web.RequestHandler): + def get(self): + uri = URIRef(self.get_argument('uri')) + + ret = {} + comment = graph.value(uri, RDFS.comment) + if comment is not None: + ret['comment'] = comment + + self.set_header("Content-type", "application/json") + self.write(json.dumps(ret))