]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
filters: re-add the possibility of filtering undelegated patches
authorMauro Carvalho Chehab <mchehab@infradead.org>
Tue, 4 Jun 2019 21:31:39 +0000 (18:31 -0300)
committerStephen Finucane <stephen@that.guru>
Wed, 5 Jun 2019 10:25:51 +0000 (11:25 +0100)
The filters.py redesign that happened for patchwork 1.1 removed
a functionality that we use a lot: to filter patches that weren't
delegated to anyone.

Also, it is a way harder to find someone to delegate with a free
text input. Use, instead a combo-box just like before.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
Signed-off-by: Stephen Finucane <stephen@that.guru>
Fixes: f439f541 ("Add delegate filter autocomplete support")
Closes: #60
[stephenfin: Rework release note and fix some style issues]

patchwork/filters.py
patchwork/templates/patchwork/partials/filters.html
releasenotes/notes/issue-60-9d4fc111242f7db6.yaml [new file with mode: 0644]

index 79aaea437c6e3cd43ef5baf74f18c3578f8a83f8..e2d2f5958dd4642a19d085c3da951d6308d1e1c7 100644 (file)
@@ -385,6 +385,7 @@ class ArchiveFilter(Filter):
 class DelegateFilter(Filter):
     name = 'Delegate'
     param = 'delegate'
+    no_delegate_str = 'Nobody'
     ANY_DELEGATE = object()
 
     def __init__(self, filters):
@@ -416,6 +417,11 @@ class DelegateFilter(Filter):
         if not key:
             return
 
+        if key == self.no_delegate_str:
+            self.delegate_match = key
+            self.applied = True
+            return
+
         try:
             self.delegate = User.objects.get(id=int(key))
         except (ValueError, User.DoesNotExist):
@@ -436,6 +442,9 @@ class DelegateFilter(Filter):
         if self.delegate:
             return {'delegate': self.delegate}
 
+        if self.delegate_match == self.no_delegate_str:
+            return {'delegate__username__isnull': True}
+
         if self.delegate_match:
             return {'delegate__username__icontains': self.delegate_match}
 
@@ -447,8 +456,31 @@ class DelegateFilter(Filter):
             return mark_safe('<input type="hidden" value="%s">%s' % (
                 self.param, self.condition))
 
-        return mark_safe('<input type="text" name="delegate" '
-                         'id="delegate_input" class="form-control">')
+        delegates = User.objects.filter(
+            profile__maintainer_projects__isnull=False)
+
+        out = '<select name="delegate" class="form-control">'
+
+        selected = ''
+        if not self.applied:
+            selected = 'selected'
+        out += '<option %s value="">------</option>' % selected
+
+        selected = ''
+        if self.applied and self.delegate is None:
+            selected = 'selected'
+        out += '<option %s value="%s">%s</option>' % (
+            selected, self.no_delegate_str, self.no_delegate_str)
+
+        for delegate in delegates:
+            selected = ''
+            if delegate == self.delegate:
+                selected = ' selected'
+
+            out += '<option %s value="%s">%s</option>' % (
+                selected, delegate.id, delegate.username)
+        out += '</select>'
+        return mark_safe(out)
 
     def set_status(self, *args, **kwargs):
         if 'delegate' in kwargs:
index 41ed2c268e460ca7c974039e2975906e40b5d382..e89c4d0f62842b69ad59599d99c5cb372738e7f4 100644 (file)
@@ -76,44 +76,6 @@ $(document).ready(function() {
             });
         }
     });
-
-    $('#delegate_input').selectize({
-        plugins: ['enter_key_submit'],
-        maxItems: 1,
-        persist: false,
-        onInitialize: function() {
-            this.on('submit', function() {
-                if (!this.items.length)
-                    this.$input.val(this.lastValue);
-                this.$input.closest('form').submit();
-            }, this);
-        },
-{% if "delegate" in filters.applied_filters %}
-{% with delegate_filter=filters.applied_filters.delegate %}
-        options: [
-            {
-                value: "{{ delegate_filter.key }}",
-                text: "{{ delegate_filter.condition }}",
-            },
-        ],
-        items: ["{{ delegate_filter.key }}"],
-{% endwith %}
-{% endif %}
-        load: function(query, callback) {
-            req = $.ajax({
-                url: "{% url 'api-delegates' %}",
-                data: {q: query, l: 10},
-                error: function() {
-                    callback();
-                },
-                success: function(res) {
-                    callback($.map(res, function (obj) {
-                        return {value: obj.pk, text: obj.name};
-                    }));
-                }
-            });
-        }
-    });
 });
 </script>
 
diff --git a/releasenotes/notes/issue-60-9d4fc111242f7db6.yaml b/releasenotes/notes/issue-60-9d4fc111242f7db6.yaml
new file mode 100644 (file)
index 0000000..7988659
--- /dev/null
@@ -0,0 +1,8 @@
+---
+fixes:
+  - |
+    In the past, Patchwork used to support filtering patches that weren't
+    delegated to anyone. This feature was removed in v1.1.0, as part of a patch
+    designed to support delegation to anyone. However, that feature didn't scale
+    and was later removed. The ability to delegate to anyone is now itself
+    re-introduced.