From 0067e7006fbd0bc3bebbce9b2c00ea5168eef627 Mon Sep 17 00:00:00 2001 From: Akita Noek Date: Mon, 6 Jun 2016 15:47:25 -0400 Subject: [PATCH] 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 {