From 9886b73d2cb3e237eab7b54b1792b39b2d553bdb Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 19 Mar 2014 12:05:36 -0400 Subject: [PATCH] Fixed bug in Inventory Group Add. Save was failing. Also when group vars failed to parse, the error was not bubbled up to the GroupEdit code. --- awx/ui/static/js/controllers/Jobs.js | 3 +- awx/ui/static/js/helpers/Groups.js | 168 ++++++++++++++------------ awx/ui/static/js/helpers/Variables.js | 3 + 3 files changed, 95 insertions(+), 79 deletions(-) diff --git a/awx/ui/static/js/controllers/Jobs.js b/awx/ui/static/js/controllers/Jobs.js index 08f300d028..b99da4d93f 100644 --- a/awx/ui/static/js/controllers/Jobs.js +++ b/awx/ui/static/js/controllers/Jobs.js @@ -14,7 +14,8 @@ function JobsList($scope, $compile, ClearScope, Breadcrumbs, LoadScope, RunningJ ClearScope(); - var e, completed_scope, running_scope, queued_scope, schedule_scope; + var e, completed_scope, running_scope, queued_scope; + // schedule_scope; // Add breadcrumbs e = angular.element(document.getElementById('breadcrumbs')); diff --git a/awx/ui/static/js/helpers/Groups.js b/awx/ui/static/js/helpers/Groups.js index 4da7c2b8b3..5960b6d39e 100644 --- a/awx/ui/static/js/helpers/Groups.js +++ b/awx/ui/static/js/helpers/Groups.js @@ -552,11 +552,11 @@ function(SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize) { .factory('GroupsEdit', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GroupForm', 'GenerateForm', 'Prompt', 'ProcessErrors', 'GetBasePath', 'SetNodeName', 'ParseTypeChange', 'GetSourceTypeOptions', 'InventoryUpdate', 'LookUpInit', 'Empty', 'Wait', 'GetChoices', 'UpdateGroup', 'SourceChange', 'Find','WatchInventoryWindowResize', - 'ParseVariableString', 'ToJSON', 'ScheduleList', 'SourceForm', 'SetSchedulesInnerDialogSize', + 'ParseVariableString', 'ToJSON', 'ScheduleList', 'SourceForm', 'SetSchedulesInnerDialogSize', 'BuildTree', function ($rootScope, $location, $log, $routeParams, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors, GetBasePath, SetNodeName, ParseTypeChange, GetSourceTypeOptions, InventoryUpdate, LookUpInit, Empty, Wait, GetChoices, UpdateGroup, SourceChange, Find, WatchInventoryWindowResize, ParseVariableString, ToJSON, ScheduleList, - SourceForm, SetSchedulesInnerDialogSize) { + SourceForm, SetSchedulesInnerDialogSize, BuildTree) { return function (params) { var parent_scope = params.scope, @@ -933,6 +933,27 @@ function(SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize) { Wait('start'); + if (parent_scope.removeAddTreeRefreshed) { + parent_scope.removeAddTreeRefreshed(); + } + parent_scope.removeAddTreeRefreshed = parent_scope.$on('GroupTreeRefreshed', function() { + //Clean up + if (modal_scope.searchCleanUp) { + modal_scope.searchCleanup(); + } + + $('#group-modal-dialog').dialog('close'); + + // Change the selected group + if (groups_reload && parent_scope.selected_tree_id !== tree_id) { + parent_scope.showHosts(tree_id, group_id, false); + } else { + Wait('stop'); + } + WatchInventoryWindowResize(); + parent_scope.removeAddTreeRefreshed(); + }); + if (modal_scope.removeSaveComplete) { modal_scope.removeSaveComplete(); } @@ -963,20 +984,17 @@ function(SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize) { } } - //Clean up - if (modal_scope.searchCleanUp) { - modal_scope.searchCleanup(); + if (mode === 'add') { + BuildTree({ + scope: parent_scope, + inventory_id: inventory_id, + refresh: true, + new_group_id: group_id + }); } - - $('#group-modal-dialog').dialog('close'); - - // Change the selected group - if (groups_reload && parent_scope.selected_tree_id !== tree_id) { - parent_scope.showHosts(tree_id, group_id, false); - } else { - Wait('stop'); + else { + parent_scope.$emit('GroupTreeRefreshed'); } - WatchInventoryWindowResize(); } }); @@ -1015,28 +1033,15 @@ function(SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize) { if (!parseError) { Rest.setUrl(sources_scope.source_url); - if (mode === 'edit') { - Rest.put(data) - .success(function () { - modal_scope.$emit('SaveComplete', false); - }) - .error(function (data, status) { - modal_scope.$emit('SaveComplete', true); - ProcessErrors(sources_scope, data, status, SourceForm, { hdr: 'Error!', - msg: 'Failed to update group inventory source. PUT status: ' + status }); - }); - } - else { - Rest.post(data) - .success(function () { - modal_scope.$emit('SaveComplete', false); - }) - .error(function (data, status) { - modal_scope.$emit('SaveComplete', true); - ProcessErrors(sources_scope, data, status, SourceForm, { hdr: 'Error!', - msg: 'Failed to update group inventory source. PUT status: ' + status }); - }); - } + Rest.put(data) + .success(function () { + modal_scope.$emit('SaveComplete', false); + }) + .error(function (data, status) { + modal_scope.$emit('SaveComplete', true); + ProcessErrors(sources_scope, data, status, SourceForm, { hdr: 'Error!', + msg: 'Failed to update group inventory source. PUT status: ' + status }); + }); } }); @@ -1074,51 +1079,58 @@ function(SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize) { Wait('start'); var fld, data, json_data; - json_data = ToJSON(properties_scope.parseType, properties_scope.variables); + try { + + json_data = ToJSON(properties_scope.parseType, properties_scope.variables); - data = {}; - for (fld in GroupForm.fields) { - if (fld !== 'variables') { - data[fld] = properties_scope[fld]; + data = {}; + for (fld in GroupForm.fields) { + if (fld !== 'variables') { + data[fld] = properties_scope[fld]; + } + } + + data.inventory = inventory_id; + + Rest.setUrl(defaultUrl); + if (mode === 'edit') { + Rest.put(data) + .success(function () { + if (properties_scope.variables) { + modal_scope.$emit('updateVariables', json_data, properties_scope.variable_url); + } + else { + modal_scope.$emit('formSaveSuccess'); + } + }) + .error(function (data, status) { + Wait('stop'); + ProcessErrors(properties_scope, data, status, GroupForm, { hdr: 'Error!', + msg: 'Failed to update group: ' + group_id + '. PUT status: ' + status + }); + }); + } + else { + Rest.post(data) + .success(function (data) { + if (properties_scope.variables) { + sources_scope.source_url = data.related.inventory_source; + modal_scope.$emit('updateVariables', json_data, data.related.variable_data); + } + else { + modal_scope.$emit('formSaveSuccess'); + } + }) + .error(function (data, status) { + Wait('stop'); + ProcessErrors(properties_scope, data, status, GroupForm, { hdr: 'Error!', + msg: 'Failed to create group: ' + group_id + '. POST status: ' + status + }); + }); } } - - data.inventory = inventory_id; - - Rest.setUrl(defaultUrl); - if (mode === 'edit') { - Rest.put(data) - .success(function () { - if (properties_scope.variables) { - modal_scope.$emit('updateVariables', json_data, properties_scope.variable_url); - } - else { - modal_scope.$emit('formSaveSuccess'); - } - }) - .error(function (data, status) { - Wait('stop'); - ProcessErrors(properties_scope, data, status, GroupForm, { hdr: 'Error!', - msg: 'Failed to update group: ' + group_id + '. PUT status: ' + status - }); - }); - } - else { - Rest.post(data) - .success(function () { - if (properties_scope.variables) { - modal_scope.$emit('updateVariables', json_data, properties_scope.variable_url); - } - else { - modal_scope.$emit('formSaveSuccess'); - } - }) - .error(function (data, status) { - Wait('stop'); - ProcessErrors(properties_scope, data, status, GroupForm, { hdr: 'Error!', - msg: 'Failed to create group: ' + group_id + '. POST status: ' + status - }); - }); + catch(e) { + // ignore. ToJSON will have already alerted the user } }; diff --git a/awx/ui/static/js/helpers/Variables.js b/awx/ui/static/js/helpers/Variables.js index fb9c65e526..d08fcabf7a 100644 --- a/awx/ui/static/js/helpers/Variables.js +++ b/awx/ui/static/js/helpers/Variables.js @@ -99,6 +99,9 @@ angular.module('VariablesHelper', ['Utilities']) if (typeof json_data !== 'object') { ProcessErrors(null, variables, null, null, { hdr: 'Error!', msg: 'Failed to parse variables. Attempted to parse ' + parseType + ' Parser did not return an object.' }); + setTimeout( function() { + throw { name: 'Parse error', message: 'Failed to parse variables. Attempted to parse ' + parseType + ' Parser did not return an object.' }; + }, 1000); } result = json_data; if (stringify) {