Skip to contentSkip to conversation

Series: Add multiple select/change controls

PATCH New Jose Lamego 1 participant 4 messages Feb 28, 2017

lore
Share & tools
lore
#0 lore raw

cover Series: Add multiple select/change controls

Patches displayed at Series view must be individually opened to allow change status or add them to a bundle, increasing needed time and providing a poor user experience.

These changes add to Series view multiple select controls and the required functionality for status change, bundle addition and new bundle creation.

[YOCTO #10822]

Jose Lamego (3):
series.py: add patch and bundle edition actions to view series.html: add patch and bundle edition forms and checkboxes series.js: add patch-selection-checkbox control functions

 htdocs/js/series.js                       | 145 +++++++++++++++++++++----
 patchwork/templates/patchwork/series.html | 172 ++++++++++++++++++++++--------
 patchwork/views/series.py                 |  88 ++++++++-------
 3 files changed, 307 insertions(+), 98 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 series.py: add patch and bundle edition actions to view

This change adds patch and bundle edition actions to the series view.

[YOCTO # 10822]

---
 patchwork/views/series.py | 88 ++++++++++++++++++++++++++++-------------------
 1 file changed, 52 insertions(+), 36 deletions(-)
patchwork/views/series.py +52 -36
index 7645596..cb3b721 100644
@@ -17,6 +17,7 @@
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+from django.http import HttpResponseForbidden
 from django.conf import settings
 from django.shortcuts import render, render_to_response
 from django.shortcuts import get_object_or_404, get_list_or_404
@@ -25,6 +26,7 @@ from patchwork.models import Patch, Project, Bundle
 from patchwork.models import Series, SeriesRevision, TestResult
 from patchwork.requestcontext import PatchworkRequestContext
 from patchwork.forms import PatchForm, CreateBundleForm
+import json
 
 
 class SeriesListView(View):
@@ -44,6 +46,9 @@ class SeriesView(View):
     def get(self, request, *args, **kwargs):
         series = get_object_or_404(Series, pk=kwargs['series'])
         revisions = get_list_or_404(SeriesRevision, series=series)
+        patchform = PatchForm(project=series.project)
+        createbundleform = CreateBundleForm()
+        bundles = Bundle.objects.filter(owner=request.user)
         for revision in revisions:
             revision.patch_list = revision.ordered_patches().\
                 select_related('state', 'submitter')
@@ -56,19 +61,20 @@ class SeriesView(View):
             'project': series.project,
             'cover_letter': revision.cover_letter,
             'revisions': revisions,
+            'patchform': patchform,
+            'createbundleform': createbundleform,
+            'bundles': bundles,
         })
 
     def post(self, request, *args, **kwargs):
         init_data = request.POST
-        pa_id = init_data.get('patch', None)
-        curr_rev = init_data.get('rev', None)
-        patch = get_object_or_404(Patch, id=pa_id)
+        patches = json.loads(init_data.get('patches'))
         series = get_object_or_404(Series, pk=kwargs['series'])
-        context = PatchworkRequestContext(request)
-        context.project = patch.project
-        editable = patch.is_editable(request.user)
-
         revisions = get_list_or_404(SeriesRevision, series=series)
+        context = PatchworkRequestContext(request)
+        context.project = series.project
+        form = None
+        createbundleform = None
         for revision in revisions:
             revision.patch_list = revision.ordered_patches().\
                 select_related('state', 'submitter')
@@ -76,11 +82,6 @@ class SeriesView(View):
                     .filter(revision=revision, patch=None) \
                     .order_by('test__name').select_related('test')
 
-        form = None
-        createbundleform = None
-
-        if editable:
-            form = PatchForm(instance=patch)
         if request.user.is_authenticated():
             createbundleform = CreateBundleForm()
 
@@ -90,42 +91,57 @@ class SeriesView(View):
                 action = action.lower()
 
             if action == 'createbundle':
-                bundle = Bundle(owner=request.user, project=patch.project)
+                bundle = Bundle(owner=request.user, project=series.project)
                 createbundleform = CreateBundleForm(instance=bundle,
                                                     data=request.POST)
                 if createbundleform.is_valid():
                     createbundleform.save()
