remove JobTemplateExtraVars provision & replace with REST requests in schedulerAddController

This commit is contained in:
Leigh Johnson
2016-04-19 16:45:32 -04:00
parent 1b51021a58
commit f59cb5f5a3
3 changed files with 28 additions and 30 deletions

View File

@@ -35,10 +35,7 @@ export default
resolve: { resolve: {
features: ['FeaturesService', function(FeaturesService){ features: ['FeaturesService', function(FeaturesService){
return FeaturesService.get(); return FeaturesService.get();
}], }]
JobTemplateExtraVars: function(){
return null;
}
} }
}); });
$stateExtender.addState({ $stateExtender.addState({

View File

@@ -34,15 +34,7 @@ export default
resolve: { resolve: {
features: ['FeaturesService', function(FeaturesService) { features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get(); 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({ $stateExtender.addState({
@@ -64,10 +56,7 @@ export default
resolve: { resolve: {
features: ['FeaturesService', function(FeaturesService) { features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get(); return FeaturesService.get();
}], }]
JobTemplateExtraVars: function(){
return null;
}
} }
}); });
$stateExtender.addState({ $stateExtender.addState({
@@ -78,10 +67,7 @@ export default
resolve: { resolve: {
features: ['FeaturesService', function(FeaturesService) { features: ['FeaturesService', function(FeaturesService) {
return FeaturesService.get(); return FeaturesService.get();
}], }]
JobTemplateExtraVars: function(){
return null;
}
} }
}); });
$stateExtender.addState({ $stateExtender.addState({

View File

@@ -1,4 +1,4 @@
export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', 'ParseTypeChange', 'JobTemplateExtraVars', function($compile, $state, $stateParams, AddSchedule, Wait, $scope, $rootScope, CreateSelect2, ParseTypeChange, JobTemplateExtraVars) { export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$scope', '$rootScope', 'CreateSelect2', 'ParseTypeChange', 'GetBasePath', 'Rest', function($compile, $state, $stateParams, AddSchedule, Wait, $scope, $rootScope, CreateSelect2, ParseTypeChange, GetBasePath, Rest) {
$scope.$on("ScheduleFormCreated", function(e, scope) { $scope.$on("ScheduleFormCreated", function(e, scope) {
$scope.hideForm = false; $scope.hideForm = false;
$scope = angular.extend($scope, scope); $scope = angular.extend($scope, scope);
@@ -46,14 +46,20 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s
}; };
// extra_data field is not manifested in the UI when scheduling a Management Job // extra_data field is not manifested in the UI when scheduling a Management Job
if ($state.current.name !== ('managementJobSchedules.add' || 'managementJobSchedules.edit')){ if ($state.current.name === 'jobTemplateSchedules.add'){
$scope.parseType = 'yaml'; $scope.parseType = 'yaml';
$scope.extraVars = JobTemplateExtraVars === '' || JobTemplateExtraVars === null ? '---' : JobTemplateExtraVars; var defaultUrl = GetBasePath('job_templates') + $stateParams.id + '/';
ParseTypeChange({ Rest.setUrl(defaultUrl);
scope: $scope, Rest.get().then(function(res){
variable: 'extraVars', // sanitize
parse_variable: 'parseType', var data = JSON.parse(JSON.stringify(res.data.extra_vars));
field_id: 'SchedulerForm-extraVars' $scope.extraVars = data === '' ? '---' : data;
ParseTypeChange({
scope: $scope,
variable: 'extraVars',
parse_variable: 'parseType',
field_id: 'SchedulerForm-extraVars'
});
}); });
$scope.$watch('extraVars', function(){ $scope.$watch('extraVars', function(){
if ($scope.parseType === 'yaml'){ if ($scope.parseType === 'yaml'){
@@ -70,7 +76,16 @@ export default ['$compile', '$state', '$stateParams', 'AddSchedule', 'Wait', '$s
} }
}); });
} }
else if ($state.current.name === 'projectSchedules.add'){
$scope.extraVars = '---';
$scope.parseType = 'yaml';
ParseTypeChange({
scope: $scope,
variable: 'extraVars',
parse_variable: 'parseType',
field_id: 'SchedulerForm-extraVars'
});
}
AddSchedule({ AddSchedule({
scope: $scope, scope: $scope,