12315: Add "exclude child processes" checkbox to /all_processes.
[arvados.git] / apps / workbench / app / assets / javascripts / work_unit_log.js
index 07606929c49f9f2d0a4a843547663a191e013e70..c43bae0e3c7e080d01c0fc69d19e2435612777e1 100644 (file)
@@ -1,18 +1,68 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
 $(document).on('arv-log-event', '.arv-log-event-handler-append-logs', function(event, eventData){
+    var wasatbottom, txt;
     if (this != event.target) {
         // Not interested in events sent to child nodes.
         return;
     }
-    var wasatbottom = ($(this).scrollTop() + $(this).height() >= this.scrollHeight);
 
-    if (eventData.properties != null && eventData.properties.text != null) {
-        if( eventData.prepend ) {
-            $(this).prepend(eventData.properties.text);
-        } else {
-            $(this).append(eventData.properties.text);
+    if (!('properties' in eventData)) {
+        return;
+    }
+
+    txt = '';
+    if ('text' in eventData.properties &&
+       eventData.properties.text.length > 0) {
+        txt += eventData.properties.text;
+        if (txt.slice(txt.length-1) != "\n") {
+            txt += "\n";
+        }
+    }
+    if (eventData.event_type == 'update' &&
+        eventData.object_uuid.indexOf("-dz642-") == 5 &&
+        'old_attributes' in eventData.properties &&
+        'new_attributes' in eventData.properties) {
+        // Container update
+        if (eventData.properties.old_attributes.state != eventData.properties.new_attributes.state) {
+            var stamp = eventData.event_at + " ";
+            switch(eventData.properties.new_attributes.state) {
+            case "Queued":
+                txt += stamp + "Container "+eventData.object_uuid+" was returned to the queue\n";
+                break;
+            case "Locked":
+                txt += stamp + "Container "+eventData.object_uuid+" was taken from the queue by a dispatch process\n";
+                break;
+            case "Running":
+                txt += stamp + "Container "+eventData.object_uuid+" started\n";
+                break;
+            case "Complete":
+                txt += stamp + "Container "+eventData.object_uuid+" finished\n";
+                break;
+            case "Cancelled":
+                txt += stamp + "Container "+eventData.object_uuid+" was cancelled\n";
+                break;
+            default:
+                // Unknown state -- unexpected, might as well log it.
+                txt += stamp + "Container "+eventData.object_uuid+" changed state to " +
+                    eventData.properties.new_attributes.state + "\n";
+                break;
+            }
         }
     }
 
+    if (txt == '') {
+        return;
+    }
+
+    wasatbottom = (this.scrollTop + this.clientHeight >= this.scrollHeight);
+    if (eventData.prepend) {
+        $(this).prepend(txt);
+    } else {
+        $(this).append(txt);
+    }
     if (wasatbottom) {
         this.scrollTop = this.scrollHeight;
     }