This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/pages/repo-view.js

148 lines
4.2 KiB
JavaScript
Raw Normal View History

(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
})
}]);
function RepoViewCtrl($scope, $routeParams, $location, $timeout, ApiService, UserService, AngularPollChannel, ImageLoaderService) {
2015-03-10 05:03:39 +00:00
$scope.namespace = $routeParams.namespace;
$scope.name = $routeParams.name;
var imageLoader = ImageLoaderService.getLoader($scope.namespace, $scope.name);
// 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;
$scope.buildsShown = 0;
$scope.settingsShown = 0;
$scope.viewScope = {
'selectedTags': [],
'repository': null,
'imageLoader': imageLoader,
'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);
// 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() {
// 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) {
$scope.repository = repo;
$scope.viewScope.repository = repo;
2015-03-11 00:22:46 +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.
buildPollChannel = AngularPollChannel.create($scope, loadRepositoryBuilds, 30000 /* 30s */);
buildPollChannel.start();
}, 10);
2015-03-10 05:03:39 +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) {
// 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;
}
}
$scope.viewScope.builds = resp.builds;
2015-03-11 00:27:19 +00:00
callback(true);
2015-03-11 00:22:46 +00:00
}, errorHandler);
};
// Load the repository.
2015-03-10 05:03:39 +00:00
loadRepository();
$scope.setTags = function(tagNames) {
if (!tagNames) {
$scope.viewScope.selectedTags = [];
return;
}
2015-03-11 00:22:46 +00:00
$scope.viewScope.selectedTags = $.unique(tagNames.split(','));
2015-03-10 05:03:39 +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-06-24 21:07:38 +00:00
$scope.showTags = function() {
$timeout(function() {
$scope.tagsShown = 1;
}, 10);
};
$scope.handleChangesState = function(value) {
$scope.viewScope.changesVisible = value;
};
$scope.getImages = function(callback) {
loadImages(callback);
};
2015-03-10 05:03:39 +00:00
}
})();