2015-02-20 23:15:48 +00:00
|
|
|
(function() {
|
|
|
|
/**
|
|
|
|
* Repository view page.
|
|
|
|
*/
|
|
|
|
angular.module('quayPages').config(['pages', function(pages) {
|
2015-03-10 05:03:39 +00:00
|
|
|
pages.create('repo-view', 'repo-view.html', RepoViewCtrl, {
|
|
|
|
'newLayout': true,
|
|
|
|
'title': '{{ namespace }}/{{ name }}',
|
|
|
|
'description': 'Repository {{ namespace }}/{{ name }}'
|
2015-06-29 09:33:00 +00:00
|
|
|
})
|
2015-02-20 23:15:48 +00:00
|
|
|
}]);
|
|
|
|
|
2015-03-23 20:10:33 +00:00
|
|
|
function RepoViewCtrl($scope, $routeParams, $location, $timeout, ApiService, UserService, AngularPollChannel) {
|
2015-03-10 05:03:39 +00:00
|
|
|
$scope.namespace = $routeParams.namespace;
|
|
|
|
$scope.name = $routeParams.name;
|
|
|
|
|
2015-05-06 22:16:03 +00:00
|
|
|
$scope.imagesRequired = false;
|
|
|
|
|
|
|
|
// Tab-enabled counters.
|
2015-06-24 21:07:38 +00:00
|
|
|
$scope.tagsShown = 0;
|
2015-03-10 05:03:39 +00:00
|
|
|
$scope.logsShown = 0;
|
2015-05-06 22:16:03 +00:00
|
|
|
$scope.buildsShown = 0;
|
|
|
|
$scope.settingsShown = 0;
|
|
|
|
|
2015-03-12 19:22:47 +00:00
|
|
|
$scope.viewScope = {
|
|
|
|
'selectedTags': [],
|
|
|
|
'repository': null,
|
2015-03-18 18:47:53 +00:00
|
|
|
'images': null,
|
|
|
|
'imagesResource': null,
|
2015-03-12 19:22:47 +00:00
|
|
|
'builds': null,
|
|
|
|
'changesVisible': false
|
|
|
|
};
|
2015-03-10 05:03:39 +00:00
|
|
|
|
2015-03-11 00:22:46 +00:00
|
|
|
var buildPollChannel = null;
|
|
|
|
|
2015-03-10 05:03:39 +00:00
|
|
|
// Make sure we track the current user.
|
|
|
|
UserService.updateUserIn($scope);
|
|
|
|
|
2015-03-12 19:22:47 +00:00
|
|
|
// Watch the repository to filter any tags removed.
|
|
|
|
$scope.$watch('viewScope.repository', function(repository) {
|
|
|
|
if (!repository) { return; }
|
|
|
|
$scope.viewScope.selectedTags = filterTags($scope.viewScope.selectedTags);
|
|
|
|
});
|
|
|
|
|
|
|
|
var filterTags = function(tags) {
|
|
|
|
return (tags || []).filter(function(tag) {
|
|
|
|
return !!$scope.viewScope.repository.tags[tag];
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-10 05:03:39 +00:00
|
|
|
var loadRepository = function() {
|
2015-05-07 19:51:49 +00:00
|
|
|
// Mark the images to be reloaded.
|
|
|
|
$scope.viewScope.images = null;
|
|
|
|
|
2015-03-10 05:03:39 +00:00
|
|
|
var params = {
|
|
|
|
'repository': $scope.namespace + '/' + $scope.name
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.repositoryResource = ApiService.getRepoAsResource(params).get(function(repo) {
|
2015-04-07 22:33:43 +00:00
|
|
|
$scope.repository = repo;
|
2015-03-12 19:22:47 +00:00
|
|
|
$scope.viewScope.repository = repo;
|
2015-03-11 00:22:46 +00:00
|
|
|
|
2015-03-23 20:10:33 +00:00
|
|
|
// Load the remainder of the data async, so we don't block the initial view from
|
|
|
|
// showing.
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.setTags($routeParams.tag);
|
|
|
|
|
|
|
|
// Track builds.
|
2015-05-06 22:16:03 +00:00
|
|
|
buildPollChannel = AngularPollChannel.create($scope, loadRepositoryBuilds, 30000 /* 30s */);
|
2015-05-07 22:26:11 +00:00
|
|
|
buildPollChannel.start();
|
2015-03-23 20:10:33 +00:00
|
|
|
}, 10);
|
2015-03-10 05:03:39 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-05-07 19:51:49 +00:00
|
|
|
var loadImages = function(opt_callback) {
|
2015-03-18 18:47:53 +00:00
|
|
|
var params = {
|
|
|
|
'repository': $scope.namespace + '/' + $scope.name
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.viewScope.imagesResource = ApiService.listRepositoryImagesAsResource(params).get(function(resp) {
|
|
|
|
$scope.viewScope.images = resp.images;
|
2015-05-07 19:51:49 +00:00
|
|
|
opt_callback && opt_callback(resp.images);
|
2015-03-18 18:47:53 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-11 00:22:46 +00:00
|
|
|
var loadRepositoryBuilds = function(callback) {
|
|
|
|
var params = {
|
2015-03-18 16:14:30 +00:00
|
|
|
'repository': $scope.namespace + '/' + $scope.name,
|
|
|
|
'limit': 3
|
2015-03-11 00:22:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var errorHandler = function() {
|
|
|
|
callback(false);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.repositoryBuildsResource = ApiService.getRepoBuildsAsResource(params, /* background */true).get(function(resp) {
|
2015-04-22 17:33:20 +00:00
|
|
|
// Note: We could just set the builds here, but that causes a full digest cycle. Therefore,
|
|
|
|
// to be more efficient, we do some work here to determine if anything has changed since
|
|
|
|
// the last build load in the common case.
|
|
|
|
if ($scope.viewScope.builds && resp.builds.length == $scope.viewScope.builds.length) {
|
|
|
|
var hasNewInformation = false;
|
|
|
|
for (var i = 0; i < resp.builds.length; ++i) {
|
|
|
|
var current = $scope.viewScope.builds[i];
|
|
|
|
var updated = resp.builds[i];
|
|
|
|
if (current.phase != updated.phase || current.id != updated.id) {
|
|
|
|
hasNewInformation = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasNewInformation) {
|
|
|
|
callback(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 19:22:47 +00:00
|
|
|
$scope.viewScope.builds = resp.builds;
|
2015-03-11 00:27:19 +00:00
|
|
|
callback(true);
|
2015-03-11 00:22:46 +00:00
|
|
|
}, errorHandler);
|
|
|
|
};
|
|
|
|
|
2015-03-23 20:10:33 +00:00
|
|
|
// Load the repository.
|
2015-03-10 05:03:39 +00:00
|
|
|
loadRepository();
|
|
|
|
|
2015-03-12 19:22:47 +00:00
|
|
|
$scope.setTags = function(tagNames) {
|
|
|
|
if (!tagNames) {
|
|
|
|
$scope.viewScope.selectedTags = [];
|
|
|
|
return;
|
|
|
|
}
|
2015-03-11 00:22:46 +00:00
|
|
|
|
2015-03-12 19:22:47 +00:00
|
|
|
$scope.viewScope.selectedTags = $.unique(tagNames.split(','));
|
2015-03-10 05:03:39 +00:00
|
|
|
};
|
|
|
|
|
2015-05-06 22:16:03 +00:00
|
|
|
$scope.showBuilds = function() {
|
|
|
|
$scope.buildsShown++;
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.showSettings = function() {
|
|
|
|
$scope.settingsShown++;
|
|
|
|
};
|
|
|
|
|
2015-03-10 05:03:39 +00:00
|
|
|
$scope.showLogs = function() {
|
|
|
|
$scope.logsShown++;
|
|
|
|
};
|
2015-03-12 19:22:47 +00:00
|
|
|
|
2015-06-24 21:07:38 +00:00
|
|
|
$scope.showTags = function() {
|
|
|
|
$timeout(function() {
|
|
|
|
$scope.tagsShown = 1;
|
|
|
|
}, 10);
|
|
|
|
};
|
|
|
|
|
2015-05-06 22:16:03 +00:00
|
|
|
$scope.requireImages = function() {
|
|
|
|
// Lazily load the repo's images if this is the first call to a tab
|
|
|
|
// that needs the images.
|
2015-05-07 19:51:49 +00:00
|
|
|
if ($scope.viewScope.images == null) {
|
2015-05-06 22:16:03 +00:00
|
|
|
loadImages();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-12 19:22:47 +00:00
|
|
|
$scope.handleChangesState = function(value) {
|
|
|
|
$scope.viewScope.changesVisible = value;
|
|
|
|
};
|
2015-05-07 19:51:49 +00:00
|
|
|
|
|
|
|
$scope.getImages = function(callback) {
|
|
|
|
loadImages(callback);
|
|
|
|
};
|
2015-03-10 05:03:39 +00:00
|
|
|
}
|
2015-02-20 23:15:48 +00:00
|
|
|
})();
|