From ae0a01ca6e148b78542728e5a0c9b7e3ffb78c14 Mon Sep 17 00:00:00 2001 From: Rinkit Adhana Date: Fri, 28 Mar 2025 00:07:08 +0530 Subject: [PATCH 01/14] side navbar fixed --- website/templates/queue/list.html | 1 + 1 file changed, 1 insertion(+) diff --git a/website/templates/queue/list.html b/website/templates/queue/list.html index 5333422550..2ee6ad25f6 100644 --- a/website/templates/queue/list.html +++ b/website/templates/queue/list.html @@ -4,6 +4,7 @@ Queue Management {% endblock title %} {% block content %} + {% include "includes/sidenav.html" %}

Queue Management

From ba9dbb33786ead0547154aa6946ac2a1f085fa7e Mon Sep 17 00:00:00 2001 From: Rinkit Adhana Date: Fri, 28 Mar 2025 01:22:48 +0530 Subject: [PATCH 02/14] launched_at added and conditions added for it --- website/admin.py | 4 +--- website/models.py | 19 ++++++++++++++----- website/templates/queue/list.html | 26 ++++++++++++++++++++++---- website/templates/social.html | 2 +- website/views/queue.py | 24 ++++++++++++++++-------- 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/website/admin.py b/website/admin.py index 5bafe9e27f..e43dde5650 100644 --- a/website/admin.py +++ b/website/admin.py @@ -717,9 +717,7 @@ def mark_as_launched(self, request, queryset): count = 0 for queue_item in queryset: if not queue_item.launched: - queue_item.launched = True - queue_item.launched_at = now - queue_item.save() + queue_item.launch(now) count += 1 self.message_user(request, f"{count} queue items marked as launched.") diff --git a/website/models.py b/website/models.py index 42c37fdd95..f9b73b81dc 100644 --- a/website/models.py +++ b/website/models.py @@ -2374,14 +2374,23 @@ class Meta: def __str__(self): return f"Queue item {self.id}: {self.message[:30]}{'...' if len(self.message) > 30 else ''}" - def launch(self): + def launch(self, timestamp=None): """ Mark the queue item as launched and set the launched_at timestamp. + + Args: + timestamp (datetime, optional): Custom timestamp to use. Defaults to current time. + + Returns: + bool: True if the item was launched, False if it was already launched """ - if not self.launched: - self.launched = True - self.launched_at = timezone.now() - self.save() + # Always update the timestamp, even if already launched + self.launched = True + self.launched_at = timestamp or timezone.now() + self.save() + + # Return whether this was a new launch or not + return True class Thread(models.Model): diff --git a/website/templates/queue/list.html b/website/templates/queue/list.html index 2ee6ad25f6..91e41a7b64 100644 --- a/website/templates/queue/list.html +++ b/website/templates/queue/list.html @@ -235,6 +235,10 @@

Pending Items

class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> Created + + Launched At + Actions @@ -258,6 +262,7 @@

Pending Items

{% endif %} {{ item.created|date:"M d, Y H:i" }} + {{ item.launched_at|date:"M d, Y H:i" |default:"Not launched" }}
{% csrf_token %} @@ -324,7 +329,7 @@

Recently Launched Items

No image {% endif %} - {{ item.launched_at|date:"M d, Y H:i" }} + {{ item.launched_at|date:"M d, Y H:i" | default:"Not launched" }}
{% if item.url %} @@ -407,6 +412,10 @@

Recently Launched Items

class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> Status + + Launched At + Transaction Details @@ -443,6 +452,13 @@

Recently Launched Items

{% endif %} + + {% if item.launched_at %} + {{ item.launched_at|date:"M d, Y H:i" }} + {% else %} + Not launched + {% endif %} +
{% if item.url %} @@ -487,6 +503,7 @@

Recently Launched Items

{% endif %}
+ {% if not item.launched %}
-
- +
+ + {% endif %} {% empty %} - No queue items found. + No queue items found. {% endfor %} diff --git a/website/templates/social.html b/website/templates/social.html index 631ae8e285..92f8dfc0ae 100644 --- a/website/templates/social.html +++ b/website/templates/social.html @@ -98,7 +98,7 @@

