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