-                    bundle.append_patch(patch)
-                    bundle.save()
-                    createbundleform = CreateBundleForm()
-                    context.add_message('Bundle %s created' % bundle.name)
 
             elif action == 'addtobundle':
                 bundle = get_object_or_404(
                     Bundle, id=request.POST.get('bundle_id'))
-                try:
-                    bundle.append_patch(patch)
-                    bundle.save()
-                    context.add_message('Patch added to bundle "%s"' %
-                                        bundle.name)
-                except Exception as ex:
-                    context.add_message("Couldn't add patch '%s' to bundle %s:\
- %s" % (patch.name, bundle.name, ex.message))
-
-            # all other actions require edit privs
-            elif not editable:
-                return HttpResponseForbidden()
-
-            elif action is None:
-                form = PatchForm(data=request.POST, instance=patch)
-                if form.is_valid():
-                    form.save()
-                    context.add_message('Patch ID: %s updated' % patch.pk)
+
+            for pa_id in patches:
+                patch = get_object_or_404(Patch, id=pa_id)
+                editable = patch.is_editable(request.user)
+
+                if editable:
+                    form = PatchForm(instance=patch)
+
+                if action == 'createbundle':
+                    if createbundleform.is_valid():
+                        bundle.append_patch(patch)
+                        bundle.save()
+
+                elif action == 'addtobundle':
+                    try:
+                        bundle.append_patch(patch)
+                        bundle.save()
+                        context.add_message('Patch %s added to bundle "%s"' %
+                                            (patch.pk, bundle.name))
+                    except Exception as ex:
+                        context.add_message('Couldn\'t add patch %s to bundle\
+ "%s": %s' % (patch.pk, bundle.name, ex.message))
+
+                # all other actions require edit privs
+                elif not editable:
+                    return HttpResponseForbidden()
+
+                elif action is None:
+                    form = PatchForm(data=request.POST, instance=patch)
+                    if form.is_valid():
+                        form.save()
+                        context.add_message('Patch ID: %s updated' % patch.pk)
+
+            if action == 'createbundle':
+                createbundleform.save()
+                createbundleform = CreateBundleForm()
+                context.add_message('Bundle %s created' % bundle.name)
 
         context['series'] = series
         context['patchform'] = form
         context['createbundleform'] = createbundleform
-        context['project'] = patch.project
+        context['project'] = series.project
         context['revisions'] = revisions
         context['test_results'] = TestResult.objects \
             .filter(revision=None, patch=patch) \
Signature · 1 line
2.7.4
#2 lore raw

PATCH 2/3 series.html: add patch and bundle edition forms and checkboxes

In reply to Jose Lamego

This change adds patch and bundle edition forms, and patch selection checkboxes.

