diff --git a/app/app.js b/app/app.js index fb9018dd1..b44f1d7dc 100644 --- a/app/app.js +++ b/app/app.js @@ -1,9 +1,9 @@ 'use strict'; -angular.module('dockerui', ['ngRoute', 'dockerui.services', 'dockerui.filters', 'masthead', 'footer', 'dashboard', 'container']) +angular.module('dockerui', ['ngRoute', 'dockerui.services', 'dockerui.filters', 'masthead', 'footer', 'dashboard', 'container', 'containers']) .config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/', {templateUrl: 'app/components/dashboard/dashboard.html', controller: 'DashboardController'}); - $routeProvider.when('/containers/', {templateUrl: 'partials/containers.html', controller: 'ContainersController'}); + $routeProvider.when('/containers/', {templateUrl: 'app/components/containers/containers.html', controller: 'ContainersController'}); $routeProvider.when('/containers/:id/', {templateUrl: 'app/components/container/container.html', controller: 'ContainerController'}); $routeProvider.when('/images/', {templateUrl: 'partials/images.html', controller: 'ImagesController'}); $routeProvider.when('/images/:id/', {templateUrl: 'partials/image.html', controller: 'ImageController'}); diff --git a/partials/containers.html b/app/components/containers/containers.html similarity index 100% rename from partials/containers.html rename to app/components/containers/containers.html diff --git a/app/components/containers/containersController.js b/app/components/containers/containersController.js new file mode 100644 index 000000000..7d26cba87 --- /dev/null +++ b/app/components/containers/containersController.js @@ -0,0 +1,81 @@ +angular.module('containers', []) +.controller('ContainersController', ['$scope', 'Container', 'Settings', 'Messages', 'ViewSpinner', +function($scope, Container, Settings, Messages, ViewSpinner) { + $scope.predicate = '-Created'; + $scope.toggle = false; + $scope.displayAll = Settings.displayAll; + + var update = function(data) { + ViewSpinner.spin(); + Container.query(data, function(d) { + $scope.containers = d.map(function(item) { + return new ContainerViewModel(item); }); + ViewSpinner.stop(); + }); + }; + + var batch = function(items, action, msg) { + ViewSpinner.spin(); + var counter = 0; + var complete = function() { + counter = counter -1; + if (counter === 0) { + ViewSpinner.stop(); + update({all: Settings.displayAll ? 1 : 0}); + } + }; + angular.forEach(items, function(c) { + if (c.Checked) { + counter = counter + 1; + action({id: c.Id}, function(d) { + Messages.send("Container " + msg, c.Id); + var index = $scope.containers.indexOf(c); + complete(); + }, function(e) { + Messages.error("Failure", e.data); + complete(); + }); + } + }); + if (counter === 0) { + ViewSpinner.stop(); + } + }; + + $scope.toggleSelectAll = function() { + angular.forEach($scope.containers, function(i) { + i.Checked = $scope.toggle; + }); + }; + + $scope.toggleGetAll = function() { + Settings.displayAll = $scope.displayAll; + update({all: Settings.displayAll ? 1 : 0}); + }; + + $scope.startAction = function() { + batch($scope.containers, Container.start, "Started"); + }; + + $scope.stopAction = function() { + batch($scope.containers, Container.stop, "Stopped"); + }; + + $scope.killAction = function() { + batch($scope.containers, Container.kill, "Killed"); + }; + + $scope.pauseAction = function() { + batch($scope.containers, Container.pause, "Paused"); + }; + + $scope.unpauseAction = function() { + batch($scope.containers, Container.unpause, "Unpaused"); + }; + + $scope.removeAction = function() { + batch($scope.containers, Container.remove, "Removed"); + }; + + update({all: Settings.displayAll ? 1 : 0}); +}]); diff --git a/app/controllers.js b/app/controllers.js index 6a8a3afb3..518ecf019 100644 --- a/app/controllers.js +++ b/app/controllers.js @@ -67,87 +67,6 @@ function SettingsController($scope, System, Docker, Settings, Messages) { System.get({}, function(d) { $scope.info = d; }); } -// Controller for the list of containers -function ContainersController($scope, Container, Settings, Messages, ViewSpinner) { - $scope.predicate = '-Created'; - $scope.toggle = false; - $scope.displayAll = Settings.displayAll; - - var update = function(data) { - ViewSpinner.spin(); - Container.query(data, function(d) { - $scope.containers = d.map(function(item) { - return new ContainerViewModel(item); }); - ViewSpinner.stop(); - }); - }; - - var batch = function(items, action, msg) { - ViewSpinner.spin(); - var counter = 0; - var complete = function() { - counter = counter -1; - if (counter === 0) { - ViewSpinner.stop(); - update({all: Settings.displayAll ? 1 : 0}); - } - }; - angular.forEach(items, function(c) { - if (c.Checked) { - counter = counter + 1; - action({id: c.Id}, function(d) { - Messages.send("Container " + msg, c.Id); - var index = $scope.containers.indexOf(c); - complete(); - }, function(e) { - Messages.error("Failure", e.data); - complete(); - }); - } - }); - if (counter === 0) { - ViewSpinner.stop(); - } - }; - - $scope.toggleSelectAll = function() { - angular.forEach($scope.containers, function(i) { - i.Checked = $scope.toggle; - }); - }; - - $scope.toggleGetAll = function() { - Settings.displayAll = $scope.displayAll; - update({all: Settings.displayAll ? 1 : 0}); - }; - - $scope.startAction = function() { - batch($scope.containers, Container.start, "Started"); - }; - - $scope.stopAction = function() { - batch($scope.containers, Container.stop, "Stopped"); - }; - - $scope.killAction = function() { - batch($scope.containers, Container.kill, "Killed"); - }; - - $scope.pauseAction = function() { - batch($scope.containers, Container.pause, "Paused"); - }; - - $scope.unpauseAction = function() { - batch($scope.containers, Container.unpause, "Unpaused"); - }; - - $scope.removeAction = function() { - batch($scope.containers, Container.remove, "Removed"); - }; - - update({all: Settings.displayAll ? 1 : 0}); -} - // Controller for the list of images function ImagesController($scope, Image, ViewSpinner, Messages) { $scope.toggle = false; diff --git a/index.html b/index.html index 588d48a92..45638dc9d 100644 --- a/index.html +++ b/index.html @@ -41,6 +41,7 @@ +