mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
Merge pull request #568 from jaredevantabor/source-deletion
When deleting a source, delete the source's groups too
This commit is contained in:
@@ -117,38 +117,11 @@
|
|||||||
$state.go('inventories.edit.inventory_sources.edit', {inventory_source_id: id});
|
$state.go('inventories.edit.inventory_sources.edit', {inventory_source_id: id});
|
||||||
};
|
};
|
||||||
$scope.deleteSource = function(inventory_source){
|
$scope.deleteSource = function(inventory_source){
|
||||||
var body = '<div class=\"Prompt-bodyQuery\">' + i18n._('Are you sure you want to permanently delete the inventory source below from the inventory?') + '</div><div class=\"Prompt-bodyTarget\">' + $filter('sanitize')(inventory_source.name) + '</div>';
|
var body = '<div class=\"Prompt-bodyQuery\">' + i18n._('Confirm that you want to permanently delete the inventory source below from the inventory. Deleting this inventory source also deletes its associated groups and hosts.') + '</div><div class=\"Prompt-bodyTarget\">' + $filter('sanitize')(inventory_source.name) + '</div>';
|
||||||
var action = function(){
|
var action = function(){
|
||||||
delete $rootScope.promptActionBtnClass;
|
$rootScope.promptActionBtnClass = "Modal-errorButton--sourcesDelete";
|
||||||
Wait('start');
|
Wait('start');
|
||||||
SourcesService.deleteHosts(inventory_source.id).then(() => {
|
let hostDelete = SourcesService.deleteHosts(inventory_source.id).catch(({data, status}) => {
|
||||||
SourcesService.delete(inventory_source.id).then(() => {
|
|
||||||
$('#prompt-modal').modal('hide');
|
|
||||||
let reloadListStateParams = null;
|
|
||||||
|
|
||||||
if($scope.inventory_sources.length === 1 && $state.params.inventory_source_search && !_.isEmpty($state.params.inventory_source_search.page) && $state.params.inventory_source_search.page !== '1') {
|
|
||||||
reloadListStateParams = _.cloneDeep($state.params);
|
|
||||||
reloadListStateParams.inventory_source_search.page = (parseInt(reloadListStateParams.inventory_source_search.page)-1).toString();
|
|
||||||
}
|
|
||||||
if (parseInt($state.params.inventory_source_id) === inventory_source.id) {
|
|
||||||
$state.go('^', reloadListStateParams, {reload: true});
|
|
||||||
} else {
|
|
||||||
$state.go('.', reloadListStateParams, {reload: true});
|
|
||||||
}
|
|
||||||
Wait('stop');
|
|
||||||
})
|
|
||||||
.catch(({data, status}) => {
|
|
||||||
$('#prompt-modal').modal('hide');
|
|
||||||
Wait('stop');
|
|
||||||
ProcessErrors($scope, data, status, null,
|
|
||||||
{
|
|
||||||
hdr: i18n._('Error!'),
|
|
||||||
msg: i18n._('There was an error deleting inventory source. Returned status: ') +
|
|
||||||
status
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(({data, status}) => {
|
|
||||||
$('#prompt-modal').modal('hide');
|
$('#prompt-modal').modal('hide');
|
||||||
Wait('stop');
|
Wait('stop');
|
||||||
ProcessErrors($scope, data, status, null,
|
ProcessErrors($scope, data, status, null,
|
||||||
@@ -158,6 +131,44 @@
|
|||||||
status
|
status
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
let groupDelete = SourcesService.deleteGroups(inventory_source.id).catch(({data, status}) => {
|
||||||
|
$('#prompt-modal').modal('hide');
|
||||||
|
Wait('stop');
|
||||||
|
ProcessErrors($scope, data, status, null,
|
||||||
|
{
|
||||||
|
hdr: i18n._('Error!'),
|
||||||
|
msg: i18n._('There was an error deleting inventory source groups. Returned status: ') +
|
||||||
|
status
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Promise.all([hostDelete, groupDelete]).then(() => {
|
||||||
|
SourcesService.delete(inventory_source.id).then(() => {
|
||||||
|
$('#prompt-modal').modal('hide');
|
||||||
|
delete $rootScope.promptActionBtnClass;
|
||||||
|
let reloadListStateParams = null;
|
||||||
|
|
||||||
|
if($scope.inventory_sources.length === 1 && $state.params.inventory_source_search && !_.isEmpty($state.params.inventory_source_search.page) && $state.params.inventory_source_search.page !== '1') {
|
||||||
|
reloadListStateParams = _.cloneDeep($state.params);
|
||||||
|
reloadListStateParams.inventory_source_search.page = (parseInt(reloadListStateParams.inventory_source_search.page)-1).toString();
|
||||||
|
}
|
||||||
|
if (parseInt($state.params.inventory_source_id) === inventory_source.id) {
|
||||||
|
$state.go('^', reloadListStateParams, {reload: true});
|
||||||
|
} else {
|
||||||
|
$state.go('.', reloadListStateParams, {reload: true});
|
||||||
|
}
|
||||||
|
Wait('stop');
|
||||||
|
})
|
||||||
|
.catch(({data, status}) => {
|
||||||
|
$('#prompt-modal').modal('hide');
|
||||||
|
Wait('stop');
|
||||||
|
ProcessErrors($scope, data, status, null,
|
||||||
|
{
|
||||||
|
hdr: i18n._('Error!'),
|
||||||
|
msg: i18n._('There was an error deleting inventory source. Returned status: ') +
|
||||||
|
status
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
// Prompt depends on having $rootScope.promptActionBtnClass available...
|
// Prompt depends on having $rootScope.promptActionBtnClass available...
|
||||||
Prompt({
|
Prompt({
|
||||||
|
|||||||
@@ -134,13 +134,20 @@ export default
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
deleteHosts(id) {
|
deleteHosts(id) {
|
||||||
Wait('start');
|
|
||||||
this.url = GetBasePath('inventory_sources') + id + '/hosts/';
|
this.url = GetBasePath('inventory_sources') + id + '/hosts/';
|
||||||
Rest.setUrl(this.url);
|
Rest.setUrl(this.url);
|
||||||
return Rest.destroy()
|
return Rest.destroy()
|
||||||
.success(this.success.bind(this))
|
.success(this.success.bind(this))
|
||||||
.error(this.error.bind(this))
|
.error(this.error.bind(this))
|
||||||
.finally(Wait('stop'));
|
.finally();
|
||||||
|
},
|
||||||
|
deleteGroups(id) {
|
||||||
|
this.url = GetBasePath('inventory_sources') + id + '/groups/';
|
||||||
|
Rest.setUrl(this.url);
|
||||||
|
return Rest.destroy()
|
||||||
|
.success(this.success.bind(this))
|
||||||
|
.error(this.error.bind(this))
|
||||||
|
.finally();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}];
|
}];
|
||||||
|
|||||||
@@ -97,6 +97,10 @@
|
|||||||
color: @btn-txt-sel;
|
color: @btn-txt-sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.Modal-errorButton--sourcesDelete:hover{
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
.Modal-primaryButton {
|
.Modal-primaryButton {
|
||||||
background-color: @default-link;
|
background-color: @default-link;
|
||||||
color: @default-bg;
|
color: @default-bg;
|
||||||
|
|||||||
Reference in New Issue
Block a user