Commit b77b920cac0ccb77ea6b5a8067d31006900b7c75
Committed by
Michel Felipe

1 parent
abdfbb35
Exists in
master
and in
26 other branches
Emit event when toggle comment paragraph in articles
Showing
3 changed files
with
39 additions
and
3 deletions
Show diff stats
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 | 2 | import {SideCommentsComponent} from "../side-comments/side-comments.component"; |
3 | +import {CommentParagraphEventService} from "../events/comment-paragraph-event.service"; | |
3 | 4 | |
4 | 5 | @Component({ |
5 | 6 | selector: "comment-paragraph-plugin-allow-comment", |
6 | 7 | templateUrl: "plugins/comment_paragraph/allow-comment/allow-comment.html", |
7 | 8 | directives: [SideCommentsComponent] |
8 | 9 | }) |
10 | +@Inject("$scope", CommentParagraphEventService) | |
9 | 11 | export class AllowCommentComponent { |
10 | 12 | |
11 | 13 | @Input() content: string; |
12 | 14 | @Input() paragraphUuid: string; |
13 | 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 | 26 | isActivated() { |
16 | 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 @@ |
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 | 1 | import { Input, Inject, Component } from "ng-forward"; |
2 | 2 | import {Hotspot} from "../../../app/hotspot/hotspot.decorator"; |
3 | 3 | import {CommentParagraphService} from "../http/comment-paragraph.service"; |
4 | +import {CommentParagraphEventService} from "../events/comment-paragraph-event.service"; | |
4 | 5 | |
5 | 6 | @Component({ |
6 | 7 | selector: "comment-paragraph-article-button-hotspot", |
7 | 8 | templateUrl: "plugins/comment_paragraph/hotspot/comment-paragraph-article-button.html", |
8 | 9 | }) |
9 | -@Inject("$scope", CommentParagraphService) | |
10 | +@Inject("$scope", CommentParagraphService, CommentParagraphEventService) | |
10 | 11 | @Hotspot("article_extra_toolbar_buttons") |
11 | 12 | export class CommentParagraphArticleButtonHotspotComponent { |
12 | 13 | |
13 | 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 | 20 | deactivateCommentParagraph() { |
18 | 21 | this.commentParagraphService.deactivateCommentParagraph(this.article).then((result: noosfero.RestResult<noosfero.Article>) => { |
19 | 22 | this.article = result.data; |
23 | + this.commentParagraphEventService.toggleCommentParagraph(this.article); | |
20 | 24 | }); |
21 | 25 | } |
22 | 26 | |
23 | 27 | activateCommentParagraph() { |
24 | 28 | this.commentParagraphService.activateCommentParagraph(this.article).then((result: noosfero.RestResult<noosfero.Article>) => { |
25 | 29 | this.article = result.data; |
30 | + this.commentParagraphEventService.toggleCommentParagraph(this.article); | |
26 | 31 | }); |
27 | 32 | } |
28 | 33 | } | ... | ... |