Commit e18fb08819633d9f0ba96598f6ced24cf0b21684
1 parent
e6fd2825
Exists in
master
and in
4 other branches
Use full pagination in side comments
Showing
6 changed files
with
31 additions
and
10 deletions
Show diff stats
src/app/article/comment/comments.component.ts
| ... | ... | @@ -16,6 +16,7 @@ export class CommentsComponent { |
| 16 | 16 | @Input() showForm = true; |
| 17 | 17 | @Input() article: noosfero.Article; |
| 18 | 18 | @Input() parent: noosfero.CommentViewModel; |
| 19 | + @Input() fullPagination = false; | |
| 19 | 20 | protected page = 1; |
| 20 | 21 | protected perPage = 5; |
| 21 | 22 | protected total = 0; |
| ... | ... | @@ -73,14 +74,25 @@ export class CommentsComponent { |
| 73 | 74 | |
| 74 | 75 | loadNextPage() { |
| 75 | 76 | this.loadComments().then((result: noosfero.RestResult<noosfero.Comment[]>) => { |
| 76 | - this.comments = this.comments.concat(result.data); | |
| 77 | + if (this.fullPagination) { | |
| 78 | + this.comments = result.data; | |
| 79 | + } else { | |
| 80 | + this.comments = this.comments.concat(result.data); | |
| 81 | + this.page++; | |
| 82 | + } | |
| 77 | 83 | this.total = result.headers ? result.headers("total") : this.comments.length; |
| 78 | - this.page++; | |
| 79 | 84 | }); |
| 80 | 85 | } |
| 81 | 86 | |
| 82 | 87 | displayMore() { |
| 83 | - let pages = Math.ceil(this.total / this.perPage); | |
| 84 | - return !this.parent && pages >= this.page; | |
| 88 | + return !this.parent && !this.fullPagination && this.getPages() >= this.page; | |
| 89 | + } | |
| 90 | + | |
| 91 | + displayFullPagination() { | |
| 92 | + return !this.parent && this.fullPagination && this.getPages() > 0; | |
| 93 | + } | |
| 94 | + | |
| 95 | + private getPages() { | |
| 96 | + return Math.ceil(this.total / this.perPage); | |
| 85 | 97 | } |
| 86 | 98 | } | ... | ... |
src/app/article/comment/comments.html
| ... | ... | @@ -4,5 +4,10 @@ |
| 4 | 4 | <div class="comments-list"> |
| 5 | 5 | <noosfero-comment (comment-removed)="ctrl.commentRemoved($event.detail)" ng-repeat="comment in ctrl.comments | orderBy: 'created_at':true" [comment]="comment" [article]="ctrl.article"></noosfero-comment> |
| 6 | 6 | </div> |
| 7 | + | |
| 7 | 8 | <button type="button" ng-if="ctrl.displayMore()" class="more-comments btn btn-default btn-block" ng-click="ctrl.loadNextPage()">{{"comment.pagination.more" | translate}}</button> |
| 9 | + <uib-pagination ng-if="ctrl.displayFullPagination()" ng-model="ctrl.page" total-items="ctrl.total" class="pagination-sm center-block" | |
| 10 | + boundary-links="true" items-per-page="ctrl.perPage" ng-change="ctrl.loadNextPage()" | |
| 11 | + first-text="«" last-text="»" previous-text="‹" next-text="›"> | |
| 12 | + </uib-pagination> | |
| 8 | 13 | </div> | ... | ... |
src/plugins/comment_paragraph/allow-comment/popover.html
| 1 | -<comment-paragraph-side-comments id="side-comments-{{ctrl.paragraphUuid}}" click-outside="ctrl.hideParagraphComments()" [article]="ctrl.article" [paragraph-uuid]="ctrl.paragraphUuid"></comment-paragraph-side-comments> | |
| 1 | +<comment-paragraph-side-comments id="side-comments-{{ctrl.paragraphUuid}}" click-outside="ctrl.hideParagraphComments()" [article]="ctrl.article" [paragraph-uuid]="ctrl.paragraphUuid" [full-pagination]="ctrl.fullPagination"></comment-paragraph-side-comments> | ... | ... |
src/plugins/comment_paragraph/side-comments/side-comments.component.spec.ts
| ... | ... | @@ -10,7 +10,7 @@ describe("Components", () => { |
| 10 | 10 | describe("Side Comments Component", () => { |
| 11 | 11 | |
| 12 | 12 | let serviceMock = jasmine.createSpyObj("CommentParagraphService", ["getByArticle"]); |
| 13 | - serviceMock.getByArticle = jasmine.createSpy("getByArticle").and.returnValue(Promise.resolve({ data: {} })); | |
| 13 | + serviceMock.getByArticle = jasmine.createSpy("getByArticle").and.returnValue(Promise.resolve({ data: [] })); | |
| 14 | 14 | |
| 15 | 15 | let commentServiceMock = {}; |
| 16 | 16 | let postCommentEventService = jasmine.createSpyObj("postCommentEventService", ["emit", "subscribe"]); | ... | ... |
src/plugins/comment_paragraph/side-comments/side-comments.component.ts
| 1 | -import {Component, Inject, Input, Output} from "ng-forward"; | |
| 2 | -import {CommentsComponent} from "../../../app/article/comment/comments.component"; | |
| 3 | -import {CommentService} from "../../../lib/ng-noosfero-api/http/comment.service"; | |
| 4 | -import {CommentParagraphService} from "../http/comment-paragraph.service"; | |
| 1 | +import { Component, Inject, Input, Output } from "ng-forward"; | |
| 2 | +import { CommentsComponent } from "../../../app/article/comment/comments.component"; | |
| 3 | +import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service"; | |
| 4 | +import { CommentParagraphService } from "../http/comment-paragraph.service"; | |
| 5 | 5 | |
| 6 | 6 | @Component({ |
| 7 | 7 | selector: "comment-paragraph-side-comments", |
| ... | ... | @@ -12,6 +12,7 @@ export class SideCommentsComponent extends CommentsComponent { |
| 12 | 12 | |
| 13 | 13 | @Input() article: noosfero.Article; |
| 14 | 14 | @Input() paragraphUuid: string; |
| 15 | + @Input() fullPagination = true; | |
| 15 | 16 | |
| 16 | 17 | constructor(commentService: CommentService, |
| 17 | 18 | $scope: ng.IScope, | ... | ... |