diff --git a/app/app.js b/app/app.js index 79226b539..c782bd031 100644 --- a/app/app.js +++ b/app/app.js @@ -1,8 +1,8 @@ 'use strict'; -angular.module('dockerui', ['ngRoute', 'dockerui.services', 'dockerui.filters', 'masthead', 'footer']) +angular.module('dockerui', ['ngRoute', 'dockerui.services', 'dockerui.filters', 'masthead', 'footer', 'dashboard']) .config(['$routeProvider', function ($routeProvider) { - $routeProvider.when('/', {templateUrl: 'partials/dashboard.html', controller: 'DashboardController'}); + $routeProvider.when('/', {templateUrl: 'app/components/dashboard/dashboard.html', controller: 'DashboardController'}); $routeProvider.when('/containers/', {templateUrl: 'partials/containers.html', controller: 'ContainersController'}); $routeProvider.when('/containers/:id/', {templateUrl: 'partials/container.html', controller: 'ContainerController'}); $routeProvider.when('/images/', {templateUrl: 'partials/images.html', controller: 'ImagesController'}); diff --git a/partials/dashboard.html b/app/components/dashboard/dashboard.html similarity index 100% rename from partials/dashboard.html rename to app/components/dashboard/dashboard.html diff --git a/app/components/dashboard/dashboardController.js b/app/components/dashboard/dashboardController.js new file mode 100644 index 000000000..5512faa68 --- /dev/null +++ b/app/components/dashboard/dashboardController.js @@ -0,0 +1,72 @@ +angular.module('dashboard', []) +.controller('DashboardController', ['$scope', 'Container', 'Image', 'Settings', function($scope, Container, Image, Settings) { + $scope.predicate = '-Created'; + $scope.containers = []; + + var getStarted = function(data) { + $scope.totalContainers = data.length; + newLineChart('#containers-started-chart', data, function(c) { return new Date(c.Created * 1000).toLocaleDateString(); }); + var s = $scope; + Image.query({}, function(d) { + s.totalImages = d.length; + newLineChart('#images-created-chart', d, function(c) { return new Date(c.Created * 1000).toLocaleDateString(); }); + }); + }; + + var opts = {animation:false}; + if (Settings.firstLoad) { + $('#stats').hide(); + opts.animation = true; + Settings.firstLoad = false; + $('#masthead').show(); + + setTimeout(function() { + $('#masthead').slideUp('slow'); + $('#stats').slideDown('slow'); + }, 5000); + } + + Container.query({all: 1}, function(d) { + var running = 0 + var ghost = 0; + var stopped = 0; + + for (var i = 0; i < d.length; i++) { + var item = d[i]; + + if (item.Status === "Ghost") { + ghost += 1; + } else if (item.Status.indexOf('Exit') !== -1) { + stopped += 1; + } else { + running += 1; + $scope.containers.push(new ContainerViewModel(item)); + } + } + + getStarted(d); + + var c = getChart('#containers-chart'); + var data = [ + { + value: running, + color: '#5bb75b', + title: 'Running' + }, // running + { + value: stopped, + color: '#C7604C', + title: 'Stopped' + }, // stopped + { + value: ghost, + color: '#E2EAE9', + title: 'Ghost' + } // ghost + ]; + + c.Doughnut(data, opts); + var lgd = $('#chart-legend').get(0); + legend(lgd, data); + }); +}]); diff --git a/app/controllers.js b/app/controllers.js index 423f25d87..48b97f783 100644 --- a/app/controllers.js +++ b/app/controllers.js @@ -42,78 +42,6 @@ function newLineChart(id, data, getkey) { }); } -function DashboardController($scope, Container, Image, Settings) { - $scope.predicate = '-Created'; - $scope.containers = []; - - var getStarted = function(data) { - $scope.totalContainers = data.length; - newLineChart('#containers-started-chart', data, function(c) { return new Date(c.Created * 1000).toLocaleDateString(); }); - var s = $scope; - Image.query({}, function(d) { - s.totalImages = d.length; - newLineChart('#images-created-chart', d, function(c) { return new Date(c.Created * 1000).toLocaleDateString(); }); - }); - }; - - var opts = {animation:false}; - if (Settings.firstLoad) { - $('#stats').hide(); - opts.animation = true; - Settings.firstLoad = false; - $('#masthead').show(); - - setTimeout(function() { - $('#masthead').slideUp('slow'); - $('#stats').slideDown('slow'); - }, 5000); - } - - Container.query({all: 1}, function(d) { - var running = 0 - var ghost = 0; - var stopped = 0; - - for (var i = 0; i < d.length; i++) { - var item = d[i]; - - if (item.Status === "Ghost") { - ghost += 1; - } else if (item.Status.indexOf('Exit') !== -1) { - stopped += 1; - } else { - running += 1; - $scope.containers.push(new ContainerViewModel(item)); - } - } - - getStarted(d); - - var c = getChart('#containers-chart'); - var data = [ - { - value: running, - color: '#5bb75b', - title: 'Running' - }, // running - { - value: stopped, - color: '#C7604C', - title: 'Stopped' - }, // stopped - { - value: ghost, - color: '#E2EAE9', - title: 'Ghost' - } // ghost - ]; - - c.Doughnut(data, opts); - var lgd = $('#chart-legend').get(0); - legend(lgd, data); - }); -} - function getChart(id) { var ctx = $(id).get(0).getContext("2d"); return new Chart(ctx); diff --git a/index.html b/index.html index 135b33983..0b3519b7f 100644 --- a/index.html +++ b/index.html @@ -39,6 +39,7 @@ +