2014-11-12 17:31:27 +00:00
|
|
|
angular.module('dashboard', [])
|
2016-07-13 22:58:39 +00:00
|
|
|
.controller('DashboardController', ['$scope', '$q', 'Config', 'Container', 'Image', 'Network', 'Volume', 'Info',
|
|
|
|
function ($scope, $q, Config, Container, Image, Network, Volume, Info) {
|
2016-06-02 05:34:03 +00:00
|
|
|
|
2016-07-13 22:58:39 +00:00
|
|
|
$scope.containerData = {
|
|
|
|
total: 0
|
|
|
|
};
|
|
|
|
$scope.imageData = {
|
|
|
|
total: 0
|
|
|
|
};
|
|
|
|
$scope.networkData = {
|
|
|
|
total: 0
|
|
|
|
};
|
|
|
|
$scope.volumeData = {
|
|
|
|
total: 0
|
2016-06-02 05:34:03 +00:00
|
|
|
};
|
|
|
|
|
2016-07-13 22:58:39 +00:00
|
|
|
function prepareContainerData(d) {
|
|
|
|
var running = 0;
|
|
|
|
var stopped = 0;
|
2016-06-02 05:34:03 +00:00
|
|
|
|
2016-07-13 22:58:39 +00:00
|
|
|
var containers = d;
|
|
|
|
if (hiddenLabels) {
|
|
|
|
containers = hideContainers(d);
|
|
|
|
}
|
2016-07-07 03:37:09 +00:00
|
|
|
|
2016-07-13 22:58:39 +00:00
|
|
|
for (var i = 0; i < containers.length; i++) {
|
|
|
|
var item = containers[i];
|
|
|
|
if (item.Status.indexOf('Up') !== -1) {
|
|
|
|
running += 1;
|
|
|
|
} else if (item.Status.indexOf('Exit') !== -1) {
|
|
|
|
stopped += 1;
|
2016-07-07 03:37:09 +00:00
|
|
|
}
|
2016-07-13 22:58:39 +00:00
|
|
|
}
|
|
|
|
$scope.containerData.running = running;
|
|
|
|
$scope.containerData.stopped = stopped;
|
|
|
|
$scope.containerData.total = containers.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareImageData(d) {
|
|
|
|
var images = d;
|
|
|
|
var totalImageSize = 0;
|
|
|
|
for (var i = 0; i < images.length; i++) {
|
|
|
|
var item = images[i];
|
|
|
|
totalImageSize += item.VirtualSize;
|
|
|
|
}
|
|
|
|
$scope.imageData.total = images.length;
|
|
|
|
$scope.imageData.size = totalImageSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareVolumeData(d) {
|
|
|
|
var volumes = d.Volumes;
|
|
|
|
$scope.volumeData.total = volumes.length;
|
|
|
|
}
|
2016-07-07 03:37:09 +00:00
|
|
|
|
2016-07-13 22:58:39 +00:00
|
|
|
function prepareNetworkData(d) {
|
|
|
|
var networks = d;
|
|
|
|
$scope.networkData.total = networks.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
function prepareInfoData(d) {
|
|
|
|
var info = d;
|
|
|
|
$scope.infoData = info;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fetchDashboardData() {
|
|
|
|
$('#loadingViewSpinner').show();
|
|
|
|
$q.all([
|
|
|
|
Container.query({all: 1}).$promise,
|
|
|
|
Image.query({}).$promise,
|
|
|
|
Volume.query({}).$promise,
|
|
|
|
Network.query({}).$promise,
|
2016-07-13 23:29:41 +00:00
|
|
|
Info.get({}).$promise
|
2016-07-13 22:58:39 +00:00
|
|
|
]).then(function (d) {
|
|
|
|
prepareContainerData(d[0]);
|
|
|
|
prepareImageData(d[1]);
|
|
|
|
prepareVolumeData(d[2]);
|
|
|
|
prepareNetworkData(d[3]);
|
|
|
|
prepareInfoData(d[4]);
|
|
|
|
$('#loadingViewSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
2016-07-07 03:37:09 +00:00
|
|
|
}
|
2016-06-02 05:34:03 +00:00
|
|
|
|
2016-07-07 03:37:09 +00:00
|
|
|
var hideContainers = function (containers) {
|
|
|
|
return containers.filter(function (container) {
|
|
|
|
var filterContainer = false;
|
|
|
|
hiddenLabels.forEach(function(label, index) {
|
|
|
|
if (_.has(container.Labels, label.name) &&
|
|
|
|
container.Labels[label.name] === label.value) {
|
|
|
|
filterContainer = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!filterContainer) {
|
|
|
|
return container;
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
2016-07-07 03:37:09 +00:00
|
|
|
});
|
|
|
|
};
|
2016-06-02 05:34:03 +00:00
|
|
|
|
2016-07-07 03:37:09 +00:00
|
|
|
Config.$promise.then(function (c) {
|
2016-07-13 22:58:39 +00:00
|
|
|
$scope.swarm = c.swarm;
|
2016-07-07 03:37:09 +00:00
|
|
|
hiddenLabels = c.hiddenLabels;
|
|
|
|
fetchDashboardData();
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
|
|
|
}]);
|