Commit 6e2ef9ed6f97e22ac596c2f7f6ccb8bbf974ac87
1 parent
1d6363e0
Exists in
master
and in
28 other branches
Add pagination button for comment listing
Showing
5 changed files
with
26 additions
and
4 deletions
Show diff stats
src/app/article/comment/comments.component.spec.ts
... | ... | @@ -57,5 +57,17 @@ describe("Components", () => { |
57 | 57 | done(); |
58 | 58 | }); |
59 | 59 | }); |
60 | + | |
61 | + it("load comments for next page", done => { | |
62 | + createComponent().then(fixture => { | |
63 | + commentService.getByArticle = jasmine.createSpy("getByArticle") | |
64 | + .and.returnValue(helpers.mocks.promiseResultTemplate({ data: { id: 4 } })); | |
65 | + let component: CommentsComponent = fixture.debugElement.componentViewChildren[0].componentInstance; | |
66 | + component.loadNextPage(); | |
67 | + expect(component['page']).toEqual(3); | |
68 | + expect(component.comments.length).toEqual(3); | |
69 | + done(); | |
70 | + }); | |
71 | + }); | |
60 | 72 | }); |
61 | 73 | }); | ... | ... |
src/app/article/comment/comments.component.ts
... | ... | @@ -15,6 +15,8 @@ export class CommentsComponent { |
15 | 15 | @Input() showForm = true; |
16 | 16 | @Input() article: noosfero.Article; |
17 | 17 | @Input() parent: noosfero.Comment; |
18 | + private page = 1; | |
19 | + private perPage = 5; | |
18 | 20 | |
19 | 21 | constructor(private commentService: CommentService, private $rootScope: ng.IScope) { |
20 | 22 | $rootScope.$on(PostCommentComponent.EVENT_COMMENT_RECEIVED, (event: ng.IAngularEvent, comment: noosfero.Comment) => { |
... | ... | @@ -29,9 +31,14 @@ export class CommentsComponent { |
29 | 31 | if (this.parent) { |
30 | 32 | this.comments = this.parent.replies; |
31 | 33 | } else { |
32 | - this.commentService.getByArticle(this.article).then((result: noosfero.RestResult<noosfero.Comment[]>) => { | |
33 | - this.comments = result.data; | |
34 | - }); | |
34 | + this.loadNextPage(); | |
35 | 35 | } |
36 | 36 | } |
37 | + | |
38 | + loadNextPage() { | |
39 | + this.commentService.getByArticle(this.article, { page: this.page, per_page: this.perPage }).then((result: noosfero.RestResult<noosfero.Comment[]>) => { | |
40 | + this.comments = this.comments.concat(result.data); | |
41 | + this.page++; | |
42 | + }); | |
43 | + } | |
37 | 44 | } | ... | ... |
src/app/article/comment/comments.html
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | <noosfero-post-comment ng-if="ctrl.showForm" [article]="ctrl.article" [parent]="ctrl.parent"></noosfero-post-comment> |
3 | 3 | |
4 | 4 | <div class="comments-list"> |
5 | - <noosfero-comment ng-repeat="comment in ctrl.comments | orderBy: 'created_at':true"" [comment]="comment" [article]="ctrl.article"></noosfero-comment> | |
5 | + <noosfero-comment ng-repeat="comment in ctrl.comments | orderBy: 'created_at':true" [comment]="comment" [article]="ctrl.article"></noosfero-comment> | |
6 | 6 | </div> |
7 | + <button type="button" ng-if="!ctrl.parent" class="more-comments btn btn-default btn-block" ng-click="ctrl.loadNextPage()">{{"comment.pagination.more" | translate}}</button> | |
7 | 8 | </div> | ... | ... |
src/languages/en.json
src/languages/pt.json