1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 09:51:09 +03:00

Fix infinite Wait spinner when deleting instance group

This commit is contained in:
Marliana Lara 2018-04-10 13:46:55 -04:00
parent ffa1f37742
commit 6beaa4b166
No known key found for this signature in database
GPG Key ID: 38C73B40DFA809EE
2 changed files with 37 additions and 32 deletions

View File

@ -1,10 +1,9 @@
export default ['$scope', 'resolvedModels', 'Dataset', '$state', 'ComponentsStrings', 'ProcessErrors', 'Wait',
function($scope, resolvedModels, Dataset, $state, strings, ProcessErrors, Wait) {
export default ['$scope', '$filter', '$state', 'Alert', 'resolvedModels', 'Dataset', 'ComponentsStrings', 'ProcessErrors', 'Prompt', 'Wait',
function($scope, $filter, $state, Alert, resolvedModels, Dataset, strings, ProcessErrors, Prompt, Wait) {
const vm = this;
const { instanceGroup } = resolvedModels;
vm.strings = strings;
$scope.selection = {};
init();
@ -33,31 +32,43 @@ export default ['$scope', 'resolvedModels', 'Dataset', '$state', 'ComponentsStri
vm.activeId = parseInt($state.params.instance_group_id);
});
vm.delete = () => {
Wait('start');
let deletables = $scope.selection;
deletables = Object.keys(deletables).filter((n) => deletables[n]);
vm.deleteInstanceGroup = instance_group => {
if (!instance_group) {
Alert(strings.get('error.DELETE'), strings.get('alert.MISSING_PARAMETER'));
return;
}
deletables.forEach((data) => {
let promise = instanceGroup.http.delete({resource: data});
Promise.resolve(promise).then(vm.onSaveSuccess)
.catch(({data, status}) => {
ProcessErrors($scope, data, status, null, {
hdr: 'Error!',
msg: 'Call failed. Return status: ' + status
});
})
.finally(() => {
Wait('stop');
});
Prompt({
action() {
$('#prompt-modal').modal('hide');
Wait('start');
instanceGroup
.request('delete', instance_group.id)
.then(() => handleSuccessfulDelete(instance_group))
.catch(createErrorHandler('delete instance group', 'DELETE'))
.finally(() => Wait('stop'));
},
hdr: strings.get('DELETE'),
resourceName: $filter('sanitize')(instance_group.name),
body: `${strings.get('deleteResource.CONFIRM', 'instance group')}`
});
};
vm.onSaveSuccess = () => {
$state.transitionTo($state.current, $state.params, {
reload: true, location: true, inherit: false, notify: true
});
};
function handleSuccessfulDelete(instance_group) {
if (parseInt($state.params.instance_group_id, 0) === instance_group.id) {
$state.go('instanceGroups', $state.params, { reload: true });
} else {
$state.go('.', $state.params, { reload: true });
}
}
function createErrorHandler(path, action) {
return ({ data, status }) => {
const hdr = strings.get('error.HEADER');
const msg = strings.get('error.CALL', { path, action, status });
ProcessErrors($scope, data, status, null, { hdr, msg });
};
}
$scope.createInstanceGroup = () => {
$state.go('instanceGroups.add');

View File

@ -19,10 +19,6 @@
search-tags="searchTags">
</smart-search>
<div class="at-List-toolbarAction">
<div ng-click="vm.delete()"
class="at-RowAction at-RowAction--danger">
<i class="fa fa-trash"></i>
</div>
<button
type="button"
ui-sref="instanceGroups.add"
@ -37,10 +33,6 @@
<at-row ng-repeat="instance_group in instance_groups"
ng-class="{'at-Row--active': (instance_group.id === vm.activeId)}">
<input type="checkbox"
class="at-Row-checkbox"
ng-model="selection[instance_group.id]"/>
<div class="at-Row-items">
<at-row-item
header-value="{{ instance_group.name }}"
@ -67,6 +59,8 @@
<div class="at-Row-actions">
<capacity-bar label-value="Used Capacity" capacity="instance_group.consumed_capacity" total-capacity="instance_group.capacity"></capacity-bar>
<at-row-action icon="fa-trash" ng-click="vm.deleteInstanceGroup(instance_group)">
</at-row-action>
</div>
</at-row>
</at-list>