Commit 4840baa945a854c7bc2f268cf4d4f1ed627bde59
Committed by
Michel Felipe

1 parent
f98ac330
Exists in
master
and in
26 other branches
Add paragraph uuid in comment form
Showing
5 changed files
with
64 additions
and
3 deletions
Show diff stats
src/app/article/comment/post-comment/post-comment.html
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | </div> | 8 | </div> |
9 | <div class="media-body"> | 9 | <div class="media-body"> |
10 | <textarea class="form-control custom-control" rows="1" ng-model="ctrl.comment.body" placeholder="{{'comment.post.placeholder' | translate}}"></textarea> | 10 | <textarea class="form-control custom-control" rows="1" ng-model="ctrl.comment.body" placeholder="{{'comment.post.placeholder' | translate}}"></textarea> |
11 | - <noosfero-hotspot-comment-form [comment]="ctrl.comment"></noosfero-hotspot-comment-form> | 11 | + <noosfero-hotspot-comment-form [comment]="ctrl.comment" [parent]="ctrl.parent"></noosfero-hotspot-comment-form> |
12 | <button ng-show="ctrl.comment.body" type="submit" class="btn btn-default pull-right ng-hide" ng-click="ctrl.save()">{{"comment.post" | translate}}</button> | 12 | <button ng-show="ctrl.comment.body" type="submit" class="btn btn-default pull-right ng-hide" ng-click="ctrl.save()">{{"comment.post" | translate}}</button> |
13 | </div> | 13 | </div> |
14 | </div> | 14 | </div> |
src/app/hotspot/comment-form-hotspot.component.ts
@@ -11,6 +11,7 @@ import {PluginHotspot} from "./plugin-hotspot"; | @@ -11,6 +11,7 @@ import {PluginHotspot} from "./plugin-hotspot"; | ||
11 | export class CommentFormHotspotComponent extends PluginHotspot { | 11 | export class CommentFormHotspotComponent extends PluginHotspot { |
12 | 12 | ||
13 | @Input() comment: noosfero.Comment; | 13 | @Input() comment: noosfero.Comment; |
14 | + @Input() parent: noosfero.Comment; | ||
14 | 15 | ||
15 | constructor( | 16 | constructor( |
16 | private $element: any, | 17 | private $element: any, |
@@ -20,6 +21,6 @@ export class CommentFormHotspotComponent extends PluginHotspot { | @@ -20,6 +21,6 @@ export class CommentFormHotspotComponent extends PluginHotspot { | ||
20 | } | 21 | } |
21 | 22 | ||
22 | addHotspot(directiveName: string) { | 23 | addHotspot(directiveName: string) { |
23 | - this.$element.append(this.$compile('<' + directiveName + ' [comment]="ctrl.comment"></' + directiveName + '>')(this.$scope)); | 24 | + this.$element.append(this.$compile('<' + directiveName + ' [comment]="ctrl.comment" [parent]="ctrl.parent"></' + directiveName + '>')(this.$scope)); |
24 | } | 25 | } |
25 | } | 26 | } |
src/plugins/comment_paragraph/hotspot/comment-paragraph-form.component.ts
0 → 100644
@@ -0,0 +1,26 @@ | @@ -0,0 +1,26 @@ | ||
1 | +import { Inject, Input, Component } from "ng-forward"; | ||
2 | +import {Hotspot} from "../../../app/hotspot/hotspot.decorator"; | ||
3 | + | ||
4 | +@Component({ | ||
5 | + selector: "comment-paragraph-form-hotspot", | ||
6 | + template: "<span></span>", | ||
7 | +}) | ||
8 | +@Hotspot("comment_form_extra_contents") | ||
9 | +@Inject("$scope") | ||
10 | +export class CommentParagraphFormHotspotComponent { | ||
11 | + | ||
12 | + @Input() comment: noosfero.Comment; | ||
13 | + @Input() parent: noosfero.Comment; | ||
14 | + | ||
15 | + constructor(private $scope: ng.IScope) { } | ||
16 | + | ||
17 | + ngOnInit() { | ||
18 | + this.$scope.$watch(() => { | ||
19 | + return this.parent; | ||
20 | + }, () => { | ||
21 | + if (this.parent && (<any>this.parent).paragraph_uuid) { | ||
22 | + (<any>this.comment).paragraph_uuid = (<any>this.parent).paragraph_uuid; | ||
23 | + } | ||
24 | + }); | ||
25 | + } | ||
26 | +} |
src/plugins/comment_paragraph/hotspot/comment-paragraph-from.component.spec.ts
0 → 100644
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +import {CommentParagraphFormHotspotComponent} from "./comment-paragraph-form.component"; | ||
2 | +import {ComponentTestHelper, createClass} from '../../../spec/component-test-helper'; | ||
3 | +import * as helpers from "../../../spec/helpers"; | ||
4 | +import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; | ||
5 | + | ||
6 | +let htmlTemplate = '<comment-paragraph-form-hotspot [comment]="ctrl.comment" [parent]="ctrl.parent"></comment-paragraph-form-hotspot>'; | ||
7 | + | ||
8 | +describe("Components", () => { | ||
9 | + describe("Comment Paragraph Form Hotspot Component", () => { | ||
10 | + | ||
11 | + let helper: ComponentTestHelper; | ||
12 | + | ||
13 | + beforeEach(angular.mock.module("templates")); | ||
14 | + | ||
15 | + beforeEach((done) => { | ||
16 | + let cls = createClass({ | ||
17 | + template: htmlTemplate, | ||
18 | + directives: [CommentParagraphFormHotspotComponent], | ||
19 | + providers: [], | ||
20 | + properties: { | ||
21 | + comment: {} | ||
22 | + } | ||
23 | + }); | ||
24 | + helper = new ComponentTestHelper(cls, done); | ||
25 | + }); | ||
26 | + | ||
27 | + it('set paragraph uuid when parent has it setted', () => { | ||
28 | + helper.component.parent = { paragraph_uuid: 'uuid' }; | ||
29 | + helper.detectChanges(); | ||
30 | + expect((<any>helper.component.comment).paragraph_uuid).toEqual('uuid'); | ||
31 | + }); | ||
32 | + }); | ||
33 | +}); |
src/plugins/comment_paragraph/index.ts
1 | import {AllowCommentComponent} from "./allow-comment/allow-comment.component"; | 1 | import {AllowCommentComponent} from "./allow-comment/allow-comment.component"; |
2 | import {CommentParagraphArticleButtonHotspotComponent} from "./hotspot/comment-paragraph-article-button.component"; | 2 | import {CommentParagraphArticleButtonHotspotComponent} from "./hotspot/comment-paragraph-article-button.component"; |
3 | +import {CommentParagraphFormHotspotComponent} from "./hotspot/comment-paragraph-form.component"; | ||
3 | 4 | ||
4 | export let mainComponents: any = [AllowCommentComponent]; | 5 | export let mainComponents: any = [AllowCommentComponent]; |
5 | -export let hotspots: any = [CommentParagraphArticleButtonHotspotComponent]; | 6 | +export let hotspots: any = [CommentParagraphArticleButtonHotspotComponent, CommentParagraphFormHotspotComponent]; |