Skip to content

Commit 659c429

Browse files
committed
filters: Add autocomplete to labels filter
1 parent c169b3c commit 659c429

5 files changed

Lines changed: 83 additions & 0 deletions

File tree

‎htdocs/css/style.css‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,14 @@ select[class^=change-property-], .archive-patch-select, .add-bundle {
475475
margin: 0 .1em;
476476
}
477477

478+
.labels-field {
479+
padding: 4px;
480+
margin-right: 8px;
481+
box-sizing: border-box;
482+
border-radius: 4px;
483+
min-width: 200px;
484+
}
485+
478486
.patch-form-submit {
479487
font-weight: bold;
480488
padding: 4px;

‎patchwork/forms.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@ def __init__(self, instance=None, project=None, *args, **kwargs):
148148
self.fields['labels'] = forms.ModelMultipleChoiceField(
149149
queryset=Label.get_project_labels(project),
150150
required=False,
151+
widget=forms.SelectMultiple(
152+
attrs={'class': 'labels-field', 'placeholder': 'Labels'}
153+
),
151154
)
152155

153156
class Meta:
@@ -231,6 +234,9 @@ def __init__(self, project, *args, **kwargs):
231234

232235
self.fields['labels'] = forms.ModelMultipleChoiceField(
233236
queryset=Label.get_project_labels(project),
237+
widget=forms.SelectMultiple(
238+
attrs={'class': 'labels-field', 'placeholder': 'Labels to add'}
239+
),
234240
required=False,
235241
)
236242
self.fields['state'] = OptionalModelChoiceField(

‎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/templates/patchwork/partials/patch-forms.html‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
{% load static %}
2+
3+
<script type="text/javascript">
4+
$(document).ready(function() {
5+
$('.labels-field').selectize({
6+
maxItems: null,
7+
persist: false,
8+
hideSelected: true,
9+
// Search for options that begin with a minus sign
10+
respect_word_boundaries: false,
11+
delimiter: ' ',
12+
});
13+
});
14+
</script>
15+
116
<div class="patch-forms" id="patch-forms">
217
{% if patch_form %}
318
<div id="patch-form-properties" class="patch-form">

‎patchwork/views/__init__.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,16 @@ def generic_list(
189189
if not filter_settings:
190190
filter_settings = []
191191

192+
project_labels = [
193+
label.name
194+
for label in Label.get_project_labels(project)
195+
]
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)