From 713668ea7753207a47d73b1424e50903603d704c Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 19 Jan 2016 18:16:16 -0300 Subject: [PATCH] Add pagination to blog posts --- src/app/components/noosfero-articles/blog/blog.directive.js | 19 +++++++++++++++---- src/app/components/noosfero-articles/blog/blog.html | 5 +++++ src/app/components/noosfero-blocks/recent-documents/recent-documents.directive.js | 3 ++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/app/components/noosfero-articles/blog/blog.directive.js b/src/app/components/noosfero-articles/blog/blog.directive.js index b4b3c7b..01266e1 100644 --- a/src/app/components/noosfero-articles/blog/blog.directive.js +++ b/src/app/components/noosfero-articles/blog/blog.directive.js @@ -22,13 +22,24 @@ return directive; /** @ngInject */ - function BlogController(noosfero) { + function BlogController(noosfero, Restangular) { var vm = this; vm.posts = []; + vm.perPage = 3; + vm.currentPage = 1; - noosfero.articles.one(vm.article.id).customGET('children', {content_type: 'TinyMceArticle'}).then(function(result) { - vm.posts = result.articles; - }); + vm.loadPage = function() { + Restangular.setFullResponse(true); + noosfero.articles.one(vm.article.id).customGET('children', { + content_type: 'TinyMceArticle', + per_page: vm.perPage, + page: vm.currentPage + }).then(function(result) { + vm.totalPosts = result.headers('total'); + vm.posts = result.data.articles; + }); + } + vm.loadPage(); } } diff --git a/src/app/components/noosfero-articles/blog/blog.html b/src/app/components/noosfero-articles/blog/blog.html index 3f517f2..d4c1beb 100644 --- a/src/app/components/noosfero-articles/blog/blog.html +++ b/src/app/components/noosfero-articles/blog/blog.html @@ -16,4 +16,9 @@ + + + diff --git a/src/app/components/noosfero-blocks/recent-documents/recent-documents.directive.js b/src/app/components/noosfero-blocks/recent-documents/recent-documents.directive.js index c4f64af..a5adea8 100644 --- a/src/app/components/noosfero-blocks/recent-documents/recent-documents.directive.js +++ b/src/app/components/noosfero-blocks/recent-documents/recent-documents.directive.js @@ -31,8 +31,9 @@ $state.go("main.profile.page", {page: article.path, profile: article.profile.identifier}); } + var limit = vm.block.settings.limit || 5; //FIXME get all text articles - noosfero.profiles.one(vm.profile.id).one('articles').get({content_type: 'TinyMceArticle'}).then(function(result) { + noosfero.profiles.one(vm.profile.id).one('articles').get({content_type: 'TinyMceArticle', per_page: limit}).then(function(result) { vm.documents = result.articles; }); } -- libgit2 0.21.2