From 55e46a17f19ad559423c4a20e7bb100d0c13faf5 Mon Sep 17 00:00:00 2001 From: rmanach Date: Sat, 1 Nov 2025 14:01:03 +0100 Subject: [PATCH] fix event source conn --- Makefile | 7 ++++ .../static/deployment/js/event_source.js | 24 +++++++++++- .../deployment/js/event_source_details.js | 8 +++- templates/deployment/board.html | 18 +++------ templates/deployment/details.html | 37 +++++++++---------- 5 files changed, 58 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 58fd4e3..ae3dbba 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +ROOT_DIR = $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) +PYTHON = $(ROOT_DIR)venv/bin/python + format: @./venv/bin/black mumui/*.py deployment/*.py @@ -24,6 +27,10 @@ build: $(MAKE) nginx-local $(MAKE) django +.PHONY: static +static: + $(PYTHON) manage.py collectstatic --no-input + run: docker compose up diff --git a/deployment/static/deployment/js/event_source.js b/deployment/static/deployment/js/event_source.js index 6763514..ecd2e6d 100644 --- a/deployment/static/deployment/js/event_source.js +++ b/deployment/static/deployment/js/event_source.js @@ -1,5 +1,11 @@ +var es = null; + var start = function (url) { - var es = new ReconnectingEventSource(url); + if (es) { + console.log("closing es", es); + es.close(); + } + es = new ReconnectingEventSource(url); console.log("url: " + url); @@ -60,4 +66,18 @@ var start = function (url) { } } }, false); -}; \ No newline at end of file +}; + +document.querySelectorAll(".btn-details").forEach(btn => { + btn.addEventListener("click", function(e) { + const durl = e.currentTarget.getAttribute("durl"); + console.log("details url:", durl); + + if (es) { + window.es.close() + console.log("closing sse...."); + }; + + window.location = durl; + }); +}); \ No newline at end of file diff --git a/deployment/static/deployment/js/event_source_details.js b/deployment/static/deployment/js/event_source_details.js index ef985c1..bfef663 100644 --- a/deployment/static/deployment/js/event_source_details.js +++ b/deployment/static/deployment/js/event_source_details.js @@ -1,5 +1,11 @@ var start = function (url) { - var es = new ReconnectingEventSource(url); + if (window.es) { + console.log("closing es", window.es); + window.es.close(); + } + + es = new ReconnectingEventSource(url); + window.es = es; console.log("url: " + url); diff --git a/templates/deployment/board.html b/templates/deployment/board.html index 96f5295..8a223dc 100644 --- a/templates/deployment/board.html +++ b/templates/deployment/board.html @@ -4,16 +4,6 @@ {% block title %} Deployments board {% endblock %} -{% block headscript %} - - - -{% endblock %} - -{% block bodyattr %} - onload="start('{{ url|safe }}');" -{% endblock %} - {% block content %}
@@ -33,9 +23,7 @@ {{ deployment.type }} {{ deployment.status }} - - - + {% if deployment.status == "FAILED" or deployment.status == "READY" %} @@ -85,6 +73,10 @@ {% endblock %} {% block script %} + + + + {% endblock %} \ No newline at end of file diff --git a/templates/deployment/details.html b/templates/deployment/details.html index bd741d7..4a32b60 100644 --- a/templates/deployment/details.html +++ b/templates/deployment/details.html @@ -4,20 +4,6 @@ {% block title %} Deployment details: {{ deployment.name }} {% endblock %} -{% block bodyattr %} - {% if deployment.status == "RUNNING" or deployment.status == "PENDING" %} - onload="start('{{ url|safe }}');" - {% endif %} -{% endblock %} - -{% block headscript %} - {% if deployment.status == "RUNNING" or deployment.status == "PENDING" %} - - - - {% endif %} -{% endblock %} - {% block content %}
@@ -71,7 +57,7 @@ {% csrf_token %} {% endif %} - + {% if deployment.status != "RUNNING" and deployment.status != "PENDING" %} {% else %} @@ -87,12 +73,23 @@ {% block script %} {% if deployment.status == "RUNNING" or deployment.status == "PENDING" %} - + + + + + {% endif %} {% endblock %} \ No newline at end of file