From 2943924dff1e4e720b5ea7accfccd7660b122c67 Mon Sep 17 00:00:00 2001 From: Ian Kent Date: Sun, 27 Apr 2014 23:38:43 +0100 Subject: [PATCH] Real-time updates using EventSource --- assets/js/controllers.js | 24 ++ assets/templates/layout.html | 11 + bindata.go | 549 ++++++++++++++++++----------------- mailhog/config/config.go | 1 + mailhog/http/api/v1.go | 82 ++++++ mailhog/smtp/session.go | 6 +- mailhog/storage/memory.go | 11 +- mailhog/storage/mongodb.go | 7 +- main.go | 7 +- 9 files changed, 418 insertions(+), 280 deletions(-) diff --git a/assets/js/controllers.js b/assets/js/controllers.js index 81a05b5..f5c83a1 100644 --- a/assets/js/controllers.js +++ b/assets/js/controllers.js @@ -19,6 +19,30 @@ mailhogApp.controller('MailCtrl', function ($scope, $http, $sce, $timeout) { $scope.eventDone = 0; $scope.eventFailed = 0; + $scope.hasEventSource = false; + $scope.source = null; + + $(function() { + $scope.source = new EventSource('/api/v1/events'); + $scope.source.addEventListener('message', function(e) { + $scope.$apply(function() { + $scope.messages.push(JSON.parse(e.data)); + }); + }, false); + $scope.source.addEventListener('open', function(e) { + $scope.$apply(function() { + $scope.hasEventSource = true; + }); + }, false); + $scope.source.addEventListener('error', function(e) { + if(e.readyState == EventSource.CLOSED) { + $scope.$apply(function() { + $scope.hasEventSource = false; + }); + } + }, false); + }); + $scope.startEvent = function(name, args, glyphicon) { var eID = guid(); console.log("Starting event '" + name + "' with id '" + eID + "'") diff --git a/assets/templates/layout.html b/assets/templates/layout.html index 720104c..30e90c3 100644 --- a/assets/templates/layout.html +++ b/assets/templates/layout.html @@ -76,6 +76,12 @@ padding: 9px 10px; pointer-events: none; } + .ev_good { + color: green; + } + .ev_bad { + color: red; + } @@ -108,6 +114,11 @@ +
  • + + + +