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 the ability to select a batch of QuickStatements to run #2345

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
399fd17
Start adding functionality for mutiple ArXiv IDs
carlinmack Sep 16, 2023
a344bd6
Add support for multiple quickstatements
carlinmack Sep 17, 2023
940ed73
Copy editing
carlinmack Sep 17, 2023
64e5cae
Minor linting improvements
carlinmack Sep 17, 2023
2ced1d1
add warning message
carlinmack Sep 17, 2023
6a723bb
Rename tool
carlinmack Sep 18, 2023
c29a0ce
Redirect arxiv-to-quickstatements
carlinmack Sep 18, 2023
f9a739c
Add ability to find dois, improve regexs
carlinmack Sep 19, 2023
55af8a7
First part working with arxivs
carlinmack Sep 19, 2023
7f861a8
Get first part working with DOI
carlinmack Sep 19, 2023
944a3dd
Add doi get metadata
carlinmack Sep 19, 2023
696ad4f
Add metadata_to_quickstatements to utils
carlinmack Sep 21, 2023
60de60f
replace format strings with f-strings
carlinmack Sep 21, 2023
a7402f4
Date handling improvements
carlinmack Sep 21, 2023
848ab06
Copy editing and linting
carlinmack Sep 21, 2023
806a6e4
Add error handling
carlinmack Sep 24, 2023
b48e54e
Add error checking for arxiv.py
carlinmack Sep 26, 2023
6ba2d45
Improve error handling for doi metadata
carlinmack Sep 26, 2023
3d51dea
Refactor
carlinmack Sep 26, 2023
e38ff89
Add section for IDs which failed and describe why
carlinmack Sep 26, 2023
af517e7
Fix error with author names
carlinmack Sep 26, 2023
bf5d373
Fix codacy issues
carlinmack Sep 27, 2023
85c88c2
Improve string_to_type
carlinmack Sep 27, 2023
e7d2b0b
Add number found/etc to headings
carlinmack Sep 28, 2023
22632ea
Update UI
carlinmack Oct 2, 2023
ec0a31d
Activate Select all button and add invert selection button
carlinmack Oct 3, 2023
461ba6c
Activate copy buttons
carlinmack Oct 3, 2023
34776d5
Activate copy all button
carlinmack Oct 3, 2023
d355adb
Activate submit all button
carlinmack Oct 4, 2023
c3e1a32
formatting and fix
carlinmack Oct 4, 2023
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
5 changes: 5 additions & 0 deletions scholia/app/static/css/scholia.css
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ a.dropdown-item.active {
animation-delay: 2s;
}

.large-checkbox {
width: 18.5px;
height: 18.5px;
}

@keyframes scholia {
33% {
border-color: var(--theme-red);
Expand Down
52 changes: 0 additions & 52 deletions scholia/app/templates/arxiv-to-quickstatements.html

This file was deleted.

2 changes: 1 addition & 1 deletion scholia/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@
Tools
</a>
<div class="dropdown-menu" aria-labelledby="toolsDropdown">
<a class="dropdown-item" href="{{ url_for('app.show_arxiv_to_quickstatements') }}">Arxiv to Quickstatements</a>
<a class="dropdown-item" href="{{ url_for('app.show_id_to_quickstatements') }}">Identifier to Quickstatements</a>
<a class="dropdown-item" href="{{ url_for('app.show_q_to_bibliography_templates') }}">Q to Bibliography templates</a>
<a class="dropdown-item" href="{{ url_for('app.show_text_to_topics') }}">Text to topics</a>
</div>
Expand Down
200 changes: 200 additions & 0 deletions scholia/app/templates/id-to-quickstatements.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{% extends "base.html" %}


{% block page_content %}

<h1>Identifier to QuickStatements</h1>


<h2>Input</h2>

<form action="" id="form" method="GET" class="form-horizontal mb-3">
<div class="input-group">
{% if query %}
<input type="text" class="form-control" placeholder="Enter a single or list of arXiv IDs or DOIs"
value="{{ query }}" id="searchterm" name="query" />
{% else %}
<input type="text" class="form-control" placeholder="Enter a single or list of arXiv IDs or DOIs" id="searchterm"
name="query" />
{% endif %}
<span class="input-group-append">
<button class="btn btn-primary" type="submit">
Submit
</button>
</span>
</div>
</form>

<p>Enter a single or list of <a href="https://arxiv.org">arXiv</a> identifiers or <a href="https://doi.org">DOIs</a> to
retrieve their Wikidata items or QuickStatements to create items for them.</p>

<p>Bare IDs (such as "1703.06103" or "10.1371/JOURNAL.PONE.0029797") or URLs (such as "https://arxiv.org/abs/1703.06103"
or "https://doi.org/10.1371/JOURNAL.PONE.0029797") can be used and the list can be
comma, space, pipe or tab separated. Note that new items in Wikidata may not be immediately found because of caching.
</p>

{% if error %}
<div class="alert alert-warning" role="alert">
No results returned, potentially due to the upstream server being down. Please try again later. If the issue persists
<a
href="https://github.com/WDscholia/scholia/issues/new?assignees=&labels=bug&projects=&template=bug_report.md&title=">submit
a bug report on GitHub</a>.
</div>
{% endif %}

{% if (qs|length) > 0 %}
<h2>{{ qs|length}} Found</h2>
{% endif %}

{% if (qs|length) == 1 %}

<div id="searchresult">{{ qs[0][0] }} has been entered as <a href="work/{{ qs[0][1] }}">{{ qs[0][1] }}</a></div>

{% endif %}

{% if (qs|length) > 1 %}

<div id="searchresult">In Wikidata:
<ul>
{% for q in qs %}
<li>{{ q[0] }}: <a href="work/{{ q[1] }}">{{ q[1] }}</a></li>
{% endfor %}
</ul>
</div>

{% endif %}

{% if (quickstatements|length) > 0 %}
<h2>{{(quickstatements|length)}} Not Found</h2>

<blockquote>Select statements which you want to contribute and use the buttons at the bottom of the section to complete
the action.</blockquote>
<input type="checkbox" class="d-none" id="select-all-state" />
<button class="btn btn-secondary select-all">Select all</button> <button class="btn btn-secondary invert-selection">Invert selection</button>
<div class="container">
{% for quickstatement in quickstatements %}
<div class="row">
<div class="col-1 align-self-center">
<input type="checkbox" class="select-item checkbox large-checkbox" name="select-item" value="{{loop.index}}" />
</div>
<div class="col-8">
<pre>{{ quickstatement }}</pre>
</div>
<div class="d-none" id="qs-{{loop.index}}-url">{{ quickstatement | replace('\t', '|') | replace('\n', '||') | urlencode
| replace('/','%2F') }}</div>
<div class="d-none" id="qs-{{loop.index}}-plain">{{ quickstatement | replace('\t', '|') | replace('\n', '||')
| replace('/','%2F') }}</div>
<div class="col-3 align-self-center">
<a
href="https://quickstatements.toolforge.org/#/v1={{ quickstatement | replace('\t', '|') | replace('\n', '||') | urlencode | replace('/','%2F') }}"><button
class="btn btn-outline-secondary">Submit to Quickstatements ↗</button></a>
<button class="btn btn-outline-secondary copy-button" name="{{loop.index}}">Copy to clipboard</button>
</div>
</div>
{% endfor %}
</div>

<div class="d-flex justify-content-between">
<div>
<button class="btn btn-primary select-all">Select all</button>
<button class="btn btn-primary invert-selection">Invert selection</button>
</div>
<div>
<button class="btn btn-primary ml-auto" id="submit-all-button">Submit to Quickstatements ↗</button>
<button class="btn btn-primary" id="copy-all-button">Copy to clipboard</button>
</div>
</div>
</div>


{% endif %}

{% if (failed|length) > 0 %}
<h2>{{(failed|length)}} Failed</h2>

<ul>
{% for fail in failed %}
<li>{{ fail[0] }}: {{ fail[1] }}</a></li>
{% endfor %}
</ul>
{% endif %}


{% endblock %}

{% block scripts %}
{{super()}}
<script type="text/javascript">
const select_alls = document.getElementsByClassName("select-all");
const select_all_state = document.getElementById("select-all-state");
for (const select_all of select_alls) {
select_all.addEventListener("click", () => {
select_all_state.checked = !select_all_state.checked;
const checked = select_all_state.checked;
const checkboxes = document.getElementsByClassName("checkbox");
for (const checkbox of checkboxes) {
checkbox.checked = checked;
}
})
}

const invert_selections = document.getElementsByClassName("invert-selection");
for (const invert_selection of invert_selections) {
invert_selection.addEventListener("click", () => {
const checkboxes = document.getElementsByClassName("checkbox");
for (const checkbox of checkboxes) {
checkbox.checked = !checkbox.checked;
}
})
}

const copy_buttons = document.getElementsByClassName("copy-button");
for (const copy_button of copy_buttons) {
copy_button.addEventListener("click", () => {
const qs_id = copy_button["name"];
const quickstatements = document.getElementById("qs-" + qs_id + "-plain");
if (navigator.clipboard) {
navigator.clipboard.writeText(quickstatements.innerText)
}
})
}

const copy_all = document.getElementById("copy-all-button");
copy_all.addEventListener("click", () => {
var items = [];
document.querySelectorAll("input.select-item:checked:checked").forEach((item, index) => {
console.log(index)
console.log(item)
const qs_id = item["value"];
const quickstatements = document.getElementById("qs-" + qs_id + "-plain");
items.push(quickstatements.innerText);
});
if (items.length < 1) {
const parent = copy_all.parentNode.parentNode;
parent.insertAdjacentHTML('afterend', `<div class="alert alert-warning" role="alert">Select at least one row using the checkbox on the left</div>`);
} else {
var values = items.join('\n\n');
if (navigator.clipboard) {
navigator.clipboard.writeText(values)
}
}
});

const submit_all = document.getElementById("submit-all-button");
submit_all.addEventListener("click", () => {
var items = [];
document.querySelectorAll("input.select-item:checked:checked").forEach((item, index) => {
const qs_id = item["value"];
const quickstatements = document.getElementById("qs-" + qs_id + "-url");
items.push(quickstatements.innerText);
});
if (items.length < 1) {
const parent = submit_all.parentNode.parentNode;
parent.insertAdjacentHTML('afterend', `<div class="alert alert-warning" role="alert">Select at least one row using the checkbox on the left</div>`);
} else {
const values = items.join('||');
window.location.href = "https://quickstatements.toolforge.org/#/v1=" + values

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values is urlencoded on line 83 so I think it's okay

}
});
</script>
{% endblock %}
Loading