Commit 8af6d143965a8843256bd49c71ee080843da04e3

Authored by Victor Costa
1 parent 12f1379f

Fix merge with comment-paragraph

src/app/article/comment/comment.html
... ... @@ -23,5 +23,5 @@
23 23 </a>
24 24 </div>
25 25 </div>
26   - <noosfero-comments [show-form]="ctrl.showReply" [article]="ctrl.article" [parent]="ctrl.comment" ng-if="ctrl.displayReplies"></noosfero-comments>
  26 + <noosfero-comments [show-form]="ctrl.showReply()" [article]="ctrl.article" [parent]="ctrl.comment" ng-if="ctrl.displayReplies"></noosfero-comments>
27 27 </div>
... ...
src/app/article/comment/comments.component.ts
... ... @@ -2,27 +2,27 @@ import { Inject, Input, Component, provide } from &#39;ng-forward&#39;;
2 2 import { PostCommentComponent } from "./post-comment/post-comment.component";
3 3 import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service";
4 4 import { CommentComponent } from "./comment.component";
5   -import { PostCommentEventService } from "./post-comment/post-comment-event.service";
6 5  
7 6 @Component({
8 7 selector: 'noosfero-comments',
9 8 templateUrl: 'app/article/comment/comments.html',
10   - directives: [PostCommentComponent, CommentComponent]
  9 + directives: [PostCommentComponent, CommentComponent],
  10 + outputs: ['commentAdded']
11 11 })
12   -@Inject(CommentService, PostCommentEventService, "$scope")
  12 +@Inject(CommentService, "$element")
