diff --git a/src/app/cms/cms.component.ts b/src/app/cms/cms.component.ts index a950085..a66289c 100644 --- a/src/app/cms/cms.component.ts +++ b/src/app/cms/cms.component.ts @@ -1,5 +1,4 @@ import {StateConfig, Component, Inject, provide} from 'ng-forward'; -import {Profile} from "./../models/interfaces"; import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; import {Notification} from "../components/notification/notification.component"; diff --git a/src/app/components/auth/auth_controller.ts b/src/app/components/auth/auth_controller.ts index f2cf457..768ae63 100644 --- a/src/app/components/auth/auth_controller.ts +++ b/src/app/components/auth/auth_controller.ts @@ -1,4 +1,3 @@ -import {Credentials} from "./../../models/interfaces"; import {AuthService} from "./auth_service"; export class AuthController { @@ -13,7 +12,7 @@ export class AuthController { } - credentials: Credentials; + credentials: noosfero.Credentials; login() { this.AuthService.login(this.credentials); diff --git a/src/app/components/auth/auth_service.spec.ts b/src/app/components/auth/auth_service.spec.ts index 90f7954..5b417ba 100644 --- a/src/app/components/auth/auth_service.spec.ts +++ b/src/app/components/auth/auth_service.spec.ts @@ -1,7 +1,6 @@ import {AuthService, AUTH_EVENTS} from "./"; -import {User, Credentials} from "./../../models/interfaces"; describe("Services", () => { @@ -10,9 +9,9 @@ describe("Services", () => { let $httpBackend: ng.IHttpBackendService; let authService: AuthService; - let credentials: Credentials; + let credentials: noosfero.Credentials; let $rootScope: ng.IRootScopeService; - let user: User; + let user: noosfero.User; beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => { $translateProvider.translations('en', {}); @@ -23,7 +22,7 @@ describe("Services", () => { authService = _AuthService_; $rootScope = _$rootScope_; - user = { + user = { id: 1, login: "user" }; @@ -53,7 +52,7 @@ describe("Services", () => { authService.login(credentials); let eventEmmited: boolean = false; - $rootScope.$on(AUTH_EVENTS.loginSuccess, (event: ng.IAngularEvent, userThroughEvent: User) => { + $rootScope.$on(AUTH_EVENTS.loginSuccess, (event: ng.IAngularEvent, userThroughEvent: noosfero.User) => { eventEmmited = true; expect(userThroughEvent).toEqual(user); }); @@ -66,7 +65,7 @@ describe("Services", () => { it("should return the current logged in user", () => { authService.login(credentials); $httpBackend.flush(); - let actual: User = authService.currentUser(); + let actual: noosfero.User = authService.currentUser(); expect(actual).toEqual(user, "The returned user must be present"); }); diff --git a/src/app/components/auth/auth_service.ts b/src/app/components/auth/auth_service.ts index 2b3cbc3..6b663b7 100644 --- a/src/app/components/auth/auth_service.ts +++ b/src/app/components/auth/auth_service.ts @@ -1,6 +1,6 @@ import {Injectable, Inject} from "ng-forward"; -import {Credentials, NoosferoRootScope, User, UserResponse} from "./../../models/interfaces"; +import {NoosferoRootScope, UserResponse} from "./../../models/interfaces"; import {Session} from "./session"; import {AUTH_EVENTS, IAuthEvents} from "./auth_events"; @@ -26,13 +26,13 @@ export class AuthService { private loginSuccessCallback(response: ng.IHttpPromiseCallbackArg) { this.$log.debug('AuthService.login [SUCCESS] response', response); - let currentUser: User = this.session.create(response.data); + let currentUser: noosfero.User = this.session.create(response.data); this.$rootScope.currentUser = currentUser; this.$rootScope.$broadcast(this.auth_events.loginSuccess, currentUser); return currentUser; } - login(credentials: Credentials): ng.IPromise { + login(credentials: noosfero.Credentials): ng.IPromise { let url = '/api/v1/login'; let encodedData = 'login=' + credentials.username + '&password=' + credentials.password; return this.$http.post(url, encodedData).then(this.loginSuccessCallback.bind(this), this.loginFailedCallback.bind(this)); @@ -56,7 +56,7 @@ export class AuthService { return !!this.session.currentUser(); } - public currentUser(): User { + public currentUser(): noosfero.User { return this.session.currentUser(); } diff --git a/src/app/components/auth/session.ts b/src/app/components/auth/session.ts index 24b5f0d..990a2c0 100644 --- a/src/app/components/auth/session.ts +++ b/src/app/components/auth/session.ts @@ -1,5 +1,5 @@ import {Injectable, Inject} from "ng-forward"; -import {UserResponse, User, INoosferoLocalStorage} from "./../../models/interfaces"; +import {UserResponse, INoosferoLocalStorage} from "./../../models/interfaces"; @Injectable() @Inject("$localStorage", "$log") @@ -9,7 +9,7 @@ export class Session { } - create(data: UserResponse): User { + create(data: UserResponse): noosfero.User { this.$localStorage.currentUser = data.user; this.$log.debug('User session created.', this.$localStorage.currentUser); return this.$localStorage.currentUser; @@ -20,7 +20,7 @@ export class Session { this.$log.debug('User session destroyed.'); }; - currentUser(): User { + currentUser(): noosfero.User { return this.$localStorage.currentUser; }; diff --git a/src/app/components/auth/session_spec.ts b/src/app/components/auth/session_spec.ts index 30d0fb5..7413fc6 100644 --- a/src/app/components/auth/session_spec.ts +++ b/src/app/components/auth/session_spec.ts @@ -1,7 +1,7 @@ import {Component} from "ng-forward"; import {Session} from "./"; import {fixtures, createComponentFromClass, createProviderToValue} from "./../../../spec/helpers"; -import {UserResponse, User, INoosferoLocalStorage} from "./../../models/interfaces"; +import {UserResponse, INoosferoLocalStorage} from "./../../models/interfaces"; describe("Services", () => { diff --git a/src/app/components/navbar/navbar.spec.ts b/src/app/components/navbar/navbar.spec.ts index e054da3..192f8c1 100644 --- a/src/app/components/navbar/navbar.spec.ts +++ b/src/app/components/navbar/navbar.spec.ts @@ -1,7 +1,6 @@ import * as helpers from "./../../../spec/helpers"; import {Navbar} from "./navbar"; import {AUTH_EVENTS} from "./../auth"; -import {User} from "./../../models/interfaces"; import {Injectable, Provider, provide} from "ng-forward"; import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; @@ -13,7 +12,7 @@ describe("Components", () => { describe("Navbar Component", () => { - let user: User = null; + let user: noosfero.User = null; let scope: any; let $rootScope: ng.IRootScopeService; @@ -27,7 +26,7 @@ describe("Components", () => { // before Each -> loading mocks on locals variables beforeEach(() => { - user = { + user = { id: 1, login: "user" }; diff --git a/src/app/components/navbar/navbar.ts b/src/app/components/navbar/navbar.ts index 94ae1ee..e466a76 100644 --- a/src/app/components/navbar/navbar.ts +++ b/src/app/components/navbar/navbar.ts @@ -3,7 +3,6 @@ import {LanguageSelector} from "../language-selector/language-selector.component import {Session, AuthService, AuthController, IAuthEvents, AUTH_EVENTS} from "./../auth"; -import {User} from "./../../models/interfaces"; @Component({ selector: "acme-navbar", @@ -14,7 +13,7 @@ import {User} from "./../../models/interfaces"; @Inject("$modal", AuthService, "Session", "$scope", "$state") export class Navbar { - private currentUser: User; + private currentUser: noosfero.User; private modalInstance: any = null; /** * diff --git a/src/app/components/noosfero-activities/activities.component.ts b/src/app/components/noosfero-activities/activities.component.ts index 7fe9715..e455eb1 100644 --- a/src/app/components/noosfero-activities/activities.component.ts +++ b/src/app/components/noosfero-activities/activities.component.ts @@ -1,6 +1,5 @@ import {Component, Input} from "ng-forward"; import {NoosferoActivity} from "./activity/activity.component"; -import {Activity} from "../../models/interfaces"; @Component({ selector: "noosfero-activities", @@ -9,6 +8,6 @@ import {Activity} from "../../models/interfaces"; }) export class NoosferoActivities { - @Input() activities: Activity[]; + @Input() activities: noosfero.Activity[]; } diff --git a/src/app/components/noosfero-activities/activity/activity.component.ts b/src/app/components/noosfero-activities/activity/activity.component.ts index 7d0db9c..6876405 100644 --- a/src/app/components/noosfero-activities/activity/activity.component.ts +++ b/src/app/components/noosfero-activities/activity/activity.component.ts @@ -1,5 +1,4 @@ import {Component, Input} from "ng-forward"; -import {Activity} from "../../../models/interfaces"; @Component({ selector: "noosfero-activity", @@ -7,7 +6,7 @@ import {Activity} from "../../../models/interfaces"; }) export class NoosferoActivity { - @Input() activity: Activity; + @Input() activity: noosfero.Activity; getActivityTemplate() { return 'app/components/noosfero-activities/activity/' + this.activity.verb + '.html'; diff --git a/src/app/components/noosfero-articles/article/article_view.ts b/src/app/components/noosfero-articles/article/article_view.ts index b19c863..b18de01 100644 --- a/src/app/components/noosfero-articles/article/article_view.ts +++ b/src/app/components/noosfero-articles/article/article_view.ts @@ -7,8 +7,8 @@ import {ArticleBlog} from "../blog/blog.component"; }) export class ArticleDefaultView { - @Input() article: any; - @Input() profile: any; + @Input() article: noosfero.Article; + @Input() profile: noosfero.Profile; } @@ -20,8 +20,8 @@ export class ArticleDefaultView { @Inject("$element", "$scope", "$injector", "$compile") export class ArticleView { - @Input() article: any; - @Input() profile: any; + @Input() article: noosfero.Article; + @Input() profile: noosfero.Profile; directiveName: string; ngOnInit() { diff --git a/src/app/components/noosfero-articles/blog/blog.component.ts b/src/app/components/noosfero-articles/blog/blog.component.ts index b27aa11..45ca7e7 100644 --- a/src/app/components/noosfero-articles/blog/blog.component.ts +++ b/src/app/components/noosfero-articles/blog/blog.component.ts @@ -1,6 +1,5 @@ import {Component, Input, Inject} from "ng-forward"; -import {Article, Profile} from "./../../../models/interfaces"; import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service"; @Component({ @@ -11,7 +10,7 @@ import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.servi export class ArticleBlog { @Input() article: noosfero.Article; - @Input() profile: Profile; + @Input() profile: noosfero.Profile; private posts: noosfero.Article[]; private perPage: number = 3; diff --git a/src/app/components/noosfero-blocks/members-block/members-block.component.ts b/src/app/components/noosfero-blocks/members-block/members-block.component.ts index 9a81409..108d8ca 100644 --- a/src/app/components/noosfero-blocks/members-block/members-block.component.ts +++ b/src/app/components/noosfero-blocks/members-block/members-block.component.ts @@ -8,8 +8,8 @@ import {ProfileService} from "../../../../lib/ng-noosfero-api/http/profile.servi @Inject(ProfileService) export class MembersBlock { - @Input() block: any; - @Input() owner: any; + @Input() block: noosfero.Block; + @Input() owner: noosfero.Profile; members: any = []; diff --git a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts index b2254b1..ab4f387 100644 --- a/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts +++ b/src/app/components/noosfero-blocks/profile-image-block/profile-image-block.component.ts @@ -8,7 +8,7 @@ import {ProfileImage} from "./../../../components/noosfero/profile-image/profile }) export class ProfileImageBlock { - @Input() block: any; - @Input() owner: any; + @Input() block: noosfero.Block; + @Input() owner: noosfero.Profile; } diff --git a/src/app/components/noosfero-boxes/boxes.component.spec.ts b/src/app/components/noosfero-boxes/boxes.component.spec.ts index deb21e0..8ad4510 100644 --- a/src/app/components/noosfero-boxes/boxes.component.spec.ts +++ b/src/app/components/noosfero-boxes/boxes.component.spec.ts @@ -1,6 +1,5 @@ import {Component} from 'ng-forward'; -import {Box, Profile} from "../../models/interfaces"; import {Boxes} from './boxes.component'; import { @@ -29,12 +28,12 @@ describe("Boxes Component", () => { providers: [] }) class BoxesContainerComponent { - boxes: Box[] = [ + boxes: noosfero.Box[] = [ { id: 1, position: 1 }, { id: 2, position: 2 } ]; - owner: Profile = { + owner: noosfero.Profile = { id: 1, identifier: 'profile-name', type: 'Person' diff --git a/src/app/components/noosfero-boxes/boxes.component.ts b/src/app/components/noosfero-boxes/boxes.component.ts index 085cad1..ff52b54 100644 --- a/src/app/components/noosfero-boxes/boxes.component.ts +++ b/src/app/components/noosfero-boxes/boxes.component.ts @@ -1,5 +1,4 @@ import {Input, Inject, Component} from 'ng-forward'; -import {Box, Profile} from "./../../models/interfaces"; @Component({ selector: "noosfero-boxes", @@ -7,10 +6,10 @@ import {Box, Profile} from "./../../models/interfaces"; }) export class Boxes { - @Input() boxes: Box[]; - @Input() owner: Profile; + @Input() boxes: noosfero.Box[]; + @Input() owner: noosfero.Profile; - boxesOrder(box: Box) { + boxesOrder(box: noosfero.Box) { if (box.position === 2) return 0; return box.position; } diff --git a/src/app/components/noosfero/profile-image/profile-image.component.spec.ts b/src/app/components/noosfero/profile-image/profile-image.component.spec.ts index ebe61cb..1c1ea29 100644 --- a/src/app/components/noosfero/profile-image/profile-image.component.spec.ts +++ b/src/app/components/noosfero/profile-image/profile-image.component.spec.ts @@ -17,7 +17,7 @@ describe("Components", () => { it("show community users image if profile is not Person", done => { helpers.tcb.createAsync(ProfileImage).then(fixture => { let profileImageComponent: ProfileImage = fixture.componentInstance; - let profile = { id: 1, identifier: "myprofile", type: "Community" }; + let profile = { id: 1, identifier: "myprofile", type: "Community" }; profileImageComponent.profile = profile; profileImageComponent.ngOnInit(); @@ -32,7 +32,7 @@ describe("Components", () => { it("show Person image if profile is Person", done => { tcb.createAsync(ProfileImage).then(fixture => { let profileImageComponent: ProfileImage = fixture.componentInstance; - let profile = { id: 1, identifier: "myprofile", type: "Person" }; + let profile = { id: 1, identifier: "myprofile", type: "Person" }; profileImageComponent.profile = profile; profileImageComponent.ngOnInit(); // Check the attribute diff --git a/src/app/components/noosfero/profile-image/profile-image.component.ts b/src/app/components/noosfero/profile-image/profile-image.component.ts index e7b165e..04f5d55 100644 --- a/src/app/components/noosfero/profile-image/profile-image.component.ts +++ b/src/app/components/noosfero/profile-image/profile-image.component.ts @@ -1,5 +1,4 @@ import {Inject, Input, Component} from "ng-forward"; -import {Profile} from "./../../../models/interfaces"; @Component({ selector: "noosfero-profile-image", @@ -7,7 +6,7 @@ import {Profile} from "./../../../models/interfaces"; }) export class ProfileImage { - @Input() profile: Profile; + @Input() profile: noosfero.Profile; defaultIcon: string; ngOnInit() { diff --git a/src/app/content-viewer/content-viewer.component.ts b/src/app/content-viewer/content-viewer.component.ts index f6fe388..ac90f16 100644 --- a/src/app/content-viewer/content-viewer.component.ts +++ b/src/app/content-viewer/content-viewer.component.ts @@ -4,7 +4,7 @@ import {Input, Component, StateConfig, Inject, provide} from "ng-forward"; import {ArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; -import {Profile} from "../models/interfaces"; + @Component({ selector: "content-viewer", templateUrl: "app/content-viewer/page.html", diff --git a/src/app/models/interfaces.ts b/src/app/models/interfaces.ts index 02a728f..3b384f8 100644 --- a/src/app/models/interfaces.ts +++ b/src/app/models/interfaces.ts @@ -1,61 +1,12 @@ export interface NoosferoRootScope extends ng.IScope { - currentUser: User; -} - -export interface Event extends Article { - id: number; -} - -export interface Article { - id: number; -} - -export interface Profile { - id: number; - identifier: string; - type: string; -} - -export interface Person extends Profile { - id: number; -} - -export interface TynyMceArticle extends Article { - id: number; -} - -export interface Blog extends Article { - id: number; -} - -export interface Credentials { - username: string; - password: string; -} - -export interface User { - id: number; - login: string; - email: string; - person: Person; - private_token: string; - userRole: string; + currentUser: noosfero.User; } export interface UserResponse { - user: User; + user: noosfero.User; } -export interface Box { - id: number; - position: number; -} - -export interface Activity { - verb: string; -} - export interface INoosferoLocalStorage extends angular.storage.ILocalStorageService { - currentUser: User; + currentUser: noosfero.User; } diff --git a/src/app/profile-info/profile-info.component.ts b/src/app/profile-info/profile-info.component.ts index 47d3d36..e18371e 100644 --- a/src/app/profile-info/profile-info.component.ts +++ b/src/app/profile-info/profile-info.component.ts @@ -1,6 +1,4 @@ import {StateConfig, Component, Inject, provide} from 'ng-forward'; - -import {Profile} from "./../models/interfaces"; import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; @Component({ diff --git a/src/lib/ng-noosfero-api/http/article.service.spec.ts b/src/lib/ng-noosfero-api/http/article.service.spec.ts index 07a9ba0..1453489 100644 --- a/src/lib/ng-noosfero-api/http/article.service.spec.ts +++ b/src/lib/ng-noosfero-api/http/article.service.spec.ts @@ -1,78 +1,77 @@ -import {Article} from "../../../app/models/interfaces"; import {ArticleService} from "./article.service"; -// describe("Services", () => { +describe("Services", () => { -// xdescribe("Article Service", () => { + describe("Article Service", () => { -// let $httpBackend: ng.IHttpBackendService; -// let articleService: ArticleService; + let $httpBackend: ng.IHttpBackendService; + let articleService: ArticleService; -// beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => { -// $translateProvider.translations('en', {}); -// })); + beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => { + $translateProvider.translations('en', {}); + })); -// beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _ArticleService_: ArticleService) => { -// $httpBackend = _$httpBackend_; -// articleService = _ArticleService_; -// })); + beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _ArticleService_: ArticleService) => { + $httpBackend = _$httpBackend_; + articleService = _ArticleService_; + })); -// describe("Succesfull requests", () => { + describe("Succesfull requests", () => { -// it("should return article children", (done) => { -// let articleId = 1; -// $httpBackend.expectGET(`/api/v1/articles/${articleId}/children`).respond(200, { articles: [{ name: "article1" }] }); -// articleService.getChildren(articleId).then((result: noosfero.ArticlesResult) => { -// expect(result.articles).toEqual([{ name: "article1" }]); -// done(); -// }); -// $httpBackend.flush(); -// }); + it("should return article children", (done) => { + let articleId = 1; + $httpBackend.expectGET(`/api/v1/articles/${articleId}/children`).respond(200, { articles: [{ name: "article1" }] }); + articleService.getChildren({id: articleId}).then((result: noosfero.RestResult) => { + expect(result.data).toEqual([{ name: "article1" }]); + done(); + }); + $httpBackend.flush(); + }); -// it("should get articles by profile", (done) => { -// let profileId = 1; -// $httpBackend.expectGET(`/api/v1/profiles/${profileId}/articles`).respond(200, { articles: [{ name: "article1" }] }); -// articleService.getByProfile(profileId).then((result: noosfero.ArticlesResult) => { -// expect(result.articles).toEqual([{ name: "article1" }]); -// done(); -// }); -// $httpBackend.flush(); -// }); + it("should get articles by profile", (done) => { + let profileId = 1; + $httpBackend.expectGET(`/api/v1/profiles/${profileId}/articles`).respond(200, { articles: [{ name: "article1" }] }); + articleService.getByProfile({id: profileId}).then((result: noosfero.RestResult) => { + expect(result.data).toEqual([{ name: "article1" }]); + done(); + }); + $httpBackend.flush(); + }); -// it("should get articles by profile with additional filters", (done) => { -// let profileId = 1; -// $httpBackend.expectGET(`/api/v1/profiles/${profileId}/articles?path=test`).respond(200, { articles: [{ name: "article1" }] }); -// articleService.getByProfile(profileId, { path: 'test' }).then((result: noosfero.ArticlesResult) => { -// expect(result.articles).toEqual([{ name: "article1" }]); -// done(); -// }); -// $httpBackend.flush(); -// }); + it("should get articles by profile with additional filters", (done) => { + let profileId = 1; + $httpBackend.expectGET(`/api/v1/profiles/${profileId}/articles?path=test`).respond(200, { articles: [{ name: "article1" }] }); + articleService.getByProfile({id: profileId}, { path: 'test' }).then((result: noosfero.RestResult) => { + expect(result.data).toEqual([{ name: "article1" }]); + done(); + }); + $httpBackend.flush(); + }); -// it("should get article children with additional filters", (done) => { -// let articleId = 1; -// $httpBackend.expectGET(`/api/v1/articles/${articleId}/children?path=test`).respond(200, { articles: [{ name: "article1" }] }); -// articleService.getChildren(articleId, { path: 'test' }).then((result: noosfero.ArticlesResult) => { -// expect(result.articles).toEqual([{ name: "article1" }]); -// done(); -// }); -// $httpBackend.flush(); -// }); + it("should get article children with additional filters", (done) => { + let articleId = 1; + $httpBackend.expectGET(`/api/v1/articles/${articleId}/children?path=test`).respond(200, { articles: [{ name: "article1" }] }); + articleService.getChildren({id: articleId}, { path: 'test' }).then((result: noosfero.RestResult) => { + expect(result.data).toEqual([{ name: "article1" }]); + done(); + }); + $httpBackend.flush(); + }); -// it("should create an article in a profile", (done) => { -// let profileId = 1; -// let article: noosfero.Article = { id: null}; -// $httpBackend.expectPOST(`/api/v1/profiles/${profileId}/articles`, { article: article }).respond(200, {article: { id: 2 }}); -// articleService.create(profileId, article).then((article: noosfero.Article) => { -// expect(article).toEqual({ id: 2 }); -// done(); -// }); -// $httpBackend.flush(); -// }); -// }); + it("should create an article in a profile", (done) => { + let profileId = 1; + let article: noosfero.Article = { id: null}; + $httpBackend.expectPOST(`/api/v1/profiles/${profileId}/articles`, { article: article }).respond(200, {article: { id: 2 }}); + articleService.createInProfile({id: profileId}, article).then((result: noosfero.RestResult) => { + expect(result.data).toEqual({ id: 2 }); + done(); + }); + $httpBackend.flush(); + }); + }); -// }); -// }); + }); +}); diff --git a/src/lib/ng-noosfero-api/http/article.service.ts b/src/lib/ng-noosfero-api/http/article.service.ts index edc9cd3..9e62124 100644 --- a/src/lib/ng-noosfero-api/http/article.service.ts +++ b/src/lib/ng-noosfero-api/http/article.service.ts @@ -24,6 +24,8 @@ export class ArticleService extends RestangularService { createInProfile(profile: noosfero.Profile, article: noosfero.Article): ng.IPromise> { + let profileElement = this.profileService.get(profile.id); + (profileElement).id = profile.id; return this.create(article, profile); } @@ -47,7 +49,9 @@ export class ArticleService extends RestangularService { } getChildren(article: noosfero.Article, params?: any): ng.IPromise> { - return this.listSubElements(article, "children", params); + let articleElement = this.getElement(article.id); + articleElement.id = article.id; + return this.listSubElements(articleElement, "children", params); } diff --git a/src/lib/ng-noosfero-api/http/profile.service.spec.ts b/src/lib/ng-noosfero-api/http/profile.service.spec.ts index 6789221..05a8e8c 100644 --- a/src/lib/ng-noosfero-api/http/profile.service.spec.ts +++ b/src/lib/ng-noosfero-api/http/profile.service.spec.ts @@ -1,4 +1,3 @@ -import {Profile} from "../../../app/models/interfaces"; import {ProfileService} from "./profile.service"; describe("Services", () => { diff --git a/src/lib/ng-noosfero-api/http/profile.service.ts b/src/lib/ng-noosfero-api/http/profile.service.ts index 67f4937..a84540e 100644 --- a/src/lib/ng-noosfero-api/http/profile.service.ts +++ b/src/lib/ng-noosfero-api/http/profile.service.ts @@ -1,5 +1,4 @@ import { Injectable, Inject } from "ng-forward"; -import {Profile} from "../../../app/models/interfaces"; @Injectable() @Inject("Restangular", "$q") diff --git a/src/lib/ng-noosfero-api/http/restangular_service.spec.ts b/src/lib/ng-noosfero-api/http/restangular_service.spec.ts index 3a335ec..40bf906 100644 --- a/src/lib/ng-noosfero-api/http/restangular_service.spec.ts +++ b/src/lib/ng-noosfero-api/http/restangular_service.spec.ts @@ -7,13 +7,8 @@ interface RootObjectModel extends noosfero.RestModel { } - - - describe("Restangular Service - base Class", () => { - - class ObjectRestService extends RestangularService { public getDataKeys() { return { @@ -212,8 +207,4 @@ describe("Restangular Service - base Class", () => { $httpBackend.flush(); }); - - - - }); \ No newline at end of file diff --git a/src/lib/ng-noosfero-api/http/restangular_service.ts b/src/lib/ng-noosfero-api/http/restangular_service.ts index 8bcaf46..ef93aeb 100644 --- a/src/lib/ng-noosfero-api/http/restangular_service.ts +++ b/src/lib/ng-noosfero-api/http/restangular_service.ts @@ -10,6 +10,7 @@ */ export abstract class RestangularService { + private baseResource: restangular.IElement; /** * Creates an instance of RestangularService. * @@ -18,16 +19,17 @@ export abstract class RestangularService { * @param {ng.ILogService} $log (description) */ constructor(protected restangularService: restangular.IService, protected $q: ng.IQService, protected $log: ng.ILogService) { + this.baseResource = restangularService.all(this.getResourcePath()); // TODO - this.restangularService.setResponseInterceptor((data, operation, what, url, response, deferred) => { - let transformedData: any = data; - if (operation === "getList" && url.endsWith("/" + this.getDataKeys().plural)) { - transformedData = data[this.getDataKeys()["plural"]]; - return transformedData; - } else { - return data; - } - }); + // this.restangularService.setResponseInterceptor((data, operation, what, url, response, deferred) => { + // let transformedData: any = data; + // if (operation === "getList" && url.endsWith("/" + this.getDataKeys().plural)) { + // transformedData = data[this.getDataKeys()["plural"]]; + // return transformedData; + // } else { + // return data; + // } + // }); } protected extractData(response: restangular.IResponse): noosfero.RestResult { @@ -115,7 +117,7 @@ export abstract class RestangularService { if (rootElement) { restRequest = rootElement.customGET(this.getResourcePath(), queryParams, headers); } else { - restRequest = this.restangularService.all(this.getResourcePath()).customGET("", queryParams, headers); + restRequest = this.baseResource.customGET("", queryParams, headers); } @@ -130,7 +132,8 @@ export abstract class RestangularService { public listSubElements(obj: T, subElement: string, queryParams?: any, headers?: any): ng.IPromise> { let deferred = this.$q.defer>(); let restRequest: ng.IPromise>; - restRequest = obj.all(subElement).get(queryParams, headers); + let objElement = this.getElement(obj.id); + restRequest = objElement.all(subElement).get(queryParams, headers); restRequest.then(this.getHandleSuccessFunction(deferred)) .catch(this.getHandleErrorFunction(deferred)); return deferred.promise; @@ -201,7 +204,7 @@ export abstract class RestangularService { if (rootElement) { restRequest = rootElement.all(this.getResourcePath()).post(obj, queryParams, headers); } else { - restRequest = this.restangularService.all(this.getResourcePath()).post(obj, queryParams, headers); + restRequest = this.baseResource.post(obj, queryParams, headers); } restRequest.then(this.getHandleSuccessFunction(deferred)) diff --git a/src/lib/ng-noosfero-api/interfaces/activity.ts b/src/lib/ng-noosfero-api/interfaces/activity.ts new file mode 100644 index 0000000..8303151 --- /dev/null +++ b/src/lib/ng-noosfero-api/interfaces/activity.ts @@ -0,0 +1,5 @@ +namespace noosfero { + export interface Activity { + verb: string; + } +} \ No newline at end of file diff --git a/src/lib/ng-noosfero-api/interfaces/article.ts b/src/lib/ng-noosfero-api/interfaces/article.ts index d39db57..d6ea808 100644 --- a/src/lib/ng-noosfero-api/interfaces/article.ts +++ b/src/lib/ng-noosfero-api/interfaces/article.ts @@ -3,5 +3,6 @@ namespace noosfero { export interface Article extends RestModel { path: string; profile: Profile; + type: string; } } \ No newline at end of file diff --git a/src/lib/ng-noosfero-api/interfaces/block.ts b/src/lib/ng-noosfero-api/interfaces/block.ts new file mode 100644 index 0000000..81b1748 --- /dev/null +++ b/src/lib/ng-noosfero-api/interfaces/block.ts @@ -0,0 +1,5 @@ +namespace noosfero { + export interface Block { + id: number; + } +} \ No newline at end of file diff --git a/src/lib/ng-noosfero-api/interfaces/blog.ts b/src/lib/ng-noosfero-api/interfaces/blog.ts new file mode 100644 index 0000000..9ba352c --- /dev/null +++ b/src/lib/ng-noosfero-api/interfaces/blog.ts @@ -0,0 +1,4 @@ +namespace noosfero { + export interface Blog extends Article { + } +} \ No newline at end of file diff --git a/src/lib/ng-noosfero-api/interfaces/credentials.ts b/src/lib/ng-noosfero-api/interfaces/credentials.ts new file mode 100644 index 0000000..13c315c --- /dev/null +++ b/src/lib/ng-noosfero-api/interfaces/credentials.ts @@ -0,0 +1,6 @@ +namespace noosfero { + export interface Credentials { + username: string; + password: string; + } +} \ No newline at end of file diff --git a/src/lib/ng-noosfero-api/interfaces/profile.ts b/src/lib/ng-noosfero-api/interfaces/profile.ts index f20fd3b..25f0d0d 100644 --- a/src/lib/ng-noosfero-api/interfaces/profile.ts +++ b/src/lib/ng-noosfero-api/interfaces/profile.ts @@ -3,5 +3,6 @@ namespace noosfero { export interface Profile extends RestModel { identifier: string; type: string; + name?: string; } } \ No newline at end of file diff --git a/src/lib/ng-noosfero-api/interfaces/tinymce_article.ts b/src/lib/ng-noosfero-api/interfaces/tinymce_article.ts new file mode 100644 index 0000000..c5e2f43 --- /dev/null +++ b/src/lib/ng-noosfero-api/interfaces/tinymce_article.ts @@ -0,0 +1,4 @@ +namespace noosfero { + export interface TynyMceArticle extends Article { + } +} \ No newline at end of file diff --git a/src/lib/ng-noosfero-api/interfaces/user.ts b/src/lib/ng-noosfero-api/interfaces/user.ts new file mode 100644 index 0000000..e3874f0 --- /dev/null +++ b/src/lib/ng-noosfero-api/interfaces/user.ts @@ -0,0 +1,10 @@ +namespace noosfero { + export interface User { + id: number; + login: string; + email: string; + person: Person; + private_token: string; + userRole: string; + } +} \ No newline at end of file diff --git a/src/spec/helpers.ts b/src/spec/helpers.ts index 3f5cfbb..4b93500 100644 --- a/src/spec/helpers.ts +++ b/src/spec/helpers.ts @@ -2,7 +2,6 @@ import {ngClass, TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; import {providers} from 'ng-forward/cjs/testing/providers'; import {Injectable, Inject, Provider, Input, provide, Component} from 'ng-forward'; -import {User, Person} from "./../app/models/interfaces"; export var ngforward = { @@ -101,7 +100,7 @@ export var fixtures = { id: 1, login: 'user', email: 'user@company.com', - person: { + person: { id: 1, identifier: 'user' }, -- libgit2 0.21.2