Commit b77b920cac0ccb77ea6b5a8067d31006900b7c75

Authored by Victor Costa
Committed by Michel Felipe
1 parent abdfbb35

Emit event when toggle comment paragraph in articles

src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts
1 -import {Component, Input} from "ng-forward"; 1 +import {Component, Input, Inject} from "ng-forward";
2 import {SideCommentsComponent} from "../side-comments/side-comments.component"; 2 import {SideCommentsComponent} from "../side-comments/side-comments.component";
  3 +import {CommentParagraphEventService} from "../events/comment-paragraph-event.service";
3 4
4 @Component({ 5 @Component({
5 selector: "comment-paragraph-plugin-allow-comment", 6 selector: "comment-paragraph-plugin-allow-comment",
6 templateUrl: "plugins/comment_paragraph/allow-comment/allow-comment.html", 7 templateUrl: "plugins/comment_paragraph/allow-comment/allow-comment.html",
7 directives: [SideCommentsComponent] 8 directives: [SideCommentsComponent]
8 }) 9 })
  10 +@Inject("$scope", CommentParagraphEventService)
9 export class AllowCommentComponent { 11 export class AllowCommentComponent {
10 12
11 @Input() content: string; 13 @Input() content: string;
12 @Input() paragraphUuid: string; 14 @Input() paragraphUuid: string;
13 @Input() article: noosfero.Article; 15 @Input() article: noosfero.Article;
14 16
  17 + constructor(private $scope: ng.IScope, private commentParagraphEventService: CommentParagraphEventService) { }
  18 +
  19 + ngOnInit() {
  20 + this.commentParagraphEventService.subscribeToggleCommentParagraph((article: noosfero.Article) => {
  21 + this.article = article;
  22 + this.$scope.$apply();
  23 + });
  24 + }
  25 +
15 isActivated() { 26 isActivated() {
16 return this.article.setting.comment_paragraph_plugin_activate; 27 return this.article.setting.comment_paragraph_plugin_activate;
17 } 28 }
  29 +
18 } 30 }
src/plugins/comment_paragraph/events/comment-paragraph-event.service.ts 0 → 100644
@@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
  1 +import {Injectable, EventEmitter} from "ng-forward";
  2 +
  3 +@Injectable()
  4 +export class CommentParagraphEventService {
  5 +
  6 + private toggleCommentParagraphEmitter: EventEmitter<noosfero.Article>;
  7 +
  8 + constructor() {
  9 + this.toggleCommentParagraphEmitter = new EventEmitter();
  10 + }
  11 +
  12 + toggleCommentParagraph(article: noosfero.Article) {
  13 + this.toggleCommentParagraphEmitter.next(article);
  14 + }
  15 +
  16 + subscribeToggleCommentParagraph(fn: (article: noosfero.Article) => void) {
  17 + this.toggleCommentParagraphEmitter.subscribe(fn);
  18 + }
  19 +}
src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts
1 import { Input, Inject, Component } from "ng-forward"; 1 import { Input, Inject, Component } from "ng-forward";
2 import {Hotspot} from "../../../app/hotspot/hotspot.decorator"; 2 import {Hotspot} from "../../../app/hotspot/hotspot.decorator";
3 import {CommentParagraphService} from "../http/comment-paragraph.service"; 3 import {CommentParagraphService} from "../http/comment-paragraph.service";
  4 +import {CommentParagraphEventService} from "../events/comment-paragraph-event.service";
4 5
5 @Component({ 6 @Component({
6 selector: "comment-paragraph-article-button-hotspot", 7 selector: "comment-paragraph-article-button-hotspot",
7 templateUrl: "plugins/comment_paragraph/hotspot/comment-paragraph-article-button.html", 8 templateUrl: "plugins/comment_paragraph/hotspot/comment-paragraph-article-button.html",
8 }) 9 })
9 -@Inject("$scope", CommentParagraphService) 10 +@Inject("$scope", CommentParagraphService, CommentParagraphEventService)
10 @Hotspot("article_extra_toolbar_buttons") 11 @Hotspot("article_extra_toolbar_buttons")
11 export class CommentParagraphArticleButtonHotspotComponent { 12 export class CommentParagraphArticleButtonHotspotComponent {
12 13
13 @Input() article: noosfero.Article; 14 @Input() article: noosfero.Article;
14 15
15 - constructor(private $scope: ng.IScope, private commentParagraphService: CommentParagraphService) { } 16 + constructor(private $scope: ng.IScope,
  17 + private commentParagraphService: CommentParagraphService,
  18 + private commentParagraphEventService: CommentParagraphEventService) { }
16 19
17 deactivateCommentParagraph() { 20 deactivateCommentParagraph() {
18 this.commentParagraphService.deactivateCommentParagraph(this.article).then((result: noosfero.RestResult<noosfero.Article>) => { 21 this.commentParagraphService.deactivateCommentParagraph(this.article).then((result: noosfero.RestResult<noosfero.Article>) => {
19 this.article = result.data; 22 this.article = result.data;
  23 + this.commentParagraphEventService.toggleCommentParagraph(this.article);
20 }); 24 });
21 } 25 }
22 26
23 activateCommentParagraph() { 27 activateCommentParagraph() {
24 this.commentParagraphService.activateCommentParagraph(this.article).then((result: noosfero.RestResult<noosfero.Article>) => { 28 this.commentParagraphService.activateCommentParagraph(this.article).then((result: noosfero.RestResult<noosfero.Article>) => {
25 this.article = result.data; 29 this.article = result.data;
  30 + this.commentParagraphEventService.toggleCommentParagraph(this.article);
26 }); 31 });
27 } 32 }
28 } 33 }