Skip to content

Commit a74924c

Browse files
committed
work out a default pit to compare to instead of always using the second-latest
1 parent ee82423 commit a74924c

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

indigo_app/static/javascript/indigo/views/document_editor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@
6565
this.editorReady = $.Deferred();
6666
this.setupRenderers();
6767

68-
// fake a click on the most recent point in time for comparison
69-
let mostRecent = document.querySelector('.show-pit-comparison.most-recent');
70-
if (mostRecent) {
71-
mostRecent.click();
68+
// fake a click on the previous point in time for comparison, if there is one
69+
let defaultCompareTo = document.querySelector('.show-pit-comparison.default-compare-to');
70+
if (defaultCompareTo) {
71+
defaultCompareTo.click();
7272
}
7373
},
7474

indigo_app/templates/indigo_api/document/_toolbar.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<div class="dropdown-menu">
1212
{% for exp in comparison_expressions %}
1313
<button
14-
class="dropdown-item show-pit-comparison {% if forloop.counter0 == 1 %}most-recent{% endif %}"
14+
class="dropdown-item show-pit-comparison {% if exp.id == default_comparison_id %}default-compare-to{% endif %}"
1515
data-id="{{ exp.id }}"
1616
>
1717
{{ exp.expression_date|date:"Y-m-d" }}

indigo_app/views/documents.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ def get_context_data(self, **kwargs):
4949
doc.work.expressions().all()
5050
))
5151
context['comparison_expressions'] = doc.work.expressions().filter(language=doc.language).order_by('-expression_date')
52+
previous_documents = context['comparison_expressions'].exclude(expression_date__gte=doc.expression_date)
53+
context['default_comparison_id'] = previous_documents.first().pk if previous_documents else None
5254
context['place'] = doc.work.place
5355
context['country'] = doc.work.country
5456
context['locality'] = doc.work.locality

0 commit comments

Comments
 (0)