2883: Removed commented out code related to live loading (saved it to another branch).
[arvados.git] / apps / workbench / app / views / jobs / _show_log.html.erb
1 <script>
2
3 function addToLogViewer(logViewer, lines) {
4   var re = /((\d\d\d\d)-(\d\d)-(\d\d))_((\d\d):(\d\d):(\d\d)) ([a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}) (\d+) (\d+)? (.*)/;
5   for (var a in lines) {
6     var v = lines[a].match(re);
7     if (v != null) {
8
9     var ts = new Date(Date.UTC(v[2], v[3], v[4], v[6], v[7], v[8]));
10
11     v11 = v[11];
12     if (typeof v[11] === 'undefined') {
13       v11 = '&nbsp;';
14     }
15
16   var message = v[12];
17   var type = "";
18   if (v11 != '&nbsp;') {
19     if (/^stderr /.test(message)) {
20         type = "task-output";
21         message = message.substr(7);
22     } else {
23         type = "task-dispatch";
24     }
25   } else {
26     if (/^status: /.test(message)) {
27         type = "job-status";
28         message = message.substr(8);
29     } else {
30         type = "crunch";
31     }
32   }
33
34     logViewer.add({
35       id: logViewer.items.length,
36       timestamp: ts.toLocaleDateString() + " " + ts.toLocaleTimeString(),
37       taskid: v11,
38       message: message,
39       type: type
40     });
41
42     } else {
43       console.log("Did not parse: " + lines[a]);
44     }
45   }
46   logViewer.update();
47 }
48
49 (function() {
50 var logViewer = new List('log-viewer', {
51   valueNames: [ 'id', 'timestamp', 'taskid', 'message', 'type']
52 });
53
54 var makeFilter = function() {
55   var pass = [];
56   $(".toggle-filter").each(function(i, e) {
57     if (e.checked) {
58       pass.push(e.id.substr(5));
59     }
60   });
61   return (function(item) {
62     for (a in pass) {
63       if (pass[a] == item.values().type) { return true; }
64     }
65     return false;
66   });
67 }
68
69 <% if @object.log %>
70 <% logcollection = Collection.find @object.log %>
71
72 $.ajax('<%=j url_for logcollection %>/<%=j logcollection.files[0][1] %>').
73   done(function(data, status, jqxhr) {
74     logViewer.filter();
75     addToLogViewer(logViewer, data.split("\n"));
76     logViewer.filter(makeFilter());
77     $("#logloadspinner").detach();
78   });
79 <% else %>
80   <%# Live log loading not implemented yet. %>
81 <% end %>
82
83 $(".toggle-filter").on("change", function() {
84   logViewer.filter(makeFilter());
85 });
86
87 $("#filter-all").on("click", function() {
88   $(".toggle-filter").each(function(i, f) { f.checked = true; });
89   logViewer.filter(makeFilter());
90 });
91
92 $("#filter-none").on("click", function() {
93   $(".toggle-filter").each(function(i, f) { f.checked = false; console.log(f); });
94   logViewer.filter(makeFilter());
95 });
96
97 $("#sort-by-time").on("change", function() {
98   logViewer.sort("id");
99 });
100
101 $("#sort-by-task").on("change", function() {
102   logViewer.sort("taskid");
103 });
104
105 })();
106
107 </script>
108
109 <div id="log-viewer">
110
111     <div class="radio-inline">
112       <label><input id="sort-by-time" type="radio" name="sort-radio" checked> Sort by time</label>
113     </div>
114     <div class="radio-inline">
115       <label><input id="sort-by-task" type="radio" name="sort-radio" > Sort by task</label>
116     </div>
117 <br>
118   <div class="checkbox-inline">
119     <label><input id="show-crunch" type="checkbox" checked="true" class="toggle-filter"> Show crunch output</label>
120   </div>
121   <div class="checkbox-inline">
122     <label><input id="show-job-status" type="checkbox" checked="true" class="toggle-filter"> Show job status</label>
123   </div>
124   <div class="checkbox-inline">
125     <label><input id="show-task-dispatch" type="checkbox" checked="true" class="toggle-filter"> Show task dispatch</label>
126   </div>
127   <div class="checkbox-inline">
128     <label><input id="show-task-output" type="checkbox" checked="true" class="toggle-filter"> Show task output</label>
129   </div>
130
131 <div class="pull-right">
132     <button id="filter-all" class="btn">
133       Select all
134     </button>
135     <button id="filter-none" class="btn">
136       Select none
137     </button>
138 </div>
139
140   <table class="log-viewer-table">
141     <thead>
142       <tr>
143         <th class="id" data-sort="id"></th>
144         <th class="timestamp" data-sort="timestamp">Timestamp</th>
145         <th class="type" data-sort="type">Log type</th>
146         <th class="taskid"  data-sort="taskid">Task</th>
147         <th class="message" data-sort="message">Message</th>
148       </tr>
149     </thead>
150     <tbody class="list">
151       <tr>
152         <td class="id"></td>
153         <td class="timestamp"></td>
154         <td class="type"></td>
155         <td class="taskid"></td>
156         <td class="message"></td>
157       </tr>
158     </tbody>
159   </table>
160
161 </div>
162
163 <% !if @object.log %>
164   This job is still running.  The job log will be available when the job is complete.
165 <% end %>
166
167 <%= image_tag 'ajax-loader.gif', id: "logloadspinner" %>