Commit 5e584c35bc6329527c769e0fec3a28491eb5c14d
Exists in
master
and in
4 other branches
Merge branch 'side-comments' into 'master'
Use full pagination in side comments See merge request !62
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,6 +16,7 @@ export class CommentsComponent { | ||
16 | @Input() showForm = true; | 16 | @Input() showForm = true; |
17 | @Input() article: noosfero.Article; | 17 | @Input() article: noosfero.Article; |
18 | @Input() parent: noosfero.CommentViewModel; | 18 | @Input() parent: noosfero.CommentViewModel; |
19 | + @Input() fullPagination = false; | ||
19 | protected page = 1; | 20 | protected page = 1; |
20 | protected perPage = 5; | 21 | protected perPage = 5; |
21 | protected total = 0; | 22 | protected total = 0; |
@@ -73,14 +74,25 @@ export class CommentsComponent { | @@ -73,14 +74,25 @@ export class CommentsComponent { | ||
73 | 74 | ||
74 | loadNextPage() { | 75 | loadNextPage() { |
75 | this.loadComments().then((result: noosfero.RestResult<noosfero.Comment[]>) => { | 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 | this.total = result.headers ? result.headers("total") : this.comments.length; | 83 | this.total = result.headers ? result.headers("total") : this.comments.length; |
78 | - this.page++; | ||
79 | }); | 84 | }); |
80 | } | 85 | } |
81 | 86 | ||
82 | displayMore() { | 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,5 +4,10 @@ | ||
4 | <div class="comments-list"> | 4 | <div class="comments-list"> |
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> | 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 | </div> | 6 | </div> |
7 | + | ||
7 | <button type="button" ng-if="ctrl.displayMore()" class="more-comments btn btn-default btn-block" ng-click="ctrl.loadNextPage()">{{"comment.pagination.more" | translate}}</button> | 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 | </div> | 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,7 +10,7 @@ describe("Components", () => { | ||
10 | describe("Side Comments Component", () => { | 10 | describe("Side Comments Component", () => { |
11 | 11 | ||
12 | let serviceMock = jasmine.createSpyObj("CommentParagraphService", ["getByArticle"]); | 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 | let commentServiceMock = {}; | 15 | let commentServiceMock = {}; |
16 | let postCommentEventService = jasmine.createSpyObj("postCommentEventService", ["emit", "subscribe"]); | 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 | @Component({ | 6 | @Component({ |
7 | selector: "comment-paragraph-side-comments", | 7 | selector: "comment-paragraph-side-comments", |
@@ -12,6 +12,7 @@ export class SideCommentsComponent extends CommentsComponent { | @@ -12,6 +12,7 @@ export class SideCommentsComponent extends CommentsComponent { | ||
12 | 12 | ||
13 | @Input() article: noosfero.Article; | 13 | @Input() article: noosfero.Article; |
14 | @Input() paragraphUuid: string; | 14 | @Input() paragraphUuid: string; |
15 | + @Input() fullPagination = true; | ||
15 | 16 | ||
16 | constructor(commentService: CommentService, | 17 | constructor(commentService: CommentService, |
17 | $scope: ng.IScope, | 18 | $scope: ng.IScope, |