From 1f246d3f4b9c329a60d9948b0d23ea574f72c9af Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 7 Apr 2016 15:06:50 -0300 Subject: [PATCH] Load comments by paragraph --- src/plugins/comment_paragraph/allow-comment/allow-comment.html | 2 +- src/plugins/comment_paragraph/allow-comment/popover.html | 2 +- src/plugins/comment_paragraph/http/comment-paragraph.service.ts | 34 ++++++++++++++++++++++++++++++++++ src/plugins/comment_paragraph/side-comments/side-comments.component.ts | 20 +++++++++++++++++--- src/plugins/comment_paragraph/side-comments/side-comments.scss | 10 ++++++++++ 5 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 src/plugins/comment_paragraph/http/comment-paragraph.service.ts create mode 100644 src/plugins/comment_paragraph/side-comments/side-comments.scss diff --git a/src/plugins/comment_paragraph/allow-comment/allow-comment.html b/src/plugins/comment_paragraph/allow-comment/allow-comment.html index 992e378..eb55ddc 100644 --- a/src/plugins/comment_paragraph/allow-comment/allow-comment.html +++ b/src/plugins/comment_paragraph/allow-comment/allow-comment.html @@ -1,4 +1,4 @@
- +
diff --git a/src/plugins/comment_paragraph/allow-comment/popover.html b/src/plugins/comment_paragraph/allow-comment/popover.html index 41db06a..5b9f005 100644 --- a/src/plugins/comment_paragraph/allow-comment/popover.html +++ b/src/plugins/comment_paragraph/allow-comment/popover.html @@ -1 +1 @@ - + diff --git a/src/plugins/comment_paragraph/http/comment-paragraph.service.ts b/src/plugins/comment_paragraph/http/comment-paragraph.service.ts new file mode 100644 index 0000000..c01415a --- /dev/null +++ b/src/plugins/comment_paragraph/http/comment-paragraph.service.ts @@ -0,0 +1,34 @@ +import { Injectable, Inject } from "ng-forward"; +import {RestangularService} from "../../../lib/ng-noosfero-api/http/restangular_service"; +import {ArticleService} from "../../../lib/ng-noosfero-api/http/article.service"; + +@Injectable() +@Inject("Restangular", "$q", "$log", ArticleService) +export class CommentParagraphService extends RestangularService { + + constructor(Restangular: restangular.IService, $q: ng.IQService, $log: ng.ILogService, protected articleService: ArticleService) { + super(Restangular, $q, $log); + } + + getResourcePath() { + return "comment_paragraph_plugin/comments"; + } + + getDataKeys() { + return { + singular: 'comment', + plural: 'comments' + }; + } + + getByArticle(article: noosfero.Article, params: any = {}): ng.IPromise> { + params['without_reply'] = true; + let articleElement = this.articleService.getElement(article.id); + return this.list(articleElement, params); + } + + createInArticle(article: noosfero.Article, comment: noosfero.Comment): ng.IPromise> { + let articleElement = this.articleService.getElement(article.id); + return this.create(comment, articleElement, null, { 'Content-Type': 'application/json' }, false); + } +} diff --git a/src/plugins/comment_paragraph/side-comments/side-comments.component.ts b/src/plugins/comment_paragraph/side-comments/side-comments.component.ts index 8545798..9f7b126 100644 --- a/src/plugins/comment_paragraph/side-comments/side-comments.component.ts +++ b/src/plugins/comment_paragraph/side-comments/side-comments.component.ts @@ -1,9 +1,23 @@ -import {Component} from "ng-forward"; +import {Component, Inject, Input} from "ng-forward"; +import {CommentsComponent} from "../../../app/article/comment/comments.component"; +import {CommentService} from "../../../lib/ng-noosfero-api/http/comment.service"; +import {CommentParagraphService} from "../http/comment-paragraph.service"; @Component({ selector: "comment-paragraph-side-comments", - templateUrl: "plugins/comment_paragraph/side-comments/side-comments.html" + templateUrl: 'app/article/comment/comments.html', }) -export class SideCommentsComponent { +@Inject(CommentService, "$rootScope", CommentParagraphService) +export class SideCommentsComponent extends CommentsComponent { + @Input() article: noosfero.Article; + @Input() paragraphUuid: string; + + constructor(commentService: CommentService, $rootScope: ng.IScope, private commentParagraphService: CommentParagraphService) { + super(commentService, $rootScope); + } + + loadComments() { + return this.commentParagraphService.getByArticle(this.article, { page: this.page, per_page: this.perPage, paragraph_uuid: this.paragraphUuid }); + } } diff --git a/src/plugins/comment_paragraph/side-comments/side-comments.scss b/src/plugins/comment_paragraph/side-comments/side-comments.scss new file mode 100644 index 0000000..67ccb14 --- /dev/null +++ b/src/plugins/comment_paragraph/side-comments/side-comments.scss @@ -0,0 +1,10 @@ +comment-paragraph-side-comments { + .comments { + .comment { + margin: 0; + &.media { + border-top: 0; + } + } + } +} -- libgit2 0.21.2