Commit abdfbb354e4604568eb87ab57c61dcee9a8525ab
Committed by
Michel Felipe

1 parent
5deddf45
Exists in
master
and in
26 other branches
Activate/deactivate comment paragraph in articles
Showing
10 changed files
with
78 additions
and
11 deletions
Show diff stats
src/lib/ng-noosfero-api/http/restangular_service.spec.ts
@@ -207,4 +207,27 @@ describe("Restangular Service - base Class", () => { | @@ -207,4 +207,27 @@ describe("Restangular Service - base Class", () => { | ||
207 | $httpBackend.flush(); | 207 | $httpBackend.flush(); |
208 | }); | 208 | }); |
209 | 209 | ||
210 | -}); | ||
211 | \ No newline at end of file | 210 | \ No newline at end of file |
211 | + it("post('customPath', rootObject) calls POST /rootObjects/1/customPath", (done) => { | ||
212 | + let rootObj: RootObjectModel = rootObjectRestService.getElement(1); | ||
213 | + $httpBackend.expectPOST("/api/v1/rootObjects/1/customPath").respond(201, { object: { attr: 1, rootId: 1 } }); | ||
214 | + objectRestService.post('customPath', rootObj).then((result: noosfero.RestResult<ObjectModel>) => { | ||
215 | + expect(result.data).toBeDefined(); | ||
216 | + expect((<any>result.data).attr).toEqual(1); | ||
217 | + expect((<any>result.data).rootId).toEqual(1); | ||
218 | + done(); | ||
219 | + }); | ||
220 | + $httpBackend.flush(); | ||
221 | + }); | ||
222 | + | ||
223 | + it("post('customPath') calls POST /objects/customPath", (done) => { | ||
224 | + $httpBackend.expectPOST("/api/v1/objects/customPath").respond(201, { object: { attr: 1, rootId: 1 } }); | ||
225 | + objectRestService.post('customPath').then((result: noosfero.RestResult<ObjectModel>) => { | ||
226 | + expect(result.data).toBeDefined(); | ||
227 | + expect((<any>result.data).attr).toEqual(1); | ||
228 | + expect((<any>result.data).rootId).toEqual(1); | ||
229 | + done(); | ||
230 | + }); | ||
231 | + $httpBackend.flush(); | ||
232 | + }); | ||
233 | + | ||
234 | +}); |
src/lib/ng-noosfero-api/http/restangular_service.ts
@@ -261,6 +261,22 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | @@ -261,6 +261,22 @@ export abstract class RestangularService<T extends noosfero.RestModel> { | ||
261 | return deferred.promise; | 261 | return deferred.promise; |
262 | } | 262 | } |
263 | 263 | ||
264 | + | ||
265 | + public post(path: string, rootElement?: restangular.IElement, data?: any, headers?: any): ng.IPromise<noosfero.RestResult<T>> { | ||
266 | + let deferred = this.$q.defer<noosfero.RestResult<T>>(); | ||
267 | + let restRequest: ng.IPromise<any>; | ||
268 | + | ||
269 | + if (rootElement) { | ||
270 | + restRequest = rootElement.customPOST(data, path, headers); | ||
271 | + } else { | ||
272 | + restRequest = this.baseResource.customPOST(data, path, headers); | ||
273 | + } | ||
274 | + restRequest | ||
275 | + .then(this.getHandleSuccessFunction(deferred)) | ||
276 | + .catch(this.getHandleErrorFunction(deferred)); | ||
277 | + return deferred.promise; | ||
278 | + } | ||
279 | + | ||
264 | /** | 280 | /** |
265 | * Returns a Restangular IElement representing the | 281 | * Returns a Restangular IElement representing the |
266 | */ | 282 | */ |
src/lib/ng-noosfero-api/interfaces/article.ts
1 | 1 | ||
2 | namespace noosfero { | 2 | namespace noosfero { |
3 | - export interface Article extends RestModel { | 3 | + export interface Article extends RestModel { |
4 | path: string; | 4 | path: string; |
5 | profile: Profile; | 5 | profile: Profile; |
6 | type: string; | 6 | type: string; |
7 | - parent: Article; | 7 | + parent: Article; |
8 | body: string; | 8 | body: string; |
9 | title: string; | 9 | title: string; |
10 | name: string; | 10 | name: string; |
11 | published: boolean; | 11 | published: boolean; |
12 | + setting: any; | ||
12 | } | 13 | } |
13 | -} | 14 | -} |
15 | +} | ||
14 | \ No newline at end of file | 16 | \ No newline at end of file |
src/plugins/comment_paragraph/allow-comment/allow-comment.component.ts
@@ -11,4 +11,8 @@ export class AllowCommentComponent { | @@ -11,4 +11,8 @@ export class AllowCommentComponent { | ||
11 | @Input() content: string; | 11 | @Input() content: string; |
12 | @Input() paragraphUuid: string; | 12 | @Input() paragraphUuid: string; |
13 | @Input() article: noosfero.Article; | 13 | @Input() article: noosfero.Article; |
14 | + | ||
15 | + isActivated() { | ||
16 | + return this.article.setting.comment_paragraph_plugin_activate; | ||
17 | + } | ||
14 | } | 18 | } |
src/plugins/comment_paragraph/allow-comment/allow-comment.html
1 | <div class="paragraph-content" ng-bind-html="ctrl.content"></div> | 1 | <div class="paragraph-content" ng-bind-html="ctrl.content"></div> |
2 | -<div class="actions"> | 2 | +<div ng-if="ctrl.isActivated()" class="actions"> |
3 | <a href="#" popover-placement="bottom" popover-trigger="outsideClick" uib-popover-template="'plugins/comment_paragraph/allow-comment/popover.html'" ng-click="ctrl.loadComments()"><i class="fa fa-fw fa-comments"></i></a> | 3 | <a href="#" popover-placement="bottom" popover-trigger="outsideClick" uib-popover-template="'plugins/comment_paragraph/allow-comment/popover.html'" ng-click="ctrl.loadComments()"><i class="fa fa-fw fa-comments"></i></a> |
4 | </div> | 4 | </div> |
src/plugins/comment_paragraph/hotspot/article-button.html
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 | 4 | ||
4 | @Component({ | 5 | @Component({ |
5 | selector: "comment-paragraph-article-button-hotspot", | 6 | selector: "comment-paragraph-article-button-hotspot", |
6 | - templateUrl: "plugins/comment_paragraph/hotspot/article-button.html", | 7 | + templateUrl: "plugins/comment_paragraph/hotspot/comment-paragraph-article-button.html", |
7 | }) | 8 | }) |
8 | -@Inject("$scope") | 9 | +@Inject("$scope", CommentParagraphService) |
9 | @Hotspot("article_extra_toolbar_buttons") | 10 | @Hotspot("article_extra_toolbar_buttons") |
10 | export class CommentParagraphArticleButtonHotspotComponent { | 11 | export class CommentParagraphArticleButtonHotspotComponent { |
11 | 12 | ||
12 | @Input() article: noosfero.Article; | 13 | @Input() article: noosfero.Article; |
13 | 14 | ||
14 | - constructor(private $scope: ng.IScope) { } | 15 | + constructor(private $scope: ng.IScope, private commentParagraphService: CommentParagraphService) { } |
16 | + | ||
17 | + deactivateCommentParagraph() { | ||
18 | + this.commentParagraphService.deactivateCommentParagraph(this.article).then((result: noosfero.RestResult<noosfero.Article>) => { | ||
19 | + this.article = result.data; | ||
20 | + }); | ||
21 | + } | ||
22 | + | ||
23 | + activateCommentParagraph() { | ||
24 | + this.commentParagraphService.activateCommentParagraph(this.article).then((result: noosfero.RestResult<noosfero.Article>) => { | ||
25 | + this.article = result.data; | ||
26 | + }); | ||
27 | + } | ||
15 | } | 28 | } |
src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.html
0 → 100644
@@ -0,0 +1,2 @@ | @@ -0,0 +1,2 @@ | ||
1 | +<a href='#' (click)="ctrl.activateCommentParagraph()" ng-show="!ctrl.article.setting.comment_paragraph_plugin_activate">Enable</a> | ||
2 | +<a href='#' (click)="ctrl.deactivateCommentParagraph()" ng-show="ctrl.article.setting.comment_paragraph_plugin_activate">Disable</a> |
src/plugins/comment_paragraph/http/comment-paragraph.service.ts
@@ -31,4 +31,14 @@ export class CommentParagraphService extends RestangularService<noosfero.Comment | @@ -31,4 +31,14 @@ export class CommentParagraphService extends RestangularService<noosfero.Comment | ||
31 | let articleElement = this.articleService.getElement(<number>article.id); | 31 | let articleElement = this.articleService.getElement(<number>article.id); |
32 | return this.create(comment, articleElement, null, { 'Content-Type': 'application/json' }, false); | 32 | return this.create(comment, articleElement, null, { 'Content-Type': 'application/json' }, false); |
33 | } | 33 | } |
34 | + | ||
35 | + activateCommentParagraph(article: noosfero.Article) { | ||
36 | + let articleElement = this.articleService.getElement(<number>article.id); | ||
37 | + return this.articleService.post("comment_paragraph_plugin/activate", articleElement); | ||
38 | + } | ||
39 | + | ||
40 | + deactivateCommentParagraph(article: noosfero.Article) { | ||
41 | + let articleElement = this.articleService.getElement(<number>article.id); | ||
42 | + return this.articleService.post("comment_paragraph_plugin/deactivate", articleElement); | ||
43 | + } | ||
34 | } | 44 | } |
src/plugins/comment_paragraph/side-comments/side-comments.component.ts
@@ -19,7 +19,7 @@ export class SideCommentsComponent extends CommentsComponent { | @@ -19,7 +19,7 @@ export class SideCommentsComponent extends CommentsComponent { | ||
19 | 19 | ||
20 | ngOnInit() { | 20 | ngOnInit() { |
21 | super.ngOnInit(); | 21 | super.ngOnInit(); |
22 | - this.newComment['paragraph_uuid'] = this.paragraphUuid; | 22 | + (<any>this.newComment).paragraph_uuid = this.paragraphUuid; |
23 | } | 23 | } |
24 | 24 | ||
25 | loadComments() { | 25 | loadComments() { |