parent
82287926ab
commit
143036be9c
7 changed files with 312 additions and 56 deletions
118
static/js/directives/ui/dropdown-select-direct.js
Normal file
118
static/js/directives/ui/dropdown-select-direct.js
Normal file
|
@ -0,0 +1,118 @@
|
|||
/**
|
||||
* An element which displays a dropdown select box which is (optionally) editable. This box
|
||||
* is displayed with an <input> and a menu on the right.
|
||||
*/
|
||||
angular.module('quay').directive('dropdownSelectDirect', function ($compile) {
|
||||
var directiveDefinitionObject = {
|
||||
priority: 0,
|
||||
templateUrl: '/static/directives/dropdown-select-direct.html',
|
||||
replace: true,
|
||||
transclude: true,
|
||||
restrict: 'C',
|
||||
scope: {
|
||||
'selectedItem': '=selectedItem',
|
||||
|
||||
'placeholder': '=placeholder',
|
||||
'items': '=items',
|
||||
'iconMap': '=iconMap',
|
||||
|
||||
'valueKey': '@valueKey',
|
||||
'titleKey': '@titleKey',
|
||||
'iconKey': '@iconKey',
|
||||
|
||||
'noneIcon': '@noneIcon',
|
||||
|
||||
'clearValue': '=clearValue'
|
||||
},
|
||||
controller: function($scope, $element, $rootScope) {
|
||||
if (!$rootScope.__dropdownSelectCounter) {
|
||||
$rootScope.__dropdownSelectCounter = 1;
|
||||
}
|
||||
|
||||
$scope.placeholder = $scope.placeholder || '';
|
||||
$scope.internalItem = null;
|
||||
|
||||
// Setup lookahead.
|
||||
var input = $($element).find('.lookahead-input');
|
||||
|
||||
$scope.setItem = function(item) {
|
||||
$scope.selectedItem = item;
|
||||
};
|
||||
|
||||
$scope.$watch('clearValue', function(cv) {
|
||||
if (cv) {
|
||||
$scope.selectedItem = null;
|
||||
$(input).val('');
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$watch('selectedItem', function(item) {
|
||||
if ($scope.selectedItem == $scope.internalItem) {
|
||||
// The item has already been set due to an internal action.
|
||||
return;
|
||||
}
|
||||
|
||||
if ($scope.selectedItem != null) {
|
||||
$(input).val(item[$scope.valueKey]);
|
||||
} else {
|
||||
$(input).val('');
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$watch('items', function(items) {
|
||||
$(input).off();
|
||||
if (!items || !$scope.valueKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
var formattedItems = [];
|
||||
for (var i = 0; i < items.length; ++i) {
|
||||
var currentItem = items[i];
|
||||
var formattedItem = {
|
||||
'value': currentItem[$scope.valueKey],
|
||||
'item': currentItem
|
||||
};
|
||||
|
||||
formattedItems.push(formattedItem);
|
||||
}
|
||||
|
||||
var dropdownHound = new Bloodhound({
|
||||
name: 'dropdown-items-' + $rootScope.__dropdownSelectCounter,
|
||||
local: formattedItems,
|
||||
datumTokenizer: function(d) {
|
||||
return Bloodhound.tokenizers.whitespace(d.val || d.value || '');
|
||||
},
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace
|
||||
});
|
||||
dropdownHound.initialize();
|
||||
|
||||
$(input).typeahead({}, {
|
||||
source: dropdownHound.ttAdapter(),
|
||||
templates: {
|
||||
'suggestion': function (datum) {
|
||||
template = datum['template'] ? datum['template'](datum) : datum['value'];
|
||||
return template;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$(input).on('input', function(e) {
|
||||
$scope.$apply(function() {
|
||||
$scope.internalItem = null;
|
||||
$scope.selectedItem = null;
|
||||
});
|
||||
});
|
||||
|
||||
$(input).on('typeahead:selected', function(e, datum) {
|
||||
$scope.$apply(function() {
|
||||
$scope.internalItem = datum['item'];
|
||||
$scope.selectedItem = datum['item'];
|
||||
});
|
||||
});
|
||||
|
||||
$rootScope.__dropdownSelectCounter++;
|
||||
});
|
||||
}
|
||||
};
|
||||
return directiveDefinitionObject;
|
||||
});
|
|
@ -16,6 +16,7 @@ angular.module('quay').directive('manualTriggerBuildDialog', function () {
|
|||
controller: function($scope, $element, ApiService, TriggerService) {
|
||||
$scope.parameters = {};
|
||||
$scope.fieldOptions = {};
|
||||
$scope.lookaheadItems = {};
|
||||
|
||||
$scope.startTrigger = function() {
|
||||
$('#startTriggerDialog').modal('hide');
|
||||
|
@ -36,7 +37,7 @@ angular.module('quay').directive('manualTriggerBuildDialog', function () {
|
|||
var parameters = TriggerService.getRunParameters($scope.trigger.service);
|
||||
for (var i = 0; i < parameters.length; ++i) {
|
||||
var parameter = parameters[i];
|
||||
if (parameter['type'] == 'option') {
|
||||
if (parameter['type'] == 'option' || parameter['type'] == 'autocomplete') {
|
||||
// Load the values for this parameter.
|
||||
var params = {
|
||||
'repository': $scope.repository.namespace + '/' + $scope.repository.name,
|
||||
|
|
|
@ -6,15 +6,19 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
|
|||
function(UtilService, $sanitize, KeyService, Features, CookieService, Config) {
|
||||
var triggerService = {};
|
||||
|
||||
var branch_tag = {
|
||||
'title': 'Branch/Tag',
|
||||
'type': 'autocomplete',
|
||||
'name': 'refs',
|
||||
'iconMap': {
|
||||
'branch': 'fa-code-fork',
|
||||
'tag': 'fa-tag'
|
||||
}
|
||||
};
|
||||
|
||||
var triggerTypes = {
|
||||
'github': {
|
||||
'run_parameters': [
|
||||
{
|
||||
'title': 'Branch',
|
||||
'type': 'option',
|
||||
'name': 'branch_name'
|
||||
}
|
||||
],
|
||||
'run_parameters': [branch_tag],
|
||||
'get_redirect_url': function(namespace, repository) {
|
||||
var redirect_uri = KeyService['githubRedirectUri'] + '/trigger/' +
|
||||
namespace + '/' + repository;
|
||||
|
@ -55,13 +59,7 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
|
|||
},
|
||||
|
||||
'bitbucket': {
|
||||
'run_parameters': [
|
||||
{
|
||||
'title': 'Branch',
|
||||
'type': 'option',
|
||||
'name': 'branch_name'
|
||||
}
|
||||
],
|
||||
'run_parameters': [branch_tag],
|
||||
'get_redirect_url': function(namespace, repository) {
|
||||
return Config.getUrl('/bitbucket/setup/' + namespace + '/' + repository);
|
||||
},
|
||||
|
@ -84,13 +82,7 @@ angular.module('quay').factory('TriggerService', ['UtilService', '$sanitize', 'K
|
|||
},
|
||||
|
||||
'gitlab': {
|
||||
'run_parameters': [
|
||||
{
|
||||
'title': 'Branch',
|
||||
'type': 'option',
|
||||
'name': 'branch_name'
|
||||
}
|
||||
],
|
||||
'run_parameters': [branch_tag],
|
||||
'get_redirect_url': function(namespace, repository) {
|
||||
var redirect_uri = KeyService['gitlabRedirectUri'] + '/trigger';
|
||||
var authorize_url = KeyService['gitlabTriggerAuthorizeUrl'];
|
||||
|
|
Reference in a new issue