Add a fetch tag dialog

This commit is contained in:
Joseph Schorr 2015-03-19 15:08:18 -04:00
parent c1d58bdd6c
commit 70aec00914
13 changed files with 258 additions and 2 deletions

View file

@ -12,7 +12,16 @@ angular.module('quay').directive('repoPanelInfo', function () {
'repository': '=repository',
'builds': '=builds'
},
controller: function($scope, $element, ApiService) {
controller: function($scope, $element, ApiService, Config) {
$scope.$watch('repository', function(repository) {
if (!$scope.repository) { return; }
var namespace = $scope.repository.namespace;
var name = $scope.repository.name;
$scope.pullCommand = 'docker pull ' + Config.getDomain() + '/' + namespace + '/' + name;
});
$scope.updateDescription = function(content) {
$scope.repository.description = content;
$scope.repository.put();

View file

@ -0,0 +1,104 @@
/**
* An element which adds a of dialog for fetching a tag.
*/
angular.module('quay').directive('fetchTagDialog', function () {
var directiveDefinitionObject = {
priority: 0,
templateUrl: '/static/directives/fetch-tag-dialog.html',
replace: false,
transclude: false,
restrict: 'C',
scope: {
'repository': '=repository',
'actionHandler': '=actionHandler'
},
controller: function($scope, $element, $timeout, ApiService, UserService, Config) {
$scope.clearCounter = 0;
$scope.currentFormat = null;
$scope.currentEntity = null;
$scope.currentRobot = null;
$scope.formats = [
{
'title': 'Squashed Docker Image',
'icon': 'fa-file-archive-o',
'command': 'curl -L -f {http}://{pull_user}:{pull_password}@{hostname}/c1/squash/{namespace}/{name}/{tag} | docker load',
'require_creds': true
},
{
'title': 'Basic Docker Pull',
'icon': 'docker-icon',
'command': 'docker pull {hostname}/{namespace}/{name}:{tag}'
}];
$scope.$watch('currentEntity', function(entity) {
if (!entity) {
$scope.currentRobot = null;
return;
}
if ($scope.currentRobot && $scope.currentRobot.name == entity.name) {
return;
}
$scope.currentRobot = null;
var parts = entity.name.split('+');
var namespace = parts[0];
var shortname = parts[1];
var params = {
'robot_shortname': shortname
};
var orgname = UserService.isOrganization(namespace) ? namespace : '';
ApiService.getRobot(orgname, null, params).then(function(resp) {
$scope.currentRobot = resp;
}, ApiService.errorDisplay('Cannot download robot token'));
});
$scope.getCommand = function(format, robot) {
if (!format || !format.command) { return ''; }
if (format.require_creds && !robot) { return ''; }
var params = {
'pull_user': robot ? robot.name : '',
'pull_password': robot ? robot.token : '',
'hostname': Config.getDomain(),
'http': Config.getHttp(),
'namespace': $scope.repository.namespace,
'name': $scope.repository.name,
'tag': $scope.currentTag.name
};
var value = format.command;
for (var param in params) {
if (!params.hasOwnProperty(param)) { continue; }
value = value.replace('{' + param + '}', params[param]);
}
return value;
};
$scope.setFormat = function(format) {
$scope.currentFormat = format;
};
$scope.actionHandler = {
'askFetchTag': function(tag) {
$scope.currentTag = tag;
$scope.currentFormat = null;
$scope.currentEntity = null;
$scope.currentRobot = null;
$scope.clearCounter++;
$element.find('#copyClipboard').clipboardCopy();
$element.find('#fetchTagDialog').modal({});
}
};
}
};
return directiveDefinitionObject;
});

View file

@ -54,6 +54,10 @@ angular.module('quay').factory('Config', [function() {
return config['PREFERRED_URL_SCHEME'] + '://' + auth + config['SERVER_HOSTNAME'];
};
config.getHttp = function() {
return config['PREFERRED_URL_SCHEME'];
};
config.getUrl = function(opt_path) {
var path = opt_path || '';
return config['PREFERRED_URL_SCHEME'] + '://' + config['SERVER_HOSTNAME'] + path;

View file

@ -83,6 +83,10 @@ function(ApiService, CookieService, $rootScope, Config) {
});
};
userService.isOrganization = function(name) {
return !!userService.getOrganization(name);
};
userService.getOrganization = function(name) {
if (!userResponse || !userResponse.organizations) { return null; }
for (var i = 0; i < userResponse.organizations.length; ++i) {