2020-08-17 00:30:02 +00:00
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
2021-12-14 07:34:54 +00:00
|
|
|
import { isOfflineEndpoint } from '@/portainer/helpers/endpointHelper';
|
2022-05-23 09:05:37 +00:00
|
|
|
import { PortainerEndpointTypes } from 'Portainer/models/endpoint/models';
|
2022-07-06 08:23:53 +00:00
|
|
|
import { useContainerStatusComponent } from '@/react/docker/DashboardView/ContainerStatus';
|
|
|
|
import { useImagesTotalSizeComponent } from '@/react/docker/DashboardView/ImagesTotalSize';
|
2021-12-14 07:34:54 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.docker').controller('DashboardController', [
|
|
|
|
'$scope',
|
|
|
|
'$q',
|
2020-07-27 07:11:32 +00:00
|
|
|
'Authentication',
|
2020-04-10 21:54:53 +00:00
|
|
|
'ContainerService',
|
|
|
|
'ImageService',
|
|
|
|
'NetworkService',
|
|
|
|
'VolumeService',
|
|
|
|
'SystemService',
|
|
|
|
'ServiceService',
|
|
|
|
'StackService',
|
|
|
|
'Notifications',
|
|
|
|
'StateManager',
|
2020-08-17 00:30:02 +00:00
|
|
|
'TagService',
|
2021-02-09 08:09:06 +00:00
|
|
|
'endpoint',
|
2020-04-10 21:54:53 +00:00
|
|
|
function (
|
|
|
|
$scope,
|
|
|
|
$q,
|
2020-07-27 07:11:32 +00:00
|
|
|
Authentication,
|
2020-04-10 21:54:53 +00:00
|
|
|
ContainerService,
|
|
|
|
ImageService,
|
|
|
|
NetworkService,
|
|
|
|
VolumeService,
|
|
|
|
SystemService,
|
|
|
|
ServiceService,
|
|
|
|
StackService,
|
|
|
|
Notifications,
|
2020-08-17 00:30:02 +00:00
|
|
|
StateManager,
|
2021-02-09 08:09:06 +00:00
|
|
|
TagService,
|
|
|
|
endpoint
|
2020-04-10 21:54:53 +00:00
|
|
|
) {
|
|
|
|
$scope.dismissInformationPanel = function (id) {
|
|
|
|
StateManager.dismissInformationPanel(id);
|
|
|
|
};
|
2018-08-21 18:40:42 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
$scope.offlineMode = false;
|
2020-07-27 07:11:32 +00:00
|
|
|
$scope.showStacks = false;
|
2016-07-13 22:58:39 +00:00
|
|
|
|
2022-07-17 23:02:14 +00:00
|
|
|
$scope.buildGpusStr = function (gpuUseSet) {
|
|
|
|
var gpusAvailable = new Object();
|
2022-07-29 04:08:17 +00:00
|
|
|
for (let i = 0; i < ($scope.endpoint.Gpus || []).length; i++) {
|
2022-07-17 23:02:14 +00:00
|
|
|
if (!gpuUseSet.has($scope.endpoint.Gpus[i].name)) {
|
|
|
|
var exist = false;
|
|
|
|
for (let gpuAvailable in gpusAvailable) {
|
|
|
|
if ($scope.endpoint.Gpus[i].value == gpuAvailable) {
|
|
|
|
gpusAvailable[gpuAvailable] += 1;
|
|
|
|
exist = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (exist === false) {
|
|
|
|
gpusAvailable[$scope.endpoint.Gpus[i].value] = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var retStr = Object.keys(gpusAvailable).length
|
|
|
|
? _.join(
|
|
|
|
_.map(Object.keys(gpusAvailable), (gpuAvailable) => {
|
|
|
|
var _str = gpusAvailable[gpuAvailable];
|
|
|
|
_str += ' x ';
|
|
|
|
_str += gpuAvailable;
|
|
|
|
return _str;
|
|
|
|
}),
|
|
|
|
' + '
|
|
|
|
)
|
|
|
|
: 'none';
|
|
|
|
return retStr;
|
|
|
|
};
|
|
|
|
|
2020-07-27 07:11:32 +00:00
|
|
|
async function initView() {
|
2020-07-14 20:46:38 +00:00
|
|
|
const endpointMode = $scope.applicationState.endpoint.mode;
|
2021-12-14 07:34:54 +00:00
|
|
|
$scope.endpoint = endpoint;
|
2018-10-28 09:27:06 +00:00
|
|
|
|
2020-07-27 07:11:32 +00:00
|
|
|
$scope.showStacks = await shouldShowStacks();
|
2022-05-23 09:05:37 +00:00
|
|
|
$scope.showEnvUrl = endpoint.Type !== PortainerEndpointTypes.EdgeAgentOnDockerEnvironment && endpoint.Type !== PortainerEndpointTypes.EdgeAgentOnKubernetesEnvironment;
|
2020-04-10 21:54:53 +00:00
|
|
|
$q.all({
|
|
|
|
containers: ContainerService.containers(1),
|
|
|
|
images: ImageService.images(false),
|
|
|
|
volumes: VolumeService.volumes(),
|
|
|
|
networks: NetworkService.networks(true, true, true),
|
|
|
|
services: endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER' ? ServiceService.services() : [],
|
2021-12-14 07:34:54 +00:00
|
|
|
stacks: StackService.stacks(true, endpointMode.provider === 'DOCKER_SWARM_MODE' && endpointMode.role === 'MANAGER', endpoint.Id),
|
2020-04-10 21:54:53 +00:00
|
|
|
info: SystemService.info(),
|
2020-08-17 00:30:02 +00:00
|
|
|
tags: TagService.tags(),
|
2020-04-10 21:54:53 +00:00
|
|
|
})
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.containers = data.containers;
|
2022-07-06 08:23:53 +00:00
|
|
|
$scope.containerStatusComponent = useContainerStatusComponent(data.containers);
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
$scope.images = data.images;
|
2022-07-06 08:23:53 +00:00
|
|
|
$scope.imagesTotalSizeComponent = useImagesTotalSizeComponent(imagesTotalSize(data.images));
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
$scope.volumeCount = data.volumes.length;
|
|
|
|
$scope.networkCount = data.networks.length;
|
|
|
|
$scope.serviceCount = data.services.length;
|
|
|
|
$scope.stackCount = data.stacks.length;
|
|
|
|
$scope.info = data.info;
|
2022-07-17 23:02:14 +00:00
|
|
|
|
|
|
|
$scope.gpuInfoStr = $scope.buildGpusStr(new Set());
|
|
|
|
$scope.gpuUseAll = _.get($scope, 'endpoint.Snapshots[0].GpuUseAll', false);
|
|
|
|
$scope.gpuUseList = _.get($scope, 'endpoint.Snapshots[0].GpuUseList', []);
|
|
|
|
$scope.gpuFreeStr = 'all';
|
|
|
|
if ($scope.gpuUseAll == true) $scope.gpuFreeStr = 'none';
|
|
|
|
else $scope.gpuFreeStr = $scope.buildGpusStr(new Set($scope.gpuUseList));
|
|
|
|
|
2021-12-14 07:34:54 +00:00
|
|
|
$scope.endpointTags = endpoint.TagIds.length
|
2020-08-17 00:30:02 +00:00
|
|
|
? _.join(
|
|
|
|
_.filter(
|
2021-12-14 07:34:54 +00:00
|
|
|
_.map(endpoint.TagIds, (id) => {
|
2020-08-17 00:30:02 +00:00
|
|
|
const tag = data.tags.find((tag) => tag.Id === id);
|
|
|
|
return tag ? tag.Name : '';
|
|
|
|
}),
|
|
|
|
Boolean
|
|
|
|
),
|
|
|
|
', '
|
|
|
|
)
|
|
|
|
: '-';
|
2021-12-14 07:34:54 +00:00
|
|
|
$scope.offlineMode = isOfflineEndpoint(endpoint);
|
2020-04-10 21:54:53 +00:00
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to load dashboard data');
|
|
|
|
});
|
|
|
|
}
|
2017-10-15 17:24:40 +00:00
|
|
|
|
2020-07-27 07:11:32 +00:00
|
|
|
async function shouldShowStacks() {
|
|
|
|
const isAdmin = Authentication.isAdmin();
|
|
|
|
|
2021-02-09 08:09:06 +00:00
|
|
|
return isAdmin || endpoint.SecuritySettings.allowStackManagementForRegularUsers;
|
2020-07-27 07:11:32 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
initView();
|
|
|
|
},
|
|
|
|
]);
|
2022-07-06 08:23:53 +00:00
|
|
|
|
|
|
|
function imagesTotalSize(images) {
|
|
|
|
return images.reduce((acc, image) => acc + image.VirtualSize, 0);
|
|
|
|
}
|