Fix 2.4.2 upgrade notes formatting refs #19330
[arvados.git] / apps / workbench / app / assets / javascripts / work_unit_log.js
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 $(document).on('arv-log-event', '.arv-log-event-handler-append-logs', function(event, eventData){
6     var wasatbottom, txt;
7     if (this != event.target) {
8         // Not interested in events sent to child nodes.
9         return;
10     }
11
12     if (!('properties' in eventData)) {
13         return;
14     }
15
16     txt = '';
17     if ('text' in eventData.properties &&
18        eventData.properties.text.length > 0) {
19         txt += eventData.properties.text;
20         if (txt.slice(txt.length-1) != "\n") {
21             txt += "\n";
22         }
23     }
24     if (eventData.event_type == 'update' &&
25         eventData.object_uuid.indexOf("-dz642-") == 5 &&
26         'old_attributes' in eventData.properties &&
27         'new_attributes' in eventData.properties) {
28         // Container update
29         if (eventData.properties.old_attributes.state != eventData.properties.new_attributes.state) {
30             var stamp = eventData.event_at + " ";
31             switch(eventData.properties.new_attributes.state) {
32             case "Queued":
33                 txt += stamp + "Container "+eventData.object_uuid+" was returned to the queue\n";
34                 break;
35             case "Locked":
36                 txt += stamp + "Container "+eventData.object_uuid+" was taken from the queue by a dispatch process\n";
37                 break;
38             case "Running":
39                 txt += stamp + "Container "+eventData.object_uuid+" started\n";
40                 break;
41             case "Complete":
42                 txt += stamp + "Container "+eventData.object_uuid+" finished\n";
43                 break;
44             case "Cancelled":
45                 txt += stamp + "Container "+eventData.object_uuid+" was cancelled\n";
46                 break;
47             default:
48                 // Unknown state -- unexpected, might as well log it.
49                 txt += stamp + "Container "+eventData.object_uuid+" changed state to " +
50                     eventData.properties.new_attributes.state + "\n";
51                 break;
52             }
53         }
54     }
55
56     if (txt == '') {
57         return;
58     }
59
60     wasatbottom = (this.scrollTop + this.clientHeight >= this.scrollHeight);
61     if (eventData.prepend) {
62         $(this).prepend(txt);
63     } else {
64         $(this).append(txt);
65     }
66     if (wasatbottom) {
67         this.scrollTop = this.scrollHeight;
68     }
69 });