Skip to content

Commit 249ed60

Browse files
committed
Adds support for SPARQL-level configuration
1 parent 0172d62 commit 249ed60

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

scholia/app/static/scholia.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,38 @@ function sparqlToDataTable(sparql, element, filename, options = {}) {
317317
}
318318

319319

320+
// helper method to extract config information from the SPARQL files.
321+
function extractConfig(sparql) {
322+
config = {};
323+
lines = sparql.split(/\r?\n/);
324+
lines.forEach(function(line, i) {
325+
line = line.replace(/ /g,'')
326+
if (line.startsWith("#sparql_endpoint=")) {
327+
// SPARQL endpoint against which this query should be executed
328+
var list = line.split("=")
329+
list.shift()
330+
config["url"] = list.join("=")
331+
} else if (line.startsWith("#sparql_endpoint_name=")) {
332+
// name of the SPARQL endpoint (to show up in the output)
333+
var list = line.split("=")
334+
list.shift()
335+
config["endpointName"] = list.join("=")
336+
} else if (line.startsWith("#sparql_editurl=")) {
337+
// URL pattern to give the SPARQL query in the endpoint editor
338+
var list = line.split("=")
339+
list.shift()
340+
config["editURL"] = list.join("=")
341+
} else if (line.startsWith("#sparql_embedurl=")) {
342+
// URL pattern for embeddable SPARQL endpoint results, e.g. for iframes
343+
var list = line.split("=")
344+
list.shift()
345+
config["embedURL"] = list.join("=")
346+
}
347+
});
348+
return config;
349+
}
350+
351+
320352
function sparqlToDataTable2(url, editURL, sparql, element, filename, options = {}) {
321353
// Options: paging=true
322354
if (!url) url = "https://query.wikidata.org/sparql";
@@ -326,10 +358,17 @@ function sparqlToDataTable2(url, editURL, sparql, element, filename, options = {
326358

327359
var paging = (typeof options.paging === 'undefined') ? true : options.paging;
328360
var sDom = (typeof options.sDom === 'undefined') ? 'lfrtip' : options.sDom;
329-
var url = url + "?query=" + encodeURIComponent(sparql) + '&format=json';
330361
var sparqlEndpointName = (typeof options.sparqlEndpointName === 'undefined')
331362
? window.jsConfig.sparqlEndpointName : options.sparqlEndpointName;
332363

364+
// overwrite the central URLs of SPARQL specific URLs are found
365+
configFromSPARQL = extractConfig(sparql);
366+
if (configFromSPARQL["url"]) url = configFromSPARQL["url"];
367+
if (configFromSPARQL["editURL"]) editURL = configFromSPARQL["editURL"];
368+
if (configFromSPARQL["endpointName"]) sparqlEndpointName = configFromSPARQL["endpointName"];
369+
370+
var url = url + "?query=" + encodeURIComponent(sparql) + '&format=json';
371+
333372
const datatableFooter =
334373
'<caption><span style="float:left; font-size:smaller;"><a href="' + editURL +
335374
encodeURIComponent(sparql) + '">' + sparqlEndpointName + '</a></span>' +

0 commit comments

Comments
 (0)