mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 15:21:13 +03:00
support extra_vars on job template schedules, inherit schedule extra_data field from job template. Resolves #1359
This commit is contained in:
parent
6150addc2e
commit
21e73e5d1b
@ -173,8 +173,8 @@ export default
|
||||
}
|
||||
$state.go("^");
|
||||
});
|
||||
|
||||
scope.saveSchedule = function() {
|
||||
schedule.extra_data = scope.serializedExtraVars;
|
||||
SchedulePost({
|
||||
scope: scope,
|
||||
url: url,
|
||||
@ -192,6 +192,7 @@ export default
|
||||
Rest.get()
|
||||
.success(function(data) {
|
||||
schedule = data;
|
||||
scope.serializedExtraVars = schedule.extra_data;
|
||||
if(schedule.extra_data.hasOwnProperty('granularity')){
|
||||
scope.isFactCleanup = true;
|
||||
}
|
||||
@ -312,7 +313,6 @@ export default
|
||||
schedule = (params.schedule) ? params.schedule : {},
|
||||
callback = params.callback,
|
||||
newSchedule, rrule, extra_vars;
|
||||
|
||||
if (scheduler.isValid()) {
|
||||
Wait('start');
|
||||
newSchedule = scheduler.getValue();
|
||||
@ -326,14 +326,16 @@ export default
|
||||
"older_than": scope.scheduler_form.keep_amount.$viewValue + scope.scheduler_form.keep_unit.$viewValue.value,
|
||||
"granularity": scope.scheduler_form.granularity_keep_amount.$viewValue + scope.scheduler_form.granularity_keep_unit.$viewValue.value
|
||||
};
|
||||
schedule.extra_data = JSON.stringify(extra_vars);
|
||||
} else if (scope.cleanupJob) {
|
||||
extra_vars = {
|
||||
"days" : scope.scheduler_form.schedulerPurgeDays.$viewValue
|
||||
};
|
||||
schedule.extra_data = JSON.stringify(extra_vars);
|
||||
}
|
||||
else if (scope.serializedExtraVars){
|
||||
schedule.extra_data = scope.serializedExtraVars;
|
||||
}
|
||||
schedule.extra_data = JSON.stringify(extra_vars);
|
||||
|
||||
|
||||
Rest.setUrl(url);
|
||||
if (mode === 'add') {
|
||||
Rest.post(schedule)
|
||||
|
@ -52,7 +52,7 @@ export default
|
||||
filter: "longDate",
|
||||
searchable: false,
|
||||
columnClass: "List-staticColumn--schedulerTime hidden-xs"
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
@ -34,7 +34,15 @@ export default
|
||||
resolve: {
|
||||
features: ['FeaturesService', function(FeaturesService) {
|
||||
return FeaturesService.get();
|
||||
}]
|
||||
}],
|
||||
JobTemplateExtraVars: ['Rest', 'GetBasePath', 'ToJSON', '$stateParams', function(Rest, GetBasePath, ToJSON, $stateParams) {
|
||||
var defaultUrl = GetBasePath('job_templates') + $stateParams.id + '/';
|
||||
Rest.setUrl(defaultUrl);
|
||||
return Rest.get().then(function(res){
|
||||
// handle unescaped newlines
|
||||
return JSON.parse(JSON.stringify(res.data.extra_vars))
|
||||
});
|
||||
}]
|
||||
}
|
||||
});
|
||||
$stateExtender.addState({
|
||||
|
@ -1,4 +1,4 @@
|
||||
export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', function($compile, $state, $stateParams, AddSchedule, Wait, $scope, $rootScope, CreateSelect2) {
|
||||
export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', 'ParseTypeChange', 'JobTemplateExtraVars', function($compile, $state, $stateParams, AddSchedule, Wait, $scope, $rootScope, CreateSelect2, ParseTypeChange, JobTemplateExtraVars) {
|
||||
$scope.$on("ScheduleFormCreated", function(e, scope) {
|
||||
$scope.hideForm = false;
|
||||
$scope = angular.extend($scope, scope);
|
||||
@ -41,10 +41,35 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s
|
||||
|
||||
$scope.hideForm = true;
|
||||
|
||||
|
||||
$scope.formCancel = function() {
|
||||
$state.go("^");
|
||||
};
|
||||
|
||||
$scope.parseType = 'yaml';
|
||||
$scope.extraVars = JobTemplateExtraVars === '' ? '---' : JobTemplateExtraVars;
|
||||
ParseTypeChange({
|
||||
scope: $scope,
|
||||
variable: 'extraVars',
|
||||
parse_variable: 'parseType',
|
||||
field_id: 'SchedulerForm-extraVars'
|
||||
});
|
||||
|
||||
$scope.$watch('extraVars', function(){
|
||||
if ($scope.parseType === 'yaml'){
|
||||
try{
|
||||
$scope.serializedExtraVars = jsyaml.safeLoad($scope.extraVars);
|
||||
}
|
||||
catch(err){ return; }
|
||||
}
|
||||
else if ($scope.parseType === 'json'){
|
||||
try{
|
||||
$scope.serializedExtraVars = JSON.parse($scope.extraVars);
|
||||
}
|
||||
catch(err){ return; }
|
||||
}
|
||||
});
|
||||
|
||||
AddSchedule({
|
||||
scope: $scope,
|
||||
callback: 'SchedulesRefresh',
|
||||
|
@ -1,4 +1,4 @@
|
||||
export default ['$compile', '$state', '$stateParams', 'EditSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', function($compile, $state, $stateParams, EditSchedule, Wait, $scope, $rootScope, CreateSelect2) {
|
||||
export default ['$compile', '$state', '$stateParams', 'EditSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', 'ParseTypeChange', function($compile, $state, $stateParams, EditSchedule, Wait, $scope, $rootScope, CreateSelect2, ParseTypeChange) {
|
||||
$scope.$on("ScheduleFormCreated", function(e, scope) {
|
||||
$scope.hideForm = false;
|
||||
$scope = angular.extend($scope, scope);
|
||||
@ -41,13 +41,49 @@ export default ['$compile', '$state', '$stateParams', 'EditSchedule', 'Wait', '$
|
||||
});
|
||||
|
||||
$scope.isEdit = true;
|
||||
|
||||
$scope.hideForm = true;
|
||||
$scope.parseType = 'yaml';
|
||||
|
||||
$scope.formCancel = function() {
|
||||
$state.go("^");
|
||||
}
|
||||
|
||||
$scope.$on('ScheduleFound', function(){
|
||||
if ($scope.parseType === 'yaml'){
|
||||
try{
|
||||
$scope.extraVars = '---\n' + jsyaml.safeDump($scope.serializedExtraVars);
|
||||
}
|
||||
catch(err){ return; }
|
||||
}
|
||||
else if ($scope.parseType === 'json'){
|
||||
try{
|
||||
$scope.extraVars = JSON.stringify($scope.serializedExtraVars, null, ' ');
|
||||
}
|
||||
catch(err){ return; }
|
||||
}
|
||||
ParseTypeChange({
|
||||
scope: $scope,
|
||||
variable: 'extraVars',
|
||||
parse_variable: 'parseType',
|
||||
field_id: 'SchedulerForm-extraVars'
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$watch('extraVars', function(){
|
||||
if ($scope.parseType === 'yaml'){
|
||||
try{
|
||||
$scope.serializedExtraVars = jsyaml.safeLoad($scope.extraVars);
|
||||
}
|
||||
catch(err){ return; }
|
||||
}
|
||||
else if ($scope.parseType === 'json'){
|
||||
try{
|
||||
$scope.serializedExtraVars = JSON.parse($scope.extraVars);
|
||||
}
|
||||
catch(err){ return; }
|
||||
}
|
||||
});
|
||||
|
||||
EditSchedule({
|
||||
scope: $scope,
|
||||
id: parseInt($stateParams.schedule_id),
|
||||
|
@ -632,8 +632,33 @@
|
||||
{{ occurrence.local }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-group Form-formGroup Form-textAreaLabel">
|
||||
<label for="Scheduler-extraVars">
|
||||
<span class="Form-inputLabel">
|
||||
Extra Variables
|
||||
</span>
|
||||
<!-- tooltip -->
|
||||
<a aw-pop-over="<p>Pass extra command line variables to the playbook. This is the -e or --extra-vars command line parameter for ansible-playbook. Provide key/value pairs using either YAML or JSON.</p>JSON:<br />
|
||||
<blockquote>{<br />"somevar": "somevalue",<br />"password": "magic"<br /> }</blockquote>
|
||||
YAML:<br />
|
||||
<blockquote>---<br />somevar: somevalue<br />password: magic<br /></blockquote>"
|
||||
data-placement="right" data-container="body" over-title="Extra Variables" class="help-link" data-original-title="" title="" tabindex="-1">
|
||||
<i class="fa fa-question-circle"></i>
|
||||
</a>
|
||||
|
||||
<div class="parse-selection">
|
||||
<input type="radio" ng-model="parseType" ng-change="parseTypeChange()" value="yaml"><span class="parse-label">YAML</span>
|
||||
<input type="radio" ng-model="parseType" ng-change="parseTypeChange()" value="json"> <span class="parse-label">JSON</span>
|
||||
</div>
|
||||
|
||||
</label>
|
||||
<div>
|
||||
<textarea rows="6" ng-model="extraVars" name="Scheduler-extraVars" class="form-control" id="SchedulerForm-extraVars"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="buttons Form-buttons">
|
||||
<button type="button"
|
||||
class="btn btn-sm Form-saveButton"
|
||||
|
Loading…
Reference in New Issue
Block a user