diff --git a/awx/ui/client/src/shared/pagination/main.js b/awx/ui/client/src/shared/pagination/main.js new file mode 100644 index 0000000000..088bb0e399 --- /dev/null +++ b/awx/ui/client/src/shared/pagination/main.js @@ -0,0 +1,11 @@ +/************************************************* + * Copyright (c) 2015 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + +import pagination from './pagination.service'; + +export default + angular.module('pagination', []) + .factory('pagination', pagination); diff --git a/awx/ui/client/src/shared/pagination/pagination.service.js b/awx/ui/client/src/shared/pagination/pagination.service.js new file mode 100644 index 0000000000..f18d7890e9 --- /dev/null +++ b/awx/ui/client/src/shared/pagination/pagination.service.js @@ -0,0 +1,26 @@ +/************************************************* + * Copyright (c) 2015 Ansible, Inc. + * + * All Rights Reserved + *************************************************/ + +export default ['$q', '$http', function($q, $http) { + return { + getInitialPageForList: function(id, url, pageSize) { + // get the name of the object + return $http.get(url + "?id=" + id) + .then(function (data) { + var name = data.data.results[0].name; + // get how many results are less than or equal to + // the name + return $http.get(url + "?name__lte=" + name) + .then(function (data) { + // divide by the page size to get what + // page the data should be on + var count = data.data.count; + return Math.ceil(count/pageSize); + }); + }); + } + }; +}];