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