2015-02-19 21:21:54 +00:00
|
|
|
/**
|
|
|
|
* An element which displays a dialog for manually trigger a build.
|
|
|
|
*/
|
|
|
|
angular.module('quay').directive('manualTriggerBuildDialog', function () {
|
|
|
|
var directiveDefinitionObject = {
|
|
|
|
templateUrl: '/static/directives/manual-trigger-build-dialog.html',
|
|
|
|
replace: false,
|
|
|
|
transclude: false,
|
|
|
|
restrict: 'C',
|
|
|
|
scope: {
|
|
|
|
'repository': '=repository',
|
|
|
|
'counter': '=counter',
|
|
|
|
'trigger': '=trigger',
|
2015-08-20 23:24:51 +00:00
|
|
|
'buildStarted': '&buildStarted'
|
2015-02-19 21:21:54 +00:00
|
|
|
},
|
|
|
|
controller: function($scope, $element, ApiService, TriggerService) {
|
|
|
|
$scope.parameters = {};
|
|
|
|
$scope.fieldOptions = {};
|
2015-06-19 16:54:39 +00:00
|
|
|
$scope.lookaheadItems = {};
|
2015-02-19 21:21:54 +00:00
|
|
|
|
|
|
|
$scope.startTrigger = function() {
|
2015-08-20 23:24:51 +00:00
|
|
|
$element.find('.startTriggerDialog').modal('hide');
|
|
|
|
var params = {
|
|
|
|
'repository': $scope.repository.namespace + '/' + $scope.repository.name,
|
|
|
|
'trigger_uuid': $scope.trigger.id
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.manuallyStartBuildTrigger($scope.parameters || {}, params).then(function(resp) {
|
|
|
|
$scope.buildStarted({
|
|
|
|
'trigger': $scope.trigger,
|
|
|
|
'parameters': $scope.parameters,
|
|
|
|
'build': resp
|
|
|
|
});
|
|
|
|
}, ApiService.errorDisplay('Could not start build'));
|
2015-02-19 21:21:54 +00:00
|
|
|
};
|
|
|
|
|
2015-04-22 17:22:04 +00:00
|
|
|
$scope.getPattern = function(field) {
|
|
|
|
return new RegExp(field.regex);
|
|
|
|
};
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
$scope.show = function() {
|
|
|
|
$scope.parameters = {};
|
|
|
|
$scope.fieldOptions = {};
|
|
|
|
|
|
|
|
var parameters = TriggerService.getRunParameters($scope.trigger.service);
|
|
|
|
for (var i = 0; i < parameters.length; ++i) {
|
|
|
|
var parameter = parameters[i];
|
2015-06-19 16:54:39 +00:00
|
|
|
if (parameter['type'] == 'option' || parameter['type'] == 'autocomplete') {
|
2015-02-19 21:21:54 +00:00
|
|
|
// Load the values for this parameter.
|
|
|
|
var params = {
|
|
|
|
'repository': $scope.repository.namespace + '/' + $scope.repository.name,
|
|
|
|
'trigger_uuid': $scope.trigger.id,
|
|
|
|
'field_name': parameter['name']
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.listTriggerFieldValues(null, params).then(function(resp) {
|
|
|
|
$scope.fieldOptions[parameter['name']] = resp['values'];
|
|
|
|
});
|
|
|
|
}
|
2017-03-08 01:39:57 +00:00
|
|
|
|
|
|
|
delete $scope.parameters[parameter['name']];
|
2015-02-19 21:21:54 +00:00
|
|
|
}
|
|
|
|
|
2015-08-20 23:24:51 +00:00
|
|
|
$scope.runParameters = parameters;
|
|
|
|
$element.find('.startTriggerDialog').modal('show');
|
2015-02-19 21:21:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$watch('counter', function(counter) {
|
|
|
|
if (counter) {
|
|
|
|
$scope.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return directiveDefinitionObject;
|
2015-04-22 17:22:04 +00:00
|
|
|
});
|