Skip to content

Commit

Permalink
fix: remove jinja expressions from scholia.js
Browse files Browse the repository at this point in the history
Remove jinja expressions and pass some as arguments
  • Loading branch information
curibe committed Aug 9, 2021
1 parent afaa1c4 commit e6ec48e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
41 changes: 21 additions & 20 deletions scholia/app/static/scholia.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,13 @@ function sparqlToShortInchiKey(sparql, key, element, filename) {
sparqlToDataTable2(new_sparql, element, filename);

}
};


function workWithQ(q) {
function workWithQ(q,urlstatic) {
var url = 'https://www.wikidata.org/w/api.php?action=wbgetentities&ids=' +
q +
'&format=json&callback=?';

$.getJSON(url, function (data) {
var item = data.entities[q];
if ('en' in item.labels) {
Expand All @@ -557,14 +556,14 @@ function workWithQ(q) {
var detailsList = Array();
try {
var orcid = item.claims.P496[0].mainsnak.datavalue.value;
detailsList.push( '<a href="https://orcid.org/"><img alt="' +
'ORCID logo" src="{{ url_for(\'static\', filename=\'images/orcid_16x16.gif\') }}"' +
'width="16" height="16" hspace="4" /></a> <a href="https://orcid.org/' +
detailsList.push( '<a href="https://orcid.org/">' +
`<img alt="ORCID logo" src="${urlstatic}/images/orcid_16x16.gif" width="16" height="16" hspace="4" />` +
'</a> <a href="https://orcid.org/' +
encodeURI( orcid ) + '">https://orcid.org/' + escapeHTML( orcid ) + '</a>');
}
catch(e) {}

try {s
try {
var mastodonAccount = item.claims.P4033[0].mainsnak.datavalue.value;
var mastodonComponents = mastodonAccount.split("@");
if (mastodonComponents.length == 2) {
Expand Down Expand Up @@ -618,8 +617,8 @@ function workWithQ(q) {
"@type" : "Person" ,
"http://purl.org/dc/terms/conformsTo": { "@type": "CreativeWork", "@id": "https://bioschemas.org/profiles/Person/0.2-DRAFT-2019_07_19/" },
"description" : "A person" ,
"identifier" : "{{ q }}" ,
"mainEntityOfPage" : "http://www.wikidata.org/entity/{{ q }}"
"identifier" : q ,
"mainEntityOfPage" : "http://www.wikidata.org/entity/" + q
}
if ('en' in item.labels) {
bioschemasAnnotation.name = item.labels.en.value;
Expand All @@ -634,8 +633,8 @@ function workWithQ(q) {
"@context" : "https://schema.org",
"@type" : "ChemicalSubstance" ,
"http://purl.org/dc/terms/conformsTo": { "@type": "CreativeWork", "@id": "https://bioschemas.org/profiles/ChemicalSubstance/0.4-RELEASE/" },
"identifier" : "{{ q }}" ,
"url" : "http://www.wikidata.org/entity/{{ q }}"
"identifier" : q,
"url" : "http://www.wikidata.org/entity/" + q
}
if ('en' in item.labels) {
bioschemasAnnotation.name = item.labels.en.value;
Expand All @@ -650,7 +649,7 @@ function workWithQ(q) {
"@type" : "Taxon" ,
"http://purl.org/dc/terms/conformsTo": { "@type": "CreativeWork", "@id": "https://bioschemas.org/profiles/Taxon/0.6-RELEASE/" },
"name" : taxonName ,
"url" : "http://www.wikidata.org/entity/{{ q }}"
"url" : "http://www.wikidata.org/entity/" + q
}
if (item.claims.P105) {
var taxonRank = item.claims.P105[0].mainsnak.datavalue.value.id;
Expand All @@ -670,9 +669,9 @@ function workWithQ(q) {
"@context" : "https://schema.org",
"@type" : "MolecularEntity" ,
"http://purl.org/dc/terms/conformsTo": { "@type": "CreativeWork", "@id": "https://bioschemas.org/profiles/MolecularEntity/0.5-RELEASE/" },
"identifier" : "{{ q }}" ,
"identifier" : q,
"inChIKey" : inchiKey ,
"url" : "http://www.wikidata.org/entity/{{ q }}"
"url" : "http://www.wikidata.org/entity/" + q
}
if ('en' in item.labels) {
bioschemasAnnotation.name = item.labels.en.value;
Expand Down Expand Up @@ -702,8 +701,8 @@ function workWithQ(q) {
"@context" : "https://schema.org",
"@type" : "Protein" ,
"http://purl.org/dc/terms/conformsTo": { "@type": "CreativeWork", "@id": "https://bioschemas.org/profiles/Protein/0.11-RELEASE/" },
"identifier" : "{{ q }}" ,
"url" : "http://www.wikidata.org/entity/{{ q }}" ,
"identifier" : q ,
"url" : "http://www.wikidata.org/entity/" + q ,
"sameAs": "https://www.uniprot.org/uniprot/" + uniprot
}
if ('en' in item.labels) {
Expand All @@ -718,8 +717,8 @@ function workWithQ(q) {
"@context" : "https://schema.org",
"@type" : "Gene" ,
"http://purl.org/dc/terms/conformsTo": { "@type": "CreativeWork", "@id": "https://bioschemas.org/profiles/Gene/0.7-RELEASE/" },
"identifier" : "{{ q }}" ,
"url" : "http://www.wikidata.org/entity/{{ q }}"
"identifier" : q ,
"url" : "http://www.wikidata.org/entity/" + q
}
if ('en' in item.labels) {
bioschemasAnnotation.name = item.labels.en.value;
Expand Down Expand Up @@ -882,9 +881,11 @@ function wembedder(q) {

}

function searchTerm(placeholder) {
function searchTerm(placeholder, urlfor) {

let search_text = ""


$('#searchterm').select2({
allowClear: true,
placeholder: placeholder,
Expand All @@ -907,7 +908,7 @@ function searchTerm(placeholder) {
var results = [{id: -1, text: "Advanced search"}];
$.each(data.search, function (index, item) {
results.push({
id: "{{ url_for('app.index') }}" + item.title,
id: urlfor + item.title,
text: item.label + " - " + item.description
});
});
Expand Down
5 changes: 3 additions & 2 deletions scholia/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

{% if q %}

workWithQ("{{ q }}")
workWithQ("{{ q }}", urlstatic="{{ url_for('static',filename='') }}")

{% if q2 %}
workWithQ2("{{ q2 }}")
Expand All @@ -119,7 +119,8 @@
$(document).ready(function () {
searchTerm(placeholder=`{{
"Scientist, paper, topic, DOI, etc." if request.path.endswith("search") else "Search ..."
}}`)
}}`,
urlfor="{{ url_for('app.index') }}")

// Add anchor links to all headings
var headers = document.querySelectorAll('h2[id], h3[id]')
Expand Down

0 comments on commit e6ec48e

Please sign in to comment.