function HeaderCtrl($scope, UserService) { $scope.$watch( function () { return UserService.currentUser(); }, function (currentUser) { $scope.user = currentUser; }, true); $('#repoSearch').typeahead({ name: 'repositories', remote: { url: '/api/repository/find/%QUERY', filter: function(data) { var datums = []; for (var i = 0; i < data.repositories.length; ++i) { var repo = data.repositories[i]; datums.push({ 'value': repo.name, 'tokens': [repo.name, repo.namespace], 'repo': repo }); } return datums; } }, template: function (datum) { template = '
'; template += '' template += '' + datum.repo.namespace +'/' + datum.repo.name + '' if (datum.repo.description) { template += '' + datum.repo.description + '' } template += '
' return template; }, }); $('#repoSearch').on('typeahead:selected', function (e, datum) { $('#repoSearch').typeahead('setQuery', ''); document.location = '#/repository/' + datum.repo.namespace + '/' + datum.repo.name }); } function RepoListCtrl($scope, Restangular) { var repositoryFetch = Restangular.all('repository/'); repositoryFetch.getList().then(function(resp) { $scope.repositories = resp.repositories; }); } function LandingCtrl($scope) { } function RepoCtrl($scope, Restangular, $routeParams, $rootScope) { var tabs = ['current-image', 'image-history']; $rootScope.title = 'Loading...'; $scope.showTab = function(tabName) { for (var i = 0; i < tabs.length; ++i) { $('#' + tabs[i]).hide(); $('#' + tabs[i] + '-tab').removeClass('active'); } $('#' + tabName).show(); $('#' + tabName + '-tab').addClass('active'); if (tabName == 'image-history') { $scope.listImages(); } }; $scope.editDescription = function() { if (!$scope.repo.can_write) { return; } $('#descriptionEdit')[0].value = $scope.repo.description || ''; $('#editModal').modal({}); }; $scope.saveDescription = function() { $('#editModal').modal('hide'); $scope.repo.description = $('#descriptionEdit')[0].value; $scope.repo.put(); }; $scope.parseDate = function(dateString) { return Date.parse(dateString); }; $scope.listImages = function() { if ($scope.imageHistory) { return; } var imageFetch = Restangular.one('repository/' + namespace + '/' + name + '/tag/' + $scope.currentTag.name + '/images'); imageFetch.get().then(function(resp) { $scope.imageHistory = resp.images; }); }; var namespace = $routeParams.namespace; var name = $routeParams.name; var tag = $routeParams.tag || 'latest'; var repositoryFetch = Restangular.one('repository/' + namespace + '/' + name); repositoryFetch.get().then(function(repo) { $rootScope.title = namespace + '/' + name; $scope.repo = repo; $scope.currentTag = repo.tags[tag] || repo.tags['latest']; var clip = new ZeroClipboard($('#copyClipboard'), { 'moviePath': 'static/js/ZeroClipboard.swf' }); clip.on('complete', function() { // Resets the animation. var elem = $('#clipboardCopied')[0]; elem.style.display = 'none'; // Show the notification. setTimeout(function() { elem.style.display = 'block'; }, 1); }); }, function() { $scope.repo = null; $rootScope.title = 'Unknown Repository'; }); } function RepoAdminCtrl($scope, Restangular, $routeParams, $rootScope) { var namespace = $routeParams.namespace; var name = $routeParams.name; $scope.setRole = function(username, role) { var permission = $scope.permissions[username]; permission.role = role; var permissionPut = Restangular.one('repository/' + namespace + '/' + name + '/permissions/' + username); permissionPut.customPUT(permission).then(function() {}, function(result) { if (result.status == 409) { $('#onlyAdminModal').modal(); } else { $('#cannotchangeModal').modal(); } }); }; var permissionsFetch = Restangular.one('repository/' + namespace + '/' + name + '/permissions'); permissionsFetch.get().then(function(resp) { $rootScope.title = 'Permissions - ' + namespace + '/' + name; $scope.repo = { 'namespace': namespace, 'name': name }; $scope.permissions = resp.permissions; }, function() { $scope.repo = null; $scope.permissions = null; $rootScope.title = 'Unknown Repository'; }); }