comment.component.ts
1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Inject, Input, Component, Output, EventEmitter } from 'ng-forward';
import { PostCommentComponent } from "./post-comment/post-comment.component";
import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service";
import { NotificationService } from "../../shared/services/notification.service";
@Component({
selector: 'noosfero-comment',
outputs: ['commentRemoved'],
templateUrl: 'app/article/comment/comment.html'
})
@Inject(CommentService, NotificationService)
export class CommentComponent {
@Input() comment: noosfero.CommentViewModel;
@Input() article: noosfero.Article;
@Input() displayActions = true;
@Input() displayReplies = true;
@Output() commentRemoved: EventEmitter<Comment> = new EventEmitter<Comment>();
showReply() {
return this.comment && this.comment.__show_reply === true;
}
constructor(private commentService: CommentService,
private notificationService: NotificationService) { }
reply() {
this.comment.__show_reply = !this.comment.__show_reply;
}
allowRemove() {
return true;
}
remove() {
this.notificationService.confirmation({ title: "comment.remove.confirmation.title", message: "comment.remove.confirmation.message" }, () => {
this.commentService.removeFromArticle(this.article, this.comment).then((result: noosfero.RestResult<noosfero.Comment>) => {
this.commentRemoved.next(this.comment);
this.notificationService.success({ title: "comment.remove.success.title", message: "comment.remove.success.message" });
});
});
}
}