Fixing group/hosts inventory count on deletion from one page to all

This commit is contained in:
John Mitchell
2015-01-09 12:10:55 -05:00
parent d70d5a5c99
commit c12006753e

View File

@@ -6,25 +6,31 @@
* Routines that handle group add/edit/delete on the Inventory tree widget. * Routines that handle group add/edit/delete on the Inventory tree widget.
* *
*/ */
'use strict';
/** /**
* @ngdoc function * @ngdoc function
* @name helpers.function:Groups * @name helpers.function:Groups
* @description inventory tree widget add/edit/delete * @description inventory tree widget add/edit/delete
*/ */
'use strict';
angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'GroupListDefinition', 'SearchHelper', angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'GroupListDefinition', 'SearchHelper',
'PaginationHelpers', 'ListGenerator', 'AuthService', 'GroupsHelper', 'InventoryHelper', 'SelectionHelper', 'PaginationHelpers', 'ListGenerator', 'AuthService', 'GroupsHelper', 'InventoryHelper', 'SelectionHelper',
'JobSubmissionHelper', 'RefreshHelper', 'PromptDialog', 'CredentialsListDefinition', 'InventoryTree', 'JobSubmissionHelper', 'RefreshHelper', 'PromptDialog', 'CredentialsListDefinition', 'InventoryTree',
'InventoryStatusDefinition', 'VariablesHelper', 'SchedulesListDefinition', 'SourceFormDefinition', 'LogViewerHelper', 'InventoryStatusDefinition', 'VariablesHelper', 'SchedulesListDefinition', 'SourceFormDefinition', 'LogViewerHelper',
'SchedulesHelper' ]) 'SchedulesHelper'
])
/**
*
* Lookup options for group source and build an array of drop-down choices
*
*/
.factory('GetSourceTypeOptions', ['Rest', 'ProcessErrors', 'GetBasePath', .factory('GetSourceTypeOptions', ['Rest', 'ProcessErrors', 'GetBasePath',
function (Rest, ProcessErrors, GetBasePath) { function (Rest, ProcessErrors, GetBasePath) {
return function (params) { return function (params) {
// Lookup options for source and build an array of drop-down choices
var scope = params.scope, var scope = params.scope,
variable = params.variable; variable = params.variable;
if (scope[variable] === undefined) { if (scope[variable] === undefined) {
scope[variable] = []; scope[variable] = [];
Rest.setUrl(GetBasePath('inventory_sources')); Rest.setUrl(GetBasePath('inventory_sources'));
@@ -51,7 +57,11 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
} }
]) ])
/**
*
* TODO: Document
*
*/
.factory('ViewUpdateStatus', ['Rest', 'ProcessErrors', 'GetBasePath', 'Alert', 'Wait', 'Empty', 'Find', 'LogViewer', .factory('ViewUpdateStatus', ['Rest', 'ProcessErrors', 'GetBasePath', 'Alert', 'Wait', 'Empty', 'Find', 'LogViewer',
function (Rest, ProcessErrors, GetBasePath, Alert, Wait, Empty, Find, LogViewer) { function (Rest, ProcessErrors, GetBasePath, Alert, Wait, Empty, Find, LogViewer) {
return function (params) { return function (params) {
@@ -96,6 +106,11 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
} }
]) ])
/**
*
* TODO: Document
*
*/
.factory('GetHostsStatusMsg', [ .factory('GetHostsStatusMsg', [
function () { function () {
return function (params) { return function (params) {
@@ -132,6 +147,11 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
} }
]) ])
/**
*
* TODO: Document
*
*/
.factory('GetSyncStatusMsg', [ 'Empty', .factory('GetSyncStatusMsg', [ 'Empty',
function (Empty) { function (Empty) {
return function (params) { return function (params) {
@@ -207,6 +227,11 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
} }
]) ])
/**
*
* TODO: Document
*
*/
.factory('SourceChange', ['GetBasePath', 'CredentialList', 'LookUpInit', 'Empty', 'Wait', 'ParseTypeChange', 'CustomInventoryList' , .factory('SourceChange', ['GetBasePath', 'CredentialList', 'LookUpInit', 'Empty', 'Wait', 'ParseTypeChange', 'CustomInventoryList' ,
function (GetBasePath, CredentialList, LookUpInit, Empty, Wait, ParseTypeChange, CustomInventoryList) { function (GetBasePath, CredentialList, LookUpInit, Empty, Wait, ParseTypeChange, CustomInventoryList) {
return function (params) { return function (params) {
@@ -303,8 +328,11 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
} }
]) ])
/**
// Cancel a pending or running inventory sync *
* Cancel a pending or running inventory sync
*
*/
.factory('GroupsCancelUpdate', ['Empty', 'Rest', 'ProcessErrors', 'Alert', 'Wait', 'Find', .factory('GroupsCancelUpdate', ['Empty', 'Rest', 'ProcessErrors', 'Alert', 'Wait', 'Find',
function (Empty, Rest, ProcessErrors, Alert, Wait, Find) { function (Empty, Rest, ProcessErrors, Alert, Wait, Find) {
return function (params) { return function (params) {
@@ -389,8 +417,8 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
* Add the list of schedules to the Group Edit modal * Add the list of schedules to the Group Edit modal
* *
*/ */
.factory('GroupsScheduleListInit', ['GroupsScheduleEdit', 'SchedulesList', 'GenerateList', 'SearchInit', 'PaginateInit', 'Rest', 'PageRangeSetup', .factory('GroupsScheduleListInit', ['GroupsScheduleEdit', 'SchedulesList', 'GenerateList', 'SearchInit', 'PaginateInit', 'Rest',
'Wait', 'ProcessErrors', 'Find', 'ToggleSchedule', 'DeleteSchedule', 'GetBasePath', 'SchedulesListInit', 'PageRangeSetup', 'Wait', 'ProcessErrors', 'Find', 'ToggleSchedule', 'DeleteSchedule', 'GetBasePath', 'SchedulesListInit',
function(GroupsScheduleEdit, SchedulesList, GenerateList, SearchInit, PaginateInit, Rest, PageRangeSetup, Wait, ProcessErrors, Find, function(GroupsScheduleEdit, SchedulesList, GenerateList, SearchInit, PaginateInit, Rest, PageRangeSetup, Wait, ProcessErrors, Find,
ToggleSchedule, DeleteSchedule, GetBasePath, SchedulesListInit) { ToggleSchedule, DeleteSchedule, GetBasePath, SchedulesListInit) {
return function(params) { return function(params) {
@@ -489,19 +517,24 @@ ToggleSchedule, DeleteSchedule, GetBasePath, SchedulesListInit) {
callback: 'SchedulesRefresh' callback: 'SchedulesRefresh'
}); });
}; };
}; };
}]) }
])
/**
.factory('SetSchedulesInnerDialogSize', [ function() { *
* TODO: Document
*
*/
.factory('SetSchedulesInnerDialogSize', [
function() {
return function() { return function() {
var height = $('#group-modal-dialog').outerHeight() - $('#group_tabs').outerHeight() - 25; var height = $('#group-modal-dialog').outerHeight() - $('#group_tabs').outerHeight() - 25;
height = height - 110 - $('#schedules-buttons').outerHeight(); height = height - 110 - $('#schedules-buttons').outerHeight();
$('#schedules-form-container-body').height(height); $('#schedules-form-container-body').height(height);
}; };
}]) }
])
/** /**
* *
@@ -652,9 +685,14 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
scope.$emit('ScheduleReady'); scope.$emit('ScheduleReady');
} }
}; };
}]) }
])
/**
*
* TODO: Document
*
*/
.factory('GroupsEdit', ['$rootScope', '$location', '$log', '$routeParams', '$compile', 'Rest', 'Alert', 'GroupForm', 'GenerateForm', .factory('GroupsEdit', ['$rootScope', '$location', '$log', '$routeParams', '$compile', 'Rest', 'Alert', 'GroupForm', 'GenerateForm',
'Prompt', 'ProcessErrors', 'GetBasePath', 'SetNodeName', 'ParseTypeChange', 'GetSourceTypeOptions', 'InventoryUpdate', 'Prompt', 'ProcessErrors', 'GetBasePath', 'SetNodeName', 'ParseTypeChange', 'GetSourceTypeOptions', 'InventoryUpdate',
'LookUpInit', 'Empty', 'Wait', 'GetChoices', 'UpdateGroup', 'SourceChange', 'Find', 'WatchInventoryWindowResize', 'LookUpInit', 'Empty', 'Wait', 'GetChoices', 'UpdateGroup', 'SourceChange', 'Find', 'WatchInventoryWindowResize',
@@ -1375,6 +1413,11 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
} }
]) ])
/**
*
* Set's up the process for deleting a group from an inventory page
*
*/
.factory('GroupsDelete', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GroupForm', 'GenerateForm', .factory('GroupsDelete', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GroupForm', 'GenerateForm',
'Prompt', 'ProcessErrors', 'GetBasePath', 'Wait', 'BuildTree', 'Find', 'CreateDialog', 'Prompt', 'ProcessErrors', 'GetBasePath', 'Wait', 'BuildTree', 'Find', 'CreateDialog',
function ($rootScope, $location, $log, $routeParams, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors, function ($rootScope, $location, $log, $routeParams, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors,
@@ -1420,6 +1463,7 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
if (scope.removeDeleteDialogReady) { if (scope.removeDeleteDialogReady) {
scope.removeDeleteDialogReady(); scope.removeDeleteDialogReady();
} }
scope.removeDeleteDialogReady = scope.$on('DeleteDialogReady', function() { scope.removeDeleteDialogReady = scope.$on('DeleteDialogReady', function() {
Wait('stop'); Wait('stop');
$('#group-delete-dialog').dialog('open'); $('#group-delete-dialog').dialog('open');
@@ -1428,6 +1472,7 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
if (scope.removeShowDeleteDialog) { if (scope.removeShowDeleteDialog) {
scope.removeShowDeleteDialog(); scope.removeShowDeleteDialog();
} }
scope.removeShowDeleteDialog = scope.$on('ShowDeleteDialog', function() { scope.removeShowDeleteDialog = scope.$on('ShowDeleteDialog', function() {
scope.group_name = node.name; scope.group_name = node.name;
scope.groupsCount = groups.length; scope.groupsCount = groups.length;
@@ -1447,6 +1492,7 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
if (scope.removeChildrenReady) { if (scope.removeChildrenReady) {
scope.removeChildrenReady(); scope.removeChildrenReady();
} }
scope.removeChildrenReady = scope.$on('ChildrenReady', function() { scope.removeChildrenReady = scope.$on('ChildrenReady', function() {
childCount++; childCount++;
if (childCount === 2) { if (childCount === 2) {
@@ -1456,6 +1502,43 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
Wait('start'); Wait('start');
// this function is used to make sure that we get all of the groups/hosts,
// not just the first page
scope.next_iterator = function(next_url, type) {
Rest.setUrl(next_url);
Rest.get()
.success(function(data) {
if (data.count) {
if (type === "groups") {
data.results.forEach(function(group) {
groups.push(group);
});
}
else if (type === "hosts") {
data.results.forEach(function(host) {
hosts.push(host);
});
}
}
if (data.next) {
if (type === "groups") {
scope.next_iterator(data.next, "groups");
} else if (type === "hosts") {
scope.next_iterator(data.next, "hosts");
}
}
else {
scope.$emit('ChildrenReady');
}
})
.error(function(data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
msg: 'Failed to retrieve related groups. GET returned: ' + status
});
});
};
if (node.related.children) { if (node.related.children) {
Rest.setUrl(node.related.children); Rest.setUrl(node.related.children);
Rest.get() Rest.get()
@@ -1465,7 +1548,12 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
groups.push(group); groups.push(group);
}); });
} }
if (data.next) {
scope.next_iterator(data.next, "groups");
} else {
scope.$emit('ChildrenReady'); scope.$emit('ChildrenReady');
}
}) })
.error(function(data, status) { .error(function(data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!', ProcessErrors(scope, data, status, null, { hdr: 'Error!',
@@ -1486,7 +1574,11 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
hosts.push(host); hosts.push(host);
}); });
} }
if (data.next) {
scope.next_iterator(data.next, "hosts");
} else {
scope.$emit('ChildrenReady'); scope.$emit('ChildrenReady');
}
}) })
.error( function(data, status) { .error( function(data, status) {
ProcessErrors(scope, data, status, null, { hdr: 'Error!', ProcessErrors(scope, data, status, null, { hdr: 'Error!',
@@ -1501,6 +1593,7 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
if (scope.removeDisassociateGroup) { if (scope.removeDisassociateGroup) {
scope.removeDisassociateGroup(); scope.removeDisassociateGroup();
} }
scope.removeDisassociateGroup = scope.$on('DisassociateGroup', function() { scope.removeDisassociateGroup = scope.$on('DisassociateGroup', function() {
var data, url; var data, url;
if (!scope.selected_group_id) { if (!scope.selected_group_id) {
@@ -1527,6 +1620,7 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
if (scope.removeDeleteGroup) { if (scope.removeDeleteGroup) {
scope.removeDeleteGroup(); scope.removeDeleteGroup();
} }
scope.removeDeleteGroup = scope.$on('DeleteGroup', function() { scope.removeDeleteGroup = scope.$on('DeleteGroup', function() {
var url = GetBasePath('groups') + node.id + '/'; var url = GetBasePath('groups') + node.id + '/';
Rest.setUrl(url); Rest.setUrl(url);
@@ -1560,7 +1654,13 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
} }
]) ])
.factory('GetRootGroups', ['Rest', 'ProcessErrors', 'GetBasePath', function(Rest, ProcessErrors, GetBasePath) { /**
*
* TODO: Document
*
*/
.factory('GetRootGroups', ['Rest', 'ProcessErrors', 'GetBasePath',
function(Rest, ProcessErrors, GetBasePath) {
return function(params) { return function(params) {
var scope = params.scope, var scope = params.scope,
inventory_id = params.inventory_id, inventory_id = params.inventory_id,
@@ -1579,8 +1679,14 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
msg: 'Call to ' + url + ' failed. GET returned: ' + status }); msg: 'Call to ' + url + ' failed. GET returned: ' + status });
}); });
}; };
}]) }
])
/**
*
* TODO: Document
*
*/
.factory('GroupsCopy', ['$compile', 'Rest', 'ProcessErrors', 'CreateDialog', 'GetBasePath', 'Wait', 'GenerateList', 'GroupList', 'SearchInit', .factory('GroupsCopy', ['$compile', 'Rest', 'ProcessErrors', 'CreateDialog', 'GetBasePath', 'Wait', 'GenerateList', 'GroupList', 'SearchInit',
'PaginateInit', 'GetRootGroups', 'PaginateInit', 'GetRootGroups',
function($compile, Rest, ProcessErrors, CreateDialog, GetBasePath, Wait, GenerateList, GroupList, SearchInit, PaginateInit, GetRootGroups) { function($compile, Rest, ProcessErrors, CreateDialog, GetBasePath, Wait, GenerateList, GroupList, SearchInit, PaginateInit, GetRootGroups) {
@@ -1876,8 +1982,14 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
}; };
}; };
}]) }
])
/**
*
* TODO: Document
*
*/
.factory('ShowUpdateStatus', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GenerateForm', .factory('ShowUpdateStatus', ['$rootScope', '$location', '$log', '$routeParams', 'Rest', 'Alert', 'GenerateForm',
'Prompt', 'ProcessErrors', 'GetBasePath', 'FormatDate', 'InventoryStatusForm', 'Wait', 'Prompt', 'ProcessErrors', 'GetBasePath', 'FormatDate', 'InventoryStatusForm', 'Wait',
function ($rootScope, $location, $log, $routeParams, Rest, Alert, GenerateForm, Prompt, ProcessErrors, GetBasePath, function ($rootScope, $location, $log, $routeParams, Rest, Alert, GenerateForm, Prompt, ProcessErrors, GetBasePath,