Commit d247ad88198febbc8b1f4fc51273a7482e98ff0c
1 parent
16b1a6fa
Exists in
master
and in
28 other branches
Refactor comments component to permit extensions
Showing
1 changed file
with
9 additions
and
5 deletions
Show diff stats
src/app/article/comment/comments.component.ts
| ... | ... | @@ -15,11 +15,11 @@ 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; | |
| 20 | - private total = 0; | |
| 18 | + protected page = 1; | |
| 19 | + protected perPage = 5; | |
| 20 | + protected total = 0; | |
| 21 | 21 | |
| 22 | - constructor(private commentService: CommentService, private $rootScope: ng.IScope) { | |
| 22 | + constructor(protected commentService: CommentService, protected $rootScope: ng.IScope) { | |
| 23 | 23 | $rootScope.$on(PostCommentComponent.EVENT_COMMENT_RECEIVED, (event: ng.IAngularEvent, comment: noosfero.Comment) => { |
| 24 | 24 | if ((!this.parent && !comment.reply_of) || (comment.reply_of && this.parent && comment.reply_of.id === this.parent.id)) { |
| 25 | 25 | if (!this.comments) this.comments = []; |
| ... | ... | @@ -36,8 +36,12 @@ export class CommentsComponent { |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | + loadComments() { | |
| 40 | + return this.commentService.getByArticle(this.article, { page: this.page, per_page: this.perPage }); | |
| 41 | + } | |
| 42 | + | |
| 39 | 43 | loadNextPage() { |
| 40 | - this.commentService.getByArticle(this.article, { page: this.page, per_page: this.perPage }).then((result: noosfero.RestResult<noosfero.Comment[]>) => { | |
| 44 | + this.loadComments().then((result: noosfero.RestResult<noosfero.Comment[]>) => { | |
| 41 | 45 | this.comments = this.comments.concat(result.data); |
| 42 | 46 | this.total = result.headers ? result.headers("total") : this.comments.length; |
| 43 | 47 | this.page++; | ... | ... |