From c105cb0f107a7459abc8c33988d2da24582a7a5a Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Thu, 29 Jan 2009 17:38:46 +1100 Subject: [PATCH] Initial bundle reordering support todo: * implement ajax reorder api * finish migration script * order patches in bundle view Signed-off-by: Jeremy Kerr --- apps/patchwork/models.py | 18 ++- htdocs/js/bundle.js | 41 +++++ htdocs/js/jquery-1.2.6.js | 1 + htdocs/js/jquery.tablednd_0_5.js | 1 + .../migration/005-bundle-patch-ordering.sql | 9 ++ templates/patchwork/bundle.html | 11 ++ templates/patchwork/patch-list.html | 152 +++++++++--------- 7 files changed, 158 insertions(+), 75 deletions(-) create mode 100644 htdocs/js/bundle.js create mode 120000 htdocs/js/jquery-1.2.6.js create mode 120000 htdocs/js/jquery.tablednd_0_5.js create mode 100644 lib/sql/migration/005-bundle-patch-ordering.sql diff --git a/apps/patchwork/models.py b/apps/patchwork/models.py index 162fa21..d0c2a6e 100644 --- a/apps/patchwork/models.py +++ b/apps/patchwork/models.py @@ -289,12 +289,20 @@ class Bundle(models.Model): owner = models.ForeignKey(User) project = models.ForeignKey(Project) name = models.CharField(max_length = 50, null = False, blank = False) - patches = models.ManyToManyField(Patch) + patches = models.ManyToManyField(Patch, through = 'BundlePatch') public = models.BooleanField(default = False) def n_patches(self): return self.patches.all().count() + def append_patch(self, patch): + # todo: use the aggregate queries in django 1.1 + orders = BundlePatch.objects.filter(bundle = self).values('order') + max_order = max([ v for (k, v) in orders]) + + bp = BundlePatch.objects.create(bundle = self, patch = patch, order = max_order + 1) + bp.save() + class Meta: unique_together = [('owner', 'name')] @@ -313,6 +321,14 @@ class Bundle(models.Model): return '\n'.join([p.mbox().as_string(True) \ for p in self.patches.all()]) +class BundlePatch(models.Model): + patch = models.ForeignKey(Patch) + bundle = models.ForeignKey(Bundle) + order = models.IntegerField() + + class Meta: + unique_together = [('bundle', 'patch'), ('bundle', 'order')] + class UserPersonConfirmation(models.Model): user = models.ForeignKey(User) email = models.CharField(max_length = 200) diff --git a/htdocs/js/bundle.js b/htdocs/js/bundle.js new file mode 100644 index 0000000..dc4fb9c --- /dev/null +++ b/htdocs/js/bundle.js @@ -0,0 +1,41 @@ +function parse_patch_id(id_str) +{ + var i; + + i = id_str.indexOf(':'); + if (i == -1) + return null; + + return id_str.substring(i + 1); +} + +function bundle_handle_drop(table, row) +{ + var relative, relation, current; + var relative_id, current_id; + + current = $(row); + relative = $(current).prev(); + relation = 'after'; + + /* if we have no previous row, position ourselves before the next + * row instead */ + if (!relative.length) { + relative = current.next(); + relation = 'before'; + + if (!relative) + return; + } + + current_id = parse_patch_id(current.attr('id')); + relative_id = parse_patch_id(relative.attr('id')); + + alert("put patch " + current_id + " " + relation + " " + relative_id); +} + +$(document).ready(function() { + $("#patchlist").tableDnD({ + onDrop: bundle_handle_drop + }); +}); diff --git a/htdocs/js/jquery-1.2.6.js b/htdocs/js/jquery-1.2.6.js new file mode 120000 index 0000000..cb24de6 --- /dev/null +++ b/htdocs/js/jquery-1.2.6.js @@ -0,0 +1 @@ +../../lib/packages/jquery/jquery-1.2.6.js \ No newline at end of file diff --git a/htdocs/js/jquery.tablednd_0_5.js b/htdocs/js/jquery.tablednd_0_5.js new file mode 120000 index 0000000..5918e24 --- /dev/null +++ b/htdocs/js/jquery.tablednd_0_5.js @@ -0,0 +1 @@ +../../lib/packages/jquery/jquery.tablednd_0_5.js \ No newline at end of file diff --git a/lib/sql/migration/005-bundle-patch-ordering.sql b/lib/sql/migration/005-bundle-patch-ordering.sql new file mode 100644 index 0000000..9f5bcf3 --- /dev/null +++ b/lib/sql/migration/005-bundle-patch-ordering.sql @@ -0,0 +1,9 @@ +BEGIN; +ALTER TABLE patchwork_bundle_patches RENAME TO patchwork_bundlepatch; +ALTER TABLE patchwork_bundlepatch ADD COLUMN "order" INTEGER NULL; +UPDATE patchwork_bundlepatch SET "order" = + (SELECT COALESCE(max("order"), 0) + 1 FROM patchwork_bundlepatch AS p2 + WHERE p2.bundle_id = patchwork_bundlepatch.bundle_id); +ALTER TABLE patchwork_bundlepatch ALTER COLUMN "order" SET NOT NULL; +ALTER TABLE patchwork_bundlepatch ADD UNIQUE("bundle_id", "order"); +COMMIT; diff --git a/templates/patchwork/bundle.html b/templates/patchwork/bundle.html index 68bf570..d9a2785 100644 --- a/templates/patchwork/bundle.html +++ b/templates/patchwork/bundle.html @@ -2,6 +2,17 @@ {% load person %} +{% block headers %} + + + +{% endblock %} {% block title %}{{project.name}}{% endblock %} {% block heading %}bundle: {{bundle.name}}{% endblock %} diff --git a/templates/patchwork/patch-list.html b/templates/patchwork/patch-list.html index 4c6b8a5..5518805 100644 --- a/templates/patchwork/patch-list.html +++ b/templates/patchwork/patch-list.html @@ -22,84 +22,87 @@
- - - {% if user.is_authenticated %} - - {% endif %} +
- -
+ + + {% if user.is_authenticated %} + + {% endif %} + + + + + + + + + + - - - - - - - - - - - + + {% if page %} + {% for patch in page.object_list %} - + {% if user.is_authenticated %} {% endfor %} +
+ + + {% ifequal order.name "name" %} + Patch + {% else %} + Patch + {% endifequal %} + + {% ifequal order.name "date" %} + Date + {% else %} + Date + {% endifequal %} + + {% ifequal order.name "submitter" %} + Submitter + {% else %} + Submitter + {% endifequal %} + + {% ifequal order.name "delegate" %} + Delegate + {% else %} + Delegate + {% endifequal %} + + {% ifequal order.name "state" %} + State + {% else %} + State + {% endifequal %} + - {% ifequal order.name "name" %} - Patch - {% else %} - Patch - {% endifequal %} - - {% ifequal order.name "date" %} - Date - {% else %} - Date - {% endifequal %} - - {% ifequal order.name "submitter" %} - Submitter - {% else %} - Submitter - {% endifequal %} - - {% ifequal order.name "delegate" %} - Delegate - {% else %} - Delegate - {% endifequal %} - - {% ifequal order.name "state" %} - State - {% else %} - State - {% endifequal %} -
@@ -113,6 +116,7 @@ {{ patch.state }}
{% include "patchwork/pagination.html" %} -- 2.39.2