Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add links to curation pages #1556

Merged
merged 6 commits into from
Feb 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions scholia/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
var url = 'https://www.wikidata.org/w/api.php?action=wbgetentities&ids=' +
'{{ q }}' +
'&format=json&callback=?';

const currentAspect = window.location.pathname.split("/")[1];

$.getJSON(url, function (data) {
var item = data.entities["{{ q }}"];
Expand All @@ -100,6 +102,7 @@
$("title").text(title + " - Scholia");

{% if request.path.endswith("curation") or request.path.endswith("curation/") %}
$("#h1").text("Improve " + currentAspect + ": " + title);

var linkedToFrom = "<p><a href='https://www.wikidata.org/w/index.php?hidecategorization=1&target={{ q }}&showlinkedto=1&limit=500&days=7&enhanced=1&title=Special:RecentChangesLinked&urlversion=2' >";
linkedToFrom += "Recent changes to items that link <em>to</em> " + $('<div>').text(title).html() + "</a> and ";
Expand Down Expand Up @@ -378,7 +381,17 @@
}

});


var curationElement = document.getElementById("curation-link");

{% if request.path.endswith("curation") or request.path.endswith("curation/") %}
curationElement.innerText = "Back"
curationElement.href = "/" + currentAspect + "/{{ q }}";
{% else %}
curationElement.href = "/" + currentAspect + "/{{ q }}/curation";
{% endif %}
curationElement.classList.remove("d-none");

// this query opens the Wikidata item as a different aspect
var endpointUrl = 'https://query.wikidata.org/sparql';
if ("{{q2}}".length) {
Expand Down Expand Up @@ -444,7 +457,6 @@
};

$.ajax(endpointUrl, settings).then(function (data) {
var currentAspect = window.location.pathname.split("/")[1];
createDropdownButton("aspect-chooser", 'aspectMenuButton', currentAspect, data, "{{q}}")

if (data.results.bindings.length > 1) {
Expand All @@ -462,7 +474,6 @@
};

$.ajax(endpointUrl, settings).then(function (data) {
var currentAspect = window.location.pathname.split("/")[1];
var aspectLabel = " / <a href='/" + currentAspect + "/{{q}}'>{{q}}</a> / "
document.getElementById("aspect-chooser-label").innerHTML = aspectLabel;

Expand All @@ -483,6 +494,15 @@
aspectDropdown.type = 'button';
aspectDropdown.id = id;
aspectDropdown.classList = 'btn btn-outline-secondary';

// only show aspects which have a curation page with author-disambig or wikidata links
var validCurationPages = ["author", "award", "organization", "topic", "venue"]
{% if request.path.endswith("curation") or request.path.endswith("curation/") %}
data.results.bindings = data.results.bindings.filter(elem => {
return validCurationPages.indexOf(elem.aspect.value) != -1
})
{% endif %}

if (data.results.bindings.length > 1) {
aspectDropdown.classList.add('dropdown-toggle');
aspectDropdown.setAttribute('data-toggle', 'dropdown');
Expand All @@ -508,6 +528,9 @@
var dropdownItem = document.createElement('a');
dropdownItem.classList = 'dropdown-item';
dropdownItem.href = "{{ url_for('app.index') }}" + aspect + '/{{ q }}';
{% if request.path.endswith("curation") or request.path.endswith("curation/") %}
dropdownItem.href += "/curation"
{% endif %}
dropdownItem.innerText = aspect;
aspectDropdownMenu.append(dropdownItem);
}
Expand Down Expand Up @@ -872,7 +895,10 @@

{% block content %}
<div class="content">
<div class="container dropdown" id="aspect-chooser">
<div class="container d-flex justify-content-between">
<div class="dropdown" id="aspect-chooser">
</div>
<a id='curation-link' role="button" class="btn btn-outline-secondary d-none">Improve data</a>
</div>
<div class="container">
{% block page_content %}{% endblock %}
Expand Down