From 5deddf4541b50430d20e3bf8c4629a7ad8f0ef4e Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Mon, 11 Apr 2016 09:50:59 -0300 Subject: [PATCH] Set parahraph uuid when create comments in paragraphs --- src/app/article/comment/comments.component.ts | 39 +++++++++++++++------------------------ src/app/article/comment/comments.html | 2 +- src/app/article/comment/post-comment/post-comment.component.ts | 3 +-- src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts | 21 --------------------- src/plugins/comment_paragraph/index.ts | 3 +-- src/plugins/comment_paragraph/side-comments/side-comments.component.ts | 5 +++++ 6 files changed, 23 insertions(+), 50 deletions(-) delete mode 100644 src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts diff --git a/src/app/article/comment/comments.component.ts b/src/app/article/comment/comments.component.ts index 3317ae7..b5cb813 100644 --- a/src/app/article/comment/comments.component.ts +++ b/src/app/article/comment/comments.component.ts @@ -1,30 +1,28 @@ -import { Inject, Input, Output, Component, provide, EventEmitter } from 'ng-forward'; -import {INgForwardJQuery} from "ng-forward/cjs/util/jqlite-extensions"; - - +import { Inject, Input, Component, provide } from 'ng-forward'; import { PostCommentComponent } from "./post-comment/post-comment.component"; import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service"; import { CommentComponent } from "./comment.component"; +import { PostCommentEventService } from "./post-comment/post-comment-event.service"; @Component({ selector: 'noosfero-comments', templateUrl: 'app/article/comment/comments.html', - directives: [PostCommentComponent, CommentComponent], - outputs: ['commentAdded'] + directives: [PostCommentComponent, CommentComponent] }) -@Inject(CommentService, "$element") +@Inject(CommentService, PostCommentEventService, "$scope") export class CommentsComponent { - comments: noosfero.CommentViewModel[] = []; + comments: noosfero.Comment[] = []; @Input() showForm = true; @Input() article: noosfero.Article; - @Input() parent: noosfero.CommentViewModel; - + @Input() parent: noosfero.Comment; protected page = 1; protected perPage = 5; protected total = 0; - constructor(protected commentService: CommentService) { } + newComment = {}; + + constructor(protected commentService: CommentService, private postCommentEventService: PostCommentEventService, private $scope: ng.IScope) { } ngOnInit() { if (this.parent) { @@ -32,20 +30,13 @@ export class CommentsComponent { } else { this.loadNextPage(); } - } - - commentAdded(comment: noosfero.Comment): void { - this.comments.push(comment); - this.resetShowReply(); - } - - private resetShowReply() { - this.comments.forEach((comment: noosfero.CommentViewModel) => { - comment.__show_reply = false; + this.postCommentEventService.subscribe((comment: noosfero.Comment) => { + if ((!this.parent && !comment.reply_of) || (comment.reply_of && this.parent && comment.reply_of.id === this.parent.id)) { + if (!this.comments) this.comments = []; + this.comments.push(comment); + this.$scope.$apply(); + } }); - if (this.parent) { - this.parent.__show_reply = false; - } } loadComments() { diff --git a/src/app/article/comment/comments.html b/src/app/article/comment/comments.html index 347da4b..fa93e12 100644 --- a/src/app/article/comment/comments.html +++ b/src/app/article/comment/comments.html @@ -1,5 +1,5 @@
- +
diff --git a/src/app/article/comment/post-comment/post-comment.component.ts b/src/app/article/comment/post-comment/post-comment.component.ts index de25eda..1ffc87d 100644 --- a/src/app/article/comment/post-comment/post-comment.component.ts +++ b/src/app/article/comment/post-comment/post-comment.component.ts @@ -17,8 +17,7 @@ export class PostCommentComponent { @Input() article: noosfero.Article; @Input() parent: noosfero.Comment; - - comment = {}; + @Input() comment = {}; private currentUser: noosfero.User; constructor(private commentService: CommentService, diff --git a/src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts b/src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts deleted file mode 100644 index d666413..0000000 --- a/src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Input, Inject, Component } from "ng-forward"; -import {Hotspot} from "../../../app/hotspot/hotspot.decorator"; - -@Component({ - selector: "comment-paragraph-uuid-hotspot", - template: "", -}) -@Inject("$scope") -@Hotspot("comment_form_extra_contents") -export class CommentParagraphUuidHotspotComponent { - - @Input() comment: noosfero.Comment; - - constructor(private $scope: ng.IScope) { } - - ngOnInit() { - this.$scope.$watch("comment", () => { - this.comment['paragraph_uuid'] = "???"; - }); - } -} diff --git a/src/plugins/comment_paragraph/index.ts b/src/plugins/comment_paragraph/index.ts index 9dc43ee..5de5e3f 100644 --- a/src/plugins/comment_paragraph/index.ts +++ b/src/plugins/comment_paragraph/index.ts @@ -1,6 +1,5 @@ import {AllowCommentComponent} from "./allow-comment/allow-comment.component"; -import {CommentParagraphUuidHotspotComponent} from "./hotspot/comment-paragraph-uuid-hotspot.component"; import {CommentParagraphArticleButtonHotspotComponent} from "./hotspot/comment-paragraph-article-button.component"; export let mainComponents: any = [AllowCommentComponent]; -export let hotspots: any = [CommentParagraphUuidHotspotComponent, CommentParagraphArticleButtonHotspotComponent]; +export let hotspots: any = [CommentParagraphArticleButtonHotspotComponent]; 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 a8c6d88..4b47431 100644 --- a/src/plugins/comment_paragraph/side-comments/side-comments.component.ts +++ b/src/plugins/comment_paragraph/side-comments/side-comments.component.ts @@ -17,6 +17,11 @@ export class SideCommentsComponent extends CommentsComponent { super(commentService, $rootScope); } + ngOnInit() { + super.ngOnInit(); + this.newComment['paragraph_uuid'] = this.paragraphUuid; + } + loadComments() { return this.commentParagraphService.getByArticle(this.article, { page: this.page, per_page: this.perPage, paragraph_uuid: this.paragraphUuid }); } -- libgit2 0.21.2