[PATCH 28/51] series: Add a first attempt at a Series list view

Damien Lespiau damien.lespiau at intel.com
Sat Sep 12 01:55:01 AEST 2015


It's all good that we can parse emails to build Series in the database,
but we also need to view them.

This commit introduces a new project/$project/series view that is the
list of series.

Instead of doing all server side, after the initial page load, we load
data through the JSON API. This should hopefully make the
editing/sorting/paging a bit less jarring as we're not reloading the
whole page anymore.

Signed-off-by: Damien Lespiau <damien.lespiau at intel.com>
---
 htdocs/js/patchwork.js                         | 86 ++++++++++++++++++++++++++
 patchwork/templates/patchwork/series-list.html | 52 ++++++++++++++++
 patchwork/urls.py                              |  4 ++
 patchwork/views/series.py                      | 30 +++++++++
 templates/base.html                            | 12 ++++
 5 files changed, 184 insertions(+)
 create mode 100644 htdocs/js/patchwork.js
 create mode 100644 patchwork/templates/patchwork/series-list.html
 create mode 100644 patchwork/views/series.py

diff --git a/htdocs/js/patchwork.js b/htdocs/js/patchwork.js
new file mode 100644
index 0000000..a144232
--- /dev/null
+++ b/htdocs/js/patchwork.js
@@ -0,0 +1,86 @@
+var pw = (function() {
+    var _this,
+        exports = {},
+        ctx = {
+            project: null
+        };
+
+    var columnsMap = {
+        'Series': 'name',
+        'Patches': 'n_patches',
+        'Submitter': 'submitter_name',
+        'Reviewer': 'reviewer_name',
+        'Submitted': 'submitted',
+        'Updated': 'last_updated'
+    };
+
+    function date_writer(record) {
+        return record[this.id].substr(0, 10);
+    }
+
+    function reviewer_writer(record) {
+        reviewer = record[this.id];
+        if (!reviewer)
+            return '<em class="text-muted">None</span>';
+        else
+            return reviewer;
+    }
+
+    exports.init = function(init_ctx) {
+        _this = this;
+
+        $.extend(ctx, init_ctx);
+
+        $.dynatableSetup({
+            dataset: {
+                perPageDefault: 20,
+                perPageOptions: [20, 50, 100]
+            },
+            params: {
+                perPage: 'perpage',
+                records: 'results',
+                queryRecordCount: 'count',
+                totalRecordCount: 'count'
+            },
+            inputs: {
+                pageText: '',
+                paginationPrev: '« Previous',
+                paginationNext: 'Next »',
+                paginationGap: [1,1,1,1],
+            },
+            writers: {
+                'submitted': date_writer,
+                'last_updated': date_writer,
+                'reviewer_name': reviewer_writer
+            }
+        });
+    }
+
+    exports.setup_series_list = function(selector) {
+        var table = $(selector);
+
+        table.bind('dynatable:preinit', function(e, dynatable) {
+            dynatable.utility.textTransform.PatchworkSeries = function(text) {
+                return columnsMap[text];
+            };
+        }).dynatable({
+            features: {
+                search: false,
+                recordCount: false,
+            },
+            table: {
+                defaultColumnIdStyle: 'PatchworkSeries',
+            },
+            dataset: {
+                ajax: true,
+                ajaxUrl: '/api/1.0/projects/' + ctx.project + '/series/',
+                ajaxOnLoad: true,
+                records: []
+            }
+        });
+
+        table.stickyTableHeaders();
+    }
+
+    return exports
+}());
diff --git a/patchwork/templates/patchwork/series-list.html b/patchwork/templates/patchwork/series-list.html
new file mode 100644
index 0000000..7cf0ba9
--- /dev/null
+++ b/patchwork/templates/patchwork/series-list.html
@@ -0,0 +1,52 @@
+{% extends "base.html" %}
+
+{% load person %}
+
+{% block title %}{{project.name}}{% endblock %}
+{% block heading %}{{project.name}}{% endblock %}
+{% block headers %}
+<script language="JavaScript" type="text/javascript">
+$(function () {
+    pw.setup_series_list('#serieslist');
+});
+</script>
+{% endblock %}
+{% block breadcrumb %}{{ project.name }} series{% endblock %}
+
+{% block body %}
+<h2>Incoming Series</h2>
+
+<nav class="navbar navbar-default">
+  <div class="container-fluid">
+    <ul class="nav navbar-nav navbar-right">
+     <li>
+      <div class="navbar-form pull-right">
+        <label>Show: </label>
+        <select id="dynatable-per-page-serieslist" class="form-control">
+        </select>
+      </div>
+     </li>
+    </ul>
+  </div>
+</nav>
+
+<div class='dynatable-pagination-links-serieslist'></div>
+
+<table class="table table-hover table-condensed pw-list" id="serieslist">
+<thead>
+  <tr>
+    <th>Series</th>
+    <th>Patches</th>
+    <th>Reviewer</th>
+    <th>Submitter</th>
+    <th>Submitted</th>
+    <th>Updated</th>
+  </tr>
+</thead>
+<tbody>
+</tbody>
+</table>
+
+<div class='dynatable-pagination-links-serieslist'></div>
+
+{% endblock %}
diff --git a/patchwork/urls.py b/patchwork/urls.py
index 67c6c6b..0d36ec5 100644
--- a/patchwork/urls.py
+++ b/patchwork/urls.py
@@ -22,6 +22,7 @@ from django.conf import settings
 from django.contrib import admin
 from django.contrib.auth import views as auth_views
 from rest_framework_nested import routers
