]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Move log stream frontend code
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 23:07:56 +0000 (23:07 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 23:07:56 +0000 (23:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/static/js/job-log-stream.js [deleted file]
src/static/js/pbs.js
src/templates/jobs/log-stream.html
src/templates/jobs/macros.html
src/templates/jobs/modules/log-stream.html [deleted file]

index 28d45da0413519668b8d4750b35c2ccca096fdd6..8a584848c5964444c6ac8c4cf81458bb1b32fe2b 100644 (file)
@@ -255,11 +255,6 @@ dist_templates_jobs_messages_DATA = \
 
 templates_jobs_messagesdir = $(templates_jobsdir)/messages
 
-dist_templates_jobs_modules_DATA = \
-       src/templates/jobs/modules/log-stream.html
-
-templates_jobs_modulesdir = $(templates_jobsdir)/modules
-
 templates_messagesdir = $(templatesdir)/messages
 
 dist_templates_mirrors_DATA = \
@@ -345,14 +340,12 @@ CLEANFILES += \
 
 static_js_DATA = \
        src/static/js/jquery.min.js \
-       src/static/js/job-log-stream.min.js \
        src/static/js/notification-worker.min.js \
        src/static/js/pbs.min.js
 
 static_jsdir = $(staticdir)/js
 
 EXTRA_DIST += \
-       src/static/js/job-log-stream.js \
        src/static/js/notification-worker.js \
        src/static/js/pbs.js
 
diff --git a/src/static/js/job-log-stream.js b/src/static/js/job-log-stream.js
deleted file mode 100644 (file)
index 94a20f8..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-$(".jobs-log-stream").each(function() {
-       // Fetch the UUID of the job
-       const uuid = $(this).data("uuid");
-
-       // Fetch the limit
-       const limit = $(this).data("limit");
-
-       // Find where we are appending lines to
-       const log = $(this);
-
-       // Make the URL
-       var url = "wss://" + window.location.host + "/api/v1/jobs/" + uuid + "/log/stream";
-
-       if (limit > 0)
-               url += "?limit=" + limit;
-
-       // Try to connect to the stream
-       const stream = new WebSocket(url);
-
-       stream.addEventListener("message", (event) => {
-               // Parse message as JSON
-               const data = JSON.parse(event.data);
-
-               console.log("Message from server: ", data);
-
-               // If there is a limit, reduce the number of rows first
-               while (limit > 0 && log.children().length >= limit) {
-                       log.children().first().remove();
-               }
-
-               // Create a new line
-               var line = $("<li></li>");
-
-               // Set the log level
-               line.addClass(data.level);
-
-               // Set the content
-               line.text(data.message);
-
-               // Append it to the log window
-               log.append(line);
-       });
-});
index e4603c816706d012abed344c537ce899cb329a14..a1f979f000ea3fef8a608fe12e44c5d3eed00b9d 100644 (file)
@@ -191,3 +191,50 @@ $(".builders-stats").each(function() {
                        updateProgressBar(swap_usage, data.swap_usage);
        });
 });
+
+/*
+ * Log Stream
+ */
+$(".jobs-log-stream").each(function() {
+       // Fetch the UUID of the job
+       const uuid = $(this).data("uuid");
+
+       // Fetch the limit
+       const limit = $(this).data("limit");
+
+       // Find where we are appending lines to
+       const log = $(this);
+
+       // Make the URL
+       var url = "wss://" + window.location.host + "/api/v1/jobs/" + uuid + "/log/stream";
+
+       if (limit > 0)
+               url += "?limit=" + limit;
+
+       // Try to connect to the stream
+       const stream = new WebSocket(url);
+
+       stream.addEventListener("message", (event) => {
+               // Parse message as JSON
+               const data = JSON.parse(event.data);
+
+               console.log("Message from server: ", data);
+
+               // If there is a limit, reduce the number of rows first
+               while (limit > 0 && log.children().length >= limit) {
+                       log.children().first().remove();
+               }
+
+               // Create a new line
+               var line = $("<li></li>");
+
+               // Set the log level
+               line.addClass(data.level);
+
+               // Set the content
+               line.text(data.message);
+
+               // Append it to the log window
+               log.append(line);
+       });
+});
index 2f133ba346b2f1ebbf64fe0f9a667e61437e38a9..c9820d921960b3afba890cfccd08d93d65726b1d 100644 (file)
@@ -1,6 +1,6 @@
-{% extends "../base.html" %}
+{% extends "base.html" %}
 
-{% block title %}{{ job }} - {{ _("Log") }}{% end block %}
+{% block title %}{{ job }} - {{ _("Log") }}{% endblock %}
 
 {% block container %}
        <nav class="breadcrumb" aria-label="breadcrumbs">
@@ -20,5 +20,5 @@
                </ul>
        </nav>
 
-       {% module JobsLogStream(job) %}
-{% end block %}
+       {{ JobLogStream(job) }}
+{% endblock %}
index 840a0714a82583f70c59df3618843bbdff0155af..8e8974977d355257f60d50c1073d3905696dae3b 100644 (file)
@@ -77,7 +77,7 @@
                                {# Log #}
                                {% if job.is_running() %}
                                        <div class="panel-block">
-                                               {..% module JobsLogStream(job, limit=5) %..}
+                                               {{ JobLogStream(job, limit=5) }}
                                        </div>
 
                                {# Dependency Issues #}
                {% endfor %}
        </nav>
 {% endmacro %}
+
+{% macro JobLogStream(job, small=False, limit=None) %}
+       <ul class="jobs-log-stream {% if small %}is-small{% endif %}"
+               data-uuid="{{ job.uuid }}" {% if limit %}data-limit="{{ limit }}"{% endif %}></ul>
+{% endmacro %}
diff --git a/src/templates/jobs/modules/log-stream.html b/src/templates/jobs/modules/log-stream.html
deleted file mode 100644 (file)
index 6cb93f6..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-<ul class="jobs-log-stream {% if small %}is-small{% end %}"
-       data-uuid="{{ job.uuid }}" {% if limit %}data-limit="{{ limit }}"{% end %}></ul>