diff --git a/src/app/article/comment/comment.component.spec.ts b/src/app/article/comment/comment.component.spec.ts index 4366f11..5ba026c 100644 --- a/src/app/article/comment/comment.component.spec.ts +++ b/src/app/article/comment/comment.component.spec.ts @@ -18,7 +18,11 @@ describe("Components", () => { }); function createComponent() { - let providers = helpers.provideFilters("translateFilter"); + let commentService = jasmine.createSpyObj("commentService", ["removeFromArticle"]); + let providers = [ + helpers.createProviderToValue('NotificationService', helpers.mocks.notificationService), + helpers.createProviderToValue("CommentService", commentService) + ].concat(helpers.provideFilters("translateFilter")); @Component({ selector: 'test-container-component', directives: [CommentComponent], template: htmlTemplate, providers: providers }) class ContainerComponent { diff --git a/src/app/article/comment/comment.component.ts b/src/app/article/comment/comment.component.ts index c3094c0..822b0f6 100644 --- a/src/app/article/comment/comment.component.ts +++ b/src/app/article/comment/comment.component.ts @@ -1,10 +1,13 @@ import { Inject, Input, Component, Output, EventEmitter } from 'ng-forward'; import { PostCommentComponent } from "./post-comment/post-comment.component"; +import { CommentService } from "../../../lib/ng-noosfero-api/http/comment.service"; +import { NotificationService } from "../../shared/services/notification.service"; @Component({ selector: 'noosfero-comment', templateUrl: 'app/article/comment/comment.html' }) +@Inject(CommentService, NotificationService) export class CommentComponent { @Input() comment: noosfero.CommentViewModel; @@ -16,11 +19,23 @@ export class CommentComponent { return this.comment && this.comment.__show_reply === true; } - constructor() { - } - + constructor(private commentService: CommentService, + private notificationService: NotificationService) { } reply() { this.comment.__show_reply = !this.comment.__show_reply; } + + allowRemove() { + return true; + } + + remove() { + this.notificationService.confirmation({ title: "comment.remove.confirmation.title", message: "comment.remove.confirmation.message" }, () => { + this.commentService.removeFromArticle(this.article, this.comment).then((result: noosfero.RestResult) => { + // FIXME send event + this.notificationService.success({ title: "comment.remove.success.title", message: "comment.remove.success.message" }); + }); + }); + } } diff --git a/src/app/article/comment/comment.html b/src/app/article/comment/comment.html index 868285d..0ea8a6f 100644 --- a/src/app/article/comment/comment.html +++ b/src/app/article/comment/comment.html @@ -18,9 +18,14 @@
{{ctrl.comment.title}}
{{ctrl.comment.body}}
- + + {{"comment.reply" | translate}} + + + {{"comment.remove" | translate}} +
diff --git a/src/app/article/comment/comment.scss b/src/app/article/comment/comment.scss index 246c178..b3e0b31 100644 --- a/src/app/article/comment/comment.scss +++ b/src/app/article/comment/comment.scss @@ -10,6 +10,22 @@ .title { font-weight: bold; } + .actions { + .action { + text-decoration: none; + &:first-child { + .bullet-separator { + display: none; + } + } + .bullet-separator { + font-size: 8px; + vertical-align: middle; + margin: 3px; + color: #B6C2CA; + } + } + } .media-left { min-width: 40px; } diff --git a/src/app/shared/services/notification.service.spec.ts b/src/app/shared/services/notification.service.spec.ts index 84ae614..f03ce83 100644 --- a/src/app/shared/services/notification.service.spec.ts +++ b/src/app/shared/services/notification.service.spec.ts @@ -20,10 +20,10 @@ describe("Components", () => { let component: NotificationService = new NotificationService(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService); component.error({ message: "message", title: "title" }); expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ - text: "message", title: "title", + text: "message", type: "error" - })); + }), null); done(); }); @@ -36,7 +36,7 @@ describe("Components", () => { expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ text: NotificationService.DEFAULT_ERROR_MESSAGE, type: "error" - })); + }), null); done(); }); @@ -48,7 +48,7 @@ describe("Components", () => { component.success({ title: "title", message: "message", timer: 1000 }); expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ type: "success" - })); + }), null); done(); }); @@ -60,7 +60,7 @@ describe("Components", () => { component.httpError(500, {}); expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ text: "notification.http_error.500.message" - })); + }), null); done(); }); @@ -73,7 +73,22 @@ describe("Components", () => { expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ type: "success", timer: NotificationService.DEFAULT_SUCCESS_TIMER - })); + }), null); + done(); + }); + + it("display a confirmation dialog when call confirmation method", done => { + let sweetAlert = jasmine.createSpyObj("sweetAlert", ["swal"]); + sweetAlert.swal = jasmine.createSpy("swal"); + + let component: NotificationService = new NotificationService(helpers.mocks.$log, sweetAlert, helpers.mocks.translatorService); + let func = () => { }; + component.confirmation({ title: "title", message: "message" }, func); + expect(sweetAlert.swal).toHaveBeenCalledWith(jasmine.objectContaining({ + title: "title", + text: "message", + type: "warning" + }), jasmine.any(Function)); done(); }); }); diff --git a/src/app/shared/services/notification.service.ts b/src/app/shared/services/notification.service.ts index 7a07685..438c416 100644 --- a/src/app/shared/services/notification.service.ts +++ b/src/app/shared/services/notification.service.ts @@ -36,15 +36,23 @@ export class NotificationService { this.showMessage({ title: title, text: message, timer: timer }); } - private showMessage({title, text, type = "success", timer = null, showConfirmButton = true}) { + confirmation({title, message, showCancelButton = true, type = "warning"}, confirmationFunction: Function) { + this.showMessage({ title: title, text: message, showCancelButton: showCancelButton, type: type, closeOnConfirm: false }, confirmationFunction); + } + + private showMessage({title, text, type = "success", timer = null, showConfirmButton = true, showCancelButton = false, closeOnConfirm = true}, confirmationFunction: Function = null) { this.$log.debug("Notification message:", title, text, type, this.translatorService.currentLanguage()); this.SweetAlert.swal({ title: this.translatorService.translate(title), text: this.translatorService.translate(text), type: type, timer: timer, - showConfirmButton: showConfirmButton - }); + showConfirmButton: showConfirmButton, + showCancelButton: showCancelButton, + closeOnConfirm: closeOnConfirm + }, confirmationFunction ? (isConfirm: boolean) => { + if (isConfirm) confirmationFunction(); + } : null); } } diff --git a/src/languages/en.json b/src/languages/en.json index d30aaa1..2030eb3 100644 --- a/src/languages/en.json +++ b/src/languages/en.json @@ -35,7 +35,12 @@ "comment.pagination.more": "More", "comment.post.success.title": "Good job!", "comment.post.success.message": "Comment saved!", + "comment.remove.success.title": "Good job!", + "comment.remove.success.message": "Comment removed!", + "comment.remove.confirmation.title": "Are you sure?", + "comment.remove.confirmation.message": "You will not be able to recover this comment!", "comment.reply": "reply", + "comment.remove": "remove", "article.actions.edit": "Edit", "article.actions.read_more": "Read More", "article.basic_editor.title": "Title", diff --git a/src/languages/pt.json b/src/languages/pt.json index 09d9562..1adf46d 100644 --- a/src/languages/pt.json +++ b/src/languages/pt.json @@ -35,7 +35,12 @@ "comment.pagination.more": "Mais", "comment.post.success.title": "Bom trabalho!", "comment.post.success.message": "Comentário salvo com sucesso!", + "comment.remove.success.title": "Bom trabalho!", + "comment.remove.success.message": "Comentário removido com sucesso!", + "comment.remove.confirmation.title": "Tem certeza?", + "comment.remove.confirmation.message": "Você não poderá recuperar o comentário removido!", "comment.reply": "responder", + "comment.remove": "remover", "article.actions.edit": "Editar", "article.actions.read_more": "Ler mais", "article.basic_editor.title": "Título", diff --git a/src/lib/ng-noosfero-api/http/comment.service.spec.ts b/src/lib/ng-noosfero-api/http/comment.service.spec.ts index 74bafa6..cd98bd5 100644 --- a/src/lib/ng-noosfero-api/http/comment.service.spec.ts +++ b/src/lib/ng-noosfero-api/http/comment.service.spec.ts @@ -40,6 +40,17 @@ describe("Services", () => { }); $httpBackend.flush(); }); + + it("should remove a comment from an article", (done) => { + let articleId = 1; + let comment: noosfero.Comment = { id: 2 }; + $httpBackend.expectDELETE(`/api/v1/articles/${articleId}/comments/${comment.id}`).respond(200, { comment: { id: 2 } }); + commentService.removeFromArticle({ id: articleId }, comment).then((result: noosfero.RestResult) => { + expect(result.data).toEqual({ id: 2 }); + done(); + }); + $httpBackend.flush(); + }); }); diff --git a/src/lib/ng-noosfero-api/http/comment.service.ts b/src/lib/ng-noosfero-api/http/comment.service.ts index 62e7146..0990576 100644 --- a/src/lib/ng-noosfero-api/http/comment.service.ts +++ b/src/lib/ng-noosfero-api/http/comment.service.ts @@ -31,4 +31,9 @@ export class CommentService extends RestangularService { let articleElement = this.articleService.getElement(article.id); return this.create(comment, articleElement, null, { 'Content-Type': 'application/json' }, false); } + + removeFromArticle(article: noosfero.Article, comment: noosfero.Comment): ng.IPromise> { + let articleElement = this.articleService.getElement(article.id); + return this.remove(comment, articleElement); + } } diff --git a/src/plugins/comment_paragraph/allow-comment/allow-comment.component.spec.ts b/src/plugins/comment_paragraph/allow-comment/allow-comment.component.spec.ts index a394338..1c9624a 100644 --- a/src/plugins/comment_paragraph/allow-comment/allow-comment.component.spec.ts +++ b/src/plugins/comment_paragraph/allow-comment/allow-comment.component.spec.ts @@ -57,7 +57,7 @@ describe("Components", () => { }); it('display button to side comments', () => { - expect(helper.all(".paragraph .actions a").length).toEqual(1); + expect(helper.all(".paragraph .paragraph-actions a").length).toEqual(1); }); it('set display to true when click in show paragraph', () => { diff --git a/src/plugins/comment_paragraph/allow-comment/allow-comment.html b/src/plugins/comment_paragraph/allow-comment/allow-comment.html index c853eb2..0c8525f 100644 --- a/src/plugins/comment_paragraph/allow-comment/allow-comment.html +++ b/src/plugins/comment_paragraph/allow-comment/allow-comment.html @@ -1,6 +1,6 @@