Social Feed

stroke="currentColor"> - {{ item.launched_at|date:"M j, Y" }} + {{ item.launched_at|date:"M j, Y H:i" }}
{% endif %}
diff --git a/website/views/queue.py b/website/views/queue.py index f71280882c..f3e550b100 100644 --- a/website/views/queue.py +++ b/website/views/queue.py @@ -85,7 +85,13 @@ def queue_list(request): queue_id = request.POST.get("queue_id") queue_item = get_object_or_404(Queue, id=queue_id) - if not queue_item.launched: + # Get current time + current_time = timezone.now() + + # Check if this is the first launch + was_unlaunched = not queue_item.launched + + if was_unlaunched: # Send tweet image_path = None if queue_item.image: @@ -94,9 +100,8 @@ def queue_list(request): tweet_result = twitter.send_tweet(queue_item.message, image_path) if tweet_result["success"]: - # Update queue item with tweet information - queue_item.launched = True - queue_item.launched_at = timezone.now() + # Launch the queue item with Twitter info + queue_item.launch(current_time) queue_item.txid = tweet_result["txid"] queue_item.url = tweet_result["url"] queue_item.save() @@ -109,9 +114,7 @@ def queue_list(request): messages.success(request, success_msg) else: # Still mark as launched but log the error - queue_item.launched = True - queue_item.launched_at = timezone.now() - queue_item.save() + queue_item.launch(current_time) logger.error(f"Error sending tweet: {tweet_result['error']}") warning_msg = ( @@ -120,7 +123,12 @@ def queue_list(request): ) messages.warning(request, warning_msg) else: - messages.info(request, "Queue item was already launched") + # Just update the timestamp if already launched + queue_item.launch(current_time) + messages.info( + request, + f"Queue item was already launched. Launch timestamp updated to {current_time.strftime('%Y-%m-%d %H:%M:%S')}.", + ) return redirect("queue_list") From 6e73326e1ab83bdc7f9e16d506d9697a543da854 Mon Sep 17 00:00:00 2001 From: Rinkit Adhana Date: Fri, 28 Mar 2025 15:02:01 +0530 Subject: [PATCH 03/14] transaction fixed --- website/templates/queue/list.html | 8 +- .../partials/launch_transaction_details.html | 45 ++++++++++ .../queue/partials/transaction_details.html | 85 ++++++++++--------- website/views/queue.py | 66 ++++++++++++-- 4 files changed, 152 insertions(+), 52 deletions(-) create mode 100644 website/templates/queue/partials/launch_transaction_details.html diff --git a/website/templates/queue/list.html b/website/templates/queue/list.html index 91e41a7b64..f5872613e3 100644 --- a/website/templates/queue/list.html +++ b/website/templates/queue/list.html @@ -19,8 +19,8 @@

Queue Management

Launch Control {% endif %} - Organizations + Social {% if messages %} @@ -357,7 +357,7 @@

Recently Launched Items