+from patchwork.views.series import SeriesListView
 import patchwork.views.api as api
 
 # API
@@ -57,6 +58,9 @@ urlpatterns = patterns('',
     (r'^project/(?P<project_id>[^/]+)/list/$', 'patchwork.views.patch.list'),
     (r'^project/(?P<project_id>[^/]+)/$', 'patchwork.views.project.project'),
 
+    # series views
+    (r'^project/(?P<project>[^/]+)/series/$', SeriesListView.as_view()),
+
     # patch views
     (r'^patch/(?P<patch_id>\d+)/$', 'patchwork.views.patch.patch'),
     (r'^patch/(?P<patch_id>\d+)/raw/$', 'patchwork.views.patch.content'),
diff --git a/patchwork/views/series.py b/patchwork/views/series.py
new file mode 100644
index 0000000..0f65c83
--- /dev/null
+++ b/patchwork/views/series.py
@@ -0,0 +1,30 @@
+# Patchwork - automated patch tracking system
+# Copyright (C) 2014 Intel Corporation
+#
+# This file is part of the Patchwork package.
+#
+# Patchwork is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# Patchwork is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# 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 HttpResponseRedirect
+from django.shortcuts import render, get_object_or_404
+from django.views.generic import View
+from patchwork.models import Project
+
+class SeriesListView(View):
+    def get(self, request, *args, **kwargs):
+        return render(request, 'patchwork/series-list.html', {
+            'project': get_object_or_404(Project, linkname=kwargs['project']),
+        })
+
diff --git a/templates/base.html b/templates/base.html
index 6b254f7..18c3ef6 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -8,6 +8,7 @@
   <title>{% block title %}Patchwork{% endblock %} - Patchwork</title>
   <link rel="stylesheet" type="text/css" href="{% static "css/bootstrap.min.css" %}"/>
   <link rel="stylesheet" type="text/css" href="{% static "css/selectize.bootstrap3.css" %}"/>
+  <link rel="stylesheet" type="text/css" href="{% static "css/jquery.dynatable.css" %}"/>
   <link rel="stylesheet" type="text/css" href="{% static "css/style.css" %}"/>
   <script type="text/javascript" src="{% static "js/common.js" %}"></script>
   <script type="text/javascript" src="{% static "js/jquery-1.10.1.min.js" %}"></script>
@@ -22,6 +23,17 @@
   <![endif]-->
   <script type="text/javascript" src="{% static "js/bootstrap.min.js" %}"></script>
   <script type="text/javascript" src="{% static "js/selectize.min.js" %}"></script>
+  <script type="text/javascript" src="{% static "js/jquery.dynatable.js" %}"></script>
+  <script type="text/javascript" src="{% static "js/patchwork.js" %}"></script>
+  <script type="text/javascript">
+    $(function () {
+        pw.init({
+{% if project %}
+          project: '{{ project.linkname }}'
+{% endif  %}
+        });
+    });
+  </script>
 {% block headers %}{% endblock %}
  </head>
  <body>
-- 
2.1.0



More information about the Patchwork mailing list