2018-02-01 12:27:52 +00:00
|
|
|
angular.module('portainer.docker')
|
2018-06-11 13:13:19 +00:00
|
|
|
.controller('DashboardController', ['$scope', '$q', 'Container', 'ContainerHelper', 'Image', 'Network', 'Volume', 'SystemService', 'ServiceService', 'StackService', 'Notifications', 'EndpointProvider',
|
|
|
|
function ($scope, $q, Container, ContainerHelper, Image, Network, Volume, SystemService, ServiceService, StackService, Notifications, EndpointProvider) {
|
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
|
|
|
};
|
|
|
|
|
2017-10-15 17:24:40 +00:00
|
|
|
$scope.serviceCount = 0;
|
|
|
|
$scope.stackCount = 0;
|
|
|
|
|
2017-06-01 08:14:55 +00:00
|
|
|
function prepareContainerData(d) {
|
2016-07-13 22:58:39 +00:00
|
|
|
var running = 0;
|
|
|
|
var stopped = 0;
|
|
|
|
var containers = 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;
|
2016-08-10 03:39:59 +00:00
|
|
|
if (volumes) {
|
|
|
|
$scope.volumeData.total = volumes.length;
|
|
|
|
}
|
2016-07-13 22:58:39 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-01 08:14:55 +00:00
|
|
|
function initView() {
|
2018-06-11 13:13:19 +00:00
|
|
|
var endpointMode = $scope.applicationState.endpoint.mode;
|
|
|
|
var endpointId = EndpointProvider.endpointID();
|
2017-10-15 17:24:40 +00:00
|
|
|
|
2016-07-13 22:58:39 +00:00
|
|
|
$q.all([
|
|
|
|
Container.query({all: 1}).$promise,
|
|
|
|
Image.query({}).$promise,
|
|
|
|
Volume.query({}).$promise,
|
|
|
|
Network.query({}).$promise,
|
2017-10-15 17:24:40 +00:00
|
|
|
SystemService.info(),
|
2018-06-11 13:13:19 +00:00
|
|
|
endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER' ? ServiceService.services() : [],
|
|
|
|
StackService.stacks(
|
|
|
|
true,
|
|
|
|
endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER',
|
|
|
|
endpointId
|
|
|
|
)
|
2016-07-13 22:58:39 +00:00
|
|
|
]).then(function (d) {
|
2017-06-01 08:14:55 +00:00
|
|
|
prepareContainerData(d[0]);
|
2016-07-13 22:58:39 +00:00
|
|
|
prepareImageData(d[1]);
|
|
|
|
prepareVolumeData(d[2]);
|
|
|
|
prepareNetworkData(d[3]);
|
|
|
|
prepareInfoData(d[4]);
|
2017-10-15 17:24:40 +00:00
|
|
|
$scope.serviceCount = d[5].length;
|
|
|
|
$scope.stackCount = d[6].length;
|
2016-12-15 03:33:47 +00:00
|
|
|
}, function(e) {
|
2017-05-23 18:56:10 +00:00
|
|
|
Notifications.error('Failure', e, 'Unable to load dashboard data');
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
2016-07-07 03:37:09 +00:00
|
|
|
}
|
2016-06-02 05:34:03 +00:00
|
|
|
|
2017-06-01 08:14:55 +00:00
|
|
|
initView();
|
2016-06-02 05:34:03 +00:00
|
|
|
}]);
|