comment-paragraph.service.ts
2.64 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { Injectable, Inject } from "ng-forward";
import {RestangularService} from "../../../lib/ng-noosfero-api/http/restangular_service";
import {ArticleService} from "../../../lib/ng-noosfero-api/http/article.service";
@Injectable()
@Inject("Restangular", "$q", "$log", ArticleService)
export class CommentParagraphService extends RestangularService<noosfero.Comment> {
private commentParagraphCountsPromise: ng.IPromise<any>;
constructor(Restangular: restangular.IService, $q: ng.IQService, $log: ng.ILogService, protected articleService: ArticleService) {
super(Restangular, $q, $log);
}
getResourcePath() {
return "comment_paragraph_plugin/comments";
}
getDataKeys() {
return {
singular: 'comment',
plural: 'comments'
};
}
getByArticle(article: noosfero.Article, params: any = {}): ng.IPromise<noosfero.RestResult<noosfero.Comment[]>> {
params['without_reply'] = true;
let articleElement = this.articleService.getElement(<number>article.id);
return this.list(articleElement, params);
}
createInArticle(article: noosfero.Article, comment: noosfero.Comment): ng.IPromise<noosfero.RestResult<noosfero.Comment>> {
let articleElement = this.articleService.getElement(<number>article.id);
return this.create(comment, articleElement, null, { 'Content-Type': 'application/json' }, false);
}
activateCommentParagraph(article: noosfero.Article) {
let articleElement = this.articleService.getElement(<number>article.id);
return this.articleService.post("comment_paragraph_plugin/activate", articleElement);
}
deactivateCommentParagraph(article: noosfero.Article) {
let articleElement = this.articleService.getElement(<number>article.id);
return this.articleService.post("comment_paragraph_plugin/deactivate", articleElement);
}
commentParagraphCount(article: noosfero.Article, paragraphUuid: string) {
return this.commentParagraphCounts(article).then((counts: any) => {
return counts[paragraphUuid];
});
}
private commentParagraphCounts(article: noosfero.Article) {
if (!this.commentParagraphCountsPromise) {
let articleElement = this.articleService.getElement(<number>article.id);
this.commentParagraphCountsPromise = articleElement.customGET("comment_paragraph_plugin/comments/count").then((response: restangular.IResponse) => {
return response.data;
}).catch(() => {
this.commentParagraphCountsPromise = null;
});
}
return this.commentParagraphCountsPromise;
}
}