From 9a5568e75a6c24bdd2a65af26ed1cbd23a820786 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Wed, 22 Apr 2020 15:34:15 +0530 Subject: [PATCH 01/17] Query Field: Separates query field from the pagination part Separates the query search field from the pagination part and adds filters and sorting options in UI --- weblate/static/loader-bootstrap.js | 5 +- weblate/static/style-bootstrap.css | 11 ++- weblate/templates/snippets/query-field.html | 42 +++++++++ weblate/templates/snippets/search-form.html | 3 - weblate/templates/translate.html | 99 +++++++++++---------- weblate/trans/filter.py | 29 ++++++ weblate/trans/forms.py | 11 ++- weblate/trans/views/edit.py | 2 + weblate/utils/forms.py | 6 +- 9 files changed, 150 insertions(+), 58 deletions(-) create mode 100644 weblate/templates/snippets/query-field.html diff --git a/weblate/static/loader-bootstrap.js b/weblate/static/loader-bootstrap.js index e6678e8adc04..b692a00462f0 100644 --- a/weblate/static/loader-bootstrap.js +++ b/weblate/static/loader-bootstrap.js @@ -1525,8 +1525,11 @@ $(function () { $('.search-group li a').click(function () { var $this = $(this); var $button = $this.closest('.input-group-btn').find('button'); - $button.data('field', $this.data('field')); + $button.attr('data-field', $this.data('field')); $button.find('span.search-label').text($this.text()); + if ($this.closest('.query-field').length) { + $('#id_q').insertAtCaret(' ' + $this.data('field') + ' '); + } }); $('.search-group input').on('keydown', function (event) { if (event.key === "Enter") { diff --git a/weblate/static/style-bootstrap.css b/weblate/static/style-bootstrap.css index 136fe22fd23e..5902bc2b0051 100644 --- a/weblate/static/style-bootstrap.css +++ b/weblate/static/style-bootstrap.css @@ -418,7 +418,7 @@ kbd { text-align: center; } .unit-navi { - min-width: 25em; + min-width: 17em; } .unit-navi li { float: left; @@ -429,6 +429,9 @@ kbd { .unit-navi .dropdown-menu { margin-top: 0; } +.unit-navi.pagination { + margin-top: 0; +} .fullmodal .modal-dialog { width: auto; } @@ -447,6 +450,12 @@ legend { .search-group { margin: 0 15px 15px 0; } +.search-group input{ + height: auto; +} +.query-field .btn.btn-primary{ + font-size: initial; +} #is-exact span { margin: 4px 4px 0 4px; } diff --git a/weblate/templates/snippets/query-field.html b/weblate/templates/snippets/query-field.html new file mode 100644 index 000000000000..5687c55ac017 --- /dev/null +++ b/weblate/templates/snippets/query-field.html @@ -0,0 +1,42 @@ +{% load i18n %} +{% load translations %} +{% load icons %} +{% load crispy_forms_field %} +
+
+
+
+
+
+ + +
+ {% crispy_field field 'class' 'form-control' %} +
+ + + +
+
+
+
+
+
diff --git a/weblate/templates/snippets/search-form.html b/weblate/templates/snippets/search-form.html index 190a06b4a339..a70436dd8549 100644 --- a/weblate/templates/snippets/search-form.html +++ b/weblate/templates/snippets/search-form.html @@ -10,7 +10,4 @@
{% crispy search_form %}
- diff --git a/weblate/templates/translate.html b/weblate/templates/translate.html index 412be2f5bacd..77184e3591bb 100644 --- a/weblate/templates/translate.html +++ b/weblate/templates/translate.html @@ -35,6 +35,7 @@ {% perm 'comment.add' project as user_can_add_comment %} {% perm 'glossary.add' project as user_can_add_dictionary %} +
{% if user_can_translate %} {% icon "flash.svg" %} {% trans "Zen" %} @@ -42,58 +43,58 @@ {% icon "settings.svg" %}
- -{% with comments=unit.get_comments nearby=unit.nearby nearby_keys=unit.nearby_keys shapings=unit.shapings%} - -
- +
diff --git a/weblate/trans/filter.py b/weblate/trans/filter.py index a0e9161118b6..4984a008b09e 100644 --- a/weblate/trans/filter.py +++ b/weblate/trans/filter.py @@ -128,3 +128,32 @@ def get_filter_choice(project=None): for label in project.label_set.values_list("name", flat=True) ) return result + + +def get_search_query_choices(): + """Return all filtering choices for query field.""" + result = [ + ("nottranslated", _("Not translated strings"), "state:empty"), + ("todo", _("Strings needing action"), "state:=translated"), + ("fuzzy", _("Strings marked for edit"), "state:needs-editing"), + ("suggestions", _("Strings with suggestions"), "has:suggestion"), + ("shapings", _("Strings with shapings"), "has:shaping"), + ("labels", _("Strings with labels"), "has:label"), + ("context", _("Strings with context"), "has:context"), + ( + "nosuggestions", + _("Strings needing action without suggestions"), + "state: Date: Wed, 22 Apr 2020 20:47:30 +0530 Subject: [PATCH 02/17] Query Field: Adds sorting feature from the query field dropdown --- weblate/static/loader-bootstrap.js | 6 +++++- weblate/static/style-bootstrap.css | 3 +++ weblate/templates/snippets/query-field.html | 10 +++++----- weblate/trans/views/edit.py | 6 +++++- weblate/trans/views/search.py | 4 +++- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/weblate/static/loader-bootstrap.js b/weblate/static/loader-bootstrap.js index b692a00462f0..fa9274e4cee1 100644 --- a/weblate/static/loader-bootstrap.js +++ b/weblate/static/loader-bootstrap.js @@ -1528,7 +1528,11 @@ $(function () { $button.attr('data-field', $this.data('field')); $button.find('span.search-label').text($this.text()); if ($this.closest('.query-field').length) { - $('#id_q').insertAtCaret(' ' + $this.data('field') + ' '); + if ($this.data('sort')) { + $('#id_sort_by').val($this.data('sort')); + } else { + $('#id_q').insertAtCaret(' ' + $this.data('field') + ' '); + } } }); $('.search-group input').on('keydown', function (event) { diff --git a/weblate/static/style-bootstrap.css b/weblate/static/style-bootstrap.css index 5902bc2b0051..0809a5eaae04 100644 --- a/weblate/static/style-bootstrap.css +++ b/weblate/static/style-bootstrap.css @@ -453,6 +453,9 @@ legend { .search-group input{ height: auto; } +.search-label svg { + height: 16px; +} .query-field .btn.btn-primary{ font-size: initial; } diff --git a/weblate/templates/snippets/query-field.html b/weblate/templates/snippets/query-field.html index 5687c55ac017..ef8b6899d0f0 100644 --- a/weblate/templates/snippets/query-field.html +++ b/weblate/templates/snippets/query-field.html @@ -9,7 +9,7 @@
{% crispy_field field 'class' 'form-control' %}
- +
diff --git a/weblate/trans/views/edit.py b/weblate/trans/views/edit.py index bc2500aa5974..e6b28a52c7ab 100644 --- a/weblate/trans/views/edit.py +++ b/weblate/trans/views/edit.py @@ -142,7 +142,11 @@ def search(translation, request): name = form.get_name() if form_valid else "" # Grab unit IDs - unit_ids = list(allunits.order().values_list("id", flat=True)) + unit_ids = list( + allunits.order_by(request.GET.get("sort_by", "position")).values_list( + "id", flat=True + ) + ) # Check empty search results if not unit_ids: diff --git a/weblate/trans/views/search.py b/weblate/trans/views/search.py index 289e00ebb168..2e86ea55e401 100644 --- a/weblate/trans/views/search.py +++ b/weblate/trans/views/search.py @@ -190,7 +190,9 @@ def search(request, project=None, component=None, lang=None): if lang: units = units.filter(translation__language=context["language"]) - units = get_paginator(request, units.order()) + units = get_paginator( + request, units.order_by(request.GET.get("sort_by", "position")) + ) context["show_results"] = True context["page_obj"] = units From 2159c1ebd7eccaf6f091b6065925aa9121ea8a9f Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 23 Apr 2020 14:34:19 +0530 Subject: [PATCH 03/17] Refactors code for sorting and filtering --- weblate/trans/filter.py | 41 ++++++++++++++++--------------------- weblate/trans/forms.py | 2 +- weblate/trans/views/edit.py | 9 ++++---- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/weblate/trans/filter.py b/weblate/trans/filter.py index 4984a008b09e..0d555f4efc02 100644 --- a/weblate/trans/filter.py +++ b/weblate/trans/filter.py @@ -70,7 +70,7 @@ def search_name(self): def get_search_name(self, query): try: - return self.search_name[query] + return self.search_name[query.strip()] except KeyError: return query @@ -132,28 +132,23 @@ def get_filter_choice(project=None): def get_search_query_choices(): """Return all filtering choices for query field.""" + filter_keys = [ + "nottranslated", + "todo", + "translated", + "fuzzy", + "suggestions", + "shapings", + "labels", + "context", + "nosuggestions", + "comments", + "allchecks", + "approved", + "unapproved", + ] result = [ - ("nottranslated", _("Not translated strings"), "state:empty"), - ("todo", _("Strings needing action"), "state:=translated"), - ("fuzzy", _("Strings marked for edit"), "state:needs-editing"), - ("suggestions", _("Strings with suggestions"), "has:suggestion"), - ("shapings", _("Strings with shapings"), "has:shaping"), - ("labels", _("Strings with labels"), "has:label"), - ("context", _("Strings with context"), "has:context"), - ( - "nosuggestions", - _("Strings needing action without suggestions"), - "state: Date: Fri, 24 Apr 2020 19:35:58 +0530 Subject: [PATCH 04/17] Autosort and auto filter queries on selecting dropdown --- weblate/static/loader-bootstrap.js | 4 ++- weblate/templates/snippets/query-builder.html | 3 ++ weblate/templates/snippets/query-field.html | 2 +- weblate/templates/translate.html | 2 +- weblate/trans/filter.py | 24 --------------- weblate/trans/forms.py | 4 ++- weblate/trans/models/unit.py | 10 +++++++ weblate/trans/views/edit.py | 13 ++++---- weblate/trans/views/search.py | 2 +- weblate/utils/forms.py | 30 ++++++++++++++++++- 10 files changed, 56 insertions(+), 38 deletions(-) diff --git a/weblate/static/loader-bootstrap.js b/weblate/static/loader-bootstrap.js index fa9274e4cee1..ca60e8f001b7 100644 --- a/weblate/static/loader-bootstrap.js +++ b/weblate/static/loader-bootstrap.js @@ -1530,8 +1530,10 @@ $(function () { if ($this.closest('.query-field').length) { if ($this.data('sort')) { $('#id_sort_by').val($this.data('sort')); + $this.closest('form').submit(); } else { - $('#id_q').insertAtCaret(' ' + $this.data('field') + ' '); + $('#id_q').val($this.data('field')); + $this.closest('form').submit(); } } }); diff --git a/weblate/templates/snippets/query-builder.html b/weblate/templates/snippets/query-builder.html index baea53c75cc5..696de194ed24 100644 --- a/weblate/templates/snippets/query-builder.html +++ b/weblate/templates/snippets/query-builder.html @@ -1,4 +1,6 @@ {% load i18n %} + +{% if show_builder %}
@@ -104,3 +106,4 @@
+{% endif %} diff --git a/weblate/templates/snippets/query-field.html b/weblate/templates/snippets/query-field.html index ef8b6899d0f0..a3c5b5f1b8eb 100644 --- a/weblate/templates/snippets/query-field.html +++ b/weblate/templates/snippets/query-field.html @@ -28,7 +28,7 @@ {% icon "sort-alphabetical.svg" %}{% trans "Sort By" %} - +
- {% crispy_field field 'class' 'form-control' %} + {% crispy_field field 'class' 'form-control' 'aria-label' _('Query') %}
- +
diff --git a/weblate/trans/views/edit.py b/weblate/trans/views/edit.py index c6484298d970..0d3adc767b9f 100644 --- a/weblate/trans/views/edit.py +++ b/weblate/trans/views/edit.py @@ -130,7 +130,6 @@ def search(translation, request): if ( session_key in request.session and "offset" in request.GET - and "sort_by" not in request.GET and "items" in request.session[session_key] ): search_result.update(request.session[session_key]) @@ -140,8 +139,8 @@ def search(translation, request): search_query = form.get_search_query() if form_valid else "" name = form.get_name() if form_valid else "" - print(allunits) - # Grab unit IDs) + + # Grab unit IDs unit_ids = list( allunits.order_by_request( request.GET.get("sort_by", "").split(",") From 5fed68504a1672c7ba1022f7031f4a2b2993ca34 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Tue, 28 Apr 2020 20:55:07 +0530 Subject: [PATCH 07/17] Refactor codes to make more readable --- weblate/templates/snippets/query-field.html | 11 +++++------ weblate/trans/models/unit.py | 13 ++++++------- weblate/trans/tests/test_selenium.py | 7 +++++-- weblate/trans/views/edit.py | 6 +----- weblate/trans/views/search.py | 4 +--- 5 files changed, 18 insertions(+), 23 deletions(-) diff --git a/weblate/templates/snippets/query-field.html b/weblate/templates/snippets/query-field.html index 2df4c6d8cd25..6ff5c0619a56 100644 --- a/weblate/templates/snippets/query-field.html +++ b/weblate/templates/snippets/query-field.html @@ -18,7 +18,7 @@
@@ -30,12 +30,11 @@ -
diff --git a/weblate/trans/models/unit.py b/weblate/trans/models/unit.py index 41ae2959b381..35c7746a5d6f 100644 --- a/weblate/trans/models/unit.py +++ b/weblate/trans/models/unit.py @@ -116,15 +116,14 @@ def same(self, unit, exclude=True): result = result.exclude(pk=unit.id) return result - def order_by_request(self, sort_list_request): + def order_by_request(self, request): + sort_list_request = request.GET.get("sort_by", "").split(",") available_sort_choices = ["-priority", "position", "context", "num_words"] - sort_list = [] - for choice in sort_list_request: - if choice in available_sort_choices: - sort_list.append(choice) - if not len(sort_list): + sort_list = [ + choice for choice in sort_list_request if choice in available_sort_choices + ] + if not sort_list: sort_list = ["-priority", "position"] - return self.order_by(*sort_list) def get_unit(self, ttunit): diff --git a/weblate/trans/tests/test_selenium.py b/weblate/trans/tests/test_selenium.py index 1a1482aff2e3..3ac4ee8fbf2e 100644 --- a/weblate/trans/tests/test_selenium.py +++ b/weblate/trans/tests/test_selenium.py @@ -860,12 +860,15 @@ def test_weblate(self): dropdown = self.driver.find_element_by_id("query-dropdown") dropdown.click() self.screenshot("query-dropdown.png") - self.click("Not translated strings") + with self.wait_for_page_load(): + self.click("Not translated strings") + self.screenshot("query-drop-clicked.png") # Test sort dropdown sort = self.driver.find_element_by_id("query-sort-dropdown") sort.click() self.screenshot("query-sort.png") - self.click("Position") + with self.wait_for_page_load(): + self.click("Position") # Trigger check self.clear_field(self.driver.find_element_by_id("id_a2a808c8ccbece08_0")) diff --git a/weblate/trans/views/edit.py b/weblate/trans/views/edit.py index 0d3adc767b9f..7601e6559973 100644 --- a/weblate/trans/views/edit.py +++ b/weblate/trans/views/edit.py @@ -141,11 +141,7 @@ def search(translation, request): name = form.get_name() if form_valid else "" # Grab unit IDs - unit_ids = list( - allunits.order_by_request( - request.GET.get("sort_by", "").split(",") - ).values_list("id", flat=True) - ) + unit_ids = list(allunits.order_by_request(request).values_list("id", flat=True)) # Check empty search results if not unit_ids: diff --git a/weblate/trans/views/search.py b/weblate/trans/views/search.py index 6dba8723432f..42b2e26475b0 100644 --- a/weblate/trans/views/search.py +++ b/weblate/trans/views/search.py @@ -190,9 +190,7 @@ def search(request, project=None, component=None, lang=None): if lang: units = units.filter(translation__language=context["language"]) - units = get_paginator( - request, units.order_by_request(request.GET.get("sort_by", "").split(",")) - ) + units = get_paginator(request, units.order_by_request(request)) context["show_results"] = True context["page_obj"] = units From 9dc9ef1b4a013daba4a4ede8c371b06de559da88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 28 Apr 2020 20:15:09 +0200 Subject: [PATCH 08/17] Fix selenium tests - add delay before screenshots to avoid capturing transitions - revert to original search for other tests --- weblate/trans/tests/test_selenium.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/weblate/trans/tests/test_selenium.py b/weblate/trans/tests/test_selenium.py index 3ac4ee8fbf2e..671b05900b3e 100644 --- a/weblate/trans/tests/test_selenium.py +++ b/weblate/trans/tests/test_selenium.py @@ -856,20 +856,33 @@ def test_weblate(self): self.screenshot("format-highlight.png") self.click("Comments") self.screenshot("plurals.png") + # Test search dropdown dropdown = self.driver.find_element_by_id("query-dropdown") dropdown.click() + time.sleep(0.5) self.screenshot("query-dropdown.png") with self.wait_for_page_load(): self.click("Not translated strings") - self.screenshot("query-drop-clicked.png") + self.driver.find_element_by_id("id_34a4642999e44a2b_0") + # Test sort dropdown sort = self.driver.find_element_by_id("query-sort-dropdown") sort.click() + time.sleep(0.5) self.screenshot("query-sort.png") with self.wait_for_page_load(): self.click("Position") + # Return to original unit + element = self.driver.find_element_by_id("id_q") + self.clear_field(element) + element.send_keys("'%(count)s word'") + self.screenshot("query-done-1.png") + with self.wait_for_page_load(): + element.submit() + self.screenshot("query-done.png") + # Trigger check self.clear_field(self.driver.find_element_by_id("id_a2a808c8ccbece08_0")) element = self.driver.find_element_by_id("id_a2a808c8ccbece08_1") From b4df0fe0714c85ac3e553190344002cb3d354108 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 30 Apr 2020 15:45:59 +0530 Subject: [PATCH 09/17] Adds sorting direction feature with suitable icons --- weblate/static/icons/sort-ascending.svg | 1 + weblate/static/icons/sort-descending.svg | 1 + weblate/static/loader-bootstrap.js | 26 ++++++++++++------ weblate/static/style-bootstrap.css | 26 ++++++++++++++++++ weblate/templates/snippets/query-field.html | 29 +++++++++++++++++---- weblate/templates/translate.html | 2 +- weblate/trans/models/unit.py | 9 ++++--- weblate/trans/views/edit.py | 21 +++++++++++++++ 8 files changed, 98 insertions(+), 17 deletions(-) create mode 100644 weblate/static/icons/sort-ascending.svg create mode 100644 weblate/static/icons/sort-descending.svg diff --git a/weblate/static/icons/sort-ascending.svg b/weblate/static/icons/sort-ascending.svg new file mode 100644 index 000000000000..bf905efe6596 --- /dev/null +++ b/weblate/static/icons/sort-ascending.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/weblate/static/icons/sort-descending.svg b/weblate/static/icons/sort-descending.svg new file mode 100644 index 000000000000..82d62f804c21 --- /dev/null +++ b/weblate/static/icons/sort-descending.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/weblate/static/loader-bootstrap.js b/weblate/static/loader-bootstrap.js index ba33a0feb0cb..cebe4050c104 100644 --- a/weblate/static/loader-bootstrap.js +++ b/weblate/static/loader-bootstrap.js @@ -1526,16 +1526,26 @@ $(function () { var $this = $(this); var $button = $this.closest('.input-group-btn').find('button'); $button.attr('data-field', $this.data('field')); - $button.find('span.search-label').text($this.text()); + $button.find('span.search-label').not('#query-sort-toggle span').text($this.text()); + if ($this.data('sort')) { + $('#id_sort_by').val($this.data('sort')); + $this.closest('form').submit(); + } if ($this.closest('.query-field').length) { - if ($this.data('sort')) { - $('#id_sort_by').val($this.data('sort')); - $this.closest('form').submit(); - } else { - $('#id_q').val($this.data('field')); - $this.closest('form').submit(); - } + $('#id_q').val($this.data('field')); + $this.closest('form').submit(); + } + }); + $('#query-sort-toggle').click(function () { + var $this = $(this); + var $label = $this.find('span.search-label'); + $label.toggle(); + if (!$('#id_sort_direction').val()) { + $('#id_sort_direction').val("-"); + } else { + $('#id_sort_direction').val(""); } + $this.closest('form').submit(); }); $('.search-group input').not('#id_q').on('keydown', function (event) { if (event.key === "Enter") { diff --git a/weblate/static/style-bootstrap.css b/weblate/static/style-bootstrap.css index 0809a5eaae04..b4ed95658fb7 100644 --- a/weblate/static/style-bootstrap.css +++ b/weblate/static/style-bootstrap.css @@ -431,6 +431,7 @@ kbd { } .unit-navi.pagination { margin-top: 0; + padding-left: 15px; } .fullmodal .modal-dialog { width: auto; @@ -450,15 +451,40 @@ legend { .search-group { margin: 0 15px 15px 0; } +.query-field { + margin-right: 0; +} .search-group input{ height: auto; } +.search-group li a { + cursor: pointer; +} .search-label svg { height: 16px; } .query-field .btn.btn-primary{ font-size: initial; } +.sort-field { + margin-right: 0; +} +@media (min-width: 768px) { + .sort-field { + margin-left: -15px; + } +} +#query-sort-toggle { + width: 35px; + padding-left: 0; + padding-right: 0; +} +#query-sort-toggle span:not(.active) { + display: none; +} +#query-sort-dropdown { + width: 115px; +} #is-exact span { margin: 4px 4px 0 4px; } diff --git a/weblate/templates/snippets/query-field.html b/weblate/templates/snippets/query-field.html index 6ff5c0619a56..b051c58c590f 100644 --- a/weblate/templates/snippets/query-field.html +++ b/weblate/templates/snippets/query-field.html @@ -3,7 +3,7 @@ {% load icons %} {% load crispy_forms_field %}
-
+
@@ -23,18 +23,37 @@
{% crispy_field field 'class' 'form-control' 'aria-label' _('Query') %} +
+
+
+
+
+
+
+
- + + +
diff --git a/weblate/templates/translate.html b/weblate/templates/translate.html index 015f6c6e4792..f0f6085ce51d 100644 --- a/weblate/templates/translate.html +++ b/weblate/templates/translate.html @@ -55,7 +55,7 @@
-
+
  • diff --git a/weblate/trans/models/unit.py b/weblate/trans/models/unit.py index 35c7746a5d6f..acc68f6932df 100644 --- a/weblate/trans/models/unit.py +++ b/weblate/trans/models/unit.py @@ -118,12 +118,15 @@ def same(self, unit, exclude=True): def order_by_request(self, request): sort_list_request = request.GET.get("sort_by", "").split(",") - available_sort_choices = ["-priority", "position", "context", "num_words"] + sort_direction = request.GET.get("sort_by_direction", "") + available_sort_choices = ["priority", "position", "context", "num_words"] sort_list = [ - choice for choice in sort_list_request if choice in available_sort_choices + "{}{}".format(sort_direction, choice) + for choice in sort_list_request + if choice in available_sort_choices ] if not sort_list: - sort_list = ["-priority", "position"] + return self.order() return self.order_by(*sort_list) def get_unit(self, ttunit): diff --git a/weblate/trans/views/edit.py b/weblate/trans/views/edit.py index 7601e6559973..eed817a0d32b 100644 --- a/weblate/trans/views/edit.py +++ b/weblate/trans/views/edit.py @@ -109,6 +109,22 @@ def cleanup_session(session): del session[key] +def get_sort_name(request): + """Gets sort name.""" + sort_dict = { + "position": "Position", + "priority": "Priority", + "num_words": "Word count", + "context": "Context", + } + result = { + "query": request.GET.get("sort_by", ""), + "name": sort_dict.get(request.GET.get("sort_by", ""), ""), + "direction": request.GET.get("sort_by_direction", ""), + } + return result + + def search(translation, request): """Perform search or returns cached search results.""" # Possible new search @@ -130,6 +146,7 @@ def search(translation, request): if ( session_key in request.session and "offset" in request.GET + and "sort_by" not in request.GET and "items" in request.session[session_key] ): search_result.update(request.session[session_key]) @@ -486,6 +503,7 @@ def translate(request, project, component, lang): # Prepare form form = TranslationForm(request.user, translation, unit) + sort = get_sort_name(request) return render( request, @@ -505,6 +523,9 @@ def translate(request, project, component, lang): "search_items": search_result["items"], "search_query": search_result["query"], "offset": offset, + "sort_name": sort["name"], + "sort_query": sort["query"], + "sort_direction": sort["direction"], "filter_name": search_result["name"], "filter_count": num_results, "filter_pos": offset, From fb366965557641187bb2d3b97b77fc4a896903cc Mon Sep 17 00:00:00 2001 From: Saptak S Date: Fri, 1 May 2020 22:50:11 +0530 Subject: [PATCH 10/17] Shows dropdown labels and enables autosearch in page with results --- weblate/static/loader-bootstrap.js | 18 +++++++++++++++--- weblate/static/style-bootstrap.css | 6 +++++- weblate/templates/snippets/query-field.html | 5 +++-- weblate/trans/views/edit.py | 18 +----------------- weblate/trans/views/search.py | 6 ++++++ weblate/utils/views.py | 17 +++++++++++++++++ 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/weblate/static/loader-bootstrap.js b/weblate/static/loader-bootstrap.js index cebe4050c104..95c3a281eb96 100644 --- a/weblate/static/loader-bootstrap.js +++ b/weblate/static/loader-bootstrap.js @@ -1529,11 +1529,15 @@ $(function () { $button.find('span.search-label').not('#query-sort-toggle span').text($this.text()); if ($this.data('sort')) { $('#id_sort_by').val($this.data('sort')); - $this.closest('form').submit(); + if ($('.pagination').length) { + $this.closest('form').submit(); + } } if ($this.closest('.query-field').length) { $('#id_q').val($this.data('field')); - $this.closest('form').submit(); + if ($('.pagination').length) { + $this.closest('form').submit(); + } } }); $('#query-sort-toggle').click(function () { @@ -1545,7 +1549,9 @@ $(function () { } else { $('#id_sort_direction').val(""); } - $this.closest('form').submit(); + if ($('.pagination').length) { + $this.closest('form').submit(); + } }); $('.search-group input').not('#id_q').on('keydown', function (event) { if (event.key === "Enter") { @@ -1554,6 +1560,12 @@ $(function () { return false; } }); + $('#id_q').on('keydown', function (event) { + console.log("hello") + if (event.key === "Enter") { + $(this).closest('form').submit(); + } + }); $('.search-add').click(function () { var group = $(this).closest('.input-group'); var button = group.find('button'); diff --git a/weblate/static/style-bootstrap.css b/weblate/static/style-bootstrap.css index b4ed95658fb7..d7526d3d8dab 100644 --- a/weblate/static/style-bootstrap.css +++ b/weblate/static/style-bootstrap.css @@ -478,12 +478,16 @@ legend { width: 35px; padding-left: 0; padding-right: 0; + border-top-right-radius: 4px; + border-bottom-right-radius: 4px; } #query-sort-toggle span:not(.active) { display: none; } #query-sort-dropdown { - width: 115px; + width: 160px; + border-top-left-radius: 4px; + border-bottom-left-radius: 4px; } #is-exact span { margin: 4px 4px 0 4px; diff --git a/weblate/templates/snippets/query-field.html b/weblate/templates/snippets/query-field.html index b051c58c590f..fa1c7d77108f 100644 --- a/weblate/templates/snippets/query-field.html +++ b/weblate/templates/snippets/query-field.html @@ -3,7 +3,7 @@ {% load icons %} {% load crispy_forms_field %}
    -
    +
    @@ -27,7 +27,7 @@
    -
    +
    @@ -43,6 +43,7 @@
    + -
    +
    diff --git a/weblate/utils/views.py b/weblate/utils/views.py index 0eca9317f78f..4e79bf4d0d45 100644 --- a/weblate/utils/views.py +++ b/weblate/utils/views.py @@ -83,15 +83,17 @@ def dispatch(self, request, *args, **kwargs): def get_sort_name(request): """Gets sort name.""" sort_dict = { - "position": "Position", - "priority": "Priority", - "num_words": "Word count", - "context": "Context", - "position,-priority": "Position & Priority", + "position": _("Position"), + "priority": _("Priority"), + "num_words": _("Word count"), + "context": _("Context"), + "position,-priority": _("Position and Priority"), } result = { "query": request.GET.get("sort_by", "position,-priority"), - "name": sort_dict.get(request.GET.get("sort_by", ""), "Position & Priority"), + "name": sort_dict.get( + request.GET.get("sort_by", ""), _("Position and Priority") + ), "direction": request.GET.get("sort_by_direction", ""), } return result From 461f0147c4205076a74dbc824e327143c3329b7c Mon Sep 17 00:00:00 2001 From: Saptak S Date: Sun, 3 May 2020 00:27:38 +0530 Subject: [PATCH 12/17] Use default autosizing width of button for sort dropdown --- weblate/static/style-bootstrap.css | 8 ++------ weblate/templates/snippets/query-field.html | 8 ++++---- weblate/utils/views.py | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/weblate/static/style-bootstrap.css b/weblate/static/style-bootstrap.css index d1406a2eb867..eddee426fb59 100644 --- a/weblate/static/style-bootstrap.css +++ b/weblate/static/style-bootstrap.css @@ -475,16 +475,12 @@ legend { } } #query-sort-toggle { - width: 40px; - padding-left: 0; - padding-right: 0; + padding-left: 1rem; + padding-right: 1rem; } #query-sort-toggle span:not(.active) { display: none; } -#query-sort-dropdown { - width: 200px; -} #is-exact span { margin: 4px 4px 0 4px; } diff --git a/weblate/templates/snippets/query-field.html b/weblate/templates/snippets/query-field.html index f9b05937a529..8991ac50bf98 100644 --- a/weblate/templates/snippets/query-field.html +++ b/weblate/templates/snippets/query-field.html @@ -30,8 +30,8 @@
    -
    -
    +
    + - +
    -
    -
    -
    +
    +
    +
- + - - +