]> git.ipfire.org Git - pbs.git/commitdiff
builders: Move stats JS into the main file
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 20:22:56 +0000 (20:22 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 6 Feb 2025 20:22:56 +0000 (20:22 +0000)
We currently cannot easily add more files in the right place, so since
there is only so little code, we just ship it all together.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/static/js/builders-stats.js [deleted file]
src/static/js/pbs.js
src/templates/builders/macros.html

index 8a44eb967831864200efa2bcef05d12685d4749d..61500ec9908348e4f4bc3cc2c20ff15c2c2dd011 100644 (file)
@@ -343,7 +343,6 @@ CLEANFILES += \
        src/static/css/site.css
 
 static_js_DATA = \
-       src/static/js/builders-stats.min.js \
        src/static/js/jquery.min.js \
        src/static/js/job-log-stream.min.js \
        src/static/js/notification-worker.min.js \
@@ -352,7 +351,6 @@ static_js_DATA = \
 static_jsdir = $(staticdir)/js
 
 EXTRA_DIST += \
-       src/static/js/builders-stats.js \
        src/static/js/job-log-stream.js \
        src/static/js/notification-worker.js \
        src/static/js/pbs.js
diff --git a/src/static/js/builders-stats.js b/src/static/js/builders-stats.js
deleted file mode 100644 (file)
index b65bd70..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-$(".builders-stats").each(function() {
-       // Fetch the name of the builder
-       const name = $(this).data("name");
-
-       const cpu_usage  = $(this).find("#cpu-usage");
-       const mem_usage  = $(this).find("#mem-usage");
-       const swap_usage = $(this).find("#swap-usage");
-
-       // Make the URL
-       const url = "wss://" + window.location.host + "/builders/" + name + "/stats";
-
-       // Try to connect to the stream
-       const stream = new WebSocket(url);
-
-       // Updates the progressbar and sets a colour
-       updateProgressBar = function(e, percentage) {
-               // Set the value
-               e.val(percentage * 100);
-
-               // Remove all classes
-               e.removeClass("is-dark is-light is-danger is-warning is-success");
-
-               if (percentage >= 0.9) {
-                       e.addClass("is-danger");
-
-               } else if (percentage >= 0.75) {
-                       e.addClass("is-warning");
-
-               } else {
-                       e.addClass("is-success");
-               }
-       }
-
-       stream.addEventListener("message", (event) => {
-               // Parse message as JSON
-               const data = JSON.parse(event.data);
-
-               console.debug("Message from server: ", data);
-
-               // Set CPU usage
-               if (cpu_usage)
-                       updateProgressBar(cpu_usage, data.cpu_usage);
-
-               // Set memory usage
-               if (mem_usage)
-                       updateProgressBar(mem_usage, data.mem_usage);
-
-               // Set swap usage
-               if (swap_usage)
-                       updateProgressBar(swap_usage, data.swap_usage);
-       });
-});
index 772d1cb2e0b26b2602051c80137e67bf3d8a250c..e4603c816706d012abed344c537ce899cb329a14 100644 (file)
@@ -134,3 +134,60 @@ $("#push-subscribe-button").on("click", function() {
                return subscription;
     });
 });
+
+/*
+ * Builder Stats
+ */
+
+$(".builders-stats").each(function() {
+       // Fetch the name of the builder
+       const name = $(this).data("name");
+
+       const cpu_usage  = $(this).find("#cpu-usage");
+       const mem_usage  = $(this).find("#mem-usage");
+       const swap_usage = $(this).find("#swap-usage");
+
+       // Make the URL
+       const url = "wss://" + window.location.host + "/builders/" + name + "/stats";
+
+       // Try to connect to the stream
+       const stream = new WebSocket(url);
+
+       // Updates the progressbar and sets a colour
+       updateProgressBar = function(e, percentage) {
+               // Set the value
+               e.val(percentage * 100);
+
+               // Remove all classes
+               e.removeClass("is-dark is-light is-danger is-warning is-success");
+
+               if (percentage >= 0.9) {
+                       e.addClass("is-danger");
+
+               } else if (percentage >= 0.75) {
+                       e.addClass("is-warning");
+
+               } else {
+                       e.addClass("is-success");
+               }
+       }
+
+       stream.addEventListener("message", (event) => {
+               // Parse message as JSON
+               const data = JSON.parse(event.data);
+
+               console.debug("Message from server: ", data);
+
+               // Set CPU usage
+               if (cpu_usage)
+                       updateProgressBar(cpu_usage, data.cpu_usage);
+
+               // Set memory usage
+               if (mem_usage)
+                       updateProgressBar(mem_usage, data.mem_usage);
+
+               // Set swap usage
+               if (swap_usage)
+                       updateProgressBar(swap_usage, data.swap_usage);
+       });
+});
index b1f235511ff3512af042c660707277c30e848f0a..68d14f7ce3ea75ccd7dfc0e965eb2d201b704275 100644 (file)
@@ -19,9 +19,6 @@
 ##############################################################################}
 
 {% macro BuilderStats(builder) %}
-       {# XXX Not sure if this is a good place to load the JS #}
-       <script src="{{ "js/builders-stats.min.js" | static_url }}"></script>
-
        <div class="builders-stats" data-name="{{ builder.name }}">
                <div class="columns is-vcentered">
                        <div class="column is-2">