From 96b49cf0fcb22c4bb542406fc0deadf36bcce704 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 25 Apr 2015 21:27:24 -0700 Subject: [PATCH] website subscribes to build events, update pages --- .gitignore | 4 +- Makefile | 2 +- drone.go | 12 ++++-- server/queue.go | 8 ++-- server/static/scripts/controllers/builds.js | 43 ++++++++++++++------- server/static/scripts/views/build.html | 2 +- server/static/scripts/views/builds.html | 2 +- 7 files changed, 45 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index bff14d2cf..df07484a4 100644 --- a/.gitignore +++ b/.gitignore @@ -13,9 +13,7 @@ drone.sublime-workspace *.db *.txt *.toml +*.min.js bindata.go -# combined assets -server/static/drone.js - drone diff --git a/Makefile b/Makefile index 79e879570..073067ced 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ concat: server/static/scripts/services/*.js \ server/static/scripts/filters/*.js \ server/static/scripts/controllers/*.js \ - server/static/scripts/term.js > server/static/drone.js + server/static/scripts/term.js > server/static/scripts/drone.min.js bindata_debug: go-bindata --debug server/static/... diff --git a/drone.go b/drone.go index cca4dc82b..c4fc0ffd5 100644 --- a/drone.go +++ b/drone.go @@ -109,12 +109,16 @@ func main() { queue := api.Group("/queue") { - queue.Use(server.SetRepo()) queue.GET("", server.GetQueue) queue.POST("/pull", server.PollBuild) - queue.POST("/push/:owner/:name", server.PushBuild) - queue.POST("/push/:owner/:name/:build", server.PushTask) - queue.POST("/push/:owner/:name/:build/:task/logs", server.PushLogs) + + push := queue.Group("/push/:owner/:name") + { + push.Use(server.SetRepo()) + push.POST("", server.PushBuild) + push.POST("/:build", server.PushTask) + push.POST("/:build/:task/logs", server.PushLogs) + } } events := api.Group("/stream") diff --git a/server/queue.go b/server/queue.go index e23479a22..674bdd6b5 100644 --- a/server/queue.go +++ b/server/queue.go @@ -48,9 +48,11 @@ func PushBuild(c *gin.Context) { return } - if repo.Last == nil || build.Number >= repo.Last.Number { - repo.Last = build - store.SetRepo(repo) + if build.State != common.StatePending && build.State != common.StateRunning { + if repo.Last == nil || build.Number >= repo.Last.Number { + repo.Last = build + store.SetRepo(repo) + } } // <-- FIXME diff --git a/server/static/scripts/controllers/builds.js b/server/static/scripts/controllers/builds.js index c504c7340..248a490ad 100644 --- a/server/static/scripts/controllers/builds.js +++ b/server/static/scripts/controllers/builds.js @@ -47,17 +47,28 @@ } // update repository $scope.repo = event.repo; - $scope.apply(); - - if (event.build.number !== parseInt(number)) { - return; // ignore - } - // update the build status - $scope.build.state = event.build.state; - $scope.build.started = event.build.started; - $scope.build.finished = event.build.finished; - $scope.build.duration = event.build.duration; $scope.$apply(); + + var added = false; + for (var i=0;i<$scope.builds.length;i++) { + var build = $scope.builds[i]; + if (event.build.number !== build.number) { + continue; // ignore + } + // update the build status + build.state = event.build.state; + build.started_at = event.build.started_at; + build.finished_at = event.build.finished_at; + build.duration = event.build.duration; + $scope.builds[i] = build; + $scope.$apply(); + added = true; + } + + if (!added) { + $scope.builds.push(event.build); + $scope.$apply(); + } }); } @@ -97,7 +108,9 @@ // fetch the logs for the finished build. logs.get(fullName, number, step).then(function(payload){ - $scope.logs = payload.data; + var convert = new Filter({stream:false,newline:false}); + var term = document.getElementById("term") + term.innerHTML = convert.toHtml(payload.data); }).catch(function(err){ $scope.error = err; }); @@ -127,8 +140,8 @@ } // update the build status $scope.build.state = event.build.state; - $scope.build.started = event.build.started; - $scope.build.finished = event.build.finished; + $scope.build.started_at = event.build.started_at; + $scope.build.finished_at = event.build.finished_at; $scope.build.duration = event.build.duration; $scope.$apply(); @@ -137,8 +150,8 @@ } // update the task status $scope.task.state = event.task.state; - $scope.task.started = event.task.started; - $scope.task.finished = event.task.finished; + $scope.task.started_at = event.task.started_at; + $scope.task.finished_at = event.task.finished_at; $scope.task.duration = event.task.duration; $scope.task.exit_code = event.task.exit_code; $scope.$apply(); diff --git a/server/static/scripts/views/build.html b/server/static/scripts/views/build.html index b022b7e99..85668d05d 100644 --- a/server/static/scripts/views/build.html +++ b/server/static/scripts/views/build.html @@ -57,7 +57,7 @@
-
{{ logs }}
+
{{ logs }}
diff --git a/server/static/scripts/views/builds.html b/server/static/scripts/views/builds.html index 7fb5e6d98..984d126b7 100644 --- a/server/static/scripts/views/builds.html +++ b/server/static/scripts/views/builds.html @@ -21,7 +21,7 @@ - +
{{ build.number }} {{ build.state }} {{ build.started_at | fromNow }}