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.
This commit is contained in:
Akita Noek 2016-06-06 15:47:25 -04:00
parent e11600d493
commit 0067e7006f

View File

@ -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 {