3824: Merge branch 'master' into 3824-crunch-container-setup
[arvados.git] / apps / workbench / app / views / jobs / _show_log.html.erb
index aaae89addee10492cc9c924787b6d6afac9f6779..7324104a55875903c0712e05b522a897050432ad 100644 (file)
@@ -53,32 +53,38 @@ var makeFilter = function() {
 <% if @object.log %>
   <% logcollection = Collection.find @object.log %>
   <% if logcollection %>
-    var log_maxbytes = <%= Rails.configuration.log_viewer_max_bytes %>
-    $.ajax('<%=j url_for logcollection %>/<%=j logcollection.files[0][1] %>',
-          {
-            headers: {'Range': 'bytes=0-' + log_maxbytes}
-          }).
-       done(function(data, status, jqxhr) {
-           logViewer.filter();
-           addToLogViewer(logViewer, data.split("\n"), taskState);
-           logViewer.filter(makeFilter());
-           if (data.length == log_maxbytes) {
-             $("#log-viewer-overview").html(
-               '<p>The log was truncated after ' + log_maxbytes +
-               ' bytes. To view the entire log, run this command' +
-               ' from an Arvados shell VM:</p>' +
-               ' <p><span style="font-family:monospace">arv-get' +
-               ' <%=j logcollection.uuid %>/<%=j logcollection.files[0][1] %>' +
-               '</p>'
-             );
+    log_size = <%= logcollection.files[0][2] %>
+    log_maxbytes = <%= Rails.configuration.log_viewer_max_bytes %>;
+    logcollection_url = '<%=j url_for logcollection %>/<%=j logcollection.files[0][1] %>';
+    $("#log-viewer-download-url").attr('href', logcollection_url);
+    $("#log-viewer-download-pane").show();
+    if (log_size > log_maxbytes) {
+      range_header = { 'Range': 'bytes=0-' + log_maxbytes };
+    } else {
+      range_header = null;
+    }
+    $.ajax(logcollection_url, { headers: range_header }).
+        done(function(data, status, jqxhr) {
+            logViewer.filter();
+            addToLogViewer(logViewer, data.split("\n"), taskState);
+            logViewer.filter(makeFilter());
+            content_range_hdr = jqxhr.getResponseHeader('Content-Range');
+            var v = content_range_hdr && content_range_hdr.match(/bytes \d+-(\d+)\/(.+)/);
+            short_log = v && (v[2] == '*' || parseInt(v[1]) + 1 < v[2]);
+            if (jqxhr.status == 206 && short_log) {
+              $("#log-viewer-overview").html(
+                '<p>Showing only ' + data.length + ' bytes of this log.' +
+                ' Timing information is unavailable since' +
+                ' the full log was not retrieved.</p>'
+              );
             } else {
-             generateJobOverview("#log-viewer-overview", logViewer, taskState);
-           }
-           $("#log-viewer .spinner").detach();
-       }).
-       fail(function(jqxhr, status, error) {
-           $("#log-viewer .spinner").detach();
-       });
+              generateJobOverview("#log-viewer-overview", logViewer, taskState);
+            }
+            $("#log-viewer .spinner").detach();
+        }).
+        fail(function(jqxhr, status, error) {
+            $("#log-viewer .spinner").detach();
+        });
   <% end %>
 <% else %>
   <%# Live log loading not implemented yet. %>
@@ -134,6 +140,10 @@ $("#set-show-failed-only").on("click", function() {
     <% end %>
   </p>
 
+  <p id="log-viewer-download-pane" style="display:none">
+    <a id="log-viewer-download-url" href="">Download the full log</a>
+  </p>
+
   <div class="h3">Log
 
     <span class="pull-right">