Skip to content

Commit

Permalink
Merge branch '2429-config'
Browse files Browse the repository at this point in the history
  • Loading branch information
fnielsen committed Sep 5, 2024
2 parents 9eb28f3 + 4f593ae commit c4c89d4
Show file tree
Hide file tree
Showing 13 changed files with 502 additions and 109 deletions.
62 changes: 51 additions & 11 deletions scholia/app/static/scholia.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ function addReloadButton(element, callback) {
}
}

function sparqlToResponse(sparql, doneCallback) {
var endpointUrl = "https://query.wikidata.org/bigdata/namespace/wdq/sparql";
function sparqlToResponse2(endpointUrl, sparql, doneCallback) {
var settings = {
headers: { Accept: "application/sparql-results+json" },
data: { query: sparql },
Expand All @@ -218,6 +217,14 @@ function sparqlToResponse(sparql, doneCallback) {
}


function sparqlToResponse(sparql, doneCallback) {
return sparqlToResponse2(
"https://query.wikidata.org/bigdata/namespace/wdq/sparql",
sparql, doneCallback
);
}


function sparqlDataToSimpleData(response) {
// Convert long JSON data from from SPARQL endpoint to short form
let data = response.results.bindings;
Expand All @@ -235,10 +242,20 @@ function sparqlDataToSimpleData(response) {


function sparqlToDataTablePost(sparql, element, filename, options = {}) {
sparqlToDataTablePost2(
"https://query.wikidata.org/sparql",
"https://query.wikidata.org/",
sparql, element, filename, options
);
}


function sparqlToDataTablePost2(url, editURL, sparql, element, filename, options = {}) {
// Options: paging=
if (!url) url = "https://query.wikidata.org/sparql";
if (!editURL) editURL = "https://query.wikidata.org/";
var paging = (typeof options.paging === 'undefined') ? true : options.paging;
var sDom = (typeof options.sDom === 'undefined') ? 'lfrtip' : options.sDom;
var url = "https://query.wikidata.org/sparql";

$(element).html("<div class='loader'><div></div><div></div><div></div></div>");

Expand Down Expand Up @@ -274,7 +291,7 @@ function sparqlToDataTablePost(sparql, element, filename, options = {}) {
});

$(element).append(
'<caption><span style="float:left; font-size:smaller;"><a href="https://query.wikidata.org/#' +
'<caption><span style="float:left; font-size:smaller;"><a href="' + editURL +
encodeURIComponent(sparql) +
'">Wikidata Query Service</a></span>' +
'<span style="float:right; font-size:smaller;"><a href="https://github.com/WDscholia/scholia/blob/master/scholia/app/templates/' +
Expand All @@ -287,14 +304,24 @@ function sparqlToDataTablePost(sparql, element, filename, options = {}) {


function sparqlToDataTable(sparql, element, filename, options = {}) {
sparqlToDataTablePost2(
"https://query.wikidata.org/sparql",
"https://query.wikidata.org/",
sparql, element, filename, options
);
}


function sparqlToDataTable2(url, editURL, sparql, element, filename, options = {}) {
// Options: paging=true
if (!url) url = "https://query.wikidata.org/sparql";
if (!editURL) editURL = "https://query.wikidata.org/";
var paging = (typeof options.paging === 'undefined') ? true : options.paging;
var sDom = (typeof options.sDom === 'undefined') ? 'lfrtip' : options.sDom;
var url = "https://query.wikidata.org/sparql?query=" +
encodeURIComponent(sparql) + '&format=json';
var url = url + "?query=" + encodeURIComponent(sparql) + '&format=json';

const datatableFooter =
'<caption><span style="float:left; font-size:smaller;"><a href="https://query.wikidata.org/#' +
'<caption><span style="float:left; font-size:smaller;"><a href="' + editURL +
encodeURIComponent(sparql) +
'">Wikidata Query Service</a></span>' +
'<span style="float:right; font-size:smaller;"><a href="https://github.com/WDscholia/scholia/blob/master/scholia/app/templates/' +
Expand Down Expand Up @@ -416,14 +443,27 @@ function sparqlToDataTable(sparql, element, filename, options = {}) {


function sparqlToIframe(sparql, element, filename) {
sparqlToIframe2(
"https://query.wikidata.org/sparql",
"https://query.wikidata.org/",
"https://query.wikidata.org/embed.html#",
sparql, element, filename, options
);
}


function sparqlToIframe2(url, editURL, embedURL, sparql, element, filename) {
let $iframe = $(element);
var url = "https://query.wikidata.org/embed.html#" + encodeURIComponent(sparql);
if (!url) url = "https://query.wikidata.org/sparql";
if (!editURL) editURL = "https://query.wikidata.org/";
if (!embedURL) embedURL = "https://query.wikidata.org/embed.html#";

const wikidata_sparql = url + "?query=" + encodeURIComponent(sparql);
const wikidata_query = editURL + encodeURIComponent(sparql);
var url = embedURL + encodeURIComponent(sparql);
$iframe.attr('data-src', url);
$iframe.attr('loading', 'lazy');

const wikidata_sparql = "https://query.wikidata.org/sparql?query=" + encodeURIComponent(sparql);
const wikidata_query = "https://query.wikidata.org/#" + encodeURIComponent(sparql);

// Define the options for the Intersection Observer
const options = {
root: null,
Expand Down
4 changes: 2 additions & 2 deletions scholia/app/templates/author-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ <h4 class="my-0 font-weight-normal">Redirects</h4>
resolver: 'custom',
events: {
search: debounce((searchTerm, callback) => {
var url = "https://query.wikidata.org/sparql";
var url = "{{ sparql_endpoint }}";
var settings = {
data: {
query: `
Expand Down Expand Up @@ -211,7 +211,7 @@ <h4 class="my-0 font-weight-normal">Redirects</h4>
multiple: true,
ajax: {
delay: 300,
url: "https://query.wikidata.org/sparql",
url: "{{ sparql_endpoint }}",
data: function (params) {
let search_author = params.term
return {
Expand Down
13 changes: 8 additions & 5 deletions scholia/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

{% macro sparql_to_table_post(panel, options={}) -%}
// {{ panel }} table
sparqlToDataTablePost(`# tool: scholia
sparqlToDataTablePost2("{{ sparql_endpoint }}", "{{ sparql_editURL }}",
`# tool: scholia
{% include aspect + '_' + panel + '.sparql' %}
`,
"#{{ panel }}-table", "{{ aspect }}_{{ panel }}.sparql",
Expand All @@ -11,7 +12,8 @@

{% macro sparql_to_table(panel, options={}) -%}
// {{ panel }} table
sparqlToDataTable(`# tool: scholia
sparqlToDataTable2("{{ sparql_endpoint }}", "{{ sparql_editURL }}",
`# tool: scholia
{% include aspect + '_' + panel + '.sparql' %}
`,
"#{{ panel }}-table", "{{ aspect }}_{{ panel }}.sparql",
Expand All @@ -20,7 +22,8 @@

{% macro sparql_to_iframe(panel) -%}
// {{ panel }} iframe
sparqlToIframe(`# tool: scholia
sparqlToIframe2("{{ sparql_endpoint }}", "{{ sparql_editURL }}",
"{{ sparql_embedURL }}", `# tool: scholia
{% include aspect + '_' + panel + '.sparql' %}`,
"#{{ panel }}-iframe", "{{ aspect }}_{{ panel }}.sparql");
{%- endmacro %}
Expand Down Expand Up @@ -475,7 +478,7 @@
curationElement.classList.remove("d-none");

// this query opens the Wikidata item as a different aspect
var endpointUrl = 'https://query.wikidata.org/sparql';
var endpointUrl = '{{ sparql_endpoint }}';
if ("{{q2}}".length) {
var query = `
SELECT DISTINCT ?aspect
Expand Down Expand Up @@ -552,7 +555,7 @@
}
}).then(function () {
if ("{{q2}}".length) {
var endpointUrl = 'https://query.wikidata.org/sparql';
var endpointUrl = '{{ sparql_endpoint }}';
var query = "SELECT DISTINCT ?aspect WHERE {"
query += '{ [] wdt:P921 wd:{{ q }} . BIND("topic" AS ?aspect) } }';

Expand Down
Loading

0 comments on commit c4c89d4

Please sign in to comment.