From 9790f1a0155e212e392254ca14cfafa11604a5b2 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 29 Sep 2015 23:11:27 -0700 Subject: [PATCH] ensure always using buffered streaming --- static/scripts/build.js | 54 ++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/static/scripts/build.js b/static/scripts/build.js index 609d077c..84b613bc 100644 --- a/static/scripts/build.js +++ b/static/scripts/build.js @@ -4,15 +4,38 @@ function JobViewModel(repo, build, job, status) { var self = this; self.status = status; + self.stream = function() { + $( "#output" ).html(""); + + var buf = new Drone.Buffer(); + buf.start(document.getElementById("output")); + + $( "#tail" ).show(); + $( "#tail" ).click(function() { + buf.autoFollow = !buf.autoFollow; + if (buf.autoFollow) { + $( "#tail i" ).text("pause"); + $( "#tail" ).show(); + + // scroll to the bottom of the page + window.scrollTo(0, document.body.scrollHeight); + } else { + $( "#tail i" ).text("expand_more"); + $( "#tail" ).show(); + } + }) + + Stream(repo, build, job, function(out){ + buf.write(out); + }); + }; if (status !== "running" && status !== "pending") { Logs(repo, build, job); } if (status === "running") { - Stream(repo, build, job, function(out){ - $( "#output" ).append(out); - }); + self.stream(); } $("#restart").click(function() { @@ -51,30 +74,7 @@ function JobViewModel(repo, build, job, status) { // if the status has changed we should start // streaming the build contents. if (before !== after && after === "running") { - $( "#output" ).html(""); - - var buf = new Drone.Buffer(); - buf.start(document.getElementById("output")); - - $( "#tail" ).show(); - $( "#tail" ).click(function() { - buf.autoFollow = !buf.autoFollow; - if (buf.autoFollow) { - $( "#tail i" ).text("pause"); - $( "#tail" ).show(); - - // scroll to the bottom of the page - window.scrollTo(0, document.body.scrollHeight); - } else { - $( "#tail i" ).text("expand_more"); - $( "#tail" ).show(); - } - - }) - - Stream(repo, build, job, function(out){ - buf.write(out); - }); + self.stream(); } // if the status is changes to complete, we can show