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