Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove computed inventory fields from Host and Group #5448

Prev Previous commit
Next Next commit
Use related hosts and group counts for delete modal
  • Loading branch information
jakemcdermott authored and ryanpetrello committed Jan 14, 2020
commit 2bc6521eee158eb3fa2b16179c25f67082540037
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);

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);
const promises = [];

Rest.setUrl(group.related.hosts);
promises.push(Rest.get());

Rest.setUrl(group.related.children);
promises.push(Rest.get());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These requests are needed in order to know if a group has any groups or hosts. This info is needed for deciding when to show the delete vs promote prompt on the deletion warning.


jakemcdermott marked this conversation as resolved.
Show resolved Hide resolved
Promise.all(promises)
.then(([hostResponse, groupResponse]) => {
Copy link
Contributor

@jakemcdermott jakemcdermott Dec 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marshmalien @jlmitch5
Removing the total_hosts and total_groups counts means we're no longer showing the counts on the delete warnings. Instead, a more generic message is used.

Example 1 (one group, multiple hosts):
Screenshot from 2019-12-10 12-15-44

Example 2 (no hosts or groups):
Screenshot from 2019-12-10 12-00-23

$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 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.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});
}
}
}
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');
$('#group-delete-modal').modal('show');
});


};
$scope.confirmDelete = function(){
let reloadListStateParams = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;">

Expand All @@ -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>
Expand Down