Skip to content

Commit adb4e8a

Browse files
committed
filters: Add autocomplete to labels filter
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.
1 parent 09e23b1 commit adb4e8a

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

‎patchwork/templates/patchwork/partials/filters.html‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@
3535
})();
3636
});
3737

38+
// Submit form on shift+enter or ctrl+enter
39+
Selectize.define('mod_enter_key_submit', function (options) {
40+
var self = this;
41+
42+
this.onKeyDown = (function (e) {
43+
var original = self.onKeyDown;
44+
45+
return function (e) {
46+
var wasOpened = this.isOpen;
47+
48+
if (e.keyCode === 13 && (e.shiftKey || e.ctrlKey)) {
49+
self.trigger('submit');
50+
return;
51+
}
52+
53+
original.apply(this, arguments);
54+
};
55+
})();
56+
});
57+
3858
$(document).ready(function() {
3959
$('#submitter_input').selectize({
4060
plugins: ['enter_key_submit'],
@@ -76,6 +96,30 @@
7696
});
7797
}
7898
});
99+
100+
$('#labels_input').selectize({
101+
plugins: ['mod_enter_key_submit'],
102+
maxItems: null,
103+
persist: false,
104+
hideSelected: true,
105+
// Search for options that begin with a minus sign
106+
respect_word_boundaries: false,
107+
delimiter: ' ',
108+
options: [
109+
{% for label in project_labels %}
110+
{
111+
value: "{{ label.name }}",
112+
text: "{{ label.name }}",
113+
},
114+
{% endfor %}
115+
{% for label in project_labels %}
116+
{
117+
value: "-{{ label.name }}",
118+
text: "-{{ label.name }}",
119+
},
120+
{% endfor %}
121+
],
122+
});
79123
});
80124
</script>
81125

‎patchwork/views/__init__.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from django.contrib import messages
99
from django.shortcuts import get_object_or_404
10-
from django.db.models import Prefetch
10+
from django.db.models import Prefetch, Q
1111

1212
from patchwork.filters import Filters
1313
from patchwork.forms import CreateBundleForm
@@ -189,10 +189,15 @@ def generic_list(
189189
if not filter_settings:
190190
filter_settings = []
191191

192+
project_labels = Label.objects.filter(
193+
Q(project=project) | Q(project__isnull=True)
194+
).all()
195+
192196
filters = Filters(request)
193197
context = {
194198
'project': project,
195199
'projects': Project.objects.all(),
200+
'project_labels': project_labels,
196201
'filters': filters,
197202
}
198203

0 commit comments

Comments
 (0)