From de18a308c2821701b2ca850242d1f5e12bde443f Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 2 Sep 2013 16:54:53 -0700 Subject: [PATCH 1/2] Add containers created --- js/controllers.js | 79 +++++++++++++++++++++++++++++++++++++++++--- partials/image.html | 11 +++--- partials/images.html | 6 ++-- 3 files changed, 83 insertions(+), 13 deletions(-) diff --git a/js/controllers.js b/js/controllers.js index 606ada8d1..8faddc9ec 100644 --- a/js/controllers.js +++ b/js/controllers.js @@ -25,9 +25,8 @@ function DashboardController($scope, Container) { } } - var ctx = $("#containers-chart").get(0).getContext("2d"); - var c = new Chart(ctx); - var data = [ + var c = getChart('#containers-chart'); + var data = [ { value: running, color: '#5bb75b', @@ -51,6 +50,11 @@ function DashboardController($scope, Container) { }); } +function getChart(id) { + var ctx = $(id).get(0).getContext("2d"); + return new Chart(ctx); +} + function StatusBarController($scope, Settings) { $scope.template = 'partials/statusbar.html'; @@ -265,7 +269,7 @@ function ImagesController($scope, Image, ViewSpinner, Messages) { } // Controller for a single image and actions on that image -function ImageController($scope, $routeParams, $location, Image, Messages) { +function ImageController($scope, $q, $routeParams, $location, Image, Container, Messages) { $scope.history = []; $scope.tag = {repo: '', force: false}; @@ -300,6 +304,55 @@ function ImageController($scope, $routeParams, $location, Image, Messages) { Image.get({id: $routeParams.id}, function(d) { $scope.image = d; + if ($routeParams.tag) { + var promise = getContainersFromImage($q, Container, $routeParams.tag); + + promise.then(function(containers) { + var map = {}; + + for (var i = 0; i < containers.length; i++) { + var c = containers[i]; + var date = new Date(c.Created * 1000).toLocaleDateString(); + + var count = map[date]; + if (count === undefined) { + count = 0; + } + console.log(map); + count += 1; + map[date] = count; + } + + var labels = []; + var data = []; + var keys = Object.keys(map); + + for (var i = keys.length - 1; i > -1; i--) { + var k = keys[i]; + labels.push(k); + data.push(map[k]); + }; + var dataset = { + fillColor : "rgba(151,187,205,0.5)", + strokeColor : "rgba(151,187,205,1)", + pointColor : "rgba(151,187,205,1)", + pointStrokeColor : "#fff", + data : data + }; + console.log(labels, data); + var c = getChart('#containers-started-chart'); + c.Line({ + labels: labels, + datasets: [dataset] + }, + { + scaleStepWidth: 1, + pointDotRadius:1, + scaleOverride: true, + scaleSteps: labels.length + }); + }); + } }, function(e) { if (e.status === 404) { $('.detail').hide(); @@ -379,3 +432,21 @@ function BuilderController($scope, Dockerfile, Messages) { function failedRequestHandler(e, Messages) { Messages.send({class: 'text-error', data: e.data}); } + +// This gonna get messy but we don't have a good way to do this right now +function getContainersFromImage($q, Container, tag) { + var defer = $q.defer(); + + Container.query({all:1, notruc:1}, function(d) { + var containers = []; + for (var i = 0; i < d.length; i++) { + var c = d[i]; + if (c.Image == tag) { + containers.push(new ContainerViewModel(c)); + } + } + defer.resolve(containers); + }); + + return defer.promise; +} diff --git a/partials/image.html b/partials/image.html index d94c4f96c..28bfb4ae1 100644 --- a/partials/image.html +++ b/partials/image.html @@ -12,6 +12,12 @@ +
+

Containers created:

+ + Get a better broswer... Your holding everyone back. + +
@@ -23,10 +29,6 @@ - - - - @@ -95,7 +97,6 @@
-
diff --git a/partials/images.html b/partials/images.html index fa2df94d0..7751b5d07 100644 --- a/partials/images.html +++ b/partials/images.html @@ -16,7 +16,6 @@ - @@ -24,9 +23,8 @@ - - - + + From 3643525126e4eead7469535934cf657837448444 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 2 Sep 2013 17:08:06 -0700 Subject: [PATCH 2/2] Change image chart sizes --- js/controllers.js | 7 +++++-- partials/dashboard.html | 2 +- partials/image.html | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/js/controllers.js b/js/controllers.js index 8faddc9ec..724015180 100644 --- a/js/controllers.js +++ b/js/controllers.js @@ -304,8 +304,11 @@ function ImageController($scope, $q, $routeParams, $location, Image, Container, Image.get({id: $routeParams.id}, function(d) { $scope.image = d; - if ($routeParams.tag) { - var promise = getContainersFromImage($q, Container, $routeParams.tag); + $scope.tag = d.id; + var t = $routeParams.tag; + if (t && t !== ":") { + $scope.tag = t; + var promise = getContainersFromImage($q, Container, t); promise.then(function(containers) { var map = {}; diff --git a/partials/dashboard.html b/partials/dashboard.html index 1506365ad..b06dfd224 100644 --- a/partials/dashboard.html +++ b/partials/dashboard.html @@ -16,7 +16,7 @@

Running Containers

diff --git a/partials/image.html b/partials/image.html index 28bfb4ae1..4d9e43efe 100644 --- a/partials/image.html +++ b/partials/image.html @@ -6,7 +6,7 @@
-

Image: {{ image.id }}

+

Image: {{ tag }}

Parent: {{ image.parent }}
Container:{{ image.container }}
Size: {{ image.Size|humansize }}
Action IdTag Repository Created
{{ image.Id|truncate:20}}{{ image.Tag }}{{ image.Repository }}{{ image.Id|truncate:20}}{{ image.Repository }}:{{ image.Tag }} {{ image.Created|getdate }}