Skip to content

Commit babe788

Browse files
committed
views: Add tooltips with description to labels
help_text is not relevant to database migrations. This commit modifies the label migration instead of creating a new migration.
1 parent 2fedf40 commit babe788

8 files changed

Lines changed: 56 additions & 28 deletions

File tree

‎htdocs/js/selectize-plugins.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,25 @@ Selectize.define('mod_focus_input_after_select', function (options) {
4747
prevSelect(e);
4848
};
4949
});
50+
51+
function selectize_labels_input(selector, label_options) {
52+
selector.selectize({
53+
plugins: ['mod_enter_key_submit', 'mod_focus_input_after_select'],
54+
maxItems: null,
55+
persist: false,
56+
hideSelected: true,
57+
// Search for options that begin with a minus sign
58+
respect_word_boundaries: false,
59+
delimiter: ' ',
60+
options: label_options,
61+
render: {
62+
item: function (item, escape) {
63+
return '<div><span title="' + escape(item.description) + '">' + escape(item.text) + '</span></div>';
64+
},
65+
option: function (item, escape) {
66+
console.log(item, escape);
67+
return '<div class="option" title="' + escape(item.description) + '">' + escape(item.text) + '</div>';
68+
},
69+
},
70+
});
71+
}

‎patchwork/migrations/0054_label_coverlabel_cover_labels_patchlabel_and_more.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ class Migration(migrations.Migration):
3535
models.TextField(
3636
blank=True,
3737
help_text='A description of what the label is '
38-
'and when it should be applied.',
38+
'and when it should be applied. The text will be '
39+
'visible in tooltips of label elements in the UI.',
3940
max_length=1000,
4041
null=True,
4142
),

‎patchwork/models.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,8 @@ class Label(models.Model):
290290
blank=True,
291291
max_length=1000,
292292
help_text='A description of what the label is and when it should be '
293-
'applied.',
293+
'applied. The text will be visible in tooltips of label elements in '
294+
'the UI.',
294295
)
295296
color = ColorField(help_text='The color code to use in the UI.')
296297

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

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,27 +67,20 @@
6767
);
6868

6969
let label_options = project_labels.map(l => ({
70-
value: l,
71-
text: l,
70+
value: l.name,
71+
text: l.name,
72+
description: l.description,
7273
}));
7374

7475
label_options = label_options.concat(
7576
project_labels.map(l => ({
76-
value: "-" + l,
77-
text: "-" + l,
77+
value: "-" + l.name,
78+
text: "-" + l.name,
79+
description: l.description,
7880
}))
7981
);
8082

81-
const labels_selectize = $('#labels_input').selectize({
82-
plugins: ['mod_enter_key_submit', 'mod_focus_input_after_select'],
83-
maxItems: null,
84-
persist: false,
85-
hideSelected: true,
86-
// Search for options that begin with a minus sign
87-
respect_word_boundaries: false,
88-
delimiter: ' ',
89-
options: label_options,
90-
});
83+
selectize_labels_input($('#labels_input'), label_options);
9184
});
9285
</script>
9386

‎patchwork/templates/patchwork/partials/patch-forms.html‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
{% load static %}
22

3+
{{ project_labels|json_script:"project-labels-data" }}
4+
35
<script type="text/javascript">
46
$(document).ready(function() {
5-
$('.labels-field').selectize({
6-
plugins: ['mod_focus_input_after_select'],
7-
maxItems: null,
8-
persist: false,
9-
hideSelected: true,
10-
// Search for options that begin with a minus sign
11-
respect_word_boundaries: false,
12-
delimiter: ' ',
13-
});
7+
const project_labels = JSON.parse(
8+
document.getElementById('project-labels-data').textContent
9+
);
10+
11+
let label_options = project_labels.map(l => ({
12+
value: l.id,
13+
text: l.name,
14+
description: l.description,
15+
}));
16+
17+
selectize_labels_input($('.labels-field'), label_options);
1418
});
1519
</script>
1620

‎patchwork/templatetags/patch.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def text_color(hex_color):
107107
text_color(label.color),
108108
)
109109
output.append(
110-
'<span class="label patch-label" style="%s">%s</span>'
111-
% (style, escape(label.name))
110+
'<span class="label patch-label" style="%s" title="%s">%s</span>'
111+
% (style, escape(label.description), escape(label.name))
112112
)
113113

114114
# Label name is escaped above. Color is formatted in a way that

‎patchwork/views/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def generic_list(
190190
filter_settings = []
191191

192192
project_labels = [
193-
label.name
193+
{"id": label.id, "name": label.name, "description": label.description}
194194
for label in Label.get_project_labels(project)
195195
]
196196

‎patchwork/views/patch.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from patchwork.models import Cover
1818
from patchwork.models import Patch
1919
from patchwork.models import Project
20+
from patchwork.models import Label
2021
from patchwork.views import generic_list
2122
from patchwork.views import set_bundle
2223
from patchwork.views.utils import patch_to_mbox
@@ -115,6 +116,12 @@ def patch_detail(request, project_id, msgid):
115116
related_same_project = []
116117
related_different_project = []
117118

119+
project_labels = [
120+
{"id": label.id, "name": label.name, "description": label.description}
121+
for label in Label.get_project_labels(patch.project)
122+
]
123+
124+
context['project_labels'] = project_labels
118125
context['comments'] = comments
119126
context['checks'] = Patch.filter_unique_checks(
120127
patch.check_set.all().select_related('user'),

0 commit comments

Comments
 (0)