mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 16:58:46 -03:30
Use related hosts and group counts for delete modal
This commit is contained in:
committed by
Ryan Petrello
parent
107d2da845
commit
2bc6521eee
@@ -7,11 +7,11 @@
|
||||
['$scope', '$state', '$stateParams', 'listDefinition', 'InventoryUpdate',
|
||||
'GroupsService', 'CancelSourceUpdate',
|
||||
'GetHostsStatusMsg', 'Dataset', 'inventoryData', 'canAdd',
|
||||
'InventoryHostsStrings', '$transitions',
|
||||
'InventoryHostsStrings', '$transitions', 'GetBasePath', 'Rest',
|
||||
function($scope, $state, $stateParams, listDefinition, InventoryUpdate,
|
||||
GroupsService, CancelSourceUpdate,
|
||||
GetHostsStatusMsg, Dataset, inventoryData, canAdd,
|
||||
InventoryHostsStrings, $transitions){
|
||||
InventoryHostsStrings, $transitions, GetBasePath, Rest){
|
||||
|
||||
let list = listDefinition;
|
||||
|
||||
@@ -90,35 +90,51 @@
|
||||
$state.go('inventories.edit.groups.edit.nested_groups', {group_id: id});
|
||||
};
|
||||
$scope.deleteGroup = function(group){
|
||||
$scope.toDelete = {};
|
||||
$scope.strings.deleteModal = {};
|
||||
angular.extend($scope.toDelete, group);
|
||||
if($scope.toDelete.total_groups === 0 && $scope.toDelete.total_hosts === 0) {
|
||||
// This group doesn't have any child groups or hosts - the user is just trying to delete
|
||||
// the group
|
||||
$scope.deleteOption = "delete";
|
||||
}
|
||||
else {
|
||||
$scope.strings.deleteModal.group = InventoryHostsStrings.get('deletegroup.GROUP', $scope.toDelete.total_groups);
|
||||
$scope.strings.deleteModal.host = InventoryHostsStrings.get('deletegroup.HOST', $scope.toDelete.total_hosts);
|
||||
const promises = [];
|
||||
|
||||
Rest.setUrl(group.related.hosts);
|
||||
promises.push(Rest.get());
|
||||
|
||||
Rest.setUrl(group.related.children);
|
||||
promises.push(Rest.get());
|
||||
|
||||
Promise.all(promises)
|
||||
.then(([hostResponse, groupResponse]) => {
|
||||
$scope.toDelete = {};
|
||||
$scope.strings.deleteModal = {};
|
||||
$scope.toDelete.hostCount = _.get(hostResponse, ['data', 'count'], 0);
|
||||
$scope.toDelete.groupCount = _.get(groupResponse, ['data', 'count'], 0);
|
||||
angular.extend($scope.toDelete, group);
|
||||
|
||||
if($scope.toDelete.groupCount === 0 && $scope.toDelete.hostCount === 0) {
|
||||
// This group doesn't have any child groups or hosts - the user is just trying to delete
|
||||
// the group
|
||||
$scope.deleteOption = "delete";
|
||||
}
|
||||
else {
|
||||
$scope.strings.deleteModal.group = InventoryHostsStrings.get('deletegroup.GROUP', $scope.toDelete.groupCount);
|
||||
$scope.strings.deleteModal.host = InventoryHostsStrings.get('deletegroup.HOST', $scope.toDelete.hostCount);
|
||||
|
||||
if($scope.toDelete.groupCount === 0 || $scope.toDelete.groupCount === 0) {
|
||||
if($scope.toDelete.groupCount === 0) {
|
||||
$scope.strings.deleteModal.deleteGroupsHosts = InventoryHostsStrings.get('deletegroup.DELETE_HOST', $scope.toDelete.hostCount);
|
||||
$scope.strings.deleteModal.promoteGroupsHosts = InventoryHostsStrings.get('deletegroup.PROMOTE_HOST', $scope.toDelete.hostCount);
|
||||
}
|
||||
else if($scope.toDelete.hostCount === 0) {
|
||||
$scope.strings.deleteModal.deleteGroupsHosts = InventoryHostsStrings.get('deletegroup.DELETE_GROUP', $scope.toDelete.groupCount);
|
||||
$scope.strings.deleteModal.promoteGroupsHosts = InventoryHostsStrings.get('deletegroup.PROMOTE_GROUP', $scope.toDelete.groupCount);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$scope.strings.deleteModal.deleteGroupsHosts = InventoryHostsStrings.get('deletegroup.DELETE_GROUPS_AND_HOSTS', {groups: $scope.toDelete.groupCount, hosts: $scope.toDelete.hostCount});
|
||||
$scope.strings.deleteModal.promoteGroupsHosts = InventoryHostsStrings.get('deletegroup.PROMOTE_GROUPS_AND_HOSTS', {groups: $scope.toDelete.groupCount, hosts: $scope.toDelete.hostCount});
|
||||
}
|
||||
}
|
||||
|
||||
$('#group-delete-modal').modal('show');
|
||||
});
|
||||
|
||||
if($scope.toDelete.total_groups === 0 || $scope.toDelete.total_hosts === 0) {
|
||||
if($scope.toDelete.total_groups === 0) {
|
||||
$scope.strings.deleteModal.deleteGroupsHosts = InventoryHostsStrings.get('deletegroup.DELETE_HOST', $scope.toDelete.total_hosts);
|
||||
$scope.strings.deleteModal.promoteGroupsHosts = InventoryHostsStrings.get('deletegroup.PROMOTE_HOST', $scope.toDelete.total_hosts);
|
||||
}
|
||||
else if($scope.toDelete.total_hosts === 0) {
|
||||
$scope.strings.deleteModal.deleteGroupsHosts = InventoryHostsStrings.get('deletegroup.DELETE_GROUP', $scope.toDelete.total_groups);
|
||||
$scope.strings.deleteModal.promoteGroupsHosts = InventoryHostsStrings.get('deletegroup.PROMOTE_GROUP', $scope.toDelete.total_groups);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$scope.strings.deleteModal.deleteGroupsHosts = InventoryHostsStrings.get('deletegroup.DELETE_GROUPS_AND_HOSTS', {groups: $scope.toDelete.total_groups, hosts: $scope.toDelete.total_hosts});
|
||||
$scope.strings.deleteModal.promoteGroupsHosts = InventoryHostsStrings.get('deletegroup.PROMOTE_GROUPS_AND_HOSTS', {groups: $scope.toDelete.total_groups, hosts: $scope.toDelete.total_hosts});
|
||||
}
|
||||
}
|
||||
|
||||
$('#group-delete-modal').modal('show');
|
||||
};
|
||||
$scope.confirmDelete = function(){
|
||||
let reloadListStateParams = null;
|
||||
|
||||
@@ -18,12 +18,10 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="Modal-body">
|
||||
<div ng-show="toDelete.total_groups > 0 || toDelete.total_hosts > 0">
|
||||
<div ng-show="toDelete.groupCount > 0 || toDelete.hostCount > 0">
|
||||
<div>
|
||||
<p class="Prompt-bodyQuery">Deleting group <em>{{ toDelete.name }}</em>.
|
||||
<span ng-show="toDelete.total_groups > 0 && toDelete.total_hosts > 0"> <translate>This group contains</translate> {{ toDelete.total_groups }} {{:: strings.deleteModal.group }} <translate>and</translate> {{ toDelete.total_hosts }} {{:: strings.deleteModal.host }}. </span>
|
||||
<span ng-show="toDelete.total_groups == 0 && toDelete.total_hosts > 0"> <translate>This group contains</translate> {{ toDelete.total_hosts }} {{:: strings.deleteModal.host }}. </span>
|
||||
<span ng-show="toDelete.total_groups > 0 && toDelete.total_hosts == 0"> <translate>This group contains</translate> {{ toDelete.total_groups }} {{:: strings.deleteModal.group }}. </span>
|
||||
<span> <translate>This group contains at least one group or host</translate>.</span>
|
||||
<translate>Delete or promote the group's children?</translate></p>
|
||||
<div style="margin: 15px auto;">
|
||||
|
||||
@@ -43,13 +41,13 @@
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div ng-show="toDelete.total_groups == 0 && toDelete.total_hosts == 0">
|
||||
<div ng-show="toDelete.groupCount == 0 && toDelete.hostCount == 0">
|
||||
<div class="Prompt-bodyQuery" translate>Are you sure you want to permanently delete the group below from the inventory?</div>
|
||||
<div class="Prompt-bodyTarget">{{ toDelete.name }}</div>
|
||||
</div>
|
||||
<div class="Modal-footer">
|
||||
<a href="#" data-target="#group-delete-modal" data-dismiss="modal" id="prompt_cancel_btn_groups_list" class="btn Modal-defaultButton Modal-footerButton" translate>CANCEL</a>
|
||||
<a href="" ng-class="promptActionBtnClass" ng-click="confirmDelete()" id="prompt_action_btn_groups_list" ng-disabled="!deleteOption && (toDelete.total_groups > 0 || toDelete.total_hosts > 0)" class="btn Modal-footerButton Modal-errorButton" translate>DELETE</a>
|
||||
<a href="" ng-class="promptActionBtnClass" ng-click="confirmDelete()" id="prompt_action_btn_groups_list" ng-disabled="!deleteOption && (toDelete.groupCount > 0 || toDelete.hostCount > 0)" class="btn Modal-footerButton Modal-errorButton" translate>DELETE</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user