diff --git a/src/app/article/basic-editor.component.spec.ts b/src/app/article/basic-editor.component.spec.ts index 70d987d..d86d08a 100644 --- a/src/app/article/basic-editor.component.spec.ts +++ b/src/app/article/basic-editor.component.spec.ts @@ -9,6 +9,7 @@ describe("Article BasicEditor", () => { let articleServiceMock: any; let profileServiceMock: any; let $state: any; + let $stateParams: any; let profile = { id: 1 }; let notification: any; @@ -20,9 +21,10 @@ describe("Article BasicEditor", () => { beforeEach(() => { $state = jasmine.createSpyObj("$state", ["transitionTo"]); + $stateParams = jasmine.createSpyObj("$stateParams", ["parent_id"]); notification = jasmine.createSpyObj("notification", ["success"]); profileServiceMock = jasmine.createSpyObj("profileServiceMock", ["getCurrentProfile"]); - articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["createInProfile"]); + articleServiceMock = jasmine.createSpyObj("articleServiceMock", ["createInParent"]); let getCurrentProfileResponse = $q.defer(); getCurrentProfileResponse.resolve(profile); @@ -31,20 +33,20 @@ describe("Article BasicEditor", () => { articleCreate.resolve({ data: { path: "path", profile: { identifier: "profile" } } }); profileServiceMock.getCurrentProfile = jasmine.createSpy("getCurrentProfile").and.returnValue(getCurrentProfileResponse.promise); - articleServiceMock.createInProfile = jasmine.createSpy("createInProfile").and.returnValue(articleCreate.promise); + articleServiceMock.createInParent = jasmine.createSpy("createInParent").and.returnValue(articleCreate.promise); }); it("create an article in the current profile when save", done => { - let component: BasicEditorComponent = new BasicEditorComponent(articleServiceMock, profileServiceMock, $state, notification); + let component: BasicEditorComponent = new BasicEditorComponent(articleServiceMock, profileServiceMock, $state, notification, $stateParams); component.save(); $rootScope.$apply(); expect(profileServiceMock.getCurrentProfile).toHaveBeenCalled(); - expect(articleServiceMock.createInProfile).toHaveBeenCalledWith(profile, component.article); + expect(articleServiceMock.createInParent).toHaveBeenCalledWith($stateParams.parent_id, component.article); done(); }); it("got to the new article page and display an alert when saving sucessfully", done => { - let component: BasicEditorComponent = new BasicEditorComponent(articleServiceMock, profileServiceMock, $state, notification); + let component: BasicEditorComponent = new BasicEditorComponent(articleServiceMock, profileServiceMock, $state, notification, $stateParams); component.save(); $rootScope.$apply(); expect($state.transitionTo).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "profile" }); diff --git a/src/app/article/basic-editor.component.ts b/src/app/article/basic-editor.component.ts index 59ac039..ab5f17f 100644 --- a/src/app/article/basic-editor.component.ts +++ b/src/app/article/basic-editor.component.ts @@ -12,19 +12,25 @@ import {NotificationService} from "../shared/services/notification.service.ts"; provide('notification', { useClass: NotificationService }) ] }) -@Inject(ArticleService, ProfileService, "$state", NotificationService) +@Inject(ArticleService, ProfileService, "$state", NotificationService, "$stateParams") export class BasicEditorComponent { article: noosfero.Article = {}; + parentId: number; + + editorOptions = {}; constructor(private articleService: ArticleService, private profileService: ProfileService, private $state: ng.ui.IStateService, - private notification: NotificationService) { } + private notification: NotificationService, + private $stateParams: ng.ui.IStateParamsService) { + this.parentId = this.$stateParams['parent_id']; + } save() { this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => { - return this.articleService.createInProfile(profile, this.article); + return this.articleService.createInParent(this.parentId, this.article); }).then((response: noosfero.RestResult) => { let article = (response.data); this.$state.transitionTo('main.profile.page', { page: article.path, profile: article.profile.identifier }); diff --git a/src/app/article/content-viewer/content-viewer-actions.component.spec.ts b/src/app/article/content-viewer/content-viewer-actions.component.spec.ts index 23fbae6..18eff34 100644 --- a/src/app/article/content-viewer/content-viewer-actions.component.spec.ts +++ b/src/app/article/content-viewer/content-viewer-actions.component.spec.ts @@ -20,6 +20,9 @@ describe('Content Viewer Actions Component', () => { return [ provide('ProfileService', { useValue: helpers.mocks.profileService + }), + provide('ArticleService', { + useValue: helpers.mocks.articleService }) ]; }); @@ -44,6 +47,33 @@ describe('Content Viewer Actions Component', () => { }); }); + it('return article parent as container when it is not a folder', (done: Function) => { + buildComponent().then((fixture: ComponentFixture) => { + let component = fixture.debugElement.componentViewChildren[0].componentInstance; + let article = ({ id: 1, type: 'TextArticle', parent: { id: 2 } }); + expect(component.getArticleContainer(article)).toEqual(2); + done(); + }); + }); + + it('return article as container when it is a folder', (done: Function) => { + buildComponent().then((fixture: ComponentFixture) => { + let component = fixture.debugElement.componentViewChildren[0].componentInstance; + let article = ({ id: 1, type: 'Folder' }); + expect(component.getArticleContainer(article)).toEqual(1); + done(); + }); + }); + + it('return article as container when it is a blog', (done: Function) => { + buildComponent().then((fixture: ComponentFixture) => { + let component = fixture.debugElement.componentViewChildren[0].componentInstance; + let article = ({ id: 1, type: 'Blog' }); + expect(component.getArticleContainer(article)).toEqual(1); + done(); + }); + }); + it('check if profile was loaded', (done: Function) => { let profile: any = { id: 1, diff --git a/src/app/article/content-viewer/content-viewer-actions.component.ts b/src/app/article/content-viewer/content-viewer-actions.component.ts index 6d3735e..133f589 100644 --- a/src/app/article/content-viewer/content-viewer-actions.component.ts +++ b/src/app/article/content-viewer/content-viewer-actions.component.ts @@ -1,20 +1,38 @@ import {Component, Inject, provide} from "ng-forward"; import {ProfileService} from "../../../lib/ng-noosfero-api/http/profile.service"; +import {ArticleService} from "../../../lib/ng-noosfero-api/http/article.service"; @Component({ selector: "content-viewer-actions", templateUrl: "app/article/content-viewer/navbar-actions.html", - providers: [provide('profileService', { useClass: ProfileService })] + providers: [ + provide('profileService', { useClass: ProfileService }), + provide('articleService', { useClass: ArticleService }) + ] }) -@Inject(ProfileService) +@Inject(ProfileService, ArticleService) export class ContentViewerActionsComponent { article: noosfero.Article; profile: noosfero.Profile; + parentId: number; - constructor(profileService: ProfileService) { + constructor(profileService: ProfileService, articleService: ArticleService) { profileService.getCurrentProfile().then((profile: noosfero.Profile) => { this.profile = profile; + return articleService.getCurrent(); + }).then((article: noosfero.Article) => { + this.article = article; + this.parentId = this.getArticleContainer(article); }); } + + getArticleContainer(article: noosfero.Article) { + // FIXME get folder types from api + if (article.type === "Blog" || article.type === "Folder") { + return article.id; + } else if (article.parent) { + return article.parent.id; + } + } } diff --git a/src/app/article/content-viewer/content-viewer.component.ts b/src/app/article/content-viewer/content-viewer.component.ts index 16d0741..233bfd5 100644 --- a/src/app/article/content-viewer/content-viewer.component.ts +++ b/src/app/article/content-viewer/content-viewer.component.ts @@ -28,11 +28,12 @@ export class ContentViewerComponent { } activate() { - this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => { + this.profileService.getCurrentProfile().then((profile: noosfero.Profile) => { this.profile = profile; return this.articleService.getArticleByProfileAndPath(this.profile, this.$stateParams["page"]); }).then((result: noosfero.RestResult) => { this.article = result.data; + this.articleService.setCurrent(this.article); }); } } diff --git a/src/app/article/content-viewer/navbar-actions.html b/src/app/article/content-viewer/navbar-actions.html index 1b0af5e..0ae84ab 100644 --- a/src/app/article/content-viewer/navbar-actions.html +++ b/src/app/article/content-viewer/navbar-actions.html @@ -1,6 +1,6 @@