diff --git a/src/app/article/comment/comments.component.ts b/src/app/article/comment/comments.component.ts index 64651f8..c342b50 100644 --- a/src/app/article/comment/comments.component.ts +++ b/src/app/article/comment/comments.component.ts @@ -9,7 +9,7 @@ import { CommentComponent } from "./comment.component"; directives: [PostCommentComponent, CommentComponent], outputs: ['commentAdded'] }) -@Inject(CommentService, "$element") +@Inject(CommentService, "$scope") export class CommentsComponent { comments: noosfero.CommentViewModel[] = []; @@ -30,11 +30,23 @@ export class CommentsComponent { } else { this.loadNextPage(); } + this.commentService.subscribeToModelAdded((comment: noosfero.Comment) => { + if (comment.source_id === this.article.id) { + this.commentAdded(comment); + } + }); + this.commentService.subscribeToModelRemoved((comment: noosfero.Comment) => { + if (comment.source_id === this.article.id) { + this.commentRemoved(comment); + } + }); } - commentAdded(comment: noosfero.Comment): void { + commentAdded(comment: noosfero.CommentViewModel): void { + comment.__show_reply = false; this.comments.push(comment); this.resetShowReply(); + this.$scope.$apply(); } commentRemoved(comment: noosfero.Comment): void { @@ -51,6 +63,7 @@ export class CommentsComponent { if (this.parent) { this.parent.__show_reply = false; } + } loadComments() { diff --git a/src/lib/ng-noosfero-api/http/restangular_service.ts b/src/lib/ng-noosfero-api/http/restangular_service.ts index cc8d8ba..697d28e 100644 --- a/src/lib/ng-noosfero-api/http/restangular_service.ts +++ b/src/lib/ng-noosfero-api/http/restangular_service.ts @@ -328,7 +328,7 @@ export abstract class RestangularService { deferred.resolve(resultModel); // emits the event if a successEmiter was provided in the successEmitter parameter if (successEmitter !== null) { - successEmitter.next(resultModel); + successEmitter.next(resultModel.data); } }; return successFunction; diff --git a/src/lib/ng-noosfero-api/interfaces/comment.ts b/src/lib/ng-noosfero-api/interfaces/comment.ts index ac1ddc6..6611ad8 100644 --- a/src/lib/ng-noosfero-api/interfaces/comment.ts +++ b/src/lib/ng-noosfero-api/interfaces/comment.ts @@ -1,5 +1,6 @@ namespace noosfero { export interface Comment extends RestModel { + source_id: number; reply_of_id: number; reply_of: Comment; replies: Comment[]; diff --git a/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts b/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts index f6f99b1..a091bf6 100644 --- a/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts +++ b/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts @@ -2,24 +2,27 @@ import {Component, Input, Inject} from "ng-forward"; import {SideCommentsComponent} from "../side-comments/side-comments.component"; import {CommentParagraphEventService} from "../events/comment-paragraph-event.service"; import {CommentParagraphService} from "../http/comment-paragraph.service"; +import {CommentService} from "./../../../lib/ng-noosfero-api/http/comment.service"; @Component({ selector: "comment-paragraph-plugin-allow-comment", templateUrl: "plugins/comment_paragraph/allow-comment/allow-comment.html", directives: [SideCommentsComponent] }) -@Inject("$scope", CommentParagraphEventService, CommentParagraphService) +@Inject("$scope", CommentParagraphEventService, CommentParagraphService, CommentService) export class AllowCommentComponent { @Input() content: string; @Input() paragraphUuid: string; @Input() article: noosfero.Article; - commentsCount: number; + commentsCount: number = 0; display = false; constructor(private $scope: ng.IScope, private commentParagraphEventService: CommentParagraphEventService, - private commentParagraphService: CommentParagraphService) { } + private commentParagraphService: CommentParagraphService, + private commentService: CommentService + ) { } ngOnInit() { this.commentParagraphEventService.subscribeToggleCommentParagraph((article: noosfero.Article) => { @@ -27,7 +30,21 @@ export class AllowCommentComponent { this.$scope.$apply(); }); this.commentParagraphService.commentParagraphCount(this.article, this.paragraphUuid).then((count: number) => { - this.commentsCount = count; + this.commentsCount = count ? count : 0; + }); + + this.commentService.subscribeToModelAdded((comment: noosfero.CommentParagraph) => { + if (comment.paragraph_uuid === this.paragraphUuid) { + this.commentsCount += 1; + this.$scope.$apply(); + }; + }); + + this.commentService.subscribeToModelRemoved((comment: noosfero.CommentParagraph) => { + if (comment.paragraph_uuid === this.paragraphUuid) { + this.commentsCount -= 1; + this.$scope.$apply(); + }; }); } diff --git a/src/plugins/comment_paragraph/models/comment_paragraph.ts b/src/plugins/comment_paragraph/models/comment_paragraph.ts new file mode 100644 index 0000000..30f450c --- /dev/null +++ b/src/plugins/comment_paragraph/models/comment_paragraph.ts @@ -0,0 +1,5 @@ +namespace noosfero { + export interface CommentParagraph extends noosfero.Comment { + paragraph_uuid?: string; + } +} \ No newline at end of file -- libgit2 0.21.2