|
From: <tob...@us...> - 2014-02-17 19:20:18
|
Revision: 7849
http://bigdata.svn.sourceforge.net/bigdata/?rev=7849&view=rev
Author: tobycraig
Date: 2014-02-17 19:20:06 +0000 (Mon, 17 Feb 2014)
Log Message:
-----------
Added initial navigator functionality, allowing vertex exploration.
Modified Paths:
--------------
branches/RDR/bigdata-war/src/html/index.html
branches/RDR/bigdata-war/src/html/workbench.js
Modified: branches/RDR/bigdata-war/src/html/index.html
===================================================================
--- branches/RDR/bigdata-war/src/html/index.html 2014-02-17 15:40:41 UTC (rev 7848)
+++ branches/RDR/bigdata-war/src/html/index.html 2014-02-17 19:20:06 UTC (rev 7849)
@@ -5,6 +5,11 @@
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
<title>bigdata® NanoSparqlServer</title>
<!-- $Id$ -->
+<style>
+td {
+ border: 1px solid;
+}
+</style>
</head>
<body>
@@ -174,6 +179,15 @@
Response:
<pre id="response"></pre>
+<h2>Navigator</h2>
+Enter a URI to begin navigation
+<br>
+<form id="navigator">
+<input type="text" id="navigator-uri">
+<input type="submit">
+</form>
+<div id="navigator-display"></div>
+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/jquery.min.js"><\/script>')</script>
<script src="/workbench.js"></script>
Modified: branches/RDR/bigdata-war/src/html/workbench.js
===================================================================
--- branches/RDR/bigdata-war/src/html/workbench.js 2014-02-17 15:40:41 UTC (rev 7848)
+++ branches/RDR/bigdata-war/src/html/workbench.js 2014-02-17 19:20:06 UTC (rev 7849)
@@ -1,3 +1,5 @@
+/* Multi purpose data entry */
+
function handleDragOver(e) {
e.stopPropagation();
e.preventDefault();
@@ -181,3 +183,115 @@
function updateResponseError(jqXHR, textStatus, errorThrown) {
$('#response').text('Error! ' + textStatus + ' ' + errorThrown);
}
+
+
+/* Navigator */
+
+$('#navigator').submit(function() {
+ // get URI
+ var uri = $('#navigator-uri').val();
+ if(uri) {
+ loadURI(uri);
+ }
+ return false;
+});
+
+function loadURI(uri) {
+ // send query to server
+ var query = 'select * \
+ where { \
+ bind (<URI> as ?vertex) . \
+ { \
+ bind (<<?vertex ?p ?o>> as ?sid) . \
+ optional \
+ { \
+ { \
+ ?sid ?sidP ?sidO . \
+ } union { \
+ ?sidS ?sidP ?sid . \
+ } \
+ } \
+ } union { \
+ bind (<<?s ?p ?vertex>> as ?sid) . \
+ optional \
+ { \
+ { \
+ ?sid ?sidP ?sidO . \
+ } union { \
+ ?sidS ?sidP ?sid . \
+ } \
+ } \
+ } \
+ }';
+
+ query = query.replace('URI', uri);
+ var settings = {
+ type: 'POST',
+ data: 'query=' + encodeURI(query),
+ dataType: 'json',
+ accepts: {'json': 'application/sparql-results+json'},
+ success: updateNavigationStart,
+ error: updateNavigationError
+ };
+ $.ajax('/sparql', settings);
+}
+
+function updateNavigationStart(data, textStatus, jqXHR) {
+ var disp = $('#navigator-display');
+ disp.html('');
+ // see if we got any results
+ if(data.results.bindings.length == 0) {
+ disp.append('No vertex found!');
+ return;
+ }
+
+ var vertex = data.results.bindings[0].vertex;
+ disp.append('<h3>' + vertex.value + '</h3>');
+ var outbound=[], inbound=[], attributes=[];
+ for(var i=0; i<data.results.bindings.length; i++) {
+ var binding = data.results.bindings[i];
+ // TODO: are attributes always on outbound relationships?
+ if('o' in binding) {
+ if(binding.o.type == 'uri') {
+ outbound.push(binding);
+ } else {
+ attributes.push(binding);
+ }
+ } else {
+ inbound.push(binding);
+ }
+ }
+
+ if(outbound.length) {
+ disp.append('<h4>Outbound links</h4>');
+ var table = $('<table>').appendTo(disp);
+ for(var i=0; i<outbound.length; i++) {
+ var linkAttributes = outbound[i].sidP.value + ': ' + outbound[i].sidO.value;
+ table.append('<tr><td>' + outbound[i].p.value + '</td><td><a href="#">' + outbound[i].o.value + '</a></td><td>' + linkAttributes + '</td></tr>');
+ }
+ }
+
+ if(inbound.length) {
+ disp.append('<h4>Inbound links</h4>');
+ var table = $('<table>').appendTo(disp);
+ for(var i=0; i<inbound.length; i++) {
+ var linkAttributes = inbound[i].sidP.value + ': ' + inbound[i].sidO.value;
+ table.append('<tr><td><a href="#">' + inbound[i].s.value + '</a></td><td>' + inbound[i].p.value + '</td><td>' + linkAttributes + '</td></tr>');
+ }
+ }
+
+ if(attributes.length) {
+ disp.append('<h4>Attributes</h4>');
+ var table = $('<table>').appendTo(disp);
+ for(var i=0; i<attributes.length; i++) {
+ table.append('<tr><td>' + attributes[i].p.value + '</td><td>' + attributes[i].o.value + '</td></tr>');
+ }
+ }
+
+ disp.find('a').click(function() { loadURI(this.text); return false; });
+}
+
+function updateNavigationError(jqXHR, textStatus, errorThrown) {
+ $('#navigator-display').html('Error! ' + textStatus + ' ' + errorThrown);
+}
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|