Commit d5a304a4ea340ad220de9d6b5a56826afc966567
Exists in
master
and in
18 other branches
merge with remove-article-confirmation. it closes issue #84
Showing
5 changed files
with
38 additions
and
9 deletions
Show diff stats
src/app/article/article-default-view-component.spec.ts
@@ -19,6 +19,7 @@ describe("Components", () => { | @@ -19,6 +19,7 @@ describe("Components", () => { | ||
19 | describe("Article Default View Component", () => { | 19 | describe("Article Default View Component", () => { |
20 | let helper: ComponentTestHelper<ArticleDefaultViewComponent>; | 20 | let helper: ComponentTestHelper<ArticleDefaultViewComponent>; |
21 | const defaultViewTemplate: string = '<noosfero-default-article [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-default-article>'; | 21 | const defaultViewTemplate: string = '<noosfero-default-article [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-default-article>'; |
22 | + let notificationService = helpers.mocks.notificationService; | ||
22 | let articleService: any = helpers.mocks.articleService; | 23 | let articleService: any = helpers.mocks.articleService; |
23 | let article = <noosfero.Article>{ | 24 | let article = <noosfero.Article>{ |
24 | id: 1, | 25 | id: 1, |
@@ -29,7 +30,8 @@ describe("Components", () => { | @@ -29,7 +30,8 @@ describe("Components", () => { | ||
29 | let state = <ng.ui.IStateService>jasmine.createSpyObj("state", ["go", "transitionTo"]); | 30 | let state = <ng.ui.IStateService>jasmine.createSpyObj("state", ["go", "transitionTo"]); |
30 | let providers = [ | 31 | let providers = [ |
31 | provide('$state', { useValue: state }), | 32 | provide('$state', { useValue: state }), |
32 | - provide('ArticleService', { useValue: articleService }) | 33 | + provide('ArticleService', { useValue: articleService }), |
34 | + helpers.createProviderToValue('NotificationService', notificationService), | ||
33 | ].concat(helpers.provideFilters("translateFilter")); | 35 | ].concat(helpers.provideFilters("translateFilter")); |
34 | 36 | ||
35 | /** | 37 | /** |
@@ -67,23 +69,33 @@ describe("Components", () => { | @@ -67,23 +69,33 @@ describe("Components", () => { | ||
67 | * Execute the delete method on the target component | 69 | * Execute the delete method on the target component |
68 | */ | 70 | */ |
69 | function doDeleteArticle() { | 71 | function doDeleteArticle() { |
72 | + // Create a mock for the notification service confirmation | ||
73 | + spyOn(helper.component.notificationService, 'confirmation').and.callFake(function (params: Function) { | ||
74 | + | ||
75 | + }); | ||
70 | // Create a mock for the ArticleService removeArticle method | 76 | // Create a mock for the ArticleService removeArticle method |
71 | - spyOn(helper.component.articleService, 'remove').and.callFake(function(param: noosfero.Article) { | 77 | + spyOn(helper.component.articleService, 'remove').and.callFake(function (param: noosfero.Article) { |
78 | + | ||
72 | return { | 79 | return { |
73 | - catch: () => {} | 80 | + catch: () => { } |
74 | }; | 81 | }; |
75 | }); | 82 | }); |
76 | helper.component.delete(); | 83 | helper.component.delete(); |
84 | + expect(notificationService.confirmation).toHaveBeenCalled(); | ||
85 | + helper.component.doDelete(); | ||
77 | expect(articleService.remove).toHaveBeenCalled(); | 86 | expect(articleService.remove).toHaveBeenCalled(); |
87 | + | ||
78 | // After the component delete method execution, fire the | 88 | // After the component delete method execution, fire the |
79 | // ArticleEvent.removed event | 89 | // ArticleEvent.removed event |
80 | simulateRemovedEvent(); | 90 | simulateRemovedEvent(); |
81 | } | 91 | } |
82 | 92 | ||
83 | /** | 93 | /** |
84 | - * Simulate the ArticleService ArticleEvent.removed event | 94 | + * Simulate the Notification Service confirmation and ArticleService |
95 | + * notifyArticleRemovedListeners event | ||
85 | */ | 96 | */ |
86 | function simulateRemovedEvent() { | 97 | function simulateRemovedEvent() { |
98 | + helper.component.notificationService["confirmation"]({ title: "Title", message: "Message" }, () => { }); | ||
87 | helper.component.articleService["modelRemovedEventEmitter"].next(article); | 99 | helper.component.articleService["modelRemovedEventEmitter"].next(article); |
88 | } | 100 | } |
89 | }); | 101 | }); |
src/app/article/article-default-view.component.ts
@@ -5,7 +5,8 @@ import {MacroDirective} from "./macro/macro.directive"; | @@ -5,7 +5,8 @@ import {MacroDirective} from "./macro/macro.directive"; | ||
5 | import {ArticleToolbarHotspotComponent} from "../hotspot/article-toolbar-hotspot.component"; | 5 | import {ArticleToolbarHotspotComponent} from "../hotspot/article-toolbar-hotspot.component"; |
6 | import {ArticleContentHotspotComponent} from "../hotspot/article-content-hotspot.component"; | 6 | import {ArticleContentHotspotComponent} from "../hotspot/article-content-hotspot.component"; |
7 | import {ArticleService} from "./../../lib/ng-noosfero-api/http/article.service"; | 7 | import {ArticleService} from "./../../lib/ng-noosfero-api/http/article.service"; |
8 | -import {NotificationService} from "./../shared/services/notification.service"; | 8 | +import { NotificationService } from "./../shared/services/notification.service"; |
9 | + | ||
9 | /** | 10 | /** |
10 | * @ngdoc controller | 11 | * @ngdoc controller |
11 | * @name ArticleDefaultView | 12 | * @name ArticleDefaultView |
@@ -17,13 +18,13 @@ import {NotificationService} from "./../shared/services/notification.service"; | @@ -17,13 +18,13 @@ import {NotificationService} from "./../shared/services/notification.service"; | ||
17 | selector: 'noosfero-default-article', | 18 | selector: 'noosfero-default-article', |
18 | templateUrl: 'app/article/article.html' | 19 | templateUrl: 'app/article/article.html' |
19 | }) | 20 | }) |
20 | -@Inject("$state", ArticleService) | 21 | +@Inject("$state", ArticleService, NotificationService) |
21 | export class ArticleDefaultViewComponent { | 22 | export class ArticleDefaultViewComponent { |
22 | 23 | ||
23 | @Input() article: noosfero.Article; | 24 | @Input() article: noosfero.Article; |
24 | @Input() profile: noosfero.Profile; | 25 | @Input() profile: noosfero.Profile; |
25 | 26 | ||
26 | - constructor(private $state: ng.ui.IStateService, public articleService: ArticleService) { | 27 | + constructor(private $state: ng.ui.IStateService, public articleService: ArticleService, public notificationService: NotificationService) { |
27 | // Subscribe to the Article Removed Event | 28 | // Subscribe to the Article Removed Event |
28 | this.articleService.subscribeToModelRemoved((article: noosfero.Article) => { | 29 | this.articleService.subscribeToModelRemoved((article: noosfero.Article) => { |
29 | if (this.article.parent) { | 30 | if (this.article.parent) { |
@@ -31,13 +32,20 @@ export class ArticleDefaultViewComponent { | @@ -31,13 +32,20 @@ export class ArticleDefaultViewComponent { | ||
31 | } else { | 32 | } else { |
32 | this.$state.transitionTo('main.profile.info', { profile: this.article.profile.identifier }); | 33 | this.$state.transitionTo('main.profile.info', { profile: this.article.profile.identifier }); |
33 | } | 34 | } |
35 | + this.notificationService.success({ title: "article.remove.success.title", message: "article.remove.success.message" }); | ||
34 | }); | 36 | }); |
35 | } | 37 | } |
36 | 38 | ||
37 | delete() { | 39 | delete() { |
38 | - this.articleService.remove(this.article); | 40 | + this.notificationService.confirmation({ title: "article.remove.confirmation.title", message: "article.remove.confirmation.message" }, () => { |
41 | + this.doDelete(); | ||
42 | + }); | ||
43 | + | ||
39 | } | 44 | } |
40 | 45 | ||
46 | + doDelete() { | ||
47 | + this.articleService.remove(this.article); | ||
48 | + } | ||
41 | } | 49 | } |
42 | 50 | ||
43 | /** | 51 | /** |
src/languages/en.json
@@ -56,6 +56,10 @@ | @@ -56,6 +56,10 @@ | ||
56 | "article.basic_editor.cancel": "Cancel", | 56 | "article.basic_editor.cancel": "Cancel", |
57 | "article.basic_editor.success.title": "Good job!", | 57 | "article.basic_editor.success.title": "Good job!", |
58 | "article.basic_editor.success.message": "Article saved!", | 58 | "article.basic_editor.success.message": "Article saved!", |
59 | + "article.remove.success.title": "Good job!", | ||
60 | + "article.remove.success.message": "Article removed!", | ||
61 | + "article.remove.confirmation.title": "Are you sure?", | ||
62 | + "article.remove.confirmation.message": "You will not be able to recover this article!", | ||
59 | "article.basic_editor.visibility": "Visibility", | 63 | "article.basic_editor.visibility": "Visibility", |
60 | "article.basic_editor.visibility.public": "Public", | 64 | "article.basic_editor.visibility.public": "Public", |
61 | "article.basic_editor.visibility.private": "Private", | 65 | "article.basic_editor.visibility.private": "Private", |
src/languages/pt.json
@@ -53,6 +53,10 @@ | @@ -53,6 +53,10 @@ | ||
53 | "article.basic_editor.cancel": "Cancelar", | 53 | "article.basic_editor.cancel": "Cancelar", |
54 | "article.basic_editor.success.title": "Bom trabalho!", | 54 | "article.basic_editor.success.title": "Bom trabalho!", |
55 | "article.basic_editor.success.message": "Artigo salvo com sucesso!", | 55 | "article.basic_editor.success.message": "Artigo salvo com sucesso!", |
56 | + "article.remove.success.title": "Bom trabalho!", | ||
57 | + "article.remove.success.message": "Artigo removido!", | ||
58 | + "article.remove.confirmation.title": "Tem certeza?", | ||
59 | + "article.remove.confirmation.message": "Não será possível recuperar este artigo!", | ||
56 | "article.basic_editor.visibility": "Visibilidade", | 60 | "article.basic_editor.visibility": "Visibilidade", |
57 | "article.basic_editor.visibility.public": "Público", | 61 | "article.basic_editor.visibility.public": "Público", |
58 | "article.basic_editor.visibility.private": "Privado", | 62 | "article.basic_editor.visibility.private": "Privado", |
src/spec/mocks.ts
@@ -200,6 +200,7 @@ export var mocks: any = { | @@ -200,6 +200,7 @@ export var mocks: any = { | ||
200 | translate: (text: string) => { return text; } | 200 | translate: (text: string) => { return text; } |
201 | }, | 201 | }, |
202 | notificationService: { | 202 | notificationService: { |
203 | - success: () => { } | 203 | + success: () => { }, |
204 | + confirmation: () => { } | ||
204 | } | 205 | } |
205 | }; | 206 | }; |