docker-registry-frontend/app/tag/tag-item-controller.js
Konrad Kleine 3f988e7309 Restructure code
Now all files dealing with repositories reside in app/repository and all
dealing with tag reside in app/tag. That's far more easy to maintain
than having tag files spread across multiple folders.
2015-08-31 15:32:38 +02:00

47 lines
1.4 KiB
JavaScript

'use strict';
/**
* @ngdoc function
* @name docker-registry-frontend.controller:TagItemController
* @description
* # TagItemController
* Every item in the tag list is associated with a TagItemController
*/
angular.module('tag-item-controller', ['registry-services'])
.controller('TagItemController', ['$scope', 'Image', 'Ancestry',
function($scope, Image, Ancestry){
// Assign details to "tag" variable in the parent scope
$scope.tag.details = Image.query( {imageId: $scope.tag.imageId} );
/**
* Calculates the total download size for the image based on
* it's ancestry.
*/
$scope.totalImageSize = null;
$scope.calculateTotalImageSize = function() {
/* Fetch the image's ancestry and when complete, fetch the size of each image */
Ancestry.query( {imageId: $scope.tag.imageId} ).$promise.then(function (result) {
$scope.totalImageSize = 0;
angular.forEach(result, function (id, key) {
/* We have to use the $promise object here to be sure the result is accessible */
Image.get( {imageId: id} ).$promise.then(function (result) {
if (!isNaN(result.Size-0)) {
$scope.totalImageSize += result.Size;
}
});
});
});
};
}]);