value="{{ item.txid|default:'' }}"> + + + \ No newline at end of file diff --git a/website/templates/queue/partials/transaction_details.html b/website/templates/queue/partials/transaction_details.html index 171fa90739..a6ebef9bd8 100644 --- a/website/templates/queue/partials/transaction_details.html +++ b/website/templates/queue/partials/transaction_details.html @@ -1,40 +1,47 @@ -{% if item.url %} - -{% endif %} -{% if item.txid %} -
ID: {{ item.txid }}
-{% else %} -
Transaction ID: Not available
-{% endif %} -{% if item.launched %} -
- {% csrf_token %} -
- - - +
+ {% if message %} +
+ {{ message }}
- -{% endif %} + {% endif %} + {% if item.url %} + + {% endif %} + {% if item.txid %} +
ID: {{ item.txid }}
+ {% else %} +
Transaction ID: Not available
+ {% endif %} + {% if item.launched %} +
+ {% csrf_token %} +
+ + + +
+
+ {% endif %} +
diff --git a/website/views/queue.py b/website/views/queue.py index f3e550b100..5a7e653b34 100644 --- a/website/views/queue.py +++ b/website/views/queue.py @@ -176,19 +176,67 @@ def update_txid(request, queue_id): if request.method == "POST": queue_item = get_object_or_404(Queue, id=queue_id) - txid = request.POST.get("txid", "") - url = request.POST.get("url", "") + txid = request.POST.get("txid", "").strip() + url = request.POST.get("url", "").strip() - if txid: - queue_item.txid = txid + # Track what was updated for the message + txid_updated = False + url_updated = False + txid_removed = False + url_removed = False - if url: + # Only update txid if provided, otherwise keep existing value + if txid and txid != queue_item.txid: + queue_item.txid = txid + txid_updated = True + + # Only update url if provided, otherwise keep existing value + if url and url != queue_item.url: queue_item.url = url + url_updated = True + + # Clear values if explicitly submitted as empty + if "txid" in request.POST and not txid and queue_item.txid: + queue_item.txid = None + txid_removed = True + + if "url" in request.POST and not url and queue_item.url: + queue_item.url = None + url_removed = True queue_item.save() - - # Return the updated transaction details HTML - context = {"item": queue_item} - return render(request, "queue/partials/transaction_details.html", context) + + # Build the response message + message_parts = [] + if txid_updated: + message_parts.append("Transaction ID updated") + if url_updated: + message_parts.append("URL updated") + if txid_removed: + message_parts.append("Transaction ID removed") + if url_removed: + message_parts.append("URL removed") + + # Create the appropriate message + if message_parts: + message = f"Success: {' and '.join(message_parts)}" + else: + message = "No changes were made" + + # Check which target is being updated based on the HTTP_HX_TARGET header + hx_target = request.META.get('HTTP_HX_TARGET', '') + + context = { + "item": queue_item, + "message": message + } + + # Determine which template to use based on the target ID + if 'launch-transaction-details' in hx_target: + # This is for the launch control section + return render(request, "queue/partials/launch_transaction_details.html", context) + else: + # This is for the main list section + return render(request, "queue/partials/transaction_details.html", context) return HttpResponse("Method not allowed", status=405) From 5700429e6e0ec980da99277faa68b243cae812b4 Mon Sep 17 00:00:00 2001 From: Rinkit Adhana Date: Fri, 28 Mar 2025 15:29:54 +0530 Subject: [PATCH 04/14] paid field added --- website/templates/queue/list.html | 49 +++++++++++++++++++++++++++---- website/views/queue.py | 23 +++++++-------- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/website/templates/queue/list.html b/website/templates/queue/list.html index f5872613e3..5626274be6 100644 --- a/website/templates/queue/list.html +++ b/website/templates/queue/list.html @@ -5,7 +5,7 @@ {% endblock title %} {% block content %} {% include "includes/sidenav.html" %} -
+

Queue Management

@@ -239,6 +239,10 @@

Pending Items

class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> Launched At + + Paid + Actions @@ -249,7 +253,7 @@

Pending Items

{% for item in pending_items %} {{ item.id }} - {{ item.message|truncatechars:50 }} + {{ item.message|truncatechars:10 }} {% if item.image %} Pending Items {% endif %} {{ item.created|date:"M d, Y H:i" }} - {{ item.launched_at|date:"M d, Y H:i" |default:"Not launched" }} + + {% if item.launched_at %} + {{ item.launched_at|date:"M d, Y H:i" }} + {% else %} + Not launched + {% endif %} + + + {% if item.txid %} + Paid + {% else %} + Unpaid + {% endif %} +
{% csrf_token %} @@ -307,6 +324,10 @@

Recently Launched Items

class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> Launched At + + Paid + Tweet @@ -317,7 +338,7 @@

Recently Launched Items

