Add basic sorting
authorMagnus Hagander <magnus@hagander.net>
Sat, 24 Aug 2013 13:00:04 +0000 (15:00 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sat, 24 Aug 2013 13:00:04 +0000 (15:00 +0200)
pgcommitfest/commitfest/forms.py
pgcommitfest/commitfest/static/commitfest/js/commitfest.js
pgcommitfest/commitfest/templates/commitfest.html
pgcommitfest/commitfest/views.py

index 78219c3ccdc9a6de23ec50b55798997212928308..b2ba48eb81d067ee749a9cf8532251e7a03b18ed 100644 (file)
@@ -15,10 +15,13 @@ class CommitFestFilterForm(forms.Form):
        status = forms.ChoiceField(required=False)
        author = forms.ChoiceField(required=False)
        reviewer = forms.ChoiceField(required=False)
+       sortkey = forms.IntegerField(required=False)
 
        def __init__(self, cf, *args, **kwargs):
                super(CommitFestFilterForm, self).__init__(*args, **kwargs)
 
+               self.fields['sortkey'].widget = forms.HiddenInput()
+
                c = [(-1, '* All')] + list(PatchOnCommitFest._STATUS_CHOICES)
                self.fields['status'] = forms.ChoiceField(choices=c, required=False)
 
index 8f84d8be6b52b38015d3b36d5646a6f534c7d145..c5944332d45384c6537a3631ab4f7f614b307db0 100644 (file)
@@ -109,3 +109,10 @@ function doAttachThread(cfid, patchid, msgid) {
       return false;
    });
 }
+
+function sortpatches(sortby) {
+   $('#id_sortkey').val(sortby);
+   $('#filterform').submit();
+
+   return false;
+}
index 90a98551c5a9185f63d6cbd35a9ac7ded3e394ff..5d121f88224b1829ef3d1d3a72875bb132f3fba4 100644 (file)
@@ -12,9 +12,9 @@
       <table class="table table-condensed">
        <thead>
          <tr>
-{%for f in form%}
+{%for f in form%}{%if not f.is_hidden%}
             <td>{{f.label}}</td>
-{%endfor%}
+{%endif%}{%endfor%}
            <td></td>
          </tr>
        </thead>
 <table class="table table-striped table-bordered table-hover table-condensed">
  <thead>
   <tr>
-   <th>Patch</th>
+   <th>{%if p.is_open%}<a href="#" style="color:#333333;" onclick="return sortpatches(0);">Patch</a>{%if sortkey = 0%}<div style="float:right;"><i class="icon-arrow-down"></i></div>{%endif%}{%endif%}</th>
    <th>Status</th>
    <th>Author</th>
    <th>Reviewers</th>
-   <th>Latest activity</th>
-   <th>Latest mail</th>
+   <th>{%if p.is_open%}<a href="#" style="color:#333333;" onclick="return sortpatches(1);">Latest activity</a>{%if sortkey = 1%}<div style="float:right;"><i class="icon-arrow-down"></i></div>{%endif%}{%else%}Latest activity{%endif%}</th>
+   <th>{%if p.is_open%}<a href="#" style="color:#333333;" onclick="return sortpatches(2);">Latest mail</a>{%if sortkey = 2%}<div style="float:right;"><i class="icon-arrow-down"></i></div>{%endif%}{%else%}Latest mail{%endif%}</th>
   </tr>
  </thead>
  <tbody>
 {%endifchanged%}
 
+{%if grouping%}
 {%ifchanged p.topic%}
   <tr><th colspan="6">{{p.topic}}</th></tr>
 {%endifchanged%} 
+{%endif%}
   <tr>
    <td><a href="{{p.id}}/">{{p}}</a></td>
    <td><span class="label">{{p.status|patchstatusstring}}</span></td>
index da779c8e6067cac5ad3b175c949e619bcc96c667..cec486eb763394ce028aec5b59257574e6f45ed5 100644 (file)
@@ -50,9 +50,22 @@ def commitfest(request, cfid):
        if request.GET.has_key('text') and request.GET['text'] != '':
                q = q & Q(name__icontains=request.GET['text'])
 
-       # Not sure if this is correct?
        has_filter = len(q.children) > 0
-       if not has_filter and request.GET:
+
+       # Figure out custom ordering
+       ordering = ['-is_open', 'topic__topic', 'created',]
+       if request.GET.has_key('sortkey'):
+               sortkey=int(request.GET['sortkey'])
+               if sortkey==1:
+                       ordering = ['-is_open', 'modified', 'created',]
+               elif sortkey==2:
+                       ordering = ['-is_open', 'lastmail', 'created',]
+               else:
+                       sortkey=0
+       else:
+               sortkey = 0
+
+       if not has_filter and sortkey==0 and request.GET:
                # Redirect to get rid of the ugly url
                return HttpResponseRedirect('/%s/' % cf.id)
 
@@ -61,7 +74,7 @@ def commitfest(request, cfid):
                'author_names':"SELECT string_agg(first_name || ' ' || last_name || ' (' || username || ')', ', ') FROM auth_user INNER JOIN commitfest_patch_authors cpa ON cpa.user_id=auth_user.id WHERE cpa.patch_id=commitfest_patch.id",
                'reviewer_names':"SELECT string_agg(first_name || ' ' || last_name || ' (' || username || ')', ', ') FROM auth_user INNER JOIN commitfest_patch_reviewers cpr ON cpr.user_id=auth_user.id WHERE cpr.patch_id=commitfest_patch.id",
                'is_open':'commitfest_patchoncommitfest.status IN (%s)' % ','.join([str(x) for x in PatchOnCommitFest.OPEN_STATUSES]),
-       }).order_by('-is_open', 'topic__topic', 'created')
+       }).order_by(*ordering)
 
        # Generates a fairly expensive query, which we shouldn't do unless
        # the user is logged in. XXX: Figure out how to avoid doing that..
@@ -73,6 +86,8 @@ def commitfest(request, cfid):
                'patches': patches,
                'has_filter': has_filter,
                'title': 'Commitfest %s' % cf.name,
+               'grouping': sortkey==0,
+               'sortkey': sortkey,
                }, context_instance=RequestContext(request))
 
 def patch(request, cfid, patchid):