From 56a44bd230b391ce452ab65797747ffa38272ec2 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 7 Apr 2016 18:08:50 -0300 Subject: [PATCH] Create infra for plugins hotspots --- src/app/article/article-default-view.component.ts | 4 +++- src/app/article/article.html | 4 +--- src/app/article/comment/post-comment/post-comment.component.ts | 16 ++++++++++------ src/app/article/comment/post-comment/post-comment.html | 1 + src/app/hotspot/article-toolbar-hotspot.component.ts | 25 +++++++++++++++++++++++++ src/app/hotspot/comment-form-hotspot.component.ts | 25 +++++++++++++++++++++++++ src/app/hotspot/hotspot.decorator.ts | 5 +++++ src/app/hotspot/plugin-hotspot.ts | 19 +++++++++++++++++++ src/app/main/main.component.ts | 4 ++-- src/plugins/comment_paragraph/hotspot/article-button.html | 2 ++ src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts | 15 +++++++++++++++ src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts | 21 +++++++++++++++++++++ src/plugins/comment_paragraph/index.ts | 3 +++ src/plugins/comment_paragraph/side-comments/side-comments.component.ts | 2 +- src/plugins/index.ts | 3 +++ 15 files changed, 136 insertions(+), 13 deletions(-) create mode 100644 src/app/hotspot/article-toolbar-hotspot.component.ts create mode 100644 src/app/hotspot/comment-form-hotspot.component.ts create mode 100644 src/app/hotspot/hotspot.decorator.ts create mode 100644 src/app/hotspot/plugin-hotspot.ts create mode 100644 src/plugins/comment_paragraph/hotspot/article-button.html create mode 100644 src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts create mode 100644 src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts diff --git a/src/app/article/article-default-view.component.ts b/src/app/article/article-default-view.component.ts index 58d5142..d5a832e 100644 --- a/src/app/article/article-default-view.component.ts +++ b/src/app/article/article-default-view.component.ts @@ -2,6 +2,7 @@ import { bundle, Input, Inject, Component, Directive } from 'ng-forward'; import {ArticleBlogComponent} from "./types/blog/blog.component"; import {CommentsComponent} from "./comment/comments.component"; import {MacroDirective} from "./macro/macro.directive"; +import {ArticleToolbarHotspotComponent} from "../hotspot/article-toolbar-hotspot.component"; /** * @ngdoc controller @@ -31,7 +32,8 @@ export class ArticleDefaultViewComponent { @Component({ selector: 'noosfero-article', template: 'not-used', - directives: [ArticleDefaultViewComponent, ArticleBlogComponent, CommentsComponent, MacroDirective] + directives: [ArticleDefaultViewComponent, ArticleBlogComponent, + CommentsComponent, MacroDirective, ArticleToolbarHotspotComponent] }) @Inject("$element", "$scope", "$injector", "$compile") export class ArticleViewComponent { diff --git a/src/app/article/article.html b/src/app/article/article.html index c82e068..bba9bdc 100644 --- a/src/app/article/article.html +++ b/src/app/article/article.html @@ -4,9 +4,7 @@
- - {{"article.actions.edit" | translate}} - +
diff --git a/src/app/article/comment/post-comment/post-comment.component.ts b/src/app/article/comment/post-comment/post-comment.component.ts index 343eea4..de25eda 100644 --- a/src/app/article/comment/post-comment/post-comment.component.ts +++ b/src/app/article/comment/post-comment/post-comment.component.ts @@ -1,26 +1,30 @@ -import { Inject, Input, Output, EventEmitter, Component } from 'ng-forward'; +import { Inject, Input, Component } from 'ng-forward'; import { CommentService } from "../../../../lib/ng-noosfero-api/http/comment.service"; import { NotificationService } from "../../../shared/services/notification.service"; import { SessionService } from "../../../login"; +import { PostCommentEventService } from "./post-comment-event.service"; +import { CommentFormHotspotComponent } from "../../../hotspot/comment-form-hotspot.component"; @Component({ selector: 'noosfero-post-comment', templateUrl: 'app/article/comment/post-comment/post-comment.html', - outputs: ['commentSaved'] + directives: [CommentFormHotspotComponent] }) -@Inject(CommentService, NotificationService, SessionService) +@Inject(CommentService, NotificationService, SessionService, PostCommentEventService) export class PostCommentComponent { + public static EVENT_COMMENT_RECEIVED = "comment.received"; + @Input() article: noosfero.Article; @Input() parent: noosfero.Comment; - @Output() commentSaved: EventEmitter = new EventEmitter(); comment = {}; private currentUser: noosfero.User; constructor(private commentService: CommentService, private notificationService: NotificationService, - private session: SessionService) { + private session: SessionService, + private postCommentEventService: PostCommentEventService) { this.currentUser = this.session.currentUser(); } @@ -29,7 +33,7 @@ export class PostCommentComponent { this.comment.reply_of_id = this.parent.id; } this.commentService.createInArticle(this.article, this.comment).then((result: noosfero.RestResult) => { - this.commentSaved.next(result.data); + this.postCommentEventService.emit(result.data); this.comment.body = ""; this.notificationService.success({ title: "comment.post.success.title", message: "comment.post.success.message" }); }); diff --git a/src/app/article/comment/post-comment/post-comment.html b/src/app/article/comment/post-comment/post-comment.html index 642680e..dc32447 100644 --- a/src/app/article/comment/post-comment/post-comment.html +++ b/src/app/article/comment/post-comment/post-comment.html @@ -8,6 +8,7 @@
+
diff --git a/src/app/hotspot/article-toolbar-hotspot.component.ts b/src/app/hotspot/article-toolbar-hotspot.component.ts new file mode 100644 index 0000000..ba492a3 --- /dev/null +++ b/src/app/hotspot/article-toolbar-hotspot.component.ts @@ -0,0 +1,25 @@ +import {Component, Input, Inject} from "ng-forward"; +import * as plugins from "../../plugins"; +import {dasherize} from "ng-forward/cjs/util/helpers"; +import {PluginHotspot} from "./plugin-hotspot"; + +@Component({ + selector: "noosfero-hotspot-article-toolbar", + template: "" +}) +@Inject("$element", "$scope", "$compile") +export class ArticleToolbarHotspotComponent extends PluginHotspot { + + @Input() article: noosfero.Article; + + constructor( + private $element: any, + private $scope: ng.IScope, + private $compile: ng.ICompileService) { + super("article_extra_toolbar_buttons"); + } + + addHotspot(directiveName: string) { + this.$element.append(this.$compile('<' + directiveName + ' [article]="ctrl.article">')(this.$scope)); + } +} diff --git a/src/app/hotspot/comment-form-hotspot.component.ts b/src/app/hotspot/comment-form-hotspot.component.ts new file mode 100644 index 0000000..3308a02 --- /dev/null +++ b/src/app/hotspot/comment-form-hotspot.component.ts @@ -0,0 +1,25 @@ +import {Component, Input, Inject} from "ng-forward"; +import * as plugins from "../../plugins"; +import {dasherize} from "ng-forward/cjs/util/helpers"; +import {PluginHotspot} from "./plugin-hotspot"; + +@Component({ + selector: "noosfero-hotspot-comment-form", + template: "" +}) +@Inject("$element", "$scope", "$compile") +export class CommentFormHotspotComponent extends PluginHotspot { + + @Input() comment: noosfero.Comment; + + constructor( + private $element: any, + private $scope: ng.IScope, + private $compile: ng.ICompileService) { + super("comment_form_extra_contents"); + } + + addHotspot(directiveName: string) { + this.$element.append(this.$compile('<' + directiveName + ' [comment]="ctrl.comment">')(this.$scope)); + } +} diff --git a/src/app/hotspot/hotspot.decorator.ts b/src/app/hotspot/hotspot.decorator.ts new file mode 100644 index 0000000..21d1e16 --- /dev/null +++ b/src/app/hotspot/hotspot.decorator.ts @@ -0,0 +1,5 @@ +export function Hotspot(hotspotName: string) { + return (target: any) => { + target['hotspot'] = hotspotName; + } +} diff --git a/src/app/hotspot/plugin-hotspot.ts b/src/app/hotspot/plugin-hotspot.ts new file mode 100644 index 0000000..87a4852 --- /dev/null +++ b/src/app/hotspot/plugin-hotspot.ts @@ -0,0 +1,19 @@ +import {Component, Input, Inject} from "ng-forward"; +import * as plugins from "../../plugins"; +import {dasherize} from "ng-forward/cjs/util/helpers"; + +export abstract class PluginHotspot { + + constructor(protected hotspot: string) { } + + ngOnInit() { + for (let component of plugins.hotspots) { + if (component.hotspot === this.hotspot) { + let directiveName = dasherize(component.name.replace('Component', '')); + this.addHotspot(directiveName); + } + } + } + + abstract addHotspot(directiveName: string): any; +} diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index 6dd5363..825ba82 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -1,3 +1,4 @@ +import * as plugins from "../../plugins"; import {bundle, Component, StateConfig, Inject} from "ng-forward"; import {ArticleBlogComponent} from "./../article/types/blog/blog.component"; @@ -33,7 +34,6 @@ import {SidebarComponent} from "../layout/sidebar/sidebar.component"; import {MainBlockComponent} from "../layout/blocks/main-block/main-block.component"; import {HtmlEditorComponent} from "../shared/components/html-editor/html-editor.component"; -import * as plugins from "../../plugins"; /** * @ngdoc controller @@ -94,7 +94,7 @@ export class EnvironmentContent { LinkListBlockComponent, CommunitiesBlockComponent, HtmlEditorComponent, MainBlockComponent, RecentDocumentsBlockComponent, Navbar, SidebarComponent, ProfileImageBlockComponent, MembersBlockComponent, NoosferoTemplate, DateFormat, RawHTMLBlockComponent - ].concat(plugins.mainComponents), + ].concat(plugins.mainComponents).concat(plugins.hotspots), providers: [AuthService, SessionService, NotificationService, BodyStateClassesService] }) @StateConfig([ diff --git a/src/plugins/comment_paragraph/hotspot/article-button.html b/src/plugins/comment_paragraph/hotspot/article-button.html new file mode 100644 index 0000000..62bd890 --- /dev/null +++ b/src/plugins/comment_paragraph/hotspot/article-button.html @@ -0,0 +1,2 @@ +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 new file mode 100644 index 0000000..55eabb0 --- /dev/null +++ b/src/plugins/comment_paragraph/hotspot/comment-paragraph-article-button.component.ts @@ -0,0 +1,15 @@ +import { Input, Inject, Component } from "ng-forward"; +import {Hotspot} from "../../../app/hotspot/hotspot.decorator"; + +@Component({ + selector: "comment-paragraph-article-button-hotspot", + templateUrl: "plugins/comment_paragraph/hotspot/article-button.html", +}) +@Inject("$scope") +@Hotspot("article_extra_toolbar_buttons") +export class CommentParagraphArticleButtonHotspotComponent { + + @Input() article: noosfero.Article; + + constructor(private $scope: ng.IScope) { } +} diff --git a/src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts b/src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts new file mode 100644 index 0000000..d666413 --- /dev/null +++ b/src/plugins/comment_paragraph/hotspot/comment-paragraph-uuid-hotspot.component.ts @@ -0,0 +1,21 @@ +import { Input, Inject, Component } from "ng-forward"; +import {Hotspot} from "../../../app/hotspot/hotspot.decorator"; + +@Component({ + selector: "comment-paragraph-uuid-hotspot", + template: "", +}) +@Inject("$scope") +@Hotspot("comment_form_extra_contents") +export class CommentParagraphUuidHotspotComponent { + + @Input() comment: noosfero.Comment; + + constructor(private $scope: ng.IScope) { } + + ngOnInit() { + this.$scope.$watch("comment", () => { + this.comment['paragraph_uuid'] = "???"; + }); + } +} diff --git a/src/plugins/comment_paragraph/index.ts b/src/plugins/comment_paragraph/index.ts index 0d4d08d..9dc43ee 100644 --- a/src/plugins/comment_paragraph/index.ts +++ b/src/plugins/comment_paragraph/index.ts @@ -1,3 +1,6 @@ import {AllowCommentComponent} from "./allow-comment/allow-comment.component"; +import {CommentParagraphUuidHotspotComponent} from "./hotspot/comment-paragraph-uuid-hotspot.component"; +import {CommentParagraphArticleButtonHotspotComponent} from "./hotspot/comment-paragraph-article-button.component"; export let mainComponents: any = [AllowCommentComponent]; +export let hotspots: any = [CommentParagraphUuidHotspotComponent, CommentParagraphArticleButtonHotspotComponent]; 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 9f7b126..a8c6d88 100644 --- a/src/plugins/comment_paragraph/side-comments/side-comments.component.ts +++ b/src/plugins/comment_paragraph/side-comments/side-comments.component.ts @@ -1,4 +1,4 @@ -import {Component, Inject, Input} from "ng-forward"; +import {Component, Inject, Input, Output} from "ng-forward"; import {CommentsComponent} from "../../../app/article/comment/comments.component"; import {CommentService} from "../../../lib/ng-noosfero-api/http/comment.service"; import {CommentParagraphService} from "../http/comment-paragraph.service"; diff --git a/src/plugins/index.ts b/src/plugins/index.ts index 1a13cab..8e0ae15 100644 --- a/src/plugins/index.ts +++ b/src/plugins/index.ts @@ -2,3 +2,6 @@ import * as commentParagraph from "./comment_paragraph"; export let mainComponents: any = []; mainComponents = mainComponents.concat(commentParagraph.mainComponents); + +export let hotspots: any = []; +hotspots = hotspots.concat(commentParagraph.hotspots); -- libgit2 0.21.2