2883: Adjusted task type column width. Commented out code for working with
[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   <%# backlog = ""
81      Log.filter([['object_uuid', '=', @object.uuid],
82                   ['event_type', '=', 'stderr']]).order(["id", "asc"]).each do |l|
83         backlog += l.properties[:text]
84      end
85    %>
86
87   /* var backlog = "<%#=j backlog %>";
88     logViewer.filter();
89     addToLogViewer(logViewer, backlog.split("\n"));
90     logViewer.filter(makeFilter());  */
91
92 <% end %>
93
94 $(".toggle-filter").on("change", function() {
95   logViewer.filter(makeFilter());
96 });
97
98 $("#filter-all").on("click", function() {
99   $(".toggle-filter").each(function(i, f) { f.checked = true; });
100   logViewer.filter(makeFilter());
101 });
102
103 $("#filter-none").on("click", function() {
104   $(".toggle-filter").each(function(i, f) { f.checked = false; console.log(f); });
105   logViewer.filter(makeFilter());
106 });
107
108 $("#sort-by-time").on("change", function() {
109   logViewer.sort("id");
110 });
111
112 $("#sort-by-task").on("change", function() {
113   logViewer.sort("taskid");
114 });
115
116 })();
117
118 </script>
119
120 <div id="log-viewer">
121
122     <div class="radio-inline">
123       <label><input id="sort-by-time" type="radio" name="sort-radio" checked> Sort by time</label>
124     </div>
125     <div class="radio-inline">
126       <label><input id="sort-by-task" type="radio" name="sort-radio" > Sort by task</label>
127     </div>
128 <br>
129   <div class="checkbox-inline">
130     <label><input id="show-crunch" type="checkbox" checked="true" class="toggle-filter"> Show crunch output</label>
131   </div>
132   <div class="checkbox-inline">
133     <label><input id="show-job-status" type="checkbox" checked="true" class="toggle-filter"> Show job status</label>
134   </div>
135   <div class="checkbox-inline">
136     <label><input id="show-task-dispatch" type="checkbox" checked="true" class="toggle-filter"> Show task dispatch</label>
137   </div>
138   <div class="checkbox-inline">
139     <label><input id="show-task-output" type="checkbox" checked="true" class="toggle-filter"> Show task output</label>
140   </div>
141
142 <div class="pull-right">
143     <button id="filter-all" class="btn">
144       Select all
145     </button>
146     <button id="filter-none" class="btn">
147       Select none
148     </button>
149 </div>
150
151   <table class="log-viewer-table">
152     <thead>
153       <tr>
154         <th class="id" data-sort="id"></th>
155         <th class="timestamp" data-sort="timestamp">Timestamp</th>
156         <th class="type" data-sort="type">Log type</th>
157         <th class="taskid"  data-sort="taskid">Task</th>
158         <th class="message" data-sort="message">Message</th>
159       </tr>
160     </thead>
161     <tbody class="list">
162       <tr>
163         <td class="id"></td>
164         <td class="timestamp"></td>
165         <td class="type"></td>
166         <td class="taskid"></td>
167         <td class="message"></td>
168       </tr>
169     </tbody>
170   </table>
171
172 </div>
173
174 <%= image_tag 'ajax-loader.gif', id: "logloadspinner" %>