mirror of https://github.com/portainer/portainer
feat(images): use containers instead of /system/df to check unused images (#1150)
parent
a6ef27164c
commit
8c68e92e74
|
@ -70,7 +70,7 @@
|
|||
<div class="pull-right">
|
||||
<input type="text" id="filter" ng-model="state.filter" placeholder="Filter..." class="form-control input-sm" />
|
||||
</div>
|
||||
<span class="btn-group btn-group-sm pull-right" style="margin-right: 20px;" ng-if="applicationState.endpoint.mode.provider !== 'DOCKER_SWARM' && applicationState.endpoint.apiVersion >= 1.25 && applicationState.endpoint.mode.provider !== 'VMWARE_VIC'">
|
||||
<span class="btn-group btn-group-sm pull-right" style="margin-right: 20px;">
|
||||
<label class="btn btn-primary" ng-model="state.containersCountFilter" uib-btn-radio="undefined">
|
||||
All
|
||||
</label>
|
||||
|
@ -121,12 +121,12 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr dir-paginate="image in (state.filteredImages = (images | filter:{ Containers: state.containersCountFilter } | filter:state.filter | orderBy:sortType:sortReverse | itemsPerPage: state.pagination_count))">
|
||||
<tr dir-paginate="image in (state.filteredImages = (images | filter:{ ContainerCount: state.containersCountFilter } | filter:state.filter | orderBy:sortType:sortReverse | itemsPerPage: state.pagination_count))">
|
||||
<td><input type="checkbox" ng-model="image.Checked" ng-change="selectItem(image)" /></td>
|
||||
<td>
|
||||
<a class="monospaced" ui-sref="image({id: image.Id})">{{ image.Id|truncate:20}}</a>
|
||||
<span style="margin-left: 10px;" class="label label-warning image-tag"
|
||||
ng-if="::image.Containers === 0 && applicationState.endpoint.mode.provider !== 'DOCKER_SWARM' && applicationState.endpoint.apiVersion >= 1.25 && applicationState.endpoint.mode.provider !== 'VMWARE_VIC'">
|
||||
ng-if="::image.ContainerCount === 0">
|
||||
Unused
|
||||
</span>
|
||||
</td>
|
||||
|
|
|
@ -95,7 +95,7 @@ function ($scope, $state, ImageService, Notifications, Pagination, ModalService)
|
|||
$('#loadImagesSpinner').show();
|
||||
var endpointProvider = $scope.applicationState.endpoint.mode.provider;
|
||||
var apiVersion = $scope.applicationState.endpoint.apiVersion;
|
||||
ImageService.images(apiVersion >= 1.25 && endpointProvider !== 'DOCKER_SWARM' && endpointProvider !== 'VMWARE_VIC')
|
||||
ImageService.images(true)
|
||||
.then(function success(data) {
|
||||
$scope.images = data;
|
||||
})
|
||||
|
|
|
@ -151,7 +151,7 @@ function ($scope, $q, $state, $stateParams, $anchorScroll, $filter, ContainerSer
|
|||
|
||||
$q.all({
|
||||
templates: TemplateService.getTemplates(templatesKey),
|
||||
containers: ContainerService.getContainers(0),
|
||||
containers: ContainerService.containers(0),
|
||||
volumes: VolumeService.getVolumes(),
|
||||
networks: NetworkService.networks(
|
||||
provider === 'DOCKER_STANDALONE' || provider === 'DOCKER_SWARM_MODE',
|
||||
|
|
|
@ -3,8 +3,8 @@ function ImageViewModel(data) {
|
|||
this.Tag = data.Tag;
|
||||
this.Repository = data.Repository;
|
||||
this.Created = data.Created;
|
||||
this.Containers = data.dataUsage ? data.dataUsage.Containers : 0;
|
||||
this.Checked = false;
|
||||
this.RepoTags = data.RepoTags;
|
||||
this.VirtualSize = data.VirtualSize;
|
||||
this.ContainerCount = data.ContainerCount;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ angular.module('portainer.services')
|
|||
'use strict';
|
||||
var service = {};
|
||||
|
||||
service.getContainers = function (all) {
|
||||
service.containers = function(all) {
|
||||
var deferred = $q.defer();
|
||||
Container.query({ all: all }).$promise
|
||||
.then(function success(data) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
angular.module('portainer.services')
|
||||
.factory('ImageService', ['$q', 'Image', 'ImageHelper', 'RegistryService', 'HttpRequestHelper', 'SystemService', function ImageServiceFactory($q, Image, ImageHelper, RegistryService, HttpRequestHelper, SystemService) {
|
||||
.factory('ImageService', ['$q', 'Image', 'ImageHelper', 'RegistryService', 'HttpRequestHelper', 'ContainerService', function ImageServiceFactory($q, Image, ImageHelper, RegistryService, HttpRequestHelper, ContainerService) {
|
||||
'use strict';
|
||||
var service = {};
|
||||
|
||||
|
@ -24,17 +24,23 @@ angular.module('portainer.services')
|
|||
var deferred = $q.defer();
|
||||
|
||||
$q.all({
|
||||
dataUsage: withUsage ? SystemService.dataUsage() : { Images: [] },
|
||||
containers: withUsage ? ContainerService.containers(1) : [],
|
||||
images: Image.query({}).$promise
|
||||
})
|
||||
.then(function success(data) {
|
||||
var images = data.images.map(function(item) {
|
||||
item.dataUsage = data.dataUsage.Images.find(function(usage) {
|
||||
return item.Id === usage.Id;
|
||||
});
|
||||
var containers = data.containers;
|
||||
|
||||
var images = data.images.map(function(item) {
|
||||
item.ContainerCount = 0;
|
||||
for (var i = 0; i < containers.length; i++) {
|
||||
var container = containers[i];
|
||||
if (container.ImageID === item.Id) {
|
||||
item.ContainerCount++;
|
||||
}
|
||||
}
|
||||
return new ImageViewModel(item);
|
||||
});
|
||||
|
||||
deferred.resolve(images);
|
||||
})
|
||||
.catch(function error(err) {
|
||||
|
|
Loading…
Reference in New Issue