diff --git a/src/app/article/article-default-view.component.ts b/src/app/article/article-default-view.component.ts index f8fe0ee..39076df 100644 --- a/src/app/article/article-default-view.component.ts +++ b/src/app/article/article-default-view.component.ts @@ -1,5 +1,6 @@ import { bundle, Input, Inject, Component, Directive } from 'ng-forward'; import {ArticleBlogComponent} from "./types/blog/blog.component"; +import {CommentsComponent} from "./comment/comments.component"; /** * @ngdoc controller @@ -29,7 +30,7 @@ export class ArticleDefaultViewComponent { @Component({ selector: 'noosfero-article', template: 'not-used', - directives: [ArticleDefaultViewComponent, ArticleBlogComponent] + directives: [ArticleDefaultViewComponent, ArticleBlogComponent, CommentsComponent] }) @Inject("$element", "$scope", "$injector", "$compile") export class ArticleViewComponent { diff --git a/src/app/article/article.html b/src/app/article/article.html index 0a94109..ded7a7c 100644 --- a/src/app/article/article.html +++ b/src/app/article/article.html @@ -20,4 +20,6 @@
+ + diff --git a/src/app/article/comment/comment.component.ts b/src/app/article/comment/comment.component.ts new file mode 100644 index 0000000..93e7386 --- /dev/null +++ b/src/app/article/comment/comment.component.ts @@ -0,0 +1,17 @@ +import { Input, Component } from 'ng-forward'; + +@Component({ + selector: 'comment', + templateUrl: 'app/article/comment/comment.html' +}) +export class CommentComponent { + + @Input() comment: noosfero.Comment; + @Input() article: noosfero.Article; + + showReply: boolean = false; + + reply() { + this.showReply = true; + } +} diff --git a/src/app/article/comment/comment.html b/src/app/article/comment/comment.html new file mode 100644 index 0000000..b1ede6d --- /dev/null +++ b/src/app/article/comment/comment.html @@ -0,0 +1,25 @@ +
+
+ + + +
+
+ +
{{ctrl.comment.title}}
+
{{ctrl.comment.body}}
+
+ + + +
diff --git a/src/app/article/comment/comment.scss b/src/app/article/comment/comment.scss new file mode 100644 index 0000000..b28e7cd --- /dev/null +++ b/src/app/article/comment/comment.scss @@ -0,0 +1,32 @@ +.comments { + .comment { + margin: 20px; + .date { + @extend .text-muted; + @extend .small; + margin-left: 8px; + } + .title { + font-weight: bold; + } + .media-left { + min-width: 40px; + } + .media-body { + background-color: #F9F9F9; + padding: 10px; + } + noosfero-profile-image { + img { + height: 30px; + width: 30px; + max-width: 30px; + display: inline-block; + @extend .img-circle; + } + i { + font-size: 1.7em; + } + } + } +} diff --git a/src/app/article/comment/comments.component.ts b/src/app/article/comment/comments.component.ts new file mode 100644 index 0000000..49b99d0 --- /dev/null +++ b/src/app/article/comment/comments.component.ts @@ -0,0 +1,24 @@ +import { Inject, Input, Component, provide } from 'ng-forward'; +import { PostCommentComponent } from "./post-comment.component"; +import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service"; +import { CommentComponent } from "./comment.component"; + +@Component({ + selector: 'comments', + templateUrl: 'app/article/comment/comments.html', + directives: [PostCommentComponent, CommentComponent] +}) +@Inject(CommentService) +export class CommentsComponent { + + comments: noosfero.Comment[]; + @Input() article: noosfero.Article; + + constructor(private commentService: CommentService) { } + + ngOnInit() { + this.commentService.getByArticle(this.article).then((result: noosfero.RestResult) => { + this.comments = result.data; + }); + } +} diff --git a/src/app/article/comment/comments.html b/src/app/article/comment/comments.html new file mode 100644 index 0000000..ac11b1d --- /dev/null +++ b/src/app/article/comment/comments.html @@ -0,0 +1,7 @@ +
+ + +
+ +
+
diff --git a/src/app/article/comment/post-comment.component.ts b/src/app/article/comment/post-comment.component.ts new file mode 100644 index 0000000..1992ac7 --- /dev/null +++ b/src/app/article/comment/post-comment.component.ts @@ -0,0 +1,27 @@ +import { Inject, Input, Component } from 'ng-forward'; +import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service"; +import { NotificationService } from "../../shared/services/notification.service"; + +@Component({ + selector: 'post-comment', + templateUrl: 'app/article/comment/post-comment.html' +}) +@Inject(CommentService, NotificationService) +export class PostCommentComponent { + + @Input() article: noosfero.Article; + comment: noosfero.Comment; + + @Input() replyOf: noosfero.Comment; + + constructor(private commentService: CommentService, private notificationService: NotificationService) { } + + save() { + if (this.replyOf) { + this.comment.reply_of_id = this.replyOf.id; + } + this.commentService.createInArticle(this.article, this.comment).then(() => { + this.notificationService.success({ title: "Good job!", message: "Comment saved!" }); + }); + } +} diff --git a/src/app/article/comment/post-comment.html b/src/app/article/comment/post-comment.html new file mode 100644 index 0000000..5d4f1b9 --- /dev/null +++ b/src/app/article/comment/post-comment.html @@ -0,0 +1,6 @@ +
+
+ +
+ +
diff --git a/src/languages/en.json b/src/languages/en.json index 806ab1d..902666b 100644 --- a/src/languages/en.json +++ b/src/languages/en.json @@ -22,5 +22,7 @@ "notification.error.default.title": "Oops...", "notification.profile.not_found": "Page not found", "notification.http_error.401.message": "Unauthorized", - "notification.http_error.500.message": "Server error" + "notification.http_error.500.message": "Server error", + "comment.post": "Post", + "comment.reply": "reply" } diff --git a/src/languages/pt.json b/src/languages/pt.json index c91d114..07c9e67 100644 --- a/src/languages/pt.json +++ b/src/languages/pt.json @@ -22,5 +22,7 @@ "notification.error.default.title": "Oops...", "notification.profile.not_found": "Página não encontrada", "notification.http_error.401.message": "Não autorizado", - "notification.http_error.500.message": "Erro no servidor" + "notification.http_error.500.message": "Erro no servidor", + "comment.post": "Postar", + "comment.reply": "responder" } diff --git a/src/lib/ng-noosfero-api/http/comment.service.ts b/src/lib/ng-noosfero-api/http/comment.service.ts new file mode 100644 index 0000000..ca1bbb9 --- /dev/null +++ b/src/lib/ng-noosfero-api/http/comment.service.ts @@ -0,0 +1,33 @@ +import { Injectable, Inject } from "ng-forward"; +import {RestangularService} from "./restangular_service"; +import {ArticleService} from "./article.service"; + +@Injectable() +@Inject("Restangular", "$q", "$log", ArticleService) +export class CommentService extends RestangularService { + + constructor(Restangular: restangular.IService, $q: ng.IQService, $log: ng.ILogService, protected articleService: ArticleService) { + super(Restangular, $q, $log); + } + + getResourcePath() { + return "comments"; + } + + getDataKeys() { + return { + singular: 'comment', + plural: 'comments' + }; + } + + getByArticle(article: noosfero.Article, params?: any): ng.IPromise> { + let articleElement = this.articleService.getElement(article.id); + return this.list(articleElement); + } + + createInArticle(article: noosfero.Article, comment: noosfero.Comment): ng.IPromise> { + let articleElement = this.articleService.getElement(article.id); + return articleElement.customPOST(comment, this.getResourcePath(), {}, { 'Content-Type': 'application/json' }); + } +} diff --git a/src/lib/ng-noosfero-api/interfaces/comment.ts b/src/lib/ng-noosfero-api/interfaces/comment.ts new file mode 100644 index 0000000..b14ac0c --- /dev/null +++ b/src/lib/ng-noosfero-api/interfaces/comment.ts @@ -0,0 +1,5 @@ +namespace noosfero { + export interface Comment extends RestModel { + reply_of_id: number; + } +} -- libgit2 0.21.2