diff --git a/README.md b/README.md index e4f8dc427f9dd6cdec674a6354b7a362360f1614..04c9e2fe138b949ff612fb1e99e52ebdd7a2d424 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ LODSPeaKr author: Alvaro Graves (alvaro@graves.cl) -version: 20121107 +version: 20121218 [LODSPeaKr](http://lodspeakr.org) is a framework for creating Linked Data applications in a simple and easy way. You can see [several applications](http://alangrafu.github.com/lodspeakr/applications.html) created using LODSPeaKr. diff --git a/classes/modules/adminModule.php b/classes/modules/adminModule.php index 610b1c2faa8d210e65cd9696d760c9aea7821153..af832c1ee32809848e3d23415a268f6613969cfe 100644 --- a/classes/modules/adminModule.php +++ b/classes/modules/adminModule.php @@ -559,7 +559,7 @@ class AdminModule extends abstractModule{ $selected = ""; if($k == "local") $selected = 'selected'; - $endpointOptions .= "<option $selected value='$v'>$k ($v)</option>"; + $endpointOptions .= "<option $selected value='$k'>$k ($v)</option>"; } $namespaces = "var ns = ".json_encode($conf['ns']); $lastComponentType=""; @@ -688,12 +688,41 @@ class AdminModule extends abstractModule{ }else{ HTTPStatus::send404($params[1]); } - break; + break; + case "query": + $this->queryEndpoint($_POST); + break; default: HTTPStatus::send404($params[1]); } } + protected function queryEndpoint($data){ + global $endpoints; + global $conf; + $query = $data['query']; + $endpoint = $data['endpoint']; + if(isset($endpoint) && isset($conf['endpoint'][$endpoint])){ + if(!isset($endpoints[$endpoint])){ + $e = new Endpoint($conf['endpoint'][$endpoint], $conf['endpoint']['config']); + }else{ + $e = $endpoints[$endpoint]; + } + $aux = $e->query($query, Utils::getResultsType($query)); + header("Content-type: ".$data['format']); + $jaux = json_encode($aux); + if(isset($jaux)){ + echo $jaux; + }else{ + echo $aux; + HTTPStatus::send404($params[1]); + } + }else{ + echo "no endpoint"; + HTTPStatus::send404($params[1]); + } + } + protected function getComponentDetails($params){ $componentType = $params[0]; $componentName = $params[1]; diff --git a/common.inc.php b/common.inc.php index 0fe23cdc77274aa40f8c5f2745f0055801b9c033..7abefeaff01d467a4feea2bc60317fc1b40af626 100644 --- a/common.inc.php +++ b/common.inc.php @@ -1,6 +1,6 @@ <?php -$conf['version'] = '20121107'; +$conf['version'] = '20121218'; $conf['output']['select'] = 'json'; $conf['output']['ask'] = 'json'; $conf['output']['describe'] = 'rdf'; diff --git a/doc/examples/originalComponents/static/admin/js/editor.js b/doc/examples/originalComponents/static/admin/js/editor.js index d610571d4c90780d6cc0facb1c83cd5deffe5cb8..c292873c48775744ab619c199c3bcbba4d362927 100644 --- a/doc/examples/originalComponents/static/admin/js/editor.js +++ b/doc/examples/originalComponents/static/admin/js/editor.js @@ -247,37 +247,43 @@ $(document).ready(function(){ function executeQuery(q, e){ return $.ajax({ + type: 'POST', data: { query: q, + endpoint: e, format: 'application/sparql-results+json' }, - url: e, + url: 'components/query', success: function(d){ var data = d; - if($.isXMLDoc(d)){ - alert("XML"); - console.log(d); - data = d.sparql;//$.parseXML(); - console.log(data); + if(data == undefined){ + $("#results-msg").html("An error occurred when sending a query to the endpoint").show().delay(2000).fadeOut("slow"); + }else{ + if($.isXMLDoc(d)){ + alert("XML"); + console.log(d); + data = d.sparql;//$.parseXML(); + console.log(data); + } + var variables = new Array(); + var header = $("<tr></tr>"); + $(data.head.vars).each(function(i, item){ + variables.push(item); + header.append("<td><strong>"+item+"</strong></td>"); + }); + $("#results").append(header); + $(data.results.bindings).each(function(i, item){ + var row = $("<tr></tr>"); + $.each(variables, function(j, jtem){ + var value = ""; + if(item[jtem] != undefined){ + value = item[jtem].value; + } + row.append("<td>"+value+"</td>"); + }); + $("#results").append(row); + }); } - var variables = new Array(); - var header = $("<tr></tr>"); - $(data.head.vars).each(function(i, item){ - variables.push(item); - header.append("<td><strong>"+item+"</strong></td>"); - }); - $("#results").append(header); - $(data.results.bindings).each(function(i, item){ - var row = $("<tr></tr>"); - $.each(variables, function(j, jtem){ - var value = ""; - if(item[jtem] != undefined){ - value = item[jtem].value; - } - row.append("<td>"+value+"</td>"); - }); - $("#results").append(row); - }); $("#query-test-button").addClass('btn-success').html('Test this query against'); }, error: function(e){