From 7fb593c98a3da17f857840e0320a84a8cc50a51d Mon Sep 17 00:00:00 2001 From: rmanach Date: Tue, 19 Sep 2023 12:03:36 +0200 Subject: [PATCH] format html + put js in static --- .gitignore | 2 +- .../static/deployment/js/event_source.js | 39 ++++++++++ templates/base.html | 17 ++-- templates/deployment/board.html | 77 +++++-------------- templates/deployment/create.html | 2 +- templates/deployment/details.html | 20 ++--- templates/registration/login.html | 10 +-- 7 files changed, 85 insertions(+), 82 deletions(-) create mode 100644 deployment/static/deployment/js/event_source.js diff --git a/.gitignore b/.gitignore index 7847a62..ff65788 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ __pycache__ db.sqlite3 venv -static +/static *.log *.pid \ No newline at end of file diff --git a/deployment/static/deployment/js/event_source.js b/deployment/static/deployment/js/event_source.js new file mode 100644 index 0000000..09cd1ce --- /dev/null +++ b/deployment/static/deployment/js/event_source.js @@ -0,0 +1,39 @@ +var start = function (url) { + + var es = new ReconnectingEventSource(url); + + es.onopen = function () { + console.log('connected'); + }; + + es.addEventListener('stream-error', function (e) { + es.close(); + message = JSON.parse(e.data); + console.log('stream error: ' + message.condition + ': ' + message.text); + }, false); + + es.onerror = function (e) { + console.log('connection error'); + }; + + // listening on `message` events and update the corresponding table line. + // If the status is `FAILED`, we reload the window to ensure a new csrf_token. + es.addEventListener('message', function (e) { + message = JSON.parse(e.data); + console.log("id: " + message.id); + console.log("status: " + message.status); + + const tr = document.getElementById(message.id); + if (tr) { + var th = tr.querySelector("th[name='status']"); + th.innerHTML = message.status; + + if (message.status == "FAILED") { + setTimeout(() => { + window.location.reload(); + }, 2000); + } + } + + }, false); +}; \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 98c11fb..79f6e95 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,23 +1,26 @@ + {% block title %}mumui{% endblock %} {% block headscript %}{% endblock %} +
{% if user.is_authenticated or "login" in request.path %} - {% block content %} - {% endblock %} - {% if user.is_authenticated %} -

log out

- {% endif %} + {% block content %} + {% endblock %} + {% if user.is_authenticated %} +

log out

+ {% endif %} {% else %} -

You are not logged in

- log In +

You are not logged in

+ log In {% endif %}
{% block script %}{% endblock %} + \ No newline at end of file diff --git a/templates/deployment/board.html b/templates/deployment/board.html index 1aded6f..0eb1059 100644 --- a/templates/deployment/board.html +++ b/templates/deployment/board.html @@ -2,16 +2,16 @@ {% load static %} -{% block title %}deployment's board{% endblock %} +{% block title %} deployment's board {% endblock %} {% block headscript %} - - - + + + {% endblock %} {% block bodyattr %} - onload="start();" + onload="start('{{ url|safe }}');" {% endblock %} {% block content %} @@ -48,19 +48,19 @@ {% else %} @@ -72,45 +72,6 @@ {% endblock %} {% block script %} - {% endblock %} \ No newline at end of file diff --git a/templates/deployment/create.html b/templates/deployment/create.html index c781bd2..e8b9ff0 100644 --- a/templates/deployment/create.html +++ b/templates/deployment/create.html @@ -1,6 +1,6 @@ {% extends 'base.html' %} -{% block title %}new deployment{% endblock %} +{% block title %} new deployment {% endblock %} {% block content %} {{ user.username }}'s new deployment diff --git a/templates/deployment/details.html b/templates/deployment/details.html index d5e1e8f..5d32916 100644 --- a/templates/deployment/details.html +++ b/templates/deployment/details.html @@ -1,24 +1,24 @@ {% extends 'base.html' %} -{% block title %}deployment details: {{ deployment.name }}{% endblock %} +{% block title %} deployment details: {{ deployment.name }} {% endblock %} {% block content %} - - - - + + + + - - - - + + + +
idnametypestatusidnametypestatus
{{ deployment.id }}{{ deployment.name }}{{ deployment.type }}{{ deployment.status }}{{ deployment.id }}{{ deployment.name }}{{ deployment.type }}{{ deployment.status }}
{% csrf_token %} -
+ {% endblock %} \ No newline at end of file diff --git a/templates/registration/login.html b/templates/registration/login.html index 31a1048..9d46def 100644 --- a/templates/registration/login.html +++ b/templates/registration/login.html @@ -1,16 +1,16 @@ {% extends 'base.html' %} -{% block title %}login{% endblock %} +{% block title %} login {% endblock %} {% block content %} {% if not user.is_authenticated %}

log in

- {% csrf_token %} - {{ form.as_p }} - + {% csrf_token %} + {{ form.as_p }} +
{% else %} - you're already log in ! +
you're already log in !
{% endif %} {% endblock %} \ No newline at end of file