13 13 export class CommentsComponent {
14 14  
15   - comments: noosfero.Comment[] = [];
  15 + comments: noosfero.CommentViewModel[] = [];
16 16 @Input() showForm = true;
17 17 @Input() article: noosfero.Article;
18   - @Input() parent: noosfero.Comment;
  18 + @Input() parent: noosfero.CommentViewModel;
19 19 protected page = 1;
20 20 protected perPage = 5;
21 21 protected total = 0;
22 22  
23 23 newComment = <noosfero.Comment>{};
24 24  
25   - constructor(protected commentService: CommentService, private postCommentEventService: PostCommentEventService, private $scope: ng.IScope) { }
  25 + constructor(protected commentService: CommentService, private $scope: ng.IScope) { }
26 26  
27 27 ngOnInit() {
28 28 if (this.parent) {
... ... @@ -30,13 +30,20 @@ export class CommentsComponent {
30 30 } else {
31 31 this.loadNextPage();
32 32 }
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   - }
  33 + }
  34 +
  35 + commentAdded(comment: noosfero.Comment): void {
  36 + this.comments.push(comment);
  37 + this.resetShowReply();
  38 + }
  39 +
  40 + private resetShowReply() {
  41 + this.comments.forEach((comment: noosfero.CommentViewModel) => {
  42 + comment.__show_reply = false;
39 43 });
  44 + if (this.parent) {
  45 + this.parent.__show_reply = false;
  46 + }
40 47 }
41 48  
42 49 loadComments() {
... ...
src/app/article/comment/comments.html
1 1 <div class="comments">
2   - <noosfero-post-comment ng-if="ctrl.showForm" [article]="ctrl.article" [parent]="ctrl.parent" [comment]="ctrl.newComment"></noosfero-post-comment>
  2 + <noosfero-post-comment (comment-saved)="ctrl.commentAdded($event.detail)" ng-if="ctrl.showForm" [article]="ctrl.article" [parent]="ctrl.parent" [comment]="ctrl.newComment"></noosfero-post-comment>
3 3  
4 4 <div class="comments-list">
5 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
1   -import { Inject, Input, Component } from 'ng-forward';
  1 +import { Inject, Input, Output, EventEmitter, Component } from 'ng-forward';
2 2 import { CommentService } from "../../../../lib/ng-noosfero-api/http/comment.service";
3 3 import { NotificationService } from "../../../shared/services/notification.service";
4 4 import { SessionService } from "../../../login";
5   -import { PostCommentEventService } from "./post-comment-event.service";
6 5 import { CommentFormHotspotComponent } from "../../../hotspot/comment-form-hotspot.component";
7 6  
8 7 @Component({
9 8 selector: 'noosfero-post-comment',
10 9 templateUrl: 'app/article/comment/post-comment/post-comment.html',
  10 + outputs: ['commentSaved'],
11 11 directives: [CommentFormHotspotComponent]
12 12 })
13   -@Inject(CommentService, NotificationService, SessionService, PostCommentEventService)
  13 +@Inject(CommentService, NotificationService, SessionService)
14 14 export class PostCommentComponent {
15 15  
16 16 public static EVENT_COMMENT_RECEIVED = "comment.received";
17 17  
18 18 @Input() article: noosfero.Article;
19 19 @Input() parent: noosfero.Comment;
  20 + @Output() commentSaved: EventEmitter<Comment> = new EventEmitter<Comment>();
20 21 @Input() comment = <noosfero.Comment>{};
21 22 private currentUser: noosfero.User;
22 23  
23 24 constructor(private commentService: CommentService,
24 25 private notificationService: NotificationService,
25   - private session: SessionService,
26   - private postCommentEventService: PostCommentEventService) {
  26 + private session: SessionService) {
27 27 this.currentUser = this.session.currentUser();
28 28 }
29 29  
... ... @@ -32,7 +32,7 @@ export class PostCommentComponent {
32 32 this.comment.reply_of_id = this.parent.id;
33 33 }
34 34 this.commentService.createInArticle(this.article, this.comment).then((result: noosfero.RestResult<noosfero.Comment>) => {
35   - this.postCommentEventService.emit(result.data);
  35 + this.commentSaved.next(result.data);
36 36 this.comment.body = "";
37 37 this.notificationService.success({ title: "comment.post.success.title", message: "comment.post.success.message" });
38 38 });
... ...
src/plugins/comment_paragraph/allow-comment/allow-comment.component.spec.ts
... ... @@ -26,7 +26,7 @@ describe(&quot;Components&quot;, () =&gt; {
26 26 new Provider('CommentParagraphService', { useValue: serviceMock }),
27 27 new Provider('CommentParagraphEventService', { useValue: eventServiceMock })
28 28 ];
29   - let helper: ComponentTestHelper;
  29 + let helper: ComponentTestHelper<AllowCommentComponent>;
30 30  
31 31 beforeEach(angular.mock.module("templates"));
32 32  
... ... @@ -45,7 +45,7 @@ describe(&quot;Components&quot;, () =&gt; {
45 45 }
46 46 }
47 47 });
48   - helper = new ComponentTestHelper(cls, done);
  48 + helper = new ComponentTestHelper<AllowCommentComponent>(cls, done);
49 49 });
50 50  
51 51 it('update comments count', () => {
... ...
src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.spec.ts
... ... @@ -16,7 +16,7 @@ describe(&quot;Components&quot;, () =&gt; {
16 16 new Provider('CommentParagraphService', { useValue: serviceMock }),
17 17 new Provider('CommentParagraphEventService', { useValue: eventServiceMock })
18 18 ].concat(helpers.provideFilters('translateFilter'));
19   - let helper: ComponentTestHelper;
  19 + let helper: ComponentTestHelper<CommentParagraphArticleButtonHotspotComponent>;
20 20  
21 21 beforeEach(angular.mock.module("templates"));
22 22  
... ... @@ -29,7 +29,7 @@ describe(&quot;Components&quot;, () =&gt; {
29 29 article: {}
30 30 }
31 31 });
32   - helper = new ComponentTestHelper(cls, done);
  32 + helper = new ComponentTestHelper<CommentParagraphArticleButtonHotspotComponent>(cls, done);
33 33 });
34 34  
35 35 it('emit event when deactivate comment paragraph in an article', () => {
... ... @@ -55,7 +55,7 @@ describe(&quot;Components&quot;, () =&gt; {
55 55 });
56 56  
57 57 it('return true when comment paragraph is active', () => {
58   - helper.component.article = { setting: { comment_paragraph_plugin_activate: true } };
  58 + helper.component.article = <noosfero.Article>{ setting: { comment_paragraph_plugin_activate: true } };
59 59 helper.detectChanges();
60 60 expect(helper.component.isActivated()).toBeTruthy();
61 61 });
... ... @@ -65,7 +65,7 @@ describe(&quot;Components&quot;, () =&gt; {
65 65 });
66 66  
67 67 it('return false when article has no setting attribute', () => {
68   - helper.component.article = {};
  68 + helper.component.article = <noosfero.Article>{};
69 69 helper.detectChanges();
70 70 expect(helper.component.isActivated()).toBeFalsy();
71 71 });
... ... @@ -76,7 +76,7 @@ describe(&quot;Components&quot;, () =&gt; {
76 76 });
77 77  
78 78 it('display deactivate button when comment paragraph is active', () => {
79   - helper.component.article = { setting: { comment_paragraph_plugin_activate: true } };
  79 + helper.component.article = <noosfero.Article>{ setting: { comment_paragraph_plugin_activate: true } };
80 80 helper.detectChanges();
81 81 expect(helper.all('.comment-paragraph-deactivate').length).toEqual(1);
82 82 expect(helper.all('.comment-paragraph-activate').length).toEqual(0);
... ...
src/plugins/comment_paragraph/hotspot/comment-paragraph-from.component.spec.ts
... ... @@ -8,7 +8,7 @@ let htmlTemplate = &#39;&lt;comment-paragraph-form-hotspot [comment]=&quot;ctrl.comment&quot; [pa
8 8 describe("Components", () => {
9 9 describe("Comment Paragraph Form Hotspot Component", () => {
10 10  
11   - let helper: ComponentTestHelper;
  11 + let helper: ComponentTestHelper<CommentParagraphFormHotspotComponent>;
12 12  
13 13 beforeEach(angular.mock.module("templates"));
14 14  
... ... @@ -21,7 +21,7 @@ describe(&quot;Components&quot;, () =&gt; {
21 21 comment: {}
22 22 }
23 23 });
24   - helper = new ComponentTestHelper(cls, done);
  24 + helper = new ComponentTestHelper<CommentParagraphFormHotspotComponent>(cls, done);
25 25 });
26 26  
27 27 it('set paragraph uuid when parent has it setted', () => {
... ...
src/plugins/comment_paragraph/side-comments/side-comments.component.spec.ts
... ... @@ -21,7 +21,7 @@ describe(&quot;Components&quot;, () =&gt; {
21 21 new Provider('CommentService', { useValue: commentServiceMock }),
22 22 new Provider('PostCommentEventService', { useValue: postCommentEventService })
23 23 ];
24   - let helper: ComponentTestHelper;
  24 + let helper: ComponentTestHelper<SideCommentsComponent>;
25 25  
26 26 beforeEach(angular.mock.module("templates"));
27 27  
... ... @@ -35,7 +35,7 @@ describe(&quot;Components&quot;, () =&gt; {
35 35 article: {}
36 36 }
37 37 });
38   - helper = new ComponentTestHelper(cls, done);
  38 + helper = new ComponentTestHelper<SideCommentsComponent>(cls, done);
39 39 });
40 40  
41 41 it('call service to load paragraph comments', () => {
... ...
src/plugins/comment_paragraph/side-comments/side-comments.component.ts
... ... @@ -2,23 +2,21 @@ import {Component, Inject, Input, Output} from &quot;ng-forward&quot;;
2 2 import {CommentsComponent} from "../../../app/article/comment/comments.component";
3 3 import {CommentService} from "../../../lib/ng-noosfero-api/http/comment.service";
4 4 import {CommentParagraphService} from "../http/comment-paragraph.service";
5   -import { PostCommentEventService } from "../../../app/article/comment/post-comment/post-comment-event.service";
6 5  
7 6 @Component({
8 7 selector: "comment-paragraph-side-comments",
9 8 templateUrl: 'app/article/comment/comments.html',
10 9 })
11   -@Inject(CommentService, PostCommentEventService, "$scope", CommentParagraphService)
  10 +@Inject(CommentService, "$scope", CommentParagraphService)
12 11 export class SideCommentsComponent extends CommentsComponent {
13 12  
14 13 @Input() article: noosfero.Article;
15 14 @Input() paragraphUuid: string;
16 15  
17 16 constructor(commentService: CommentService,
18   - postCommentEventService: PostCommentEventService,
19 17 $scope: ng.IScope,
20 18 private commentParagraphService: CommentParagraphService) {
21   - super(commentService, postCommentEventService, $scope);
  19 + super(commentService, $scope);
22 20 }
23 21  
24 22 ngOnInit() {
... ...