From 6012453d2da4b935b1183082384e84d211a62327 Mon Sep 17 00:00:00 2001 From: Kevan Ahlquist Date: Sat, 18 Apr 2015 23:06:58 -0700 Subject: [PATCH] Switch to ngOboe, for DI and promise interface. --- app/components/events/eventsController.js | 21 ++++++++++++++----- assets/js/angular-oboe.min.js | 1 + gruntFile.js | 3 ++- .../components/containerController.spec.js | 4 ++-- 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 assets/js/angular-oboe.min.js diff --git a/app/components/events/eventsController.js b/app/components/events/eventsController.js index e0dc5d213..25743f526 100644 --- a/app/components/events/eventsController.js +++ b/app/components/events/eventsController.js @@ -1,5 +1,5 @@ -angular.module('events', []) - .controller('EventsController', ['Settings', '$scope', function(Settings, $scope) { +angular.module('events', ['ngOboe']) + .controller('EventsController', ['Settings', '$scope', 'Oboe', 'Messages', '$timeout', function(Settings, $scope, oboe, Messages, $timeout) { $scope.updateEvents = function() { $scope.dockerEvents = []; @@ -15,10 +15,21 @@ angular.module('events', []) url += 'until=' + untilSecs; } - oboe(url) - .done(function(node) { + oboe({ + url: url, + pattern: '{id status time}' + }) + .then(function(node) { + // finished loading + $timeout(function() { + $scope.$apply(); + }); + }, function(error) { + // handle errors + Messages.error("Failure", error.data); + }, function(node) { + // node received $scope.dockerEvents.push(node); - $scope.$apply(); }); }; diff --git a/assets/js/angular-oboe.min.js b/assets/js/angular-oboe.min.js new file mode 100644 index 000000000..6812e6a15 --- /dev/null +++ b/assets/js/angular-oboe.min.js @@ -0,0 +1 @@ +"use strict";angular.module("ngOboe",[]).service("Oboe",["OboeStream",function(a){return function(b){return a.get(b)}}]).factory("OboeStream",["$q",function(a){return{get:function(b){var c=a.defer();return oboe(b).start(function(){}).node(b.pattern||".",function(a){return c.notify(a),oboe.drop}).done(function(){return oboe.drop}),c.promise}}}]); \ No newline at end of file diff --git a/gruntFile.js b/gruntFile.js index fc061812b..a81483254 100644 --- a/gruntFile.js +++ b/gruntFile.js @@ -87,7 +87,8 @@ module.exports = function (grunt) { src:['assets/js/angularjs/1.3.15/angular.min.js', 'assets/js/angularjs/1.3.15/angular-route.min.js', 'assets/js/angularjs/1.3.15/angular-resource.min.js', - 'assets/js/ui-bootstrap/ui-bootstrap-custom-tpls-0.12.0.min.js'], + 'assets/js/ui-bootstrap/ui-bootstrap-custom-tpls-0.12.0.min.js', + 'assets/js/angular-oboe.min.js'], dest: '<%= distdir %>/angular.js' } }, diff --git a/test/unit/app/components/containerController.spec.js b/test/unit/app/components/containerController.spec.js index a64643e3a..d466fa902 100644 --- a/test/unit/app/components/containerController.spec.js +++ b/test/unit/app/components/containerController.spec.js @@ -19,7 +19,7 @@ describe('ContainerController', function () { })); function expectGetContainer() { - $httpBackend.expectGET('dockerapi/containers/json?').respond({ + $httpBackend.expectGET('dockerapi/containers/json').respond({ 'Created': 1421817232, 'id': 'b17882378cee8ec0136f482681b764cca430befd52a9bfd1bde031f49b8bba9f', 'Image': 'dockerui:latest', @@ -41,7 +41,7 @@ describe('ContainerController', function () { var newContainerName = "newName"; expectGetContainer(); - $httpBackend.expectGET('dockerapi/containers/changes?').respond([{"Kind": 1, "Path": "/docker.sock"}]); + $httpBackend.expectGET('dockerapi/containers/changes').respond([{"Kind": 1, "Path": "/docker.sock"}]); $httpBackend.expectPOST('dockerapi/containers/' + $routeParams.id + '/rename?name=newName'). respond({