@@ -96,69 +96,74 @@ function convertDataTableData(data, columns) {
9696 }
9797 }
9898 for ( var i = 0 ; i < data . length ; i ++ ) {
99- var convertedRow = { } ;
100- for ( var key in data [ i ] ) {
101- if ( key . slice ( - 11 ) == 'Description' ) {
102- convertedRow [ key . slice ( 0 , key . length - 11 ) + ' description' ] = data [ i ] [ key ] ;
99+ var convertedRow = { } ;
100+ for ( var key in data [ i ] ) {
101+ if ( key . slice ( - 11 ) == 'Description' ) {
102+ convertedRow [ key . slice ( 0 , key . length - 11 ) + ' description' ] = data [ i ] [ key ] ;
103103
104- } else if (
105- key + 'Label' in data [ i ] &&
104+ } else if (
105+ key + 'Label' in data [ i ] &&
106106 key + 'Url' in data [ i ]
107- ) {
107+ ) {
108108 convertedRow [ key ] = '<a href="' +
109- data [ i ] [ key + 'Url' ] +
110- '">' + data [ i ] [ key + 'Label' ] + '</a>' ;
109+ data [ i ] [ key + 'Url' ] +
110+ '">' + data [ i ] [ key + 'Label' ] + '</a>' ;
111111
112- } else if ( key . slice ( - 17 ) == 'ChemicalStructure' ) {
112+ } else if ( key . slice ( - 17 ) == 'ChemicalStructure' ) {
113113 convertedRow [ key . slice ( 0 , key . length - 17 ) + ' structure' ] = '<img loading="lazy" src="' +
114114 'https://cdkdepict.toolforge.org/depict/bow/svg?smi=' +
115- encodeURIComponent ( data [ i ] [ key ] ) +
115+ encodeURIComponent ( data [ i ] [ key ] ) +
116116 '&abbr=on&hdisp=bridgehead&showtitle=false&zoom=2&annotate=cip' +
117- '" />' ;
117+ '" />' ;
118118
119- } else if (
120- key + 'Label' in data [ i ] &&
121- / ^ h t t p / . test ( data [ i ] [ key ] ) &&
122- data [ i ] [ key ] . length > 30
123- ) {
124- convertedRow [ key ] = '<a href="../' +
125- data [ i ] [ key ] . slice ( 31 ) +
126- '">' + data [ i ] [ key + 'Label' ] + '</a>' ;
119+ } else if (
120+ key + 'Label' in data [ i ] &&
121+ / ^ h t t p / . test ( data [ i ] [ key ] ) &&
122+ data [ i ] [ key ] . length > 30
123+ ) {
124+ convertedRow [ key ] = '<a href="../' +
125+ data [ i ] [ key ] . slice ( 31 ) +
126+ '">' + data [ i ] [ key + 'Label' ] + '</a>' ;
127127
128128 } else if ( key . slice ( - 5 ) == 'Label' ) {
129- // pass
130-
131- } else if ( key + 'Url' in data [ i ] ) {
132- convertedRow [ key ] = '<a href="' +
133- data [ i ] [ key + 'Url' ] +
134- '">' + data [ i ] [ key ] + '</a>' ;
135-
136- } else if ( key . slice ( - 3 ) == 'Url' ) {
137- // pass
138-
139- } else if ( key . slice ( - 3 ) == 'url' ) {
140- // Convert URL to a link
141- convertedRow [ key ] = "<a href='" +
142- data [ i ] [ key ] + "'>" +
143- $ ( "<div>" ) . text ( data [ i ] [ key ] ) . html ( ) + '</a>' ;
144-
145- } else if ( key == 'orcid' ) {
146- // Add link to ORCID website
147- convertedRow [ key ] = '<a href="https://orcid.org/' +
148- data [ i ] [ key ] + '">' +
149- data [ i ] [ key ] + '</a>' ;
150-
151- } else if ( key == 'doi' ) {
152- // Add link to Crossref
153- convertedRow [ key ] = '<a href="https://doi.org/' +
154- encodeURIComponent ( data [ i ] [ key ] ) + '">' +
155- $ ( "<div>" ) . text ( data [ i ] [ key ] ) . html ( ) + '</a>' ;
156-
157- } else {
158- convertedRow [ key ] = data [ i ] [ key ] ;
159- }
160- }
161- convertedData . push ( convertedRow ) ;
129+ // pass
130+
131+ } else if ( key + 'Url' in data [ i ] ) {
132+ convertedRow [ key ] = '<a href="' +
133+ data [ i ] [ key + 'Url' ] +
134+ '">' + data [ i ] [ key ] + '</a>' ;
135+
136+ } else if ( key . slice ( - 3 ) == 'Url' ) {
137+ // pass
138+
139+ } else if ( key . slice ( - 3 ) == 'url' ) {
140+ // Convert URL to a link
141+ convertedRow [ key ] = "<a href='" +
142+ data [ i ] [ key ] + "'>" +
143+ $ ( "<div>" ) . text ( data [ i ] [ key ] ) . html ( ) + '</a>' ;
144+
145+ } else if ( key == 'orcid' ) {
146+ // Add link to ORCID website
147+ convertedRow [ key ] = '<a href="https://orcid.org/' +
148+ data [ i ] [ key ] + '">' +
149+ data [ i ] [ key ] + '</a>' ;
150+
151+ } else if ( key == 'doi' ) {
152+ // Add link to Crossref
153+ convertedRow [ key ] = '<a href="https://doi.org/' +
154+ encodeURIComponent ( data [ i ] [ key ] ) + '">' +
155+ $ ( "<div>" ) . text ( data [ i ] [ key ] ) . html ( ) + '</a>' ;
156+
157+ } else {
158+ var convertedRowValue = data [ i ] [ key ] ;
159+ if ( convertedRowValue . startsWith ( "http://www.wikidata.org/entity/Q" ) ) {
160+ var qid = convertedRowValue . slice ( 31 ) ;
161+ convertedRowValue = '<a href="../' + qid + '">' + qid + '</a>' ;
162+ }
163+ convertedRow [ key ] = convertedRowValue ;
164+ }
165+ }
166+ convertedData . push ( convertedRow ) ;
162167 }
163168 return { data : convertedData , columns : convertedColumns } ;
164169}
@@ -260,7 +265,7 @@ function sparqlToDataTablePost2(url, editURL, sparql, element, filename, options
260265 var paging = ( typeof options . paging === 'undefined' ) ? true : options . paging ;
261266 var sDom = ( typeof options . sDom === 'undefined' ) ? 'lfrtip' : options . sDom ;
262267 var sparqlEndpointName = ( typeof options . sparqlEndpointName === 'undefined' )
263- ? window . jsConfig . sparqlEndpointName : options . sparqlEndpointName ;
268+ ? window . jsConfig . sparqlEndpointName : options . sparqlEndpointName ;
264269
265270 $ ( element ) . html ( "<div class='loader'><div></div><div></div><div></div></div>" ) ;
266271
@@ -277,7 +282,7 @@ function sparqlToDataTablePost2(url, editURL, sparql, element, filename, options
277282 } ;
278283 columns . push ( column ) ;
279284 }
280-
285+
281286 if ( convertedData . data . length <= 10 ) {
282287 paging = false ;
283288 }
@@ -299,7 +304,7 @@ function sparqlToDataTablePost2(url, editURL, sparql, element, filename, options
299304 '<caption><span style="float:left; font-size:smaller;"><a href="' + editURL +
300305 encodeURIComponent ( sparql ) +
301306 '">' + sparqlEndpointName + '</a></span>' +
302- '<span style="float:right; font-size:smaller;"><a href="https://github.com/WDscholia /scholia/blob/main /scholia/app/templates/' +
307+ '<span style="float:right; font-size:smaller;"><a href="https://github.com/ad-freiburg /scholia/blob/qlever /scholia/app/templates/' +
303308 filename + '">' +
304309 filename . replace ( "_" , ": " ) +
305310 '</a></span></caption>'
@@ -359,7 +364,7 @@ function sparqlToDataTable2(url, editURL, sparql, element, filename, options = {
359364 var paging = ( typeof options . paging === 'undefined' ) ? true : options . paging ;
360365 var sDom = ( typeof options . sDom === 'undefined' ) ? 'lfrtip' : options . sDom ;
361366 var sparqlEndpointName = ( typeof options . sparqlEndpointName === 'undefined' )
362- ? window . jsConfig . sparqlEndpointName : options . sparqlEndpointName ;
367+ ? window . jsConfig . sparqlEndpointName : options . sparqlEndpointName ;
363368
364369 // overwrite the central URLs of SPARQL specific URLs are found
365370 configFromSPARQL = extractConfig ( sparql ) ;
@@ -372,7 +377,7 @@ function sparqlToDataTable2(url, editURL, sparql, element, filename, options = {
372377 const datatableFooter =
373378 '<caption><span style="float:left; font-size:smaller;"><a href="' + editURL +
374379 encodeURIComponent ( sparql ) + '">' + sparqlEndpointName + '</a></span>' +
375- '<span style="float:right; font-size:smaller;"><a href="https://github.com/WDscholia /scholia/blob/main /scholia/app/templates/' +
380+ '<span style="float:right; font-size:smaller;"><a href="https://github.com/ad-freiburg /scholia/blob/qlever /scholia/app/templates/' +
376381 filename +
377382 '">' +
378383 filename . replace ( '_' , ': ' ) +
@@ -484,11 +489,15 @@ function sparqlToDataTable2(url, editURL, sparql, element, filename, options = {
484489 }
485490 $ ( element ) . append ( datatableFooter ) ;
486491 }
487- } ) . fail ( function ( ) {
492+ } ) . fail ( function ( jqXHR , textStatus , errorThrown ) {
488493 $ ( '#' + loaderID ) . remove ( ) ; // remove loader
489- $ ( element ) . prepend (
490- '<p>This query has timed out, we recommend that you follow the link to the Wikidata Query Service below to modify the query to be less intensive. </p> '
491- ) ;
494+ let error_message = "" ;
495+ try {
496+ error_message = "QLever execption: " + JSON . parse ( jqXHR . responseText ) . exception ;
497+ } catch ( e ) {
498+ error_message = "getJSON query failed: " + textStatus + " " + errorThrown ;
499+ }
500+ $ ( element ) . prepend ( "<p style='color:red;'>" + escapeHTML ( error_message ) + "</p>" ) ;
492501 const reloadButton = document . getElementById ( element . slice ( 1 ) + '-reload' ) ;
493502 reloadButton . classList . add ( 'btn-secondary' ) ;
494503 reloadButton . classList . remove ( 'btn-outline-secondary' ) ;
@@ -516,6 +525,13 @@ function sparqlToIframe2(url, editURL, embedURL, sparql, element, filename) {
516525
517526 if ( ! embedURL ) embedURL = "https://query.wikidata.org/embed.html#" ;
518527
528+ // overwrite the central URLs of SPARQL specific URLs are found
529+ configFromSPARQL = extractConfig ( sparql ) ;
530+ if ( configFromSPARQL [ "url" ] ) url = configFromSPARQL [ "url" ] ;
531+ if ( configFromSPARQL [ "editURL" ] ) editURL = configFromSPARQL [ "editURL" ] ;
532+ if ( configFromSPARQL [ "embedURL" ] ) embedURL = configFromSPARQL [ "embedURL" ] ;
533+ if ( configFromSPARQL [ "endpointName" ] ) sparqlEndpointName = configFromSPARQL [ "endpointName" ] ;
534+
519535 const wikidata_sparql = url + "?query=" + encodeURIComponent ( sparql ) ;
520536 const wikidata_query = editURL + encodeURIComponent ( sparql ) ;
521537 var url = embedURL + encodeURIComponent ( sparql ) ;
@@ -549,6 +565,7 @@ function sparqlToIframe2(url, editURL, embedURL, sparql, element, filename) {
549565
550566 $ . ajax ( {
551567 url : wikidata_sparql ,
568+ headers : { Accept : "application/sparql-results+xml" } ,
552569 success : function ( data ) {
553570 let $xml = $ ( data ) ;
554571 let results = $xml . find ( 'results' ) ;
@@ -559,7 +576,7 @@ function sparqlToIframe2(url, editURL, embedURL, sparql, element, filename) {
559576 }
560577 $iframe . parent ( ) . after (
561578 '<span style="float:right; font-size:smaller">' +
562- '<a href="https://github.com/WDscholia /scholia/blob/main /scholia/app/templates/' + filename + '">' +
579+ '<a href="https://github.com/ad-freiburg /scholia/blob/qlever /scholia/app/templates/' + filename + '">' +
563580 filename . replace ( "_" , ": " ) +
564581 '</a>' +
565582 '</span>'
@@ -796,9 +813,12 @@ function askQuery(panel, askQuery, callback) {
796813
797814
798815function askQuery2 ( endpointUrl , panel , askQuery , callback ) {
799- if ( ! endpointUrl ) endpointUrl = "https://query.wikidata.org/sparql" ;
800-
801- var settings = {
816+ if ( ! endpointUrl ) endpointUrl = "https://query.wikidata.org/sparql" ;
817+ // overwrite the central URLs of SPARQL specific URLs are found
818+ configFromSPARQL = extractConfig ( askQuery ) ;
819+ if ( configFromSPARQL [ "url" ] ) endpointUrl = configFromSPARQL [ "url" ] ;
820+
821+ var settings = {
802822 headers : { Accept : 'application/sparql-results+json' } ,
803823 data : { query : askQuery } ,
804824 } ;
0 commit comments