Added Callback checkbox and Host Config Key field to Job Template. Also added button to generate a config key value using md5 hash. Added button to select-all on key so user can ctrl-c copy to clipboard.

This commit is contained in:
chouseknecht
2013-06-21 17:45:24 -04:00
parent 5495709a61
commit 8ef9c9ed0b
9 changed files with 397 additions and 9 deletions

View File

@@ -55,7 +55,8 @@ angular.module('ansible', [
'ParseHelper',
'ChildrenHelper',
'EventsHelper',
'ProjectPathHelper'
'ProjectPathHelper',
'md5Helper'
])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.

View File

@@ -158,7 +158,7 @@ JobTemplatesList.$inject = [ '$scope', '$rootScope', '$location', '$log', '$rout
function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, ReturnToCaller, ClearScope,
GetBasePath, InventoryList, CredentialList, ProjectList, LookUpInit)
GetBasePath, InventoryList, CredentialList, ProjectList, LookUpInit, md5Setup)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
@@ -168,17 +168,26 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP
var form = JobTemplateForm;
var generator = GenerateForm;
var scope = generator.inject(form, {mode: 'add', related: false});
var master = {};
scope.job_type_options = [{ value: 'run', label: 'Run' }, { value: 'check', label: 'Check' }];
scope.verbosity_options = [
{ value: '0', label: 'Default' },
{ value: '1', label: 'Verbose' },
{ value: '3', label: 'Debug' }];
scope.playbook_options = [];
scope.allow_callbacks = 'false';
generator.reset();
LoadBreadCrumbs();
md5Setup({
scope: scope,
master: master,
check_field: 'allow_callbacks',
default_val: false
});
LookUpInit({
scope: scope,
form: form,
@@ -259,18 +268,21 @@ function JobTemplatesAdd ($scope, $rootScope, $compile, $location, $log, $routeP
// Defaults
generator.reset();
$('#forks-slider').slider("option", "value", scope.forks);
for (var fld in master) {
scope[fld] = master[fld];
}
};
}
JobTemplatesAdd.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'ReturnToCaller', 'ClearScope',
'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit' ];
'GetBasePath', 'InventoryList', 'CredentialList', 'ProjectList', 'LookUpInit', 'md5Setup' ];
function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, JobTemplateForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, CredentialList,
ProjectList, LookUpInit, PromptPasswords, GetBasePath)
ProjectList, LookUpInit, PromptPasswords, GetBasePath, md5Setup)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
@@ -335,6 +347,15 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
}
getPlaybooks(scope.project);
$('#forks-slider').slider('value',scope.forks); // align slider handle with value.
var dft = (scope['host_config_key']) ? 'true' : 'false';
md5Setup({
scope: scope,
master: master,
check_field: 'allow_callbacks',
default_val: dft
});
});
// Retrieve detail record and prepopulate the form
@@ -484,5 +505,5 @@ function JobTemplatesEdit ($scope, $rootScope, $compile, $location, $log, $route
JobTemplatesEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobTemplateForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList',
'ProjectList', 'LookUpInit', 'PromptPasswords', 'GetBasePath'
'ProjectList', 'LookUpInit', 'PromptPasswords', 'GetBasePath', 'md5Setup'
];

View File

