diff --git a/src/app/article/comment/comments.component.spec.ts b/src/app/article/comment/comments.component.spec.ts index a190788..9d51b4b 100644 --- a/src/app/article/comment/comments.component.spec.ts +++ b/src/app/article/comment/comments.component.spec.ts @@ -57,5 +57,17 @@ describe("Components", () => { done(); }); }); + + it("load comments for next page", done => { + createComponent().then(fixture => { + commentService.getByArticle = jasmine.createSpy("getByArticle") + .and.returnValue(helpers.mocks.promiseResultTemplate({ data: { id: 4 } })); + let component: CommentsComponent = fixture.debugElement.componentViewChildren[0].componentInstance; + component.loadNextPage(); + expect(component['page']).toEqual(3); + expect(component.comments.length).toEqual(3); + done(); + }); + }); }); }); diff --git a/src/app/article/comment/comments.component.ts b/src/app/article/comment/comments.component.ts index 30cc96b..87ea5f3 100644 --- a/src/app/article/comment/comments.component.ts +++ b/src/app/article/comment/comments.component.ts @@ -15,6 +15,8 @@ export class CommentsComponent { @Input() showForm = true; @Input() article: noosfero.Article; @Input() parent: noosfero.Comment; + private page = 1; + private perPage = 5; constructor(private commentService: CommentService, private $rootScope: ng.IScope) { $rootScope.$on(PostCommentComponent.EVENT_COMMENT_RECEIVED, (event: ng.IAngularEvent, comment: noosfero.Comment) => { @@ -29,9 +31,14 @@ export class CommentsComponent { if (this.parent) { this.comments = this.parent.replies; } else { - this.commentService.getByArticle(this.article).then((result: noosfero.RestResult) => { - this.comments = result.data; - }); + this.loadNextPage(); } } + + loadNextPage() { + this.commentService.getByArticle(this.article, { page: this.page, per_page: this.perPage }).then((result: noosfero.RestResult) => { + this.comments = this.comments.concat(result.data); + this.page++; + }); + } } diff --git a/src/app/article/comment/comments.html b/src/app/article/comment/comments.html index f995524..f7aa1ec 100644 --- a/src/app/article/comment/comments.html +++ b/src/app/article/comment/comments.html @@ -2,6 +2,7 @@
- +
+ diff --git a/src/languages/en.json b/src/languages/en.json index c5bcc1f..966eec5 100644 --- a/src/languages/en.json +++ b/src/languages/en.json @@ -32,5 +32,6 @@ "notification.http_error.500.message": "Server error", "comment.post": "Post a comment", "comment.post.placeholder": "Join the discussion...", + "comment.pagination.more": "More", "comment.reply": "reply" } diff --git a/src/languages/pt.json b/src/languages/pt.json index 7236d81..dbedfd5 100644 --- a/src/languages/pt.json +++ b/src/languages/pt.json @@ -32,5 +32,6 @@ "notification.http_error.500.message": "Erro no servidor", "comment.post": "Commentar", "comment.post.placeholder": "Participe da discussão...", + "comment.pagination.more": "Mais", "comment.reply": "responder" } -- libgit2 0.21.2