{% for item in launched_items %} {{ item.id }} - {{ item.message|truncatechars:50 }} + {{ item.message|truncatechars:10 }} {% if item.image %} Recently Launched Items {% endif %} {{ item.launched_at|date:"M d, Y H:i" | default:"Not launched" }} + + {% if item.txid %} + Paid + {% else %} + Unpaid + {% endif %} +
{% if item.url %} @@ -416,6 +444,10 @@

Recently Launched Items

class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider"> Launched At + + Paid + Transaction Details @@ -430,7 +462,7 @@

Recently Launched Items

{% for item in queue_items %} {{ item.id }} - {{ item.message|truncatechars:50 }} + {{ item.message|truncatechars:10 }} {% if item.image %} Recently Launched Items Not launched {% endif %} + + {% if item.txid %} + Paid + {% else %} + Unpaid + {% endif %} +
{% if item.url %} diff --git a/website/views/queue.py b/website/views/queue.py index 5a7e653b34..f54da078ed 100644 --- a/website/views/queue.py +++ b/website/views/queue.py @@ -189,23 +189,23 @@ def update_txid(request, queue_id): if txid and txid != queue_item.txid: queue_item.txid = txid txid_updated = True - + # Only update url if provided, otherwise keep existing value if url and url != queue_item.url: queue_item.url = url url_updated = True - + # Clear values if explicitly submitted as empty if "txid" in request.POST and not txid and queue_item.txid: queue_item.txid = None txid_removed = True - + if "url" in request.POST and not url and queue_item.url: queue_item.url = None url_removed = True queue_item.save() - + # Build the response message message_parts = [] if txid_updated: @@ -216,7 +216,7 @@ def update_txid(request, queue_id): message_parts.append("Transaction ID removed") if url_removed: message_parts.append("URL removed") - + # Create the appropriate message if message_parts: message = f"Success: {' and '.join(message_parts)}" @@ -224,15 +224,12 @@ def update_txid(request, queue_id): message = "No changes were made" # Check which target is being updated based on the HTTP_HX_TARGET header - hx_target = request.META.get('HTTP_HX_TARGET', '') - - context = { - "item": queue_item, - "message": message - } - + hx_target = request.META.get("HTTP_HX_TARGET", "") + + context = {"item": queue_item, "message": message} + # Determine which template to use based on the target ID - if 'launch-transaction-details' in hx_target: + if "launch-transaction-details" in hx_target: # This is for the launch control section return render(request, "queue/partials/launch_transaction_details.html", context) else: From 5b22b4953da3d03a1c0ac0ba73d8d03c6fed58c7 Mon Sep 17 00:00:00 2001 From: Rinkit Adhana Date: Fri, 28 Mar 2025 15:51:05 +0530 Subject: [PATCH 05/14] view queue feature added --- website/templates/queue/list.html | 134 ++++++++++++++++++++++++++++-- 1 file changed, 129 insertions(+), 5 deletions(-) diff --git a/website/templates/queue/list.html b/website/templates/queue/list.html index 5626274be6..c0022a592d 100644 --- a/website/templates/queue/list.html +++ b/website/templates/queue/list.html @@ -32,6 +32,54 @@

Queue Management

{% endfor %}
{% endif %} + + - {% if not item.launched %}
+ -
- - {% endif %} +
+ {% empty %} @@ -732,6 +786,76 @@

Recently Launched Items

launchControlContainer.classList.add('hidden'); }); } + + // View modal functionality + const viewBtns = document.querySelectorAll('.view-btn'); + const closeViewModalBtn = document.getElementById('closeViewModalBtn'); + const viewModalContainer = document.getElementById('viewModalContainer'); + const viewMessage = document.getElementById('viewMessage'); + const viewImageContainer = document.getElementById('viewImageContainer'); + const viewImage = document.getElementById('viewImage'); + const noImageText = document.getElementById('noImageText'); + const copyMessageBtn = document.getElementById('copyMessageBtn'); + const copyImageBtn = document.getElementById('copyImageBtn'); + const copySuccessMessage = document.getElementById('copySuccessMessage'); + + function showCopySuccess() { + copySuccessMessage.classList.remove('hidden'); + setTimeout(() => { + copySuccessMessage.classList.add('hidden'); + }, 2000); + } + + viewBtns.forEach(function(btn) { + btn.addEventListener('click', function() { + const message = this.getAttribute('data-message'); + const imageUrl = this.getAttribute('data-image'); + + viewMessage.value = message; + + if (imageUrl) { + viewImage.src = imageUrl; + viewImageContainer.classList.remove('hidden'); + noImageText.classList.add('hidden'); + } else { + viewImageContainer.classList.add('hidden'); + noImageText.classList.remove('hidden'); + } + + viewModalContainer.classList.remove('hidden'); + }); + }); + + if (closeViewModalBtn) { + closeViewModalBtn.addEventListener('click', function() { + viewModalContainer.classList.add('hidden'); + }); + } + + if (copyMessageBtn) { + copyMessageBtn.addEventListener('click', function() { + viewMessage.select(); + document.execCommand('copy'); + showCopySuccess(); + }); + } + + if (copyImageBtn) { + copyImageBtn.addEventListener('click', async function() { + try { + const response = await fetch(viewImage.src); + const blob = await response.blob(); + const data = new ClipboardItem({ + [blob.type]: blob + }); + await navigator.clipboard.write([data]); + showCopySuccess(); + } catch (err) { + console.error('Failed to copy image:', err); + alert('Failed to copy image. Please try again.'); + } + }); + } }); {% endblock content %} From a14a1aac49f430c6ceeff1eec62064eb4cbf21a3 Mon Sep 17 00:00:00 2001 From: Rinkit Adhana Date: Fri, 28 Mar 2025 15:51:19 +0530 Subject: [PATCH 06/14] pre-commit error --- .../queue/partials/launch_transaction_details.html | 6 ++---- website/templates/queue/partials/transaction_details.html | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/website/templates/queue/partials/launch_transaction_details.html b/website/templates/queue/partials/launch_transaction_details.html index a5c33bf983..789514c8e2 100644 --- a/website/templates/queue/partials/launch_transaction_details.html +++ b/website/templates/queue/partials/launch_transaction_details.html @@ -1,8 +1,6 @@
{% if message %} -
- {{ message }} -
+
{{ message }}
{% endif %} {% if item.url %}
@@ -42,4 +40,4 @@
-
\ No newline at end of file +
diff --git a/website/templates/queue/partials/transaction_details.html b/website/templates/queue/partials/transaction_details.html index a6ebef9bd8..ebf7b37877 100644 --- a/website/templates/queue/partials/transaction_details.html +++ b/website/templates/queue/partials/transaction_details.html @@ -1,8 +1,6 @@
{% if message %} -
- {{ message }} -
+
{{ message }}
{% endif %} {% if item.url %}
From e4a47721fbed569a1a8dae2650f353672939abec Mon Sep 17 00:00:00 2001 From: Rinkit Adhana Date: Fri, 28 Mar 2025 16:44:31 +0530 Subject: [PATCH 07/14] improved UI/UX of whole page --- website/templates/queue/list.html | 1455 ++++++++++++++++------------- 1 file changed, 809 insertions(+), 646 deletions(-) diff --git a/website/templates/queue/list.html b/website/templates/queue/list.html index c0022a592d..ccaa309fba 100644 --- a/website/templates/queue/list.html +++ b/website/templates/queue/list.html @@ -5,632 +5,833 @@ {% endblock title %} {% block content %} {% include "includes/sidenav.html" %} -
-
-

Queue Management

-
- - {% if is_launch_authorized %} - - {% endif %} - Social -
-
- {% if messages %} -
- {% for message in messages %} -
- {{ message|safe }} +
+
+ +
+
+
+
+ + + +
+
+

Queue Management

+ + {{ queue_items|length }} item + {% if queue_items|length != 1 %}s{% endif %} + in queue + +
- {% endfor %} -
- {% endif %} - -