feat(volume-details): show a list of containers using the volume

pull/1289/merge
G07cha 2017-10-17 09:45:19 +03:00 committed by Anthony Lapenna
parent dc05ad4c8c
commit 925326e8aa
3 changed files with 45 additions and 4 deletions

View File

@ -73,3 +73,26 @@
</rd-widget>
</div>
</div>
<div class="row" ng-if="containersUsingVolume.length > 0">
<div class="col-lg-12 col-md-12 col-xs-12">
<rd-widget>
<rd-widget-header icon="fa-server" title="Containers using volume"></rd-widget-header>
<rd-widget-body classes="no-padding">
<table class="table">
<thead>
<th>Container Name</th>
<th>Mounted At</th>
<th>Read-only</th>
</thead>
<tbody>
<tr ng-repeat="container in containersUsingVolume">
<td><a ui-sref="container({id: container.Id})">{{ container | containername }}</a></td>
<td>{{ container.volumeData.Destination }}</td>
<td>{{ !container.volumeData.RW }}</td>
</tr>
</tbody>
</table>
</rd-widget-body>
</rd-widget>
</div>
</div>

View File

@ -1,6 +1,6 @@
angular.module('volume', [])
.controller('VolumeController', ['$scope', '$state', '$transition$', 'VolumeService', 'Notifications',
function ($scope, $state, $transition$, VolumeService, Notifications) {
.controller('VolumeController', ['$scope', '$state', '$transition$', 'VolumeService', 'ContainerService', 'Notifications',
function ($scope, $state, $transition$, VolumeService, ContainerService, Notifications) {
$scope.removeVolume = function removeVolume() {
$('#loadingViewSpinner').show();
@ -16,6 +16,12 @@ function ($scope, $state, $transition$, VolumeService, Notifications) {
$('#loadingViewSpinner').hide();
});
};
function getVolumeDataFromContainer(container, volumeId) {
return container.Mounts.find(function(volume) {
return volume.Name === volumeId;
});
}
function initView() {
$('#loadingViewSpinner').show();
@ -23,6 +29,18 @@ function ($scope, $state, $transition$, VolumeService, Notifications) {
.then(function success(data) {
var volume = data;
$scope.volume = volume;
return ContainerService.containers(1, {
filters: {
volume: [volume.Id]
}
});
})
.then(function success(data) {
var containers = data.map(function(container) {
container.volumeData = getVolumeDataFromContainer(container, $scope.volume.Id);
return container;
});
$scope.containersUsingVolume = containers;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve volume details');

View File

@ -20,8 +20,8 @@ angular.module('portainer.services')
service.containers = function(all, filters) {
var deferred = $q.defer();
Container.query({ all: all, filters: filters ? filters : {} }).$promise
filters.all = all;
Container.query(filters).$promise
.then(function success(data) {
var containers = data.map(function (item) {
return new ContainerViewModel(item);