diff --git a/src/lib/ng-noosfero-api/http/restangular_service.spec.ts b/src/lib/ng-noosfero-api/http/restangular_service.spec.ts index 40bf906..363154e 100644 --- a/src/lib/ng-noosfero-api/http/restangular_service.spec.ts +++ b/src/lib/ng-noosfero-api/http/restangular_service.spec.ts @@ -207,4 +207,27 @@ describe("Restangular Service - base Class", () => { $httpBackend.flush(); }); -}); \ No newline at end of file + it("post('customPath', rootObject) calls POST /rootObjects/1/customPath", (done) => { + let rootObj: RootObjectModel = rootObjectRestService.getElement(1); + $httpBackend.expectPOST("/api/v1/rootObjects/1/customPath").respond(201, { object: { attr: 1, rootId: 1 } }); + objectRestService.post('customPath', rootObj).then((result: noosfero.RestResult) => { + expect(result.data).toBeDefined(); + expect((result.data).attr).toEqual(1); + expect((result.data).rootId).toEqual(1); + done(); + }); + $httpBackend.flush(); + }); + + it("post('customPath') calls POST /objects/customPath", (done) => { + $httpBackend.expectPOST("/api/v1/objects/customPath").respond(201, { object: { attr: 1, rootId: 1 } }); + objectRestService.post('customPath').then((result: noosfero.RestResult) => { + expect(result.data).toBeDefined(); + expect((result.data).attr).toEqual(1); + expect((result.data).rootId).toEqual(1); + done(); + }); + $httpBackend.flush(); + }); + +}); diff --git a/src/lib/ng-noosfero-api/http/restangular_service.ts b/src/lib/ng-noosfero-api/http/restangular_service.ts index dc93594..46db39b 100644 --- a/src/lib/ng-noosfero-api/http/restangular_service.ts +++ b/src/lib/ng-noosfero-api/http/restangular_service.ts @@ -261,6 +261,22 @@ export abstract class RestangularService { return deferred.promise; } + + public post(path: string, rootElement?: restangular.IElement, data?: any, headers?: any): ng.IPromise> { + let deferred = this.$q.defer>(); + let restRequest: ng.IPromise; + + if (rootElement) { + restRequest = rootElement.customPOST(data, path, headers); + } else { + restRequest = this.baseResource.customPOST(data, path, headers); + } + restRequest + .then(this.getHandleSuccessFunction(deferred)) + .catch(this.getHandleErrorFunction(deferred)); + return deferred.promise; + } + /** * Returns a Restangular IElement representing the */ diff --git a/src/lib/ng-noosfero-api/interfaces/article.ts b/src/lib/ng-noosfero-api/interfaces/article.ts index 17c97df..4ca2e4c 100644 --- a/src/lib/ng-noosfero-api/interfaces/article.ts +++ b/src/lib/ng-noosfero-api/interfaces/article.ts @@ -1,13 +1,14 @@ namespace noosfero { - export interface Article extends RestModel { + export interface Article extends RestModel { path: string; profile: Profile; type: string; - parent: Article; + parent: Article; body: string; title: string; name: string; published: boolean; + setting: any; } -} +} \ No newline at end of file diff --git a/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts b/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts index 17da9ed..48d9adc 100644 --- a/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts +++ b/src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts @@ -11,4 +11,8 @@ export class AllowCommentComponent { @Input() content: string; @Input() paragraphUuid: string; @Input() article: noosfero.Article; + + isActivated() { + return this.article.setting.comment_paragraph_plugin_activate; + } } diff --git a/src/plugins/comment_paragraph/allow-comment/allow-comment.html b/src/plugins/comment_paragraph/allow-comment/allow-comment.html index eb55ddc..6a76794 100644 --- a/src/plugins/comment_paragraph/allow-comment/allow-comment.html +++ b/src/plugins/comment_paragraph/allow-comment/allow-comment.html @@ -1,4 +1,4 @@
-
+
diff --git a/src/plugins/comment_paragraph/hotspot/article-button.html b/src/plugins/comment_paragraph/hotspot/article-button.html deleted file mode 100644 index 62bd890..0000000 --- a/src/plugins/comment_paragraph/hotspot/article-button.html +++ /dev/null @@ -1,2 +0,0 @@ -Enable -Disable diff --git a/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts b/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts index 55eabb0..6d9f0ad 100644 --- a/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts +++ b/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts @@ -1,15 +1,28 @@ import { Input, Inject, Component } from "ng-forward"; import {Hotspot} from "../../../app/hotspot/hotspot.decorator"; +import {CommentParagraphService} from "../http/comment-paragraph.service"; @Component({ selector: "comment-paragraph-article-button-hotspot", - templateUrl: "plugins/comment_paragraph/hotspot/article-button.html", + templateUrl: "plugins/comment_paragraph/hotspot/comment-paragraph-article-button.html", }) -@Inject("$scope") +@Inject("$scope", CommentParagraphService) @Hotspot("article_extra_toolbar_buttons") export class CommentParagraphArticleButtonHotspotComponent { @Input() article: noosfero.Article; - constructor(private $scope: ng.IScope) { } + constructor(private $scope: ng.IScope, private commentParagraphService: CommentParagraphService) { } + + deactivateCommentParagraph() { + this.commentParagraphService.deactivateCommentParagraph(this.article).then((result: noosfero.RestResult) => { + this.article = result.data; + }); + } + + activateCommentParagraph() { + this.commentParagraphService.activateCommentParagraph(this.article).then((result: noosfero.RestResult) => { + this.article = result.data; + }); + } } diff --git a/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.html b/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.html new file mode 100644 index 0000000..b0896f1 --- /dev/null +++ b/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.html @@ -0,0 +1,2 @@ +Enable +Disable diff --git a/src/plugins/comment_paragraph/http/comment-paragraph.service.ts b/src/plugins/comment_paragraph/http/comment-paragraph.service.ts index c01415a..14c3dc0 100644 --- a/src/plugins/comment_paragraph/http/comment-paragraph.service.ts +++ b/src/plugins/comment_paragraph/http/comment-paragraph.service.ts @@ -31,4 +31,14 @@ export class CommentParagraphService extends RestangularServicearticle.id); return this.create(comment, articleElement, null, { 'Content-Type': 'application/json' }, false); } + + activateCommentParagraph(article: noosfero.Article) { + let articleElement = this.articleService.getElement(article.id); + return this.articleService.post("comment_paragraph_plugin/activate", articleElement); + } + + deactivateCommentParagraph(article: noosfero.Article) { + let articleElement = this.articleService.getElement(article.id); + return this.articleService.post("comment_paragraph_plugin/deactivate", articleElement); + } } diff --git a/src/plugins/comment_paragraph/side-comments/side-comments.component.ts b/src/plugins/comment_paragraph/side-comments/side-comments.component.ts index 4b47431..8ed147c 100644 --- a/src/plugins/comment_paragraph/side-comments/side-comments.component.ts +++ b/src/plugins/comment_paragraph/side-comments/side-comments.component.ts @@ -19,7 +19,7 @@ export class SideCommentsComponent extends CommentsComponent { ngOnInit() { super.ngOnInit(); - this.newComment['paragraph_uuid'] = this.paragraphUuid; + (this.newComment).paragraph_uuid = this.paragraphUuid; } loadComments() { -- libgit2 0.21.2