From 0067e7006fbd0bc3bebbce9b2c00ea5168eef627 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Mon, 6 Jun 2016 15:47:25 -0400 Subject: [PATCH 1/4] Fix app crash from our pagination when editing invalid things Addresses the most important part of #1742 , next patch will be to make it so we just navigate away from the detail page if we delete the item we're on. --- .../src/shared/pagination/pagination.service.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/awx/ui/client/src/shared/pagination/pagination.service.js b/awx/ui/client/src/shared/pagination/pagination.service.js index 36e87c0807..73249da8ad 100644 --- a/awx/ui/client/src/shared/pagination/pagination.service.js +++ b/awx/ui/client/src/shared/pagination/pagination.service.js @@ -12,11 +12,16 @@ export default ['$http', '$q', function($http, $q) { return $http.get(url + "?id=" + id) .then(function (data) { var queryValue, queryType; - if (data.data.results[0].type === "user") { - queryValue = data.data.results[0].username; - queryType = "username"; + if (data.data.results.length) { + if (data.data.results[0].type === "user") { + queryValue = data.data.results[0].username; + queryType = "username"; + } else { + queryValue = data.data.results[0].name; + queryType = "name"; + } } else { - queryValue = data.data.results[0].name; + queryValue = ""; queryType = "name"; } // get how many results are less than or equal to @@ -26,7 +31,7 @@ export default ['$http', '$q', function($http, $q) { // divide by the page size to get what // page the data should be on var count = data.data.count; - return Math.ceil(count/parseInt(pageSize)); + return Math.max(1, Math.ceil(count/parseInt(pageSize))); }); }); } else { From f24818148cdb1fc5fe1846c3fa38f5b7b831142d Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Tue, 7 Jun 2016 10:49:34 -0400 Subject: [PATCH 2/4] Navigate to list view if you delete an object you are editing This patch covers all the cases I could find of places where you could delete items that you are currently editing. When this happens, we should now exit the edit mode and return to the list view for whatever we were viewing. Related to #1742 --- awx/ui/client/src/controllers/Credentials.js | 3 +++ awx/ui/client/src/controllers/Projects.js | 3 +++ awx/ui/client/src/controllers/Teams.js | 3 +++ awx/ui/client/src/controllers/Users.js | 3 +++ awx/ui/client/src/helpers/Schedules.js | 7 +++++-- .../src/inventories/list/inventory-list.controller.js | 3 +++ .../client/src/inventory-scripts/list/list.controller.js | 7 +++++-- .../job-templates/list/job-templates-list.controller.js | 3 +++ .../notification-templates-list/list.controller.js | 7 +++++-- 9 files changed, 33 insertions(+), 6 deletions(-) diff --git a/awx/ui/client/src/controllers/Credentials.js b/awx/ui/client/src/controllers/Credentials.js index db1b3a3527..fa3ca54c10 100644 --- a/awx/ui/client/src/controllers/Credentials.js +++ b/awx/ui/client/src/controllers/Credentials.js @@ -103,6 +103,9 @@ export function CredentialsList($scope, $rootScope, $location, $log, Rest.destroy() .success(function () { $scope.search(list.iterator); + if (new RegExp('/' + id + '$').test($location.$$url)) { + $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + } }) .error(function (data, status) { ProcessErrors($scope, data, status, null, { hdr: 'Error!', diff --git a/awx/ui/client/src/controllers/Projects.js b/awx/ui/client/src/controllers/Projects.js index 089fda112a..2d706fa8f4 100644 --- a/awx/ui/client/src/controllers/Projects.js +++ b/awx/ui/client/src/controllers/Projects.js @@ -247,6 +247,9 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $stateParams, Rest.destroy() .success(function () { $scope.search(list.iterator); + if (new RegExp('/' + id + '$').test($location.$$url)) { + $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + } }) .error(function (data, status) { ProcessErrors($scope, data, status, null, { hdr: 'Error!', diff --git a/awx/ui/client/src/controllers/Teams.js b/awx/ui/client/src/controllers/Teams.js index e2be443712..afdef86d0c 100644 --- a/awx/ui/client/src/controllers/Teams.js +++ b/awx/ui/client/src/controllers/Teams.js @@ -98,6 +98,9 @@ export function TeamsList($scope, $rootScope, $location, $log, $stateParams, Wait('stop'); $('#prompt-modal').modal('hide'); $scope.search(list.iterator); + if (new RegExp('/' + id + '$').test($location.$$url)) { + $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + } }) .error(function (data, status) { Wait('stop'); diff --git a/awx/ui/client/src/controllers/Users.js b/awx/ui/client/src/controllers/Users.js index bd1a8ecfc5..a0628a9812 100644 --- a/awx/ui/client/src/controllers/Users.js +++ b/awx/ui/client/src/controllers/Users.js @@ -112,6 +112,9 @@ export function UsersList($scope, $rootScope, $location, $log, $stateParams, Rest.destroy() .success(function () { $scope.search(list.iterator); + if (new RegExp('/' + id + '$').test($location.$$url)) { + $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + } }) .error(function (data, status) { ProcessErrors($scope, data, status, null, { hdr: 'Error!', diff --git a/awx/ui/client/src/helpers/Schedules.js b/awx/ui/client/src/helpers/Schedules.js index 72761011a7..5f0c589e32 100644 --- a/awx/ui/client/src/helpers/Schedules.js +++ b/awx/ui/client/src/helpers/Schedules.js @@ -429,8 +429,8 @@ export default * }) * */ - .factory('DeleteSchedule', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', 'Prompt', 'Find', - function(GetBasePath, Rest, Wait, ProcessErrors, Prompt, Find) { + .factory('DeleteSchedule', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', 'Prompt', 'Find', '$location', '$state', + function(GetBasePath, Rest, Wait, ProcessErrors, Prompt, Find, $location, $state) { return function(params) { var scope = params.scope, @@ -456,6 +456,9 @@ 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 + } }) .error(function (data, status) { try { diff --git a/awx/ui/client/src/inventories/list/inventory-list.controller.js b/awx/ui/client/src/inventories/list/inventory-list.controller.js index f38e99239f..c27b7c7252 100644 --- a/awx/ui/client/src/inventories/list/inventory-list.controller.js +++ b/awx/ui/client/src/inventories/list/inventory-list.controller.js @@ -323,6 +323,9 @@ function InventoriesList($scope, $rootScope, $location, $log, Rest.destroy() .success(function () { $scope.search(list.iterator); + if (new RegExp('/' + id + '$').test($location.$$url)) { + $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + } }) .error(function (data, status) { ProcessErrors( $scope, data, status, null, { hdr: 'Error!', diff --git a/awx/ui/client/src/inventory-scripts/list/list.controller.js b/awx/ui/client/src/inventory-scripts/list/list.controller.js index 293bd7c4a4..bd73527328 100644 --- a/awx/ui/client/src/inventory-scripts/list/list.controller.js +++ b/awx/ui/client/src/inventory-scripts/list/list.controller.js @@ -7,11 +7,11 @@ export default [ '$rootScope','Wait', 'generateList', 'inventoryScriptsListObject', 'GetBasePath' , 'SearchInit' , 'PaginateInit', - 'Rest' , 'ProcessErrors', 'Prompt', '$state', + 'Rest' , 'ProcessErrors', 'Prompt', '$state', '$location', function( $rootScope,Wait, GenerateList, inventoryScriptsListObject, GetBasePath, SearchInit, PaginateInit, - Rest, ProcessErrors, Prompt, $state + Rest, ProcessErrors, Prompt, $state, $location ) { var scope = $rootScope.$new(), defaultUrl = GetBasePath('inventory_scripts'), @@ -59,6 +59,9 @@ export default Rest.destroy() .success(function () { scope.search(list.iterator); + if (new RegExp('/' + id + '$').test($location.$$url)) { + $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + } }) .error(function (data, status) { ProcessErrors(scope, data, status, null, { hdr: 'Error!', diff --git a/awx/ui/client/src/job-templates/list/job-templates-list.controller.js b/awx/ui/client/src/job-templates/list/job-templates-list.controller.js index 366f89ddf3..845aba1fd7 100644 --- a/awx/ui/client/src/job-templates/list/job-templates-list.controller.js +++ b/awx/ui/client/src/job-templates/list/job-templates-list.controller.js @@ -78,6 +78,9 @@ export default Rest.destroy() .success(function () { $scope.search(list.iterator); + if (new RegExp('/' + id + '$').test($location.$$url)) { + $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + } }) .error(function (data) { Wait('stop'); diff --git a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js index 5c64299c70..b67a192cb0 100644 --- a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js +++ b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js @@ -8,12 +8,12 @@ export default [ '$rootScope','Wait', 'generateList', 'NotificationTemplatesList', 'GetBasePath' , 'SearchInit' , 'PaginateInit', 'Rest' , 'ProcessErrors', 'Prompt', '$state', 'GetChoices', 'Empty', 'Find', - 'ngToast', '$compile', '$filter', + 'ngToast', '$compile', '$filter', '$location', function( $rootScope,Wait, GenerateList, NotificationTemplatesList, GetBasePath, SearchInit, PaginateInit, Rest, ProcessErrors, Prompt, $state, GetChoices, Empty, Find, ngToast, - $compile, $filter) { + $compile, $filter, $location) { var scope = $rootScope.$new(), defaultUrl = GetBasePath('notification_templates'), list = NotificationTemplatesList, @@ -183,6 +183,9 @@ export default Rest.destroy() .success(function () { scope.search(list.iterator); + if (new RegExp('/' + id + '$').test($location.$$url)) { + $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + } }) .error(function (data, status) { ProcessErrors(scope, data, status, null, { hdr: 'Error!', From c601ca7738f09dd39b76ea6b6679d34dedbe9d29 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Tue, 7 Jun 2016 11:22:52 -0400 Subject: [PATCH 3/4] jshint --- awx/ui/client/src/helpers/Schedules.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/awx/ui/client/src/helpers/Schedules.js b/awx/ui/client/src/helpers/Schedules.js index 5f0c589e32..29892f1ab3 100644 --- a/awx/ui/client/src/helpers/Schedules.js +++ b/awx/ui/client/src/helpers/Schedules.js @@ -429,8 +429,8 @@ export default * }) * */ - .factory('DeleteSchedule', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', 'Prompt', 'Find', '$location', '$state', - function(GetBasePath, Rest, Wait, ProcessErrors, Prompt, Find, $location, $state) { + .factory('DeleteSchedule', ['GetBasePath','Rest', 'Wait', 'ProcessErrors', 'Prompt', 'Find', '$location', + function(GetBasePath, Rest, Wait, ProcessErrors, Prompt, Find, $location) { return function(params) { var scope = params.scope, @@ -457,7 +457,7 @@ export default $('#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 + $location.url($location.url().replace(/[/][0-9]+$/, "")); // go to list view } }) .error(function (data, status) { From c1f40f9cbf31ffab591ad147bc6aacef2e3b292e Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Wed, 8 Jun 2016 14:33:18 -0400 Subject: [PATCH 4/4] Better "go to parent state" code --- awx/ui/client/src/controllers/Credentials.js | 2 +- awx/ui/client/src/controllers/Projects.js | 2 +- awx/ui/client/src/controllers/Teams.js | 2 +- awx/ui/client/src/controllers/Users.js | 2 +- awx/ui/client/src/inventories/list/inventory-list.controller.js | 2 +- awx/ui/client/src/inventory-scripts/list/list.controller.js | 2 +- .../src/job-templates/list/job-templates-list.controller.js | 2 +- .../notification-templates-list/list.controller.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/awx/ui/client/src/controllers/Credentials.js b/awx/ui/client/src/controllers/Credentials.js index fa3ca54c10..618879037a 100644 --- a/awx/ui/client/src/controllers/Credentials.js +++ b/awx/ui/client/src/controllers/Credentials.js @@ -104,7 +104,7 @@ export function CredentialsList($scope, $rootScope, $location, $log, .success(function () { $scope.search(list.iterator); if (new RegExp('/' + id + '$').test($location.$$url)) { - $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + $state.go('^'); } }) .error(function (data, status) { diff --git a/awx/ui/client/src/controllers/Projects.js b/awx/ui/client/src/controllers/Projects.js index 2d706fa8f4..dd63cc237d 100644 --- a/awx/ui/client/src/controllers/Projects.js +++ b/awx/ui/client/src/controllers/Projects.js @@ -248,7 +248,7 @@ export function ProjectsList ($scope, $rootScope, $location, $log, $stateParams, .success(function () { $scope.search(list.iterator); if (new RegExp('/' + id + '$').test($location.$$url)) { - $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + $state.go('^'); } }) .error(function (data, status) { diff --git a/awx/ui/client/src/controllers/Teams.js b/awx/ui/client/src/controllers/Teams.js index afdef86d0c..a430a7fb6a 100644 --- a/awx/ui/client/src/controllers/Teams.js +++ b/awx/ui/client/src/controllers/Teams.js @@ -99,7 +99,7 @@ export function TeamsList($scope, $rootScope, $location, $log, $stateParams, $('#prompt-modal').modal('hide'); $scope.search(list.iterator); if (new RegExp('/' + id + '$').test($location.$$url)) { - $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + $state.go('^'); } }) .error(function (data, status) { diff --git a/awx/ui/client/src/controllers/Users.js b/awx/ui/client/src/controllers/Users.js index a0628a9812..179aa2b8ad 100644 --- a/awx/ui/client/src/controllers/Users.js +++ b/awx/ui/client/src/controllers/Users.js @@ -113,7 +113,7 @@ export function UsersList($scope, $rootScope, $location, $log, $stateParams, .success(function () { $scope.search(list.iterator); if (new RegExp('/' + id + '$').test($location.$$url)) { - $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + $state.go('^'); } }) .error(function (data, status) { diff --git a/awx/ui/client/src/inventories/list/inventory-list.controller.js b/awx/ui/client/src/inventories/list/inventory-list.controller.js index c27b7c7252..54fc4fd3eb 100644 --- a/awx/ui/client/src/inventories/list/inventory-list.controller.js +++ b/awx/ui/client/src/inventories/list/inventory-list.controller.js @@ -324,7 +324,7 @@ function InventoriesList($scope, $rootScope, $location, $log, .success(function () { $scope.search(list.iterator); if (new RegExp('/' + id + '$').test($location.$$url)) { - $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + $state.go('^'); } }) .error(function (data, status) { diff --git a/awx/ui/client/src/inventory-scripts/list/list.controller.js b/awx/ui/client/src/inventory-scripts/list/list.controller.js index bd73527328..c7a2b3e404 100644 --- a/awx/ui/client/src/inventory-scripts/list/list.controller.js +++ b/awx/ui/client/src/inventory-scripts/list/list.controller.js @@ -60,7 +60,7 @@ export default .success(function () { scope.search(list.iterator); if (new RegExp('/' + id + '$').test($location.$$url)) { - $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + $state.go('^'); } }) .error(function (data, status) { diff --git a/awx/ui/client/src/job-templates/list/job-templates-list.controller.js b/awx/ui/client/src/job-templates/list/job-templates-list.controller.js index 845aba1fd7..6fe7410e4d 100644 --- a/awx/ui/client/src/job-templates/list/job-templates-list.controller.js +++ b/awx/ui/client/src/job-templates/list/job-templates-list.controller.js @@ -79,7 +79,7 @@ export default .success(function () { $scope.search(list.iterator); if (new RegExp('/' + id + '$').test($location.$$url)) { - $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + $state.go('^'); } }) .error(function (data) { diff --git a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js index b67a192cb0..0167b32d3f 100644 --- a/awx/ui/client/src/notifications/notification-templates-list/list.controller.js +++ b/awx/ui/client/src/notifications/notification-templates-list/list.controller.js @@ -184,7 +184,7 @@ export default .success(function () { scope.search(list.iterator); if (new RegExp('/' + id + '$').test($location.$$url)) { - $state.transitionTo($state.current.name.replace(/[.][a-zA-Z]+$/, "")); /* go to the list view */ + $state.go('^'); } }) .error(function (data, status) {