More code cleanup and fix bug around can_admin in the trigger_view

This commit is contained in:
Joseph Schorr 2015-05-03 11:02:05 -07:00
parent c89760278f
commit 0b990677a0
3 changed files with 25 additions and 39 deletions

View file

@ -52,6 +52,9 @@ def trigger_view(trigger, can_read=False, can_admin=False):
repo_url = build_trigger.get_repository_url() if build_source else None
if can_admin:
can_read = True
return {
'service': trigger.service.name,
'build_source': build_source if can_read else None,

View file

@ -179,11 +179,7 @@ angular.module('quay').directive('triggerSetupGithost', function () {
};
$scope.scmIcon = function(kind) {
if (kind == 'gitlab') {
return 'fa-git-square';
}
return 'fa-' + kind;
return TriggerService.getIcon(kind);
};
var setupTypeahead = function() {

View file

@ -8,13 +8,6 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
var triggerTypes = {
'github': {
'description': function(config) {
var source = UtilService.textToSafeHtml(config['build_source']);
var desc = '<i class="fa fa-github fa-lg" style="margin-left: 2px; margin-right: 2px"></i> Push to Github Repository ';
desc += '<a href="https://github.com/' + source + '" target="_blank">' + source + '</a>';
desc += '<br>Dockerfile folder: //' + UtilService.textToSafeHtml(config['subdir']);
return desc;
},
'run_parameters': [
{
'title': 'Branch',
@ -63,13 +56,6 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
},
'bitbucket': {
'description': function(config) {
var source = UtilService.textToSafeHtml(config['build_source']);
var desc = '<i class="fa fa-bitbucket fa-lg" style="margin-left: 2px; margin-right: 2px"></i> Push to Bitbucket Repository ';
desc += '<a href="https://bitbucket.org/' + source + '" target="_blank">' + source + '</a>';
desc += '<br>Dockerfile folder: //' + UtilService.textToSafeHtml(config['subdir']);
return desc;
},
'run_parameters': [
{
'title': 'Branch',
@ -99,13 +85,6 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
},
'gitlab': {
'description': function(config) {
var source = UtilService.textToSafeHtml(config['build_source']);
var desc = '<i class="fa fa-git-square fa-lg" style="margin-left: 2px; margin-right: 2px"></i> Push to GitLab Repository ';
desc += '<a href="https://gitlab.com/' + source + '" target="_blank">' + source + '</a>';
desc += '<br>Dockerfile folder: //' + UtilService.textToSafeHtml(config['subdir']);
return desc;
},
'run_parameters': [
{
'title': 'Branch',
@ -139,12 +118,6 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
},
'custom-git': {
'description': function(config) {
var source = UtilService.textToSafeHtml(config['build_source']);
var desc = '<i class"fa fa-git fa-lg" style="margin-left:2px; margin-right: 2px"></i> Push to Custom Git Repository ' + source;
desc += '<br>Dockerfile folder: //' + UtilService.textToSafeHtml(config['subdir']);
return desc;
},
'run_parameters': [
{
'title': 'Commit',
@ -232,10 +205,16 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
};
triggerService.getDockerfileLocation = function(trigger) {
if (!trigger.config.subdir) {
var subdirectory = trigger.config.subdir;
if (!subdirectory) {
return '//Dockerfile';
}
return '//' + trigger.config.subdir.replace(new RegExp('(^\/+|\/+$)'), '') + '/Dockerfile';
if (subdirectory[subdirectory.length - 1] != '/') {
subdirectory = subdirectory + '/';
}
return '//' + subdirectory.replace(new RegExp('(^\/+|\/+$)'), '') + 'Dockerfile';
};
triggerService.isEnabled = function(name) {
@ -246,6 +225,14 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
return type['is_enabled']();
};
triggerService.getIcon = function(name) {
var type = triggerTypes[name];
if (!type) {
return 'Unknown';
}
return type['icon'];
};
triggerService.getTitle = function(name) {
var type = triggerTypes[name];
if (!type) {
@ -255,11 +242,11 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
};
triggerService.getDescription = function(name, config) {
var type = triggerTypes[name];
if (!type) {
return 'Unknown';
}
return type['description'](config);
var icon = triggerService.getIcon(config['service']);
var title = triggerService.getTitle(config['service']);
var source = UtilService.textToSafeHtml(config['build_source']);
var desc = '<i class"fa ' + icon + ' fa-lg" style="margin-left:2px; margin-right: 2px"></i> Push to ' + title + ' ' + source;
return desc;
};
triggerService.getMetadata = function(name) {