|
From: <tob...@us...> - 2014-03-01 00:13:02
|
Revision: 7903
http://sourceforge.net/p/bigdata/code/7903
Author: tobycraig
Date: 2014-03-01 00:12:57 +0000 (Sat, 01 Mar 2014)
Log Message:
-----------
#830 - Output RDF data from CONSTRUCT query in table
Modified Paths:
--------------
branches/RDR/bigdata-war/src/html/workbench.js
Modified: branches/RDR/bigdata-war/src/html/workbench.js
===================================================================
--- branches/RDR/bigdata-war/src/html/workbench.js 2014-02-28 19:56:28 UTC (rev 7902)
+++ branches/RDR/bigdata-war/src/html/workbench.js 2014-03-01 00:12:57 UTC (rev 7903)
@@ -344,8 +344,7 @@
var settings = {
type: 'POST',
data: $(this).serialize(),
- dataType: 'json',
- accepts: {'json': 'application/sparql-results+json'},
+ headers: { 'Accept': 'application/sparql-results+json, application/rdf+xml' },
success: showQueryResults,
error: queryResultsError
}
@@ -375,21 +374,48 @@
function showQueryResults(data) {
$('#query-response').empty();
var table = $('<table>').appendTo($('#query-response'));
- var thead = $('<thead>').appendTo(table);
- var vars = [];
- var tr = $('<tr>');
- for(var i=0; i<data.head.vars.length; i++) {
- tr.append('<td>' + data.head.vars[i] + '</td>');
- vars.push(data.head.vars[i]);
- }
- thead.append(tr);
- table.append(thead);
- for(var i=0; i<data.results.bindings.length; i++) {
+ if(this.dataTypes[1] == 'xml') {
+ // RDF
+ table.append($('<thead><tr><td>s</td><td>p</td><td>o</td></tr></thead>'));
+ var rows = $(data).find('Description');
+ for(var i=0; i<rows.length; i++) {
+ // FIXME: are about and nodeID the only possible attributes here?
+ var s = rows[i].attributes['rdf:about'];
+ if(typeof(s) == 'undefined') {
+ s = rows[i].attributes['rdf:nodeID'];
+ }
+ s = s.textContent;
+ for(var j=0; j<rows[i].children.length; j++) {
+ var p = rows[i].children[j].tagName;
+ var o = rows[i].children[j].attributes['rdf:resource'];
+ // FIXME: is this the correct behaviour?
+ if(typeof(o) == 'undefined') {
+ o = rows[i].children[j].textContent;
+ } else {
+ o = o.textContent;
+ }
+ var tr = $('<tr><td>' + (j == 0 ? s : '') + '</td><td>' + p + '</td><td>' + o + '</td>');
+ table.append(tr);
+ }
+ }
+ } else {
+ // JSON
+ var thead = $('<thead>').appendTo(table);
+ var vars = [];
var tr = $('<tr>');
- for(var j=0; j<vars.length; j++) {
- tr.append('<td>' + data.results.bindings[i][vars[j]].value + '</td>');
+ for(var i=0; i<data.head.vars.length; i++) {
+ tr.append('<td>' + data.head.vars[i] + '</td>');
+ vars.push(data.head.vars[i]);
}
- table.append(tr);
+ thead.append(tr);
+ table.append(thead);
+ for(var i=0; i<data.results.bindings.length; i++) {
+ var tr = $('<tr>');
+ for(var j=0; j<vars.length; j++) {
+ tr.append('<td>' + data.results.bindings[i][vars[j]].value + '</td>');
+ }
+ table.append(tr);
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|