[YOCTO #10822]

---
 patchwork/templates/patchwork/series.html | 172 ++++++++++++++++++++++--------
 1 file changed, 130 insertions(+), 42 deletions(-)
patchwork/templates/patchwork/series.html +130 -42
index 0ba1f14..3c2cad9 100644
@@ -2,6 +2,9 @@
 
 {% load person %}
 {% load static %}
+{% load patch %}
+{% load listurl %}
+
 
 {% block title %}{{project.name}}{% endblock %}
 {% block headers %}
@@ -78,67 +81,152 @@ function toggle_headers(link_id, headers_id)
   </nav>
 
   <div id="cover-letter-view">
-{% if cover_letter %}
-  <h2>Cover Letter</h2>
-  <div class="comment">
-    <pre class="content">
-      {{ cover_letter }}
-    </pre>
-  </div>
-{% else %}
-  <h2 style="color:#909090">No cover letter was found for this series.</h2>
-{% endif %}
+    {% if cover_letter %}
+      <h2>Cover Letter</h2>
+      <div class="comment">
+        <pre class="content">
+          {{ cover_letter }}
+        </pre>
+      </div>
+    {% else %}
+      <h2 style="color:#909090">No cover letter was found for this series.</h2>
+    {% endif %}
   </div>
 
   <div class="tab-content" id="patches-list">
-{% for revision in revisions %}
-    <div role="tabpanel" id="rev{{ revision.version }}"
-         class="tab-pane fade{% if forloop.last %} in active{% endif %}">
-
-    <h3>Patches <a href="{% url 'seriesrevision-mbox' series.pk revision.version %}" >download mbox</a></h3>
-
-      <div class="well transparent">
-        <table class="table table-hover table-condensed pw-list" id="series-patchlist">
+    {% for revision in revisions %}
+      <div role="tabpanel" id="rev{{ revision.version }}"
+           class="tab-pane fade{% if forloop.last %} in active{% endif %}">
+        <h3>Patches <a href="{% url 'seriesrevision-mbox' series.pk revision.version %}" data-toggle="tooltip"
+                     title="Download all patches in selected revision as mbox">download mbox</a></h3>
+        <div class="well transparent">
+        <table class="table table-hover table-condensed pw-list">
           <thead>
             <tr>
-              <th>#</th>
+              {% if user.is_authenticated %}
+                <th>
+                  <input type="checkbox" name="{{ revision.version }}-sel-all" data-toggle="tooltip"
+                    title="Select all patches in current revision for status or bundling changing"/>
+                </th>
+              {% endif %}
               <th>Name</th>
               <th>Submitter</th>
               <th>State</th>
             </tr>
           </thead>
-          <tbody>
-        {% for patch in revision.patch_list %}
-            <tr>
-              <td></td>
-              <td><a href="#" class="patch-link" data-toggle="tooltip" title="Click to view the patch at bottom section"data-url="{% url 'patchwork.views.patch.patch' patch_id=patch.id %}">{{ patch.name|default:"[no subject]"|truncatechars:100 }}</a></td>
-              <td>{{ patch.submitter|personify:project }}</td>
-              <td>{{ patch.state }}</td>
-            <tr>
-        {% endfor %}
-          </tbody>
+          {% for patch in revision.patch_list %}
+            <tbody>
+              <tr id="patch_row:{{patch.id}}">
+                {% if user.is_authenticated %}
+                  <td>
+                    <input type="checkbox" name="patch_id:{{patch.id}}" data-rev="{{ revision.version }}"
+                     data-toggle="tooltip" title="Select this patch for status or bundling changing"/>
+                  </td>
+                {% endif %}
+                <td><a href="#" class="patch-link" data-toggle="tooltip" title="Click to view the patch at bottom section"
+                     data-url="{% url 'patchwork.views.patch.patch' patch_id=patch.id %}"
+                     >{{ patch.name|default:"[no subject]"|truncatechars:100 }}</a></td>
+                <td>{{ patch.submitter|personify:project }}</td>
+                <td>{{ patch.state }}</td>
+              <tr>
+            </tbody>
+          {% endfor %}
         </table>
+        </div>
       </div>
-
-    {% if revision.test_results %}
-    <h3>Tests</h3>
-
-    <div class="well transparent">
-      <div class="panel-group" id="test-accordion" role="tablist" aria-multiselectable="true" data-toggle="tooltip" title="Click to view/hide available test results">
-        {% for test_result in revision.test_results %}
-        {% include "patchwork/test-result.html" %}
-        {% endfor %}
-      </div>
+    {% endfor %}
+
+    <div id="seriesForm">
+    {% if user.is_authenticated %}
+    <div class="patchforms">
+      {% if patchform %}
+        <div class="patchform patchform-properties">
+          <h3>Series patches edit</h3>
+          <form method="post" id="seriesForm-patches">
+            {% csrf_token %}
+            <input type="hidden" name="patches"/>
+            <table class="form">
+              <tr>
+                <th>Change state:</th>
+                <td>
+                  {{ patchform.state }}
+                  {{ patchform.state.errors }}
+                </td>
+              </tr>
+              <tr>
+                <th>Delegate to:</th>
+                <td>
+                    {{ patchform.delegate }}
+                    {{ patchform.delegate.errors }}
+                </td>
+              </tr>
+              <tr>
+                <th>Archive:</th>
+                <td>
+                  {{ patchform.archived }}
+                  {{ patchform.archived.errors }}
+                </td>
+              </tr>
+              <tr>
+                <td></td>
+                <td>
+                  <button id="seriesPatches-update">Update</button>
+                </td>
+              </tr>
+            </table>
+          </form>
+        </div>
+      {% endif %}
     </div>
 
     {% endif %}
 
+    {% if createbundleform %}
+      <div class="patchform patchform-bundle" id="seriesForm-bundles">
+        <h3>Bundling</h3>
+          <table class="form">
+          <tr>
+            <td>Create bundle:</td>
+            <td>
+              {% if createbundleform.non_field_errors %}
+                <dd class="errors">{{createbundleform.non_field_errors}}</dd>
+              {% endif %}
+                <form method="post">
+                {% csrf_token %}
+                <input type="hidden" name="patches"/>
+                <input type="hidden" name="action" value="createbundle"/>
+                {% if createbundleform.name.errors %}
+                  <dd class="errors">{{createbundleform.name.errors}}</dd>
+                {% endif %}
+                {{ createbundleform.name }}
+                <input value="Create" type="submit" id="seriesPatches-create"/>
+              </form>
+            </td>
+          </tr>
+          {% if bundles %}
+            <tr>
+              <td>Add to bundle:</td>
+              <td>
+                <form method="post">
+                {% csrf_token %}
+                <input type="hidden" name="patches"/>
+                <input type="hidden" name="action" value="addtobundle"/>
+                <select name="bundle_id">
+                  {% for bundle in bundles %}
+                    <option value="{{bundle.id}}">{{bundle.name}}</option>
+                  {% endfor %}
+                </select>
+                <input value="Add" type="submit" id="seriesPatches-add"/>
+                </form>
+              </td>
+            </tr>
+          {% endif %}
+          </table>
+      </div>
+    {% endif %}
     </div>
-{% endfor %}
   </div>
 
   <div id="patch-view" class="container-fluid"></div>
 
-</div>
-
 {% endblock %}
Signature · 1 line
2.7.4
#3 lore raw

PATCH 3/3 series.js: add patch-selection-checkbox control functions

In reply to Jose Lamego

This change adds control functions for individual and multiple selection checkboxes.

[YOCTO #10822]

---
 htdocs/js/series.js | 145 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 125 insertions(+), 20 deletions(-)
htdocs/js/series.js +125 -20
index bd75790..c4bbb0e 100644
@@ -1,27 +1,47 @@
 $(document).ready(function(){
     $('[data-toggle="tooltip"]').tooltip()
     revTab=document.getElementById('revs-list')
-    coverView=document.getElementById('cover-letter-view'),
-    patchView=document.getElementById('patch-view'),
+    coverView=document.getElementById('cover-letter-view')
+    patchView=document.getElementById('patch-view')
     patchList=document.getElementById('patches-list')
-
+    patchesInput=$( "input[name^='patches']" )
+    seriesForms=document.getElementById('seriesForm')
+    var patches = new Array()
+    if ($( patchesInput[0] ).value){
+        patches=json_decode($( patchesInput[0] ).value, true)
+    }
+    else{
+        patches=[]
+    }
     revTab.style.border='none'
     revTab.style.background='transparent'
     revTab.style.padding='15px'
     coverView.style.display='block'
     patchView.style.display='none'
     patchList.style.display='none'
+    seriesForms.style.display='none'
 
     document.getElementById('cover-letter-tab').onclick=function(){
         coverView.style.display='block'
         patchView.style.display='none'
         patchList.style.display='none'
+        patches=[]
+        for (i=0; i<patchesInput.length; ++i){
+            $( patchesInput[i] ).prop('value', JSON.stringify(patches))
+        }
     }
 
     document.getElementById('patches-tab').onclick=function(){
         coverView.style.display='none'
         patchList.style.display='block'
         patchView.style.display="none"
+        patches=[]
+        for (i=0; i<patchesInput.length; ++i){
+            $( patchesInput[i] ).prop('value', "")
+        }
+        uncheck_allSel()
+        uncheck_allInput()
+        seriesForms.style.display='none'
     }
 
     $('#revs-list').on('change', function(e){
@@ -31,34 +51,119 @@ $(document).ready(function(){
         jQuery('.tab-content div#'+this.value+'.tab-pane.fade').
         addClass(' in active')
         patchView.style.display='none'
+        uncheck_allSel()
+        uncheck_allInput()
+        patches=[]
+        for (i=0; i<patchesInput.length; ++i){
+            $( patchesInput[i] ).prop('value', "")
+        }
+        seriesForms.style.display='none'
     })
 
     $('.patch-link').on('click', function(){
         var pa=this.getAttribute("data-url")
-        var curr_rev=document.getElementById('revs-list').value
         pa=pa.match(/\d+/)[0]
         coverView.style.display='none'
+        patchList.style.display='none'
         patchView.style.display='block'
         patchView.innerHTML=
         '<p style="text-align:center;">Loading patch...</p>'
-        $("#patch-view").load(
-            this.getAttribute("data-url") + " #patch-body", function() {
-                forms=document.forms
-                for (i=0; i<document.forms.length; i++){
-                    var n=(i + 1)
-                    var patch_field=document.createElement("input")
-                    patch_field.type="hidden"
-                    patch_field.name="patch"
-                    patch_field.value=pa
-                    var div=document.createElement("div")
-                    var this_form=document.forms.item(i)
-                    if (typeof this_form !== "undefined"){
-                        this_form.appendChild(div)
-                        div.appendChild(patch_field)
-                    }
+        uncheck_allInput()
+        uncheck_allSel()
+        patches=[]
+        for (i=0; i<patchesInput.length; ++i){
+            $( patchesInput[i] ).prop('value', "")
+        }
+        seriesForms.style.display='none'
+        $("#patch-view").load(this.getAttribute("data-url") + " #patch-body", 
+                              function(){
+            $( '#patch-view form' ).append(
+                    '<input type="hidden" name="patches" value="['+pa+']"/>')
+        })
+    })
+
+    $( "input[name^='patch_id']" ).change(function(){
+        patchView.style.display="none"
+        uncheck_allSel()
+        var p_id=$(this).attr('name').replace('patch_id:', '')
+        if ($(this).prop('checked')){
+            insert_patchId(p_id)
+            for (i=0; i<patchesInput.length; ++i){
+                $( patchesInput[i] ).prop('value', JSON.stringify(patches))
+            }
+            seriesForms.style.display='block'
+        }
+        else{
+            remove_patchId(p_id)
+            if (patches==""){
+                for (i=0; i<patchesInput.length; ++i){
+                    $( patchesInput[i] ).prop('value', "")
+                }
+                seriesForms.style.display='none'
+            }
+            else{
+                for (i=0; i<patchesInput.length; ++i){
+                    $( patchesInput[i] ).prop('value', JSON.stringify(patches))
                 }
             }
+        }
+    })
+
 
-        )
+    $( "input[name$='sel-all']" ).change(function(){
+        rev=this.getAttribute("name")
+        rev=rev.match(/\d+/)[0]
+        uncheck_allInput()
+        patches=[]
+        boxes=$( "input[name^='patch_id']" )
+        if ( $(this).prop('checked') ){
+            for (i=0; i<boxes.length; ++i){
+                if (boxes[i].getAttribute("data-rev")==rev){
+                    p_id=boxes[i].getAttribute("name")
+                    p_id=p_id.match(/\d+/)[0]
+                    $(boxes[i]).prop('checked', true)
+                    insert_patchId(p_id)
+                }
+                seriesForms.style.display='block'
+            }
+            for (i=0; i<patchesInput.length; ++i){
+                $( patchesInput[i] ).prop('value', JSON.stringify(patches))
+            }
+        }
+        else{
+            seriesForms.style.display='none'
+            for (i=0; i<patchesInput.length; ++i){
+                $( patchesInput[i] ).prop('value', "")
+            }
+        }
     })
+
+    function insert_patchId(id){
+        if (!patches.includes(id)){
+            patches.push(id)
+        }
+    }
+
+    function remove_patchId(id){
+        if (patches.includes(id)){
+            index=patches.indexOf(id)
+            patches.splice(index, 1)
+       }
+    }
+
+    function uncheck_allInput(){
+        boxes=$( "input[name^='patch_id']" )
+        for (i=0; i<boxes.length; ++i){
+            $(boxes[i]).prop("checked", false)
+        }
+    }
+
+    function uncheck_allSel(){
+        sels=$( "input[name$='sel-all']" )
+        for (i=0; i<sels.length; ++i){
+            $(sels[i]).prop("checked", false)
+        }
+
+    }
+
 })
Signature · 1 line
2.7.4