@@ -129,7 +129,7 @@ JobsListCtrl.$inject = [ '$scope', '$rootScope', '$location', '$log', '$routePar
function JobsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams, JobForm,
GenerateForm, Rest, Alert, ProcessErrors, LoadBreadCrumbs, RelatedSearchInit,
RelatedPaginateInit, ReturnToCaller, ClearScope, InventoryList, CredentialList,
ProjectList, LookUpInit, PromptPasswords, GetBasePath)
ProjectList, LookUpInit, PromptPasswords, GetBasePath, md5Setup)
{
ClearScope('htmlTemplate'); //Garbage collection. Don't leave behind any listeners/watchers from the prior
//scope.
@@ -190,8 +190,19 @@ function JobsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
}
// Set the playbook lookup
getPlaybooks(scope.project);
// display/hide host callback fields
var dft = (scope['host_config_key']) ? 'true' : 'false';
md5Setup({
scope: scope,
master: master,
check_field: 'allow_callbacks',
default_val: dft
});
$('#forks-slider').slider("option", "value", scope.forks);
$('#forks-slider').slider("disable");
$('input[type="checkbox"]').attr('disabled','disabled');
});
// Our job type options
@@ -387,5 +398,5 @@ function JobsEdit ($scope, $rootScope, $compile, $location, $log, $routeParams,
JobsEdit.$inject = [ '$scope', '$rootScope', '$compile', '$location', '$log', '$routeParams', 'JobForm',
'GenerateForm', 'Rest', 'Alert', 'ProcessErrors', 'LoadBreadCrumbs', 'RelatedSearchInit',
'RelatedPaginateInit', 'ReturnToCaller', 'ClearScope', 'InventoryList', 'CredentialList',
'ProjectList', 'LookUpInit', 'PromptPasswords', 'GetBasePath'
'ProjectList', 'LookUpInit', 'PromptPasswords', 'GetBasePath', 'md5Setup'
];

View File

@@ -141,6 +141,24 @@ angular.module('JobTemplateFormDefinition', [])
"#passing-variables-on-the-command-line\" target=\"_blank\">Click here to view documentation and examples.</a></p>",
dataTitle: 'Extra Variables',
dataPlacement: 'left'
},
allow_callbacks: {
label: 'Allow Callbacks',
type: 'checkbox',
addRequired: false,
editRequird: false,
trueValue: 'true',
falseValue: 'false',
ngChange: "toggleCallback('host_config_key')",
"class": "span12",
column: 2
},
host_config_key: {
label: 'Host Config Key',
type: 'text',
ngShow: "allow_callbacks",
genMD5: true,
column: 2
}
},

View File

@@ -133,6 +133,24 @@ angular.module('JobFormDefinition', [])
"for ansible-playbook. Provide key=value pairs or JSON. <p><a href=\"http://www.ansibleworks.com/docs/playbooks2.html" +
"#passing-variables-on-the-command-line\" target=\"_blank\">Click here to view documentation and examples.</a></p>",
column: 2
},
allow_callbacks: {
label: 'Allow Callbacks',
type: 'checkbox',
addRequired: false,
editRequird: false,
trueValue: 'true',
falseValue: 'false',
ngChange: "toggleCallback('host_config_key')",
"class": "span12",
column: 2
},
host_config_key: {
label: 'Host Config Key',
type: 'text',
ngShow: "allow_callbacks",
genMD5: true,
column: 2
}
},

View File

@@ -0,0 +1,40 @@
/*********************************************
* Copyright (c) 2013 AnsibleWorks, Inc.
*
* md5helper
*
* Run md5Setup({ scope: , master:, check_field:, default_val: })
* to initialize md5 fields (checkbox and text field).
*
*/
angular.module('md5Helper', ['RestServices', 'Utilities'])
.factory('md5Setup', ['Alert', 'Rest', 'GetBasePath','ProcessErrors',
function(Alert, Rest, GetBasePath, ProcessErrors) {
return function(params) {
var scope = params.scope;
var master = params.master;
var check_field = params.check_field;
var default_val = params.default_val; //default(true/false) for the checkbox
scope[check_field] = default_val;
master[check_field] = default_val;
scope.genMD5 = function(fld) {
var now = new Date();
scope[fld] = $.md5('AnsibleWorks' + now.getTime());
}
scope.toggleCallback = function(fld) {
if (scope.allow_callbacks == 'false') {
scope[fld] = null;
}
}
scope.selectAll = function(fld) {
$('input[name="' + fld +'"]').focus().select();
}
}
}]);