Fixed deleting last resource on a page 404 error

This commit is contained in:
Michael Abashian 2017-06-26 16:22:54 -04:00
parent 6ef7b88675
commit da0dfdbe13
20 changed files with 188 additions and 64 deletions

View File

@ -61,10 +61,18 @@ export default ['$rootScope', '$scope', 'Wait', 'CredentialTypesList',
Rest.setUrl(url);
Rest.destroy()
.success(function() {
let reloadListStateParams = null;
if($scope.credential_types.length === 1 && $state.params.credential_type_search && !_.isEmpty($state.params.credential_type_search.page) && $state.params.credential_type_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.credential_type_search.page = (parseInt(reloadListStateParams.credential_type_search.page)-1).toString();
}
if (parseInt($state.params.credential_type_id) === id) {
$state.go('^', null, { reload: true });
$state.go('^', reloadListStateParams, { reload: true });
} else {
$state.go('.', null, { reload: true });
$state.go('.', reloadListStateParams, { reload: true });
}
})
.error(function(data, status) {

View File

@ -76,10 +76,18 @@ export default ['$scope', 'Rest', 'CredentialList', 'Prompt', 'ClearScope',
Rest.setUrl(url);
Rest.destroy()
.success(function() {
let reloadListStateParams = null;
if($scope.credentials.length === 1 && $state.params.credential_search && !_.isEmpty($state.params.credential_search.page) && $state.params.credential_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.credential_search.page = (parseInt(reloadListStateParams.credential_search.page)-1).toString();
}
if (parseInt($state.params.credential_id) === id) {
$state.go("^", null, { reload: true });
$state.go("^", reloadListStateParams, { reload: true });
} else {
$state.go('.', null, {reload: true});
$state.go('.', reloadListStateParams, {reload: true});
}
Wait('stop');
})

View File

@ -68,31 +68,6 @@ function HostsList($scope, HostsList, $rootScope, GetBasePath,
$scope.goToInsights = function(id){
$state.go('hosts.edit.insights', {host_id:id});
};
$scope.deleteHost = function(id, name){
var body = '<div class=\"Prompt-bodyQuery\">Are you sure you want to permanently delete the host below from the inventory?</div><div class=\"Prompt-bodyTarget\">' + $filter('sanitize')(name) + '</div>';
var action = function(){
delete $rootScope.promptActionBtnClass;
Wait('start');
HostsService.delete(id).then(() => {
$('#prompt-modal').modal('hide');
if (parseInt($state.params.host_id) === id) {
$state.go("hosts", null, {reload: true});
} else {
$state.go($state.current.name, null, {reload: true});
}
Wait('stop');
});
};
// Prompt depends on having $rootScope.promptActionBtnClass available...
Prompt({
hdr: 'Delete Host',
body: body,
action: action,
actionText: 'DELETE',
});
$rootScope.promptActionBtnClass = 'Modal-errorButton';
};
$scope.toggleHost = function(event, host) {
try {
$(event.target).tooltip('hide');

View File

@ -70,7 +70,15 @@
$('#host-disassociate-modal').off('hidden.bs.modal').on('hidden.bs.modal', function () {
$('#host-disassociate-modal').off('hidden.bs.modal');
$state.go('.', null, {reload: true});
let reloadListStateParams = null;
if($scope.groups.length === 1 && $state.params.group_search && !_.isEmpty($state.params.group_search.page) && $state.params.group_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.group_search.page = (parseInt(reloadListStateParams.group_search.page)-1).toString();
}
$state.go('.', reloadListStateParams, {reload: true});
});
GroupsService.disassociateHost(host.id, $scope.disassociateGroup.id).then(() => {

View File

@ -86,12 +86,7 @@ function InventoriesList($scope,
Rest.setUrl(url);
Rest.destroy()
.success(function () {
if (parseInt($state.params.inventory_id) === id) {
$state.go("^", null, {reload: true});
} else {
$state.go('.', null, {reload: true});
Wait('stop');
}
Wait('stop');
})
.error(function (data, status) {
ProcessErrors( $scope, data, status, null, { hdr: 'Error!',
@ -114,6 +109,20 @@ function InventoriesList($scope,
if (data.status === 'pending_deletion') {
inventory.pending_deletion = true;
}
if (data.status === 'deleted') {
let reloadListStateParams = null;
if($scope.inventories.length === 1 && $state.params.inventory_search && !_.isEmpty($state.params.inventory_search.page) && $state.params.inventory_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.inventory_search.page = (parseInt(reloadListStateParams.inventory_search.page)-1).toString();
}
if (parseInt($state.params.inventory_id) === data.inventory_id) {
$state.go("^", reloadListStateParams, {reload: true});
} else {
$state.go('.', reloadListStateParams, {reload: true});
}
}
});
}

View File

@ -100,14 +100,21 @@
$state.go('.', null, {reload: true});
});
let reloadListStateParams = null;
if($scope.groups.length === 1 && $state.params.group_search && !_.isEmpty($state.params.group_search.page) && $state.params.group_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.group_search.page = (parseInt(reloadListStateParams.group_search.page)-1).toString();
}
switch($scope.deleteOption){
case 'promote':
GroupsService.promote($scope.toDelete.id, $stateParams.inventory_id)
.then(() => {
if (parseInt($state.params.group_id) === $scope.toDelete.id) {
$state.go("^", null, {reload: true});
$state.go("^", reloadListStateParams, {reload: true});
} else {
$state.go($state.current, null, {reload: true});
$state.go($state.current, reloadListStateParams, {reload: true});
}
$('#group-delete-modal').modal('hide');
$('body').removeClass('modal-open');
@ -117,9 +124,9 @@
default:
GroupsService.delete($scope.toDelete.id).then(() => {
if (parseInt($state.params.group_id) === $scope.toDelete.id) {
$state.go("^", null, {reload: true});
$state.go("^", reloadListStateParams, {reload: true});
} else {
$state.go($state.current, null, {reload: true});
$state.go($state.current, reloadListStateParams, {reload: true});
}
$('#group-delete-modal').modal('hide');
$('body').removeClass('modal-open');

View File

@ -87,8 +87,16 @@
$('#group-disassociate-modal').off('hidden.bs.modal').on('hidden.bs.modal', function () {
// Remove the event handler so that we don't end up with multiple bindings
$('#group-disassociate-modal').off('hidden.bs.modal');
let reloadListStateParams = null;
if($scope.nested_groups.length === 1 && $state.params.nested_group_search && !_.isEmpty($state.params.nested_group_search.page) && $state.params.nested_group_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.nested_group_search.page = (parseInt(reloadListStateParams.nested_group_search.page)-1).toString();
}
// Reload the inventory manage page and show that the group has been removed
$state.go('.', null, {reload: true});
$state.go('.', reloadListStateParams, {reload: true});
});
let closeModal = function(){

View File

@ -100,8 +100,16 @@ export default ['$scope', 'NestedHostsListDefinition', '$rootScope', 'GetBasePat
$('#host-disassociate-modal').off('hidden.bs.modal').on('hidden.bs.modal', function () {
// Remove the event handler so that we don't end up with multiple bindings
$('#host-disassociate-modal').off('hidden.bs.modal');
let reloadListStateParams = null;
if($scope.nested_hosts.length === 1 && $state.params.nested_host_search && !_.isEmpty($state.params.nested_host_search.page) && $state.params.nested_host_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.nested_host_search.page = (parseInt(reloadListStateParams.nested_host_search.page)-1).toString();
}
// Reload the inventory manage page and show that the group has been removed
$state.go('.', null, {reload: true});
$state.go('.', reloadListStateParams, {reload: true});
});
let closeModal = function(){

View File

@ -96,10 +96,18 @@ export default ['$scope', 'ListDefinition', '$rootScope', 'GetBasePath',
Wait('start');
HostsService.delete(id).then(() => {
$('#prompt-modal').modal('hide');
let reloadListStateParams = null;
if($scope.hosts.length === 1 && $state.params.host_search && !_.isEmpty($state.params.host_search.page) && $state.params.host_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.host_search.page = (parseInt(reloadListStateParams.host_search.page)-1).toString();
}
if (parseInt($state.params.host_id) === id) {
$state.go("hosts", null, {reload: true});
$state.go('^', reloadListStateParams, {reload: true});
} else {
$state.go($state.current.name, null, {reload: true});
$state.go('.', reloadListStateParams, {reload: true});
}
Wait('stop');
});

View File

@ -83,8 +83,16 @@
$('#group-disassociate-modal').off('hidden.bs.modal').on('hidden.bs.modal', function () {
// Remove the event handler so that we don't end up with multiple bindings
$('#group-disassociate-modal').off('hidden.bs.modal');
let reloadListStateParams = null;
if($scope.nested_groups.length === 1 && $state.params.nested_group_search && !_.isEmpty($state.params.nested_group_search.page) && $state.params.nested_group_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.nested_group_search.page = (parseInt(reloadListStateParams.nested_group_search.page)-1).toString();
}
// Reload the inventory manage page and show that the group has been removed
$state.go('.', null, {reload: true});
$state.go('.', reloadListStateParams, {reload: true});
});
let closeModal = function(){

View File

@ -123,10 +123,16 @@
Wait('start');
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("inventories.edit.inventory_sources", {inventory_id: $scope.inventory_id}, {reload: true});
$state.go('^', reloadListStateParams, {reload: true});
} else {
$state.go($state.current.name, null, {reload: true});
$state.go('.', reloadListStateParams, {reload: true});
}
Wait('stop');
});

View File

@ -51,10 +51,18 @@ export default ['$rootScope', '$scope', 'Wait', 'InventoryScriptsList',
Rest.setUrl(url);
Rest.destroy()
.success(function() {
let reloadListStateParams = null;
if($scope.inventory_scripts.length === 1 && $state.params.inventory_script_search && !_.isEmpty($state.params.inventory_script_search.page) && $state.params.inventory_script_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.inventory_script_search.page = (parseInt(reloadListStateParams.inventory_script_search.page)-1).toString();
}
if (parseInt($state.params.inventory_script_id) === id) {
$state.go('^', null, { reload: true });
$state.go('^', reloadListStateParams, { reload: true });
} else {
$state.go('.', null, { reload: true });
$state.go('.', reloadListStateParams, { reload: true });
}
})
.error(function(data, status) {

View File

@ -70,7 +70,14 @@ export default
scope.$emit(callback, action_label);
}
else {
$state.reload();
let reloadListStateParams = null;
if(scope.jobs.length === 1 && $state.params.job_search && !_.isEmpty($state.params.job_search.page) && $state.params.job_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.job_search.page = (parseInt(reloadListStateParams.job_search.page)-1).toString();
}
$state.go('.', reloadListStateParams, {reload: true});
Wait('stop');
}
})

View File

@ -165,10 +165,18 @@
Rest.setUrl(url);
Rest.destroy()
.success(function() {
let reloadListStateParams = null;
if($scope.notification_templates.length === 1 && $state.params.notification_template_search && !_.isEmpty($state.params.notification_template_search.page) && $state.params.notification_template_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.notification_template_search.page = (parseInt(reloadListStateParams.notification_template_search.page)-1).toString();
}
if (parseInt($state.params.notification_template_id) === id) {
$state.go("^", null, { reload: true });
$state.go("^", reloadListStateParams, { reload: true });
} else {
$state.go('.', null, {reload: true});
$state.go('.', reloadListStateParams, {reload: true});
}
Wait('stop');
})

View File

@ -147,10 +147,18 @@ export default ['$stateParams', '$scope', '$rootScope',
Rest.destroy()
.success(function() {
Wait('stop');
let reloadListStateParams = null;
if($scope.organizations.length === 1 && $state.params.organization_search && !_.isEmpty($state.params.organization_search.page) && $state.params.organization_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.organization_search.page = (parseInt(reloadListStateParams.organization_search.page)-1).toString();
}
if (isDeletedOrganizationBeingEdited(id, parseInt($stateParams.organization_id)) === true) {
$state.go('^', null, { reload: true });
$state.go('^', reloadListStateParams, { reload: true });
} else {
$state.reload('organizations');
$state.go('.', reloadListStateParams, { reload: true });
}
})
.error(function(data, status) {

View File

@ -179,10 +179,18 @@ export default ['$scope', '$rootScope', '$log', 'Rest', 'Alert',
Rest.setUrl(url);
Rest.destroy()
.success(function() {
let reloadListStateParams = null;
if($scope.projects.length === 1 && $state.params.project_search && !_.isEmpty($state.params.project_search.page) && $state.params.project_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.project_search.page = (parseInt(reloadListStateParams.project_search.page)-1).toString();
}
if (parseInt($state.params.project_id) === id) {
$state.go("^", null, { reload: true });
$state.go("^", reloadListStateParams, { reload: true });
} else {
$state.go('.', null, {reload: true});
$state.go('.', reloadListStateParams, {reload: true});
}
})
.error(function (data, status) {

View File

@ -25,11 +25,19 @@ export default
.success(function () {
$('#prompt-modal').modal('hide');
scope.$emit(callback, id);
if (new RegExp('/' + id + '$').test($location.$$url)) {
$location.url($location.url().replace(/[/][0-9]+$/, "")); // go to list view
let reloadListStateParams = null;
if(scope.schedules.length === 1 && $state.params.schedule_search && !_.isEmpty($state.params.schedule_search.page) && $state.params.schedule_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.schedule_search.page = (parseInt(reloadListStateParams.schedule_search.page)-1).toString();
}
if (parseInt($state.params.schedule_id) === id) {
$state.go('^', reloadListStateParams, {reload: true});
}
else{
$state.go('.', null, {reload: true});
$state.go('.', reloadListStateParams, {reload: true});
}
})
.error(function (data, status) {

View File

@ -53,10 +53,18 @@ export default ['$scope', 'Rest', 'TeamList', 'Prompt', 'ClearScope',
.success(function() {
Wait('stop');
$('#prompt-modal').modal('hide');
let reloadListStateParams = null;
if($scope.teams.length === 1 && $state.params.team_search && !_.isEmpty($state.params.team_search.page) && $state.params.team_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.team_search.page = (parseInt(reloadListStateParams.team_search.page)-1).toString();
}
if (parseInt($state.params.team_id) === id) {
$state.go('^', null, { reload: true });
$state.go('^', reloadListStateParams, { reload: true });
} else {
$state.go('.', null, { reload: true });
$state.go('.', reloadListStateParams, { reload: true });
}
})
.error(function(data, status) {

View File

@ -77,7 +77,7 @@ export default ['$scope', '$rootScope',
$scope[list.name] = $scope[`${list.iterator}_dataset`].results;
});
});
$scope.editJobTemplate = function(template) {
if(template) {
if(template.type && (template.type === 'Job Template' || template.type === 'job_template')) {
@ -106,11 +106,19 @@ export default ['$scope', '$rootScope',
function handleSuccessfulDelete(isWorkflow) {
let stateParamId = isWorkflow ? $state.params.workflow_job_template_id : $state.params.job_template_id;
let reloadListStateParams = null;
if($scope.templates.length === 1 && $state.params.template_search && !_.isEmpty($state.params.template_search.page) && $state.params.template_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.template_search.page = (parseInt(reloadListStateParams.template_search.page)-1).toString();
}
if (parseInt(stateParamId) === template.id) {
// Move the user back to the templates list
$state.go("templates", null, {reload: true});
$state.go("templates", reloadListStateParams, {reload: true});
} else {
$state.go(".", null, {reload: true});
$state.go(".", reloadListStateParams, {reload: true});
}
Wait('stop');
}

View File

@ -65,6 +65,14 @@ export default ['$scope', '$rootScope', 'Rest', 'UserList', 'Prompt',
Rest.setUrl(url);
Rest.destroy()
.success(function() {
let reloadListStateParams = null;
if($scope.users.length === 1 && $state.params.user_search && !_.isEmpty($state.params.user_search.page) && $state.params.user_search.page !== '1') {
reloadListStateParams = _.cloneDeep($state.params);
reloadListStateParams.user_search.page = (parseInt(reloadListStateParams.user_search.page)-1).toString();
}
if (parseInt($state.params.user_id) === id) {
$state.go('^', null, { reload: true });
} else {