mirror of https://github.com/portainer/portainer
Moved LineChart to services, cleaned up remaining functions in controller, cleanup.
parent
e3eb37ba56
commit
ada1c6a4e4
|
@ -1,5 +1,5 @@
|
|||
angular.module('builder', [])
|
||||
.controller('BuilderController', ['$scope', 'Dockerfile', 'Messages',
|
||||
function($scope, Dockerfile, Messages) {
|
||||
$scope.template = 'partials/builder.html';
|
||||
$scope.template = 'app/components/builder/builder.html';
|
||||
}]);
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
angular.module('dashboard', [])
|
||||
.controller('DashboardController', ['$scope', 'Container', 'Image', 'Settings', function($scope, Container, Image, Settings) {
|
||||
.controller('DashboardController', ['$scope', 'Container', 'Image', 'Settings', 'LineChart', function($scope, Container, Image, Settings, LineChart) {
|
||||
$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(); });
|
||||
LineChart.build('#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(); });
|
||||
LineChart.build('#images-created-chart', d, function(c) { return new Date(c.Created * 1000).toLocaleDateString(); });
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -46,7 +46,7 @@ angular.module('dashboard', [])
|
|||
|
||||
getStarted(d);
|
||||
|
||||
var c = getChart('#containers-chart');
|
||||
var c = new Chart($('#containers-chart').get(0).getContext("2d"));
|
||||
var data = [
|
||||
{
|
||||
value: running,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
angular.module('image', [])
|
||||
.controller('ImageController', ['$scope', '$q', '$routeParams', '$location', 'Image', 'Container', 'Messages',
|
||||
function($scope, $q, $routeParams, $location, Image, Container, Messages) {
|
||||
.controller('ImageController', ['$scope', '$q', '$routeParams', '$location', 'Image', 'Container', 'Messages', 'LineChart',
|
||||
function($scope, $q, $routeParams, $location, Image, Container, Messages, LineChart) {
|
||||
$scope.history = [];
|
||||
$scope.tag = {repo: '', force: false};
|
||||
|
||||
|
@ -29,6 +29,23 @@ function($scope, $q, $routeParams, $location, Image, Container, Messages) {
|
|||
});
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
Image.get({id: $routeParams.id}, function(d) {
|
||||
$scope.image = d;
|
||||
$scope.tag = d.id;
|
||||
|
@ -38,7 +55,7 @@ function($scope, $q, $routeParams, $location, Image, Container, Messages) {
|
|||
var promise = getContainersFromImage($q, Container, t);
|
||||
|
||||
promise.then(function(containers) {
|
||||
newLineChart('#containers-started-chart', containers, function(c) { return new Date(c.Created * 1000).toLocaleDateString(); });
|
||||
LineChart.build('#containers-started-chart', containers, function(c) { return new Date(c.Created * 1000).toLocaleDateString(); });
|
||||
});
|
||||
}
|
||||
}, function(e) {
|
||||
|
|
|
@ -13,6 +13,10 @@ function($scope, $routeParams, $location, Container, Messages) {
|
|||
};
|
||||
$scope.commandPlaceholder = '["/bin/echo", "Hello world"]';
|
||||
|
||||
function failedRequestHandler(e, Messages) {
|
||||
Messages.send({class: 'text-error', data: e.data});
|
||||
}
|
||||
|
||||
$scope.create = function() {
|
||||
var cmds = null;
|
||||
if ($scope.config.commands !== '') {
|
||||
|
@ -39,6 +43,8 @@ function($scope, $routeParams, $location, Container, Messages) {
|
|||
}, function(e) {
|
||||
failedRequestHandler(e, Messages);
|
||||
});
|
||||
} else {
|
||||
failedRequestHandler(d, Messages);
|
||||
}
|
||||
}, function(e) {
|
||||
failedRequestHandler(e, Messages);
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
function newLineChart(id, data, getkey) {
|
||||
var chart = getChart(id);
|
||||
var map = {};
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var c = data[i];
|
||||
var key = getkey(c);
|
||||
|
||||
var count = map[key];
|
||||
if (count === undefined) {
|
||||
count = 0;
|
||||
}
|
||||
count += 1;
|
||||
map[key] = 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
|
||||
};
|
||||
chart.Line({
|
||||
labels: labels,
|
||||
datasets: [dataset]
|
||||
},
|
||||
{
|
||||
scaleStepWidth: 1,
|
||||
pointDotRadius:1,
|
||||
scaleOverride: true,
|
||||
scaleSteps: labels.length
|
||||
});
|
||||
}
|
||||
|
||||
function getChart(id) {
|
||||
var ctx = $(id).get(0).getContext("2d");
|
||||
return new Chart(ctx);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
|
@ -123,4 +123,52 @@ angular.module('dockerui.services', ['ngResource'])
|
|||
request.send(data);
|
||||
}
|
||||
};
|
||||
})
|
||||
.factory('LineChart', function(Settings) {
|
||||
var url = Settings.rawUrl + '/build';
|
||||
return {
|
||||
build: function(id, data, getkey){
|
||||
var chart = new Chart($(id).get(0).getContext("2d"));
|
||||
var map = {};
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var c = data[i];
|
||||
var key = getkey(c);
|
||||
|
||||
var count = map[key];
|
||||
if (count === undefined) {
|
||||
count = 0;
|
||||
}
|
||||
count += 1;
|
||||
map[key] = 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
|
||||
};
|
||||
chart.Line({
|
||||
labels: labels,
|
||||
datasets: [dataset]
|
||||
},
|
||||
{
|
||||
scaleStepWidth: 1,
|
||||
pointDotRadius:1,
|
||||
scaleOverride: true,
|
||||
scaleSteps: labels.length
|
||||
});
|
||||
}
|
||||
};
|
||||
});
|
|
@ -18,7 +18,6 @@
|
|||
<![endif]-->
|
||||
|
||||
<script src="assets/js/jquery-1.11.1.min.js"></script>
|
||||
<script src="//code.jquery.com/jquery-migrate-1.2.1.js"></script>
|
||||
<script src="assets/js/bootstrap.min.js"></script>
|
||||
|
||||
|
||||
|
@ -33,9 +32,9 @@
|
|||
<script src="assets/js/legend.js"></script>
|
||||
|
||||
<script src="app/app.js"></script>
|
||||
<script src="app/services.js"></script>
|
||||
<script src="app/filters.js"></script>
|
||||
<script src="app/controllers.js"></script>
|
||||
<script src="app/shared/services.js"></script>
|
||||
<script src="app/shared/filters.js"></script>
|
||||
<script src="app/shared/viewmodel.js"></script>
|
||||
<!-- TODO: Add minification build step -->
|
||||
<script src="app/components/masthead/mastheadController.js"></script>
|
||||
<script src="app/components/footer/footerController.js"></script>
|
||||
|
@ -48,7 +47,6 @@
|
|||
<script src="app/components/sidebar/sidebarController.js"></script>
|
||||
<script src="app/components/settings/settingsController.js"></script>
|
||||
<script src="app/components/builder/builderController.js"></script>
|
||||
<script src="app/viewmodel.js"></script>
|
||||
|
||||
<!-- Fav and touch icons -->
|
||||
<link rel="shortcut icon" href="assets/ico/favicon.ico">
|
||||
|
|
Loading…
Reference in New Issue