From 0bebf2de86a013397eebdb455f4197c635d33784 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 14 Oct 2019 13:07:59 +0100 Subject: [PATCH] Add depicts drop downs to the catalog page. --- static/js/catalog.js | 38 +++++++++++++++++++++++++++++ templates/catalog.html | 55 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 static/js/catalog.js diff --git a/static/js/catalog.js b/static/js/catalog.js new file mode 100644 index 0000000..0a209ee --- /dev/null +++ b/static/js/catalog.js @@ -0,0 +1,38 @@ +var typingTimer; +var doneTypingInterval = 500; + +var app = new Vue({ + el: '#app', + delimiters: ['${', '}'], + data: { + prevTerms: {}, + searchTerms: {}, + hits: {}, + }, + methods: { + run_search(qid) { + var terms = this.searchTerms[qid]; + if (terms == this.prevTerms[qid]) { + return; // no change + } + this.prevTerms[qid] = terms; + if (terms.length < 3) { + this.hits[qid] = []; + return; + } + + var vm = this; + + fetch(lookup_url + '?terms=' + encodeURI(terms)) + .then((res) => res.json()) + .then((data) => { + vm.hits[qid] = data.hits; + }) + }, + search(event) { + var qid = event.target.dataset.qid + clearTimeout(typingTimer); + typingTimer = setTimeout(this.run_search, doneTypingInterval, qid); + } + } +}); diff --git a/templates/catalog.html b/templates/catalog.html index 47c64e9..2212bf5 100644 --- a/templates/catalog.html +++ b/templates/catalog.html @@ -21,8 +21,34 @@ {% block title %}{{ title }}{% endblock %} +{% block style %} + +{% endblock %} + {% block content %} -
+

{{ self.title() }}

{% for item in items %}
@@ -39,6 +65,25 @@

{{ item_detail(item.entity) }} + +
+ + +
+
+
+ ${ hit.label } + (${ hit.alt_label }) + — ${ hit.count } existing paintings + (${ hit.qid }) + view on Wikidata +
+
+
${ hit.description }
+
+
+
+
@@ -47,3 +92,11 @@ {% endblock %} + +{% block script %} + + + +{% endblock %}