Skip to content

Commit 9ede0fe

Browse files
committed
filters: Add autocomplete to labels filter
1 parent c8699be commit 9ede0fe

2 files changed

Lines changed: 55 additions & 1 deletion

File tree

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{% load static %}
22

3+
{{ project_labels|json_script:"project-labels-data" }}
34
<script type="text/javascript">
45
var filterform_displayed = false;
56
function filter_click()
@@ -35,6 +36,26 @@
3536
})();
3637
});
3738

39+
// Submit form on shift+enter or ctrl+enter
40+
Selectize.define('mod_enter_key_submit', function (options) {
41+
var self = this;
42+
43+
this.onKeyDown = (function (e) {
44+
var original = self.onKeyDown;
45+
46+
return function (e) {
47+
var wasOpened = this.isOpen;
48+
49+
if (e.keyCode === 13 && (e.shiftKey || e.ctrlKey)) {
50+
self.trigger('submit');
51+
return;
52+
}
53+
54+
original.apply(this, arguments);
55+
};
56+
})();
57+
});
58+
3859
$(document).ready(function() {
3960
$('#submitter_input').selectize({
4061
plugins: ['enter_key_submit'],
@@ -76,6 +97,33 @@
7697
});
7798
}
7899
});
100+
101+
const project_labels = JSON.parse(
102+
document.getElementById('project-labels-data').textContent
103+
);
104+
105+
let label_options = project_labels.map(l => ({
106+
value: l,
107+
text: l,
108+
}));
109+
110+
label_options = label_options.concat(
111+
project_labels.map(l => ({
112+
value: "-" + l,
113+
text: "-" + l,
114+
}))
115+
);
116+
117+
$('#labels_input').selectize({
118+
plugins: ['mod_enter_key_submit'],
119+
maxItems: null,
120+
persist: false,
121+
hideSelected: true,
122+
// Search for options that begin with a minus sign
123+
respect_word_boundaries: false,
124+
delimiter: ' ',
125+
options: label_options,
126+
});
79127
});
80128
</script>
81129

‎patchwork/views/__init__.py‎

Lines changed: 7 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,16 @@ 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+
project_labels = [label.name for label in project_labels]
196+
192197
filters = Filters(request)
193198
context = {
194199
'project': project,
195200
'projects': Project.objects.all(),
201+
'project_labels': project_labels,
196202
'filters': filters,
197203
}
198204

0 commit comments

Comments
 (0)