Commit 5deddf4541b50430d20e3bf8c4629a7ad8f0ef4e
Committed by
Michel Felipe

1 parent
56a44bd2
Exists in
master
and in
26 other branches
Set parahraph uuid when create comments in paragraphs
Showing
6 changed files
with
23 additions
and
50 deletions
Show diff stats
src/app/article/comment/comments.component.ts
1 | -import { Inject, Input, Output, Component, provide, EventEmitter } from 'ng-forward'; | ||
2 | -import {INgForwardJQuery} from "ng-forward/cjs/util/jqlite-extensions"; | ||
3 | - | ||
4 | - | 1 | +import { Inject, Input, Component, provide } from 'ng-forward'; |
5 | import { PostCommentComponent } from "./post-comment/post-comment.component"; | 2 | import { PostCommentComponent } from "./post-comment/post-comment.component"; |
6 | import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service"; | 3 | import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service"; |
7 | import { CommentComponent } from "./comment.component"; | 4 | import { CommentComponent } from "./comment.component"; |
5 | +import { PostCommentEventService } from "./post-comment/post-comment-event.service"; | ||
8 | 6 | ||
9 | @Component({ | 7 | @Component({ |
10 | selector: 'noosfero-comments', | 8 | selector: 'noosfero-comments', |
11 | templateUrl: 'app/article/comment/comments.html', | 9 | templateUrl: 'app/article/comment/comments.html', |
12 | - directives: [PostCommentComponent, CommentComponent], | ||
13 | - outputs: ['commentAdded'] | 10 | + directives: [PostCommentComponent, CommentComponent] |
14 | }) | 11 | }) |
15 | -@Inject(CommentService, "$element") | 12 | +@Inject(CommentService, PostCommentEventService, "$scope") |
16 | export class CommentsComponent { | 13 | export class CommentsComponent { |
17 | 14 | ||
18 | - comments: noosfero.CommentViewModel[] = []; | 15 | + comments: noosfero.Comment[] = []; |
19 | @Input() showForm = true; | 16 | @Input() showForm = true; |
20 | @Input() article: noosfero.Article; | 17 | @Input() article: noosfero.Article; |
21 | - @Input() parent: noosfero.CommentViewModel; | ||
22 | - | 18 | + @Input() parent: noosfero.Comment; |
23 | protected page = 1; | 19 | protected page = 1; |
24 | protected perPage = 5; | 20 | protected perPage = 5; |
25 | protected total = 0; | 21 | protected total = 0; |
26 | 22 | ||
27 | - constructor(protected commentService: CommentService) { } | 23 | + newComment = <noosfero.Comment>{}; |
24 | + | ||
25 | + constructor(protected commentService: CommentService, private postCommentEventService: PostCommentEventService, private $scope: ng.IScope) { } | ||
28 | 26 | ||
29 | ngOnInit() { | 27 | ngOnInit() { |
30 | if (this.parent) { | 28 | if (this.parent) { |
@@ -32,20 +30,13 @@ export class CommentsComponent { | @@ -32,20 +30,13 @@ export class CommentsComponent { | ||
32 | } else { | 30 | } else { |
33 | this.loadNextPage(); | 31 | this.loadNextPage(); |
34 | } | 32 | } |
35 | - } | ||
36 | - | ||
37 | - commentAdded(comment: noosfero.Comment): void { | ||
38 | - this.comments.push(comment); | ||
39 | - this.resetShowReply(); | ||
40 | - } | ||
41 | - | ||
42 | - private resetShowReply() { | ||
43 | - this.comments.forEach((comment: noosfero.CommentViewModel) => { | ||
44 | - comment.__show_reply = false; | 33 | + this.postCommentEventService.subscribe((comment: noosfero.Comment) => { |
34 | + if ((!this.parent && !comment.reply_of) || (comment.reply_of && this.parent && comment.reply_of.id === this.parent.id)) { | ||
35 | + if (!this.comments) this.comments = []; | ||
36 | + this.comments.push(comment); | ||
37 | + this.$scope.$apply(); | ||
38 | + } | ||
45 | }); | 39 | }); |
46 | - if (this.parent) { | ||
47 | - this.parent.__show_reply = false; | ||
48 | - } | ||
49 | } | 40 | } |
50 | 41 | ||
51 | loadComments() { | 42 | loadComments() { |
src/app/article/comment/comments.html
1 | <div class="comments"> | 1 | <div class="comments"> |
2 | - <noosfero-post-comment (comment-saved)="ctrl.commentAdded($event.detail)" ng-if="ctrl.showForm" [article]="ctrl.article" [parent]="ctrl.parent"></noosfero-post-comment> | 2 | + <noosfero-post-comment ng-if="ctrl.showForm" [article]="ctrl.article" [parent]="ctrl.parent" [comment]="ctrl.newComment"></noosfero-post-comment> |
3 | 3 | ||
4 | <div class="comments-list"> | 4 | <div class="comments-list"> |
5 | <noosfero-comment ng-repeat="comment in ctrl.comments | orderBy: 'created_at':true" [comment]="comment" [article]="ctrl.article"></noosfero-comment> | 5 | <noosfero-comment ng-repeat="comment in ctrl.comments | orderBy: 'created_at':true" [comment]="comment" [article]="ctrl.article"></noosfero-comment> |
src/app/article/comment/post-comment/post-comment.component.ts
@@ -17,8 +17,7 @@ export class PostCommentComponent { | @@ -17,8 +17,7 @@ export class PostCommentComponent { | ||
17 | 17 | ||
18 | @Input() article: noosfero.Article; | 18 | @Input() article: noosfero.Article; |
19 | @Input() parent: noosfero.Comment; | 19 | @Input() parent: noosfero.Comment; |
20 | - | ||
21 | - comment = <noosfero.Comment>{}; | 20 | + @Input() comment = <noosfero.Comment>{}; |
22 | private currentUser: noosfero.User; | 21 | private currentUser: noosfero.User; |
23 | 22 | ||
24 | constructor(private commentService: CommentService, | 23 | constructor(private commentService: CommentService, |
src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts
@@ -1,21 +0,0 @@ | @@ -1,21 +0,0 @@ | ||
1 | -import { Input, Inject, Component } from "ng-forward"; | ||
2 | -import {Hotspot} from "../../../app/hotspot/hotspot.decorator"; | ||
3 | - | ||
4 | -@Component({ | ||
5 | - selector: "comment-paragraph-uuid-hotspot", | ||
6 | - template: "<span></span>", | ||
7 | -}) | ||
8 | -@Inject("$scope") | ||
9 | -@Hotspot("comment_form_extra_contents") | ||
10 | -export class CommentParagraphUuidHotspotComponent { | ||
11 | - | ||
12 | - @Input() comment: noosfero.Comment; | ||
13 | - | ||
14 | - constructor(private $scope: ng.IScope) { } | ||
15 | - | ||
16 | - ngOnInit() { | ||
17 | - this.$scope.$watch("comment", () => { | ||
18 | - this.comment['paragraph_uuid'] = "???"; | ||
19 | - }); | ||
20 | - } | ||
21 | -} |
src/plugins/comment_paragraph/index.ts
1 | import {AllowCommentComponent} from "./allow-comment/allow-comment.component"; | 1 | import {AllowCommentComponent} from "./allow-comment/allow-comment.component"; |
2 | -import {CommentParagraphUuidHotspotComponent} from "./hotspot/comment-paragraph-uuid-hotspot.component"; | ||
3 | import {CommentParagraphArticleButtonHotspotComponent} from "./hotspot/comment-paragraph-article-button.component"; | 2 | import {CommentParagraphArticleButtonHotspotComponent} from "./hotspot/comment-paragraph-article-button.component"; |
4 | 3 | ||
5 | export let mainComponents: any = [AllowCommentComponent]; | 4 | export let mainComponents: any = [AllowCommentComponent]; |
6 | -export let hotspots: any = [CommentParagraphUuidHotspotComponent, CommentParagraphArticleButtonHotspotComponent]; | 5 | +export let hotspots: any = [CommentParagraphArticleButtonHotspotComponent]; |
src/plugins/comment_paragraph/side-comments/side-comments.component.ts
@@ -17,6 +17,11 @@ export class SideCommentsComponent extends CommentsComponent { | @@ -17,6 +17,11 @@ export class SideCommentsComponent extends CommentsComponent { | ||
17 | super(commentService, $rootScope); | 17 | super(commentService, $rootScope); |
18 | } | 18 | } |
19 | 19 | ||
20 | + ngOnInit() { | ||
21 | + super.ngOnInit(); | ||
22 | + this.newComment['paragraph_uuid'] = this.paragraphUuid; | ||
23 | + } | ||
24 | + | ||
20 | loadComments() { | 25 | loadComments() { |
21 | return this.commentParagraphService.getByArticle(this.article, { page: this.page, per_page: this.perPage, paragraph_uuid: this.paragraphUuid }); | 26 | return this.commentParagraphService.getByArticle(this.article, { page: this.page, per_page: this.perPage, paragraph_uuid: this.paragraphUuid }); |
22 | } | 27 | } |