Signed-off-by: Franciszek Stachura <[email protected]>
---
I have decided to render all labels into the html instead of
requesting them through the API. I'm assuming that there won't be that
many different labels for a project, so I went with the simpler
approach. The main upside is no latency.
---
.../templates/patchwork/partials/filters.html | 44 +++++++++++++++++++
patchwork/views/__init__.py | 7 ++-
2 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/patchwork/templates/patchwork/partials/filters.html
b/patchwork/templates/patchwork/partials/filters.html
index 1175af14..8bad9d4e 100644
--- a/patchwork/templates/patchwork/partials/filters.html
+++ b/patchwork/templates/patchwork/partials/filters.html
@@ -35,6 +35,26 @@ Selectize.define('enter_key_submit', function (options) {
})();
});
+// Submit form on shift+enter or ctrl+enter
+Selectize.define('mod_enter_key_submit', function (options) {
+ var self = this;
+
+ this.onKeyDown = (function (e) {
+ var original = self.onKeyDown;
+
+ return function (e) {
+ var wasOpened = this.isOpen;
+
+ if (e.keyCode === 13 && (e.shiftKey || e.ctrlKey)) {
+ self.trigger('submit');
+ return;
+ }
+
+ original.apply(this, arguments);
+ };
+ })();
+});
+
$(document).ready(function() {
$('#submitter_input').selectize({
plugins: ['enter_key_submit'],
@@ -76,6 +96,30 @@ $(document).ready(function() {
});
}
});
+
+ $('#labels_input').selectize({
+ plugins: ['mod_enter_key_submit'],
+ maxItems: null,
+ persist: false,
+ hideSelected: true,
+ // Search for options that begin with a minus sign
+ respect_word_boundaries: false,
+ delimiter: ' ',
+ options: [
+{% for label in project_labels %}
+ {
+ value: "{{ label.name }}",
+ text: "{{ label.name }}",
+ },
+{% endfor %}
+{% for label in project_labels %}
+ {
+ value: "-{{ label.name }}",
+ text: "-{{ label.name }}",
+ },
+{% endfor %}
+ ],
+ });
});
</script>
diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py
index 2685d2a5..c3f40b92 100644
--- a/patchwork/views/__init__.py
+++ b/patchwork/views/__init__.py
@@ -7,7 +7,7 @@ import json
from django.contrib import messages
from django.shortcuts import get_object_or_404
-from django.db.models import Prefetch
+from django.db.models import Prefetch, Q
from patchwork.filters import Filters
from patchwork.forms import CreateBundleForm
@@ -189,10 +189,15 @@ def generic_list(
if not filter_settings:
filter_settings = []
+ project_labels = Label.objects.filter(
+ Q(project=project) | Q(project__isnull=True)
+ ).all()
+
filters = Filters(request)
context = {
'project': project,
'projects': Project.objects.all(),
+ 'project_labels': project_labels,
'filters': filters,
}
--
2.55.0
_______________________________________________
Patchwork mailing list
[email protected]
https://lists.ozlabs.org/listinfo/patchwork