aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Axtens <dja@axtens.net>2017-03-27 16:42:51 +1100
committerStephen Finucane <stephen@that.guru>2017-04-15 12:51:43 +0100
commit6e32965b04cc326a678a7b7a499f1389e44b6de9 (patch)
tree721a34e0cddcf62ae4d756db5ef2108b0ef53eab
parent562b4c66f292bb4a37804a9a9b53e3f85305cafe (diff)
downloadpatchwork-6e32965b04cc326a678a7b7a499f1389e44b6de9.tar
patchwork-6e32965b04cc326a678a7b7a499f1389e44b6de9.tar.gz
'mpe mode': click to copy patch IDs
If 'Show Patch IDs' is turned on in settings, add an extra column to the patch list, with buttons showing the patch IDs. The buttons copy the patch IDs to the clipboard. JavaScript inspired by https://github.com/Triforcey/clip-j and many many StackOverflow answers. Suggested-by: Michael Ellerman <mpe@ellerman.id.au> Signed-off-by: Daniel Axtens <dja@axtens.net> Reviewed-by: Stephen Finucane <stephen@that.guru>
-rw-r--r--patchwork/forms.py5
-rw-r--r--patchwork/migrations/0019_userprofile_show_ids.py20
-rw-r--r--patchwork/models.py3
-rw-r--r--patchwork/templates/patchwork/patch-list.html25
4 files changed, 52 insertions, 1 deletions
diff --git a/patchwork/forms.py b/patchwork/forms.py
index f42a224..0dd1185 100644
--- a/patchwork/forms.py
+++ b/patchwork/forms.py
@@ -107,7 +107,10 @@ class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
- fields = ['items_per_page']
+ fields = ['items_per_page', 'show_ids']
+ labels = {
+ 'show_ids': 'Show Patch IDs:'
+ }
def _get_delegate_qs(project, instance=None):
diff --git a/patchwork/migrations/0019_userprofile_show_ids.py b/patchwork/migrations/0019_userprofile_show_ids.py
new file mode 100644
index 0000000..d924184
--- /dev/null
+++ b/patchwork/migrations/0019_userprofile_show_ids.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.6 on 2017-03-26 20:59
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('patchwork', '0018_add_event_model'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='userprofile',
+ name='show_ids',
+ field=models.BooleanField(default=False, help_text=b'Show click-to-copy patch IDs in the list view'),
+ ),
+ ]
diff --git a/patchwork/models.py b/patchwork/models.py
index 05c6976..a336219 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -138,6 +138,9 @@ class UserProfile(models.Model):
items_per_page = models.PositiveIntegerField(
default=100, null=False, blank=False,
help_text='Number of items to display per page')
+ show_ids = models.BooleanField(
+ default=False,
+ help_text='Show click-to-copy patch IDs in the list view')
@property
def name(self):
diff --git a/patchwork/templates/patchwork/patch-list.html b/patchwork/templates/patchwork/patch-list.html
index 4b979ac..cdc368f 100644
--- a/patchwork/templates/patchwork/patch-list.html
+++ b/patchwork/templates/patchwork/patch-list.html
@@ -50,6 +50,18 @@ $(document).ready(function() {
e.preventDefault();
});
});
+
+{% if user.is_authenticated and user.profile.show_ids %}
+function copyToClipboard(patch_id) {
+ input = document.createElement('input');
+ input.setAttribute('type', 'text');
+ input.setAttribute('value', patch_id);
+ input = document.body.appendChild(input);
+ input.select();
+ document.execCommand('copy');
+ input.remove();
+}
+{% endif %}
</script>
<form method="post">
{% csrf_token %}
@@ -65,6 +77,12 @@ $(document).ready(function() {
</th>
{% endif %}
+ {% if user.is_authenticated and user.profile.show_ids %}
+ <th>
+ ID
+ </th>
+ {% endif %}
+
<th>
{% ifequal order.name "name" %}
<a class="colactive" href="{% listurl order=order.reversed_name %}">
@@ -175,6 +193,13 @@ $(document).ready(function() {
<input type="checkbox" name="patch_id:{{patch.id}}"/>
</td>
{% endif %}
+ {% if user.is_authenticated and user.profile.show_ids %}
+ <td>
+ <button type="button" class="btn btn-xs"
+ onClick="javascript:copyToClipboard('{{patch.id}}');"
+ title="Copy to Clipboard">{{ patch.id }}</button>
+ </td>
+ {% endif %}
<td>
<a href="{% url 'patch-detail' patch_id=patch.id %}">
{{ patch.name|default:"[no subject]"|truncatechars:100 }}