mirror of
https://github.com/ansible/awx.git
synced 2026-05-24 17:17:45 -02:30
Fixing group/hosts inventory count on deletion from one page to all
This commit is contained in:
@@ -6,25 +6,31 @@
|
||||
* Routines that handle group add/edit/delete on the Inventory tree widget.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name helpers.function:Groups
|
||||
* @description inventory tree widget add/edit/delete
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', 'GroupListDefinition', 'SearchHelper',
|
||||
'PaginationHelpers', 'ListGenerator', 'AuthService', 'GroupsHelper', 'InventoryHelper', 'SelectionHelper',
|
||||
'JobSubmissionHelper', 'RefreshHelper', 'PromptDialog', 'CredentialsListDefinition', 'InventoryTree',
|
||||
'InventoryStatusDefinition', 'VariablesHelper', 'SchedulesListDefinition', 'SourceFormDefinition', 'LogViewerHelper',
|
||||
'SchedulesHelper' ])
|
||||
'PaginationHelpers', 'ListGenerator', 'AuthService', 'GroupsHelper', 'InventoryHelper', 'SelectionHelper',
|
||||
'JobSubmissionHelper', 'RefreshHelper', 'PromptDialog', 'CredentialsListDefinition', 'InventoryTree',
|
||||
'InventoryStatusDefinition', 'VariablesHelper', 'SchedulesListDefinition', 'SourceFormDefinition', 'LogViewerHelper',
|
||||
'SchedulesHelper'
|
||||
])
|
||||
|
||||
/**
|
||||
*
|
||||
* Lookup options for group source and build an array of drop-down choices
|
||||
*
|
||||
*/
|
||||
.factory('GetSourceTypeOptions', ['Rest', 'ProcessErrors', 'GetBasePath',
|
||||
function (Rest, ProcessErrors, GetBasePath) {
|
||||
return function (params) {
|
||||
// Lookup options for source and build an array of drop-down choices
|
||||
var scope = params.scope,
|
||||
variable = params.variable;
|
||||
|
||||
if (scope[variable] === undefined) {
|
||||
scope[variable] = [];
|
||||
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',
|
||||
function (Rest, ProcessErrors, GetBasePath, Alert, Wait, Empty, Find, LogViewer) {
|
||||
return function (params) {
|
||||
@@ -96,6 +106,11 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
}
|
||||
])
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Document
|
||||
*
|
||||
*/
|
||||
.factory('GetHostsStatusMsg', [
|
||||
function () {
|
||||
return function (params) {
|
||||
@@ -132,6 +147,11 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
}
|
||||
])
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Document
|
||||
*
|
||||
*/
|
||||
.factory('GetSyncStatusMsg', [ 'Empty',
|
||||
function (Empty) {
|
||||
return function (params) {
|
||||
@@ -207,6 +227,11 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
}
|
||||
])
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Document
|
||||
*
|
||||
*/
|
||||
.factory('SourceChange', ['GetBasePath', 'CredentialList', 'LookUpInit', 'Empty', 'Wait', 'ParseTypeChange', 'CustomInventoryList' ,
|
||||
function (GetBasePath, CredentialList, LookUpInit, Empty, Wait, ParseTypeChange, CustomInventoryList) {
|
||||
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',
|
||||
function (Empty, Rest, ProcessErrors, Alert, Wait, Find) {
|
||||
return function (params) {
|
||||
@@ -389,10 +417,10 @@ angular.module('GroupsHelper', [ 'RestServices', 'Utilities', 'ListGenerator', '
|
||||
* Add the list of schedules to the Group Edit modal
|
||||
*
|
||||
*/
|
||||
.factory('GroupsScheduleListInit', ['GroupsScheduleEdit', 'SchedulesList', 'GenerateList', 'SearchInit', 'PaginateInit', 'Rest', 'PageRangeSetup',
|
||||
'Wait', 'ProcessErrors', 'Find', 'ToggleSchedule', 'DeleteSchedule', 'GetBasePath', 'SchedulesListInit',
|
||||
function(GroupsScheduleEdit, SchedulesList, GenerateList, SearchInit, PaginateInit, Rest, PageRangeSetup, Wait, ProcessErrors, Find,
|
||||
ToggleSchedule, DeleteSchedule, GetBasePath, SchedulesListInit) {
|
||||
.factory('GroupsScheduleListInit', ['GroupsScheduleEdit', 'SchedulesList', 'GenerateList', 'SearchInit', 'PaginateInit', 'Rest',
|
||||
'PageRangeSetup', 'Wait', 'ProcessErrors', 'Find', 'ToggleSchedule', 'DeleteSchedule', 'GetBasePath', 'SchedulesListInit',
|
||||
function(GroupsScheduleEdit, SchedulesList, GenerateList, SearchInit, PaginateInit, Rest, PageRangeSetup, Wait, ProcessErrors, Find,
|
||||
ToggleSchedule, DeleteSchedule, GetBasePath, SchedulesListInit) {
|
||||
return function(params) {
|
||||
var schedule_scope = params.scope,
|
||||
url = params.url,
|
||||
@@ -489,19 +517,24 @@ ToggleSchedule, DeleteSchedule, GetBasePath, SchedulesListInit) {
|
||||
callback: 'SchedulesRefresh'
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
}])
|
||||
}
|
||||
])
|
||||
|
||||
|
||||
.factory('SetSchedulesInnerDialogSize', [ function() {
|
||||
/**
|
||||
*
|
||||
* TODO: Document
|
||||
*
|
||||
*/
|
||||
.factory('SetSchedulesInnerDialogSize', [
|
||||
function() {
|
||||
return function() {
|
||||
var height = $('#group-modal-dialog').outerHeight() - $('#group_tabs').outerHeight() - 25;
|
||||
height = height - 110 - $('#schedules-buttons').outerHeight();
|
||||
$('#schedules-form-container-body').height(height);
|
||||
};
|
||||
}])
|
||||
|
||||
}
|
||||
])
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -509,7 +542,7 @@ ToggleSchedule, DeleteSchedule, GetBasePath, SchedulesListInit) {
|
||||
*
|
||||
*/
|
||||
.factory('GroupsScheduleEdit', ['$compile','SchedulerInit', 'Rest', 'Wait', 'SetSchedulesInnerDialogSize', 'SchedulePost', 'ProcessErrors',
|
||||
function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, SchedulePost, ProcessErrors) {
|
||||
function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, SchedulePost, ProcessErrors) {
|
||||
return function(params) {
|
||||
var parent_scope = params.scope,
|
||||
mode = params.mode, // 'add' or 'edit'
|
||||
@@ -652,13 +685,18 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
scope.$emit('ScheduleReady');
|
||||
}
|
||||
};
|
||||
}])
|
||||
|
||||
}
|
||||
])
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Document
|
||||
*
|
||||
*/
|
||||
.factory('GroupsEdit', ['$rootScope', '$location', '$log', '$routeParams', '$compile', 'Rest', 'Alert', 'GroupForm', 'GenerateForm',
|
||||
'Prompt', 'ProcessErrors', 'GetBasePath', 'SetNodeName', 'ParseTypeChange', 'GetSourceTypeOptions', 'InventoryUpdate',
|
||||
'LookUpInit', 'Empty', 'Wait', 'GetChoices', 'UpdateGroup', 'SourceChange', 'Find', 'WatchInventoryWindowResize',
|
||||
'ParseVariableString', 'ToJSON', 'GroupsScheduleListInit', 'SourceForm', 'SetSchedulesInnerDialogSize',
|
||||
'Prompt', 'ProcessErrors', 'GetBasePath', 'SetNodeName', 'ParseTypeChange', 'GetSourceTypeOptions', 'InventoryUpdate',
|
||||
'LookUpInit', 'Empty', 'Wait', 'GetChoices', 'UpdateGroup', 'SourceChange', 'Find', 'WatchInventoryWindowResize',
|
||||
'ParseVariableString', 'ToJSON', 'GroupsScheduleListInit', 'SourceForm', 'SetSchedulesInnerDialogSize',
|
||||
function ($rootScope, $location, $log, $routeParams, $compile, Rest, Alert, GroupForm, GenerateForm, Prompt, ProcessErrors,
|
||||
GetBasePath, SetNodeName, ParseTypeChange, GetSourceTypeOptions, InventoryUpdate, LookUpInit, Empty, Wait,
|
||||
GetChoices, UpdateGroup, SourceChange, Find, WatchInventoryWindowResize, ParseVariableString, ToJSON, GroupsScheduleListInit,
|
||||
@@ -1375,8 +1413,13 @@ 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',
|
||||
'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,
|
||||
GetBasePath, Wait, BuildTree, Find, CreateDialog) {
|
||||
return function (params) {
|
||||
@@ -1420,6 +1463,7 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
if (scope.removeDeleteDialogReady) {
|
||||
scope.removeDeleteDialogReady();
|
||||
}
|
||||
|
||||
scope.removeDeleteDialogReady = scope.$on('DeleteDialogReady', function() {
|
||||
Wait('stop');
|
||||
$('#group-delete-dialog').dialog('open');
|
||||
@@ -1428,6 +1472,7 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
if (scope.removeShowDeleteDialog) {
|
||||
scope.removeShowDeleteDialog();
|
||||
}
|
||||
|
||||
scope.removeShowDeleteDialog = scope.$on('ShowDeleteDialog', function() {
|
||||
scope.group_name = node.name;
|
||||
scope.groupsCount = groups.length;
|
||||
@@ -1447,6 +1492,7 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
if (scope.removeChildrenReady) {
|
||||
scope.removeChildrenReady();
|
||||
}
|
||||
|
||||
scope.removeChildrenReady = scope.$on('ChildrenReady', function() {
|
||||
childCount++;
|
||||
if (childCount === 2) {
|
||||
@@ -1456,6 +1502,43 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
|
||||
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) {
|
||||
Rest.setUrl(node.related.children);
|
||||
Rest.get()
|
||||
@@ -1465,7 +1548,12 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
groups.push(group);
|
||||
});
|
||||
}
|
||||
|
||||
if (data.next) {
|
||||
scope.next_iterator(data.next, "groups");
|
||||
} else {
|
||||
scope.$emit('ChildrenReady');
|
||||
}
|
||||
})
|
||||
.error(function(data, status) {
|
||||
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
|
||||
@@ -1486,7 +1574,11 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
hosts.push(host);
|
||||
});
|
||||
}
|
||||
if (data.next) {
|
||||
scope.next_iterator(data.next, "hosts");
|
||||
} else {
|
||||
scope.$emit('ChildrenReady');
|
||||
}
|
||||
})
|
||||
.error( function(data, status) {
|
||||
ProcessErrors(scope, data, status, null, { hdr: 'Error!',
|
||||
@@ -1501,6 +1593,7 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
if (scope.removeDisassociateGroup) {
|
||||
scope.removeDisassociateGroup();
|
||||
}
|
||||
|
||||
scope.removeDisassociateGroup = scope.$on('DisassociateGroup', function() {
|
||||
var data, url;
|
||||
if (!scope.selected_group_id) {
|
||||
@@ -1527,6 +1620,7 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
if (scope.removeDeleteGroup) {
|
||||
scope.removeDeleteGroup();
|
||||
}
|
||||
|
||||
scope.removeDeleteGroup = scope.$on('DeleteGroup', function() {
|
||||
var url = GetBasePath('groups') + node.id + '/';
|
||||
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) {
|
||||
var scope = params.scope,
|
||||
inventory_id = params.inventory_id,
|
||||
@@ -1579,10 +1679,16 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
msg: 'Call to ' + url + ' failed. GET returned: ' + status });
|
||||
});
|
||||
};
|
||||
}])
|
||||
}
|
||||
])
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Document
|
||||
*
|
||||
*/
|
||||
.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) {
|
||||
return function(params) {
|
||||
|
||||
@@ -1876,10 +1982,16 @@ function($compile, SchedulerInit, Rest, Wait, SetSchedulesInnerDialogSize, Sched
|
||||
};
|
||||
|
||||
};
|
||||
}])
|
||||
}
|
||||
])
|
||||
|
||||
/**
|
||||
*
|
||||
* TODO: Document
|
||||
*
|
||||
*/
|
||||
.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,
|
||||
FormatDate, InventoryStatusForm, Wait) {
|
||||
return function (params) {
|
||||
|
||||
Reference in New Issue
Block a user