2883: Log viewer works, supports sorting and filtering.
[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     v11 = v[11];
9     if (typeof v[11] === 'undefined') {
10       v11 = '&nbsp;';
11     }
12
13   var message = v[12];
14   var type = "";
15   if (v11 != '&nbsp;') {
16     if (/^stderr /.test(message)) {
17         type = "task-output";
18     } else {
19         type = "task-dispatch";
20     }
21   } else {
22     if (/^status: /.test(message)) {
23         type = "job-progress";
24     } else {
25         type = "crunch";
26     }
27   }
28
29     logViewer.add({
30       id: logViewer.items.length,
31       timestamp: v[1] + " " + v[5],
32       taskid: v11,
33       message: message,
34       type: type
35     });
36
37     } else {
38       console.log("Did not parse: " + lines[a]);
39     }
40   }
41   logViewer.update();
42 }
43
44 (function() {
45 var logViewer = new List('log-viewer', {
46   valueNames: [ 'id', 'timestamp', 'taskid', 'message', 'type']
47 });
48
49 var makeFilter = function() {
50   var pass = [];
51   $(".toggle-filter").each(function(i, e) {
52     if (e.checked) {
53       pass.push(e.id.substr(5));
54     }
55   });
56   return (function(item) {
57     for (a in pass) {
58       if (pass[a] == item.values().type) { return true; }
59     }
60     return false;
61   });
62 }
63
64 <% logcollection = Collection.find @object.log %>
65
66 $.ajax('<%=j url_for logcollection %>/<%=j logcollection.files[0][1] %>').
67   done(function(data, status, jqxhr) {
68     logViewer.filter();
69     addToLogViewer(logViewer, data.split("\n"));
70     logViewer.filter(makeFilter());
71     $("#logloadspinner").detach();
72   });
73
74 $(".toggle-filter").on("change", function() {
75   logViewer.filter(makeFilter());
76 });
77
78 $("#filter-all").on("click", function() {
79   $(".toggle-filter").each(function(i, f) { f.checked = true; });
80   logViewer.filter(makeFilter());
81 });
82
83 $("#filter-none").on("click", function() {
84   $(".toggle-filter").each(function(i, f) { f.checked = false; console.log(f); });
85   logViewer.filter(makeFilter());
86 });
87
88 $("#sort-by-time").on("change", function() {
89   logViewer.sort("id");
90 });
91
92 $("#sort-by-task").on("change", function() {
93   logViewer.sort("taskid");
94 });
95
96 })();
97
98 </script>
99
100 <div id="log-viewer">
101
102     <div class="radio-inline">
103       <label><input id="sort-by-time" type="radio" name="sort-radio" checked> Sort by time</label>
104     </div>
105     <div class="radio-inline">
106       <label><input id="sort-by-task" type="radio" name="sort-radio" > Sort by task</label>
107     </div>
108 <br>
109   <div class="checkbox-inline">
110     <label><input id="show-task-output" type="checkbox" checked="true" class="toggle-filter"> Show task output</label>
111   </div>
112   <div class="checkbox-inline">
113     <label><input id="show-task-dispatch" type="checkbox" checked="true" class="toggle-filter"> Show task dispatch</label>
114   </div>
115   <div class="checkbox-inline">
116     <label><input id="show-crunch" type="checkbox" checked="true" class="toggle-filter"> Show crunch output</label>
117   </div>
118   <div class="checkbox-inline">
119     <label><input id="show-job-progress" type="checkbox" checked="true" class="toggle-filter"> Show job progress</label>
120   </div>
121
122 <div class="pull-right">
123     <button id="filter-all" class="btn">
124       Select all
125     </button>
126     <button id="filter-none" class="btn">
127       Select none
128     </button>
129 </div>
130
131   <table style='width: 100%; font-family:"Lucida Console", Monaco, monospace; font-size: 11px'>
132     <thead>
133       <tr>
134         <th class="sort" data-sort="id" style="display:none;"></th>
135         <th class="sort" data-sort="timestamp" style="width: 12em">Timestamp</th>
136         <th class="sort" data-sort="type" style="width: 8em">Log type</th>
137         <th class="sort" data-sort="taskid" style="width: 4em">Task</th>
138         <th class="sort" data-sort="message" >Message</th>
139       </tr>
140     </thead>
141     <tbody class="list">
142       <tr>
143         <td class="id" style="display:none;">0</td>
144         <td class="timestamp"></td>
145         <td class="type"></td>
146         <td class="taskid" style="text-align: center"></td>
147         <td class="message"></td>
148       </tr>
149     </tbody>
150   </table>
151
152 </div>
153
154 <%= image_tag 'ajax-loader.gif', id: "logloadspinner" %>