Created
April 7, 2016 23:18
-
-
Save adamf321/34d7ccc75b83f3ad939141606444bb31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular | |
.module('app') | |
.factory('paginationService', paginationService); | |
paginationService.$inject = ['lnCmsClientService', '$state']; | |
function paginationService(lnCmsClientService, $state){ | |
var current = 1; | |
var total = 1; | |
var callback = () => {}; | |
const endpoint = $state.current.data.endpoint; | |
return { | |
init: init, | |
nextPage: nextPage, | |
hasPages: hasPages | |
}; | |
function init( data = {} ) { | |
total = data.pages || 1; | |
current = 1; | |
} | |
function nextPage(cb){ | |
if ( hasPages() ) { | |
var params = angular.extend( | |
{}, | |
$state.current.data.fixedParams, | |
{ paged: current + 1 } | |
); | |
callback = cb; | |
lnCmsClientService | |
.getView(endpoint, params) | |
.then(response); | |
} | |
} | |
function response(response) { | |
current += 1; | |
callback(response); | |
} | |
function hasPages(){ | |
return current < total; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment