Commit bdd92ab95ce62d9cf4ac47ad8a6ee0dfa5bf230b
1 parent
e7a64b2d
Exists in
master
and in
1 other branch
refactory of interfaces
Showing
36 changed files
with
158 additions
and
190 deletions
Show diff stats
src/app/cms/cms.component.ts
1 | 1 | import {StateConfig, Component, Inject, provide} from 'ng-forward'; |
2 | -import {Profile} from "./../models/interfaces"; | |
3 | 2 | import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; |
4 | 3 | import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; |
5 | 4 | import {Notification} from "../components/notification/notification.component"; | ... | ... |
src/app/components/auth/auth_controller.ts
1 | -import {Credentials} from "./../../models/interfaces"; | |
2 | 1 | import {AuthService} from "./auth_service"; |
3 | 2 | |
4 | 3 | export class AuthController { |
... | ... | @@ -13,7 +12,7 @@ export class AuthController { |
13 | 12 | |
14 | 13 | } |
15 | 14 | |
16 | - credentials: Credentials; | |
15 | + credentials: noosfero.Credentials; | |
17 | 16 | |
18 | 17 | login() { |
19 | 18 | this.AuthService.login(this.credentials); | ... | ... |
src/app/components/auth/auth_service.spec.ts
1 | 1 | |
2 | 2 | |
3 | 3 | import {AuthService, AUTH_EVENTS} from "./"; |
4 | -import {User, Credentials} from "./../../models/interfaces"; | |
5 | 4 | |
6 | 5 | describe("Services", () => { |
7 | 6 | |
... | ... | @@ -10,9 +9,9 @@ describe("Services", () => { |
10 | 9 | |
11 | 10 | let $httpBackend: ng.IHttpBackendService; |
12 | 11 | let authService: AuthService; |
13 | - let credentials: Credentials; | |
12 | + let credentials: noosfero.Credentials; | |
14 | 13 | let $rootScope: ng.IRootScopeService; |
15 | - let user: User; | |
14 | + let user: noosfero.User; | |
16 | 15 | |
17 | 16 | beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => { |
18 | 17 | $translateProvider.translations('en', {}); |
... | ... | @@ -23,7 +22,7 @@ describe("Services", () => { |
23 | 22 | authService = _AuthService_; |
24 | 23 | $rootScope = _$rootScope_; |
25 | 24 | |
26 | - user = <User>{ | |
25 | + user = <noosfero.User>{ | |
27 | 26 | id: 1, |
28 | 27 | login: "user" |
29 | 28 | }; |
... | ... | @@ -53,7 +52,7 @@ describe("Services", () => { |
53 | 52 | authService.login(credentials); |
54 | 53 | |
55 | 54 | let eventEmmited: boolean = false; |
56 | - $rootScope.$on(AUTH_EVENTS.loginSuccess, (event: ng.IAngularEvent, userThroughEvent: User) => { | |
55 | + $rootScope.$on(AUTH_EVENTS.loginSuccess, (event: ng.IAngularEvent, userThroughEvent: noosfero.User) => { | |
57 | 56 | eventEmmited = true; |
58 | 57 | expect(userThroughEvent).toEqual(user); |
59 | 58 | }); |
... | ... | @@ -66,7 +65,7 @@ describe("Services", () => { |
66 | 65 | it("should return the current logged in user", () => { |
67 | 66 | authService.login(credentials); |
68 | 67 | $httpBackend.flush(); |
69 | - let actual: User = authService.currentUser(); | |
68 | + let actual: noosfero.User = authService.currentUser(); | |
70 | 69 | expect(actual).toEqual(user, "The returned user must be present"); |
71 | 70 | }); |
72 | 71 | ... | ... |
src/app/components/auth/auth_service.ts
1 | 1 | import {Injectable, Inject} from "ng-forward"; |
2 | 2 | |
3 | -import {Credentials, NoosferoRootScope, User, UserResponse} from "./../../models/interfaces"; | |
3 | +import {NoosferoRootScope, UserResponse} from "./../../models/interfaces"; | |
4 | 4 | import {Session} from "./session"; |
5 | 5 | |
6 | 6 | import {AUTH_EVENTS, IAuthEvents} from "./auth_events"; |
... | ... | @@ -26,13 +26,13 @@ export class AuthService { |
26 | 26 | |
27 | 27 | private loginSuccessCallback(response: ng.IHttpPromiseCallbackArg<UserResponse>) { |
28 | 28 | this.$log.debug('AuthService.login [SUCCESS] response', response); |
29 | - let currentUser: User = this.session.create(response.data); | |
29 | + let currentUser: noosfero.User = this.session.create(response.data); | |
30 | 30 | this.$rootScope.currentUser = currentUser; |
31 | 31 | this.$rootScope.$broadcast(this.auth_events.loginSuccess, currentUser); |
32 | 32 | return currentUser; |
33 | 33 | } |
34 | 34 | |
35 | - login(credentials: Credentials): ng.IPromise<User> { | |
35 | + login(credentials: noosfero.Credentials): ng.IPromise<noosfero.User> { | |
36 | 36 | let url = '/api/v1/login'; |
37 | 37 | let encodedData = 'login=' + credentials.username + '&password=' + credentials.password; |
38 | 38 | return this.$http.post(url, encodedData).then(this.loginSuccessCallback.bind(this), this.loginFailedCallback.bind(this)); |
... | ... | @@ -56,7 +56,7 @@ export class AuthService { |
56 | 56 | return !!this.session.currentUser(); |
57 | 57 | } |
58 | 58 | |
59 | - public currentUser(): User { | |
59 | + public currentUser(): noosfero.User { | |
60 | 60 | return this.session.currentUser(); |
61 | 61 | } |
62 | 62 | ... | ... |
src/app/components/auth/session.ts
1 | 1 | import {Injectable, Inject} from "ng-forward"; |
2 | -import {UserResponse, User, INoosferoLocalStorage} from "./../../models/interfaces"; | |
2 | +import {UserResponse, INoosferoLocalStorage} from "./../../models/interfaces"; | |
3 | 3 | |
4 | 4 | @Injectable() |
5 | 5 | @Inject("$localStorage", "$log") |
... | ... | @@ -9,7 +9,7 @@ export class Session { |
9 | 9 | |
10 | 10 | } |
11 | 11 | |
12 | - create(data: UserResponse): User { | |
12 | + create(data: UserResponse): noosfero.User { | |
13 | 13 | this.$localStorage.currentUser = data.user; |
14 | 14 | this.$log.debug('User session created.', this.$localStorage.currentUser); |
15 | 15 | return this.$localStorage.currentUser; |
... | ... | @@ -20,7 +20,7 @@ export class Session { |
20 | 20 | this.$log.debug('User session destroyed.'); |
21 | 21 | }; |
22 | 22 | |
23 | - currentUser(): User { | |
23 | + currentUser(): noosfero.User { | |
24 | 24 | return this.$localStorage.currentUser; |
25 | 25 | }; |
26 | 26 | ... | ... |
src/app/components/auth/session_spec.ts
1 | 1 | import {Component} from "ng-forward"; |
2 | 2 | import {Session} from "./"; |
3 | 3 | import {fixtures, createComponentFromClass, createProviderToValue} from "./../../../spec/helpers"; |
4 | -import {UserResponse, User, INoosferoLocalStorage} from "./../../models/interfaces"; | |
4 | +import {UserResponse, INoosferoLocalStorage} from "./../../models/interfaces"; | |
5 | 5 | |
6 | 6 | |
7 | 7 | describe("Services", () => { | ... | ... |
src/app/components/navbar/navbar.spec.ts
1 | 1 | import * as helpers from "./../../../spec/helpers"; |
2 | 2 | import {Navbar} from "./navbar"; |
3 | 3 | import {AUTH_EVENTS} from "./../auth"; |
4 | -import {User} from "./../../models/interfaces"; | |
5 | 4 | import {Injectable, Provider, provide} from "ng-forward"; |
6 | 5 | |
7 | 6 | import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; |
... | ... | @@ -13,7 +12,7 @@ describe("Components", () => { |
13 | 12 | |
14 | 13 | describe("Navbar Component", () => { |
15 | 14 | |
16 | - let user: User = null; | |
15 | + let user: noosfero.User = null; | |
17 | 16 | let scope: any; |
18 | 17 | let $rootScope: ng.IRootScopeService; |
19 | 18 | |
... | ... | @@ -27,7 +26,7 @@ describe("Components", () => { |
27 | 26 | |
28 | 27 | // before Each -> loading mocks on locals variables |
29 | 28 | beforeEach(() => { |
30 | - user = <User>{ | |
29 | + user = <noosfero.User>{ | |
31 | 30 | id: 1, |
32 | 31 | login: "user" |
33 | 32 | }; | ... | ... |
src/app/components/navbar/navbar.ts
... | ... | @@ -3,7 +3,6 @@ import {LanguageSelector} from "../language-selector/language-selector.component |
3 | 3 | |
4 | 4 | |
5 | 5 | import {Session, AuthService, AuthController, IAuthEvents, AUTH_EVENTS} from "./../auth"; |
6 | -import {User} from "./../../models/interfaces"; | |
7 | 6 | |
8 | 7 | @Component({ |
9 | 8 | selector: "acme-navbar", |
... | ... | @@ -14,7 +13,7 @@ import {User} from "./../../models/interfaces"; |
14 | 13 | @Inject("$modal", AuthService, "Session", "$scope", "$state") |
15 | 14 | export class Navbar { |
16 | 15 | |
17 | - private currentUser: User; | |
16 | + private currentUser: noosfero.User; | |
18 | 17 | private modalInstance: any = null; |
19 | 18 | /** |
20 | 19 | * | ... | ... |
src/app/components/noosfero-activities/activities.component.ts
1 | 1 | import {Component, Input} from "ng-forward"; |
2 | 2 | import {NoosferoActivity} from "./activity/activity.component"; |
3 | -import {Activity} from "../../models/interfaces"; | |
4 | 3 | |
5 | 4 | @Component({ |
6 | 5 | selector: "noosfero-activities", |
... | ... | @@ -9,6 +8,6 @@ import {Activity} from "../../models/interfaces"; |
9 | 8 | }) |
10 | 9 | export class NoosferoActivities { |
11 | 10 | |
12 | - @Input() activities: Activity[]; | |
11 | + @Input() activities: noosfero.Activity[]; | |
13 | 12 | |
14 | 13 | } | ... | ... |
src/app/components/noosfero-activities/activity/activity.component.ts
1 | 1 | import {Component, Input} from "ng-forward"; |
2 | -import {Activity} from "../../../models/interfaces"; | |
3 | 2 | |
4 | 3 | @Component({ |
5 | 4 | selector: "noosfero-activity", |
... | ... | @@ -7,7 +6,7 @@ import {Activity} from "../../../models/interfaces"; |
7 | 6 | }) |
8 | 7 | export class NoosferoActivity { |
9 | 8 | |
10 | - @Input() activity: Activity; | |
9 | + @Input() activity: noosfero.Activity; | |
11 | 10 | |
12 | 11 | getActivityTemplate() { |
13 | 12 | return 'app/components/noosfero-activities/activity/' + this.activity.verb + '.html'; | ... | ... |
src/app/components/noosfero-articles/article/article_view.ts
... | ... | @@ -7,8 +7,8 @@ import {ArticleBlog} from "../blog/blog.component"; |
7 | 7 | }) |
8 | 8 | export class ArticleDefaultView { |
9 | 9 | |
10 | - @Input() article: any; | |
11 | - @Input() profile: any; | |
10 | + @Input() article: noosfero.Article; | |
11 | + @Input() profile: noosfero.Profile; | |
12 | 12 | |
13 | 13 | } |
14 | 14 | |
... | ... | @@ -20,8 +20,8 @@ export class ArticleDefaultView { |
20 | 20 | @Inject("$element", "$scope", "$injector", "$compile") |
21 | 21 | export class ArticleView { |
22 | 22 | |
23 | - @Input() article: any; | |
24 | - @Input() profile: any; | |
23 | + @Input() article: noosfero.Article; | |
24 | + @Input() profile: noosfero.Profile; | |
25 | 25 | directiveName: string; |
26 | 26 | |
27 | 27 | ngOnInit() { | ... | ... |
src/app/components/noosfero-articles/blog/blog.component.ts
1 | 1 | import {Component, Input, Inject} from "ng-forward"; |
2 | 2 | |
3 | -import {Article, Profile} from "./../../../models/interfaces"; | |
4 | 3 | import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.service"; |
5 | 4 | |
6 | 5 | @Component({ |
... | ... | @@ -11,7 +10,7 @@ import {ArticleService} from "../../../../lib/ng-noosfero-api/http/article.servi |
11 | 10 | export class ArticleBlog { |
12 | 11 | |
13 | 12 | @Input() article: noosfero.Article; |
14 | - @Input() profile: Profile; | |
13 | + @Input() profile: noosfero.Profile; | |
15 | 14 | |
16 | 15 | private posts: noosfero.Article[]; |
17 | 16 | private perPage: number = 3; | ... | ... |
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 |
8 | 8 | @Inject(ProfileService) |
9 | 9 | export class MembersBlock { |
10 | 10 | |
11 | - @Input() block: any; | |
12 | - @Input() owner: any; | |
11 | + @Input() block: noosfero.Block; | |
12 | + @Input() owner: noosfero.Profile; | |
13 | 13 | |
14 | 14 | members: any = []; |
15 | 15 | ... | ... |
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 |
8 | 8 | }) |
9 | 9 | export class ProfileImageBlock { |
10 | 10 | |
11 | - @Input() block: any; | |
12 | - @Input() owner: any; | |
11 | + @Input() block: noosfero.Block; | |
12 | + @Input() owner: noosfero.Profile; | |
13 | 13 | |
14 | 14 | } | ... | ... |
src/app/components/noosfero-boxes/boxes.component.spec.ts
1 | 1 | import {Component} from 'ng-forward'; |
2 | 2 | |
3 | -import {Box, Profile} from "../../models/interfaces"; | |
4 | 3 | import {Boxes} from './boxes.component'; |
5 | 4 | |
6 | 5 | import { |
... | ... | @@ -29,12 +28,12 @@ describe("Boxes Component", () => { |
29 | 28 | providers: [] |
30 | 29 | }) |
31 | 30 | class BoxesContainerComponent { |
32 | - boxes: Box[] = [ | |
31 | + boxes: noosfero.Box[] = [ | |
33 | 32 | { id: 1, position: 1 }, |
34 | 33 | { id: 2, position: 2 } |
35 | 34 | ]; |
36 | 35 | |
37 | - owner: Profile = { | |
36 | + owner: noosfero.Profile = <noosfero.Profile> { | |
38 | 37 | id: 1, |
39 | 38 | identifier: 'profile-name', |
40 | 39 | type: 'Person' | ... | ... |
src/app/components/noosfero-boxes/boxes.component.ts
1 | 1 | import {Input, Inject, Component} from 'ng-forward'; |
2 | -import {Box, Profile} from "./../../models/interfaces"; | |
3 | 2 | |
4 | 3 | @Component({ |
5 | 4 | selector: "noosfero-boxes", |
... | ... | @@ -7,10 +6,10 @@ import {Box, Profile} from "./../../models/interfaces"; |
7 | 6 | }) |
8 | 7 | export class Boxes { |
9 | 8 | |
10 | - @Input() boxes: Box[]; | |
11 | - @Input() owner: Profile; | |
9 | + @Input() boxes: noosfero.Box[]; | |
10 | + @Input() owner: noosfero.Profile; | |
12 | 11 | |
13 | - boxesOrder(box: Box) { | |
12 | + boxesOrder(box: noosfero.Box) { | |
14 | 13 | if (box.position === 2) return 0; |
15 | 14 | return box.position; |
16 | 15 | } | ... | ... |
src/app/components/noosfero/profile-image/profile-image.component.spec.ts
... | ... | @@ -17,7 +17,7 @@ describe("Components", () => { |
17 | 17 | it("show community users image if profile is not Person", done => { |
18 | 18 | helpers.tcb.createAsync(ProfileImage).then(fixture => { |
19 | 19 | let profileImageComponent: ProfileImage = fixture.componentInstance; |
20 | - let profile = { id: 1, identifier: "myprofile", type: "Community" }; | |
20 | + let profile = <noosfero.Profile>{ id: 1, identifier: "myprofile", type: "Community" }; | |
21 | 21 | profileImageComponent.profile = profile; |
22 | 22 | profileImageComponent.ngOnInit(); |
23 | 23 | |
... | ... | @@ -32,7 +32,7 @@ describe("Components", () => { |
32 | 32 | it("show Person image if profile is Person", done => { |
33 | 33 | tcb.createAsync(ProfileImage).then(fixture => { |
34 | 34 | let profileImageComponent: ProfileImage = fixture.componentInstance; |
35 | - let profile = { id: 1, identifier: "myprofile", type: "Person" }; | |
35 | + let profile = <noosfero.Profile>{ id: 1, identifier: "myprofile", type: "Person" }; | |
36 | 36 | profileImageComponent.profile = profile; |
37 | 37 | profileImageComponent.ngOnInit(); |
38 | 38 | // Check the attribute | ... | ... |
src/app/components/noosfero/profile-image/profile-image.component.ts
1 | 1 | import {Inject, Input, Component} from "ng-forward"; |
2 | -import {Profile} from "./../../../models/interfaces"; | |
3 | 2 | |
4 | 3 | @Component({ |
5 | 4 | selector: "noosfero-profile-image", |
... | ... | @@ -7,7 +6,7 @@ import {Profile} from "./../../../models/interfaces"; |
7 | 6 | }) |
8 | 7 | export class ProfileImage { |
9 | 8 | |
10 | - @Input() profile: Profile; | |
9 | + @Input() profile: noosfero.Profile; | |
11 | 10 | defaultIcon: string; |
12 | 11 | |
13 | 12 | ngOnInit() { | ... | ... |
src/app/content-viewer/content-viewer.component.ts
... | ... | @@ -4,7 +4,7 @@ import {Input, Component, StateConfig, Inject, provide} from "ng-forward"; |
4 | 4 | import {ArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; |
5 | 5 | import {ArticleService} from "../../lib/ng-noosfero-api/http/article.service"; |
6 | 6 | import {ProfileService} from "../../lib/ng-noosfero-api/http/profile.service"; |
7 | -import {Profile} from "../models/interfaces"; | |
7 | + | |
8 | 8 | @Component({ |
9 | 9 | selector: "content-viewer", |
10 | 10 | templateUrl: "app/content-viewer/page.html", | ... | ... |
src/app/models/interfaces.ts
1 | 1 | export interface NoosferoRootScope extends ng.IScope { |
2 | - currentUser: User; | |
3 | -} | |
4 | - | |
5 | -export interface Event extends Article { | |
6 | - id: number; | |
7 | -} | |
8 | - | |
9 | -export interface Article { | |
10 | - id: number; | |
11 | -} | |
12 | - | |
13 | -export interface Profile { | |
14 | - id: number; | |
15 | - identifier: string; | |
16 | - type: string; | |
17 | -} | |
18 | - | |
19 | -export interface Person extends Profile { | |
20 | - id: number; | |
21 | -} | |
22 | - | |
23 | -export interface TynyMceArticle extends Article { | |
24 | - id: number; | |
25 | -} | |
26 | - | |
27 | -export interface Blog extends Article { | |
28 | - id: number; | |
29 | -} | |
30 | - | |
31 | -export interface Credentials { | |
32 | - username: string; | |
33 | - password: string; | |
34 | -} | |
35 | - | |
36 | -export interface User { | |
37 | - id: number; | |
38 | - login: string; | |
39 | - email: string; | |
40 | - person: Person; | |
41 | - private_token: string; | |
42 | - userRole: string; | |
2 | + currentUser: noosfero.User; | |
43 | 3 | } |
44 | 4 | |
45 | 5 | export interface UserResponse { |
46 | - user: User; | |
6 | + user: noosfero.User; | |
47 | 7 | } |
48 | 8 | |
49 | 9 | |
50 | -export interface Box { | |
51 | - id: number; | |
52 | - position: number; | |
53 | -} | |
54 | - | |
55 | -export interface Activity { | |
56 | - verb: string; | |
57 | -} | |
58 | - | |
59 | 10 | export interface INoosferoLocalStorage extends angular.storage.ILocalStorageService { |
60 | - currentUser: User; | |
11 | + currentUser: noosfero.User; | |
61 | 12 | } | ... | ... |
src/app/profile-info/profile-info.component.ts
src/lib/ng-noosfero-api/http/article.service.spec.ts
1 | -import {Article} from "../../../app/models/interfaces"; | |
2 | 1 | import {ArticleService} from "./article.service"; |
3 | 2 | |
4 | 3 | |
5 | -// describe("Services", () => { | |
4 | +describe("Services", () => { | |
6 | 5 | |
7 | -// xdescribe("Article Service", () => { | |
6 | + describe("Article Service", () => { | |
8 | 7 | |
9 | -// let $httpBackend: ng.IHttpBackendService; | |
10 | -// let articleService: ArticleService; | |
8 | + let $httpBackend: ng.IHttpBackendService; | |
9 | + let articleService: ArticleService; | |
11 | 10 | |
12 | -// beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => { | |
13 | -// $translateProvider.translations('en', {}); | |
14 | -// })); | |
11 | + beforeEach(angular.mock.module("noosferoApp", ($translateProvider: angular.translate.ITranslateProvider) => { | |
12 | + $translateProvider.translations('en', {}); | |
13 | + })); | |
15 | 14 | |
16 | -// beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _ArticleService_: ArticleService) => { | |
17 | -// $httpBackend = _$httpBackend_; | |
18 | -// articleService = _ArticleService_; | |
19 | -// })); | |
15 | + beforeEach(inject((_$httpBackend_: ng.IHttpBackendService, _ArticleService_: ArticleService) => { | |
16 | + $httpBackend = _$httpBackend_; | |
17 | + articleService = _ArticleService_; | |
18 | + })); | |
20 | 19 | |
21 | 20 | |
22 | -// describe("Succesfull requests", () => { | |
21 | + describe("Succesfull requests", () => { | |
23 | 22 | |
24 | -// it("should return article children", (done) => { | |
25 | -// let articleId = 1; | |
26 | -// $httpBackend.expectGET(`/api/v1/articles/${articleId}/children`).respond(200, { articles: [{ name: "article1" }] }); | |
27 | -// articleService.getChildren<noosfero.ArticlesResult>(articleId).then((result: noosfero.ArticlesResult) => { | |
28 | -// expect(result.articles).toEqual([{ name: "article1" }]); | |
29 | -// done(); | |
30 | -// }); | |
31 | -// $httpBackend.flush(); | |
32 | -// }); | |
23 | + it("should return article children", (done) => { | |
24 | + let articleId = 1; | |
25 | + $httpBackend.expectGET(`/api/v1/articles/${articleId}/children`).respond(200, { articles: [{ name: "article1" }] }); | |
26 | + articleService.getChildren(<noosfero.Article>{id: articleId}).then((result: noosfero.RestResult<noosfero.Article[]>) => { | |
27 | + expect(result.data).toEqual([{ name: "article1" }]); | |
28 | + done(); | |
29 | + }); | |
30 | + $httpBackend.flush(); | |
31 | + }); | |
33 | 32 | |
34 | -// it("should get articles by profile", (done) => { | |
35 | -// let profileId = 1; | |
36 | -// $httpBackend.expectGET(`/api/v1/profiles/${profileId}/articles`).respond(200, { articles: [{ name: "article1" }] }); | |
37 | -// articleService.getByProfile<noosfero.ArticlesResult>(profileId).then((result: noosfero.ArticlesResult) => { | |
38 | -// expect(result.articles).toEqual([{ name: "article1" }]); | |
39 | -// done(); | |
40 | -// }); | |
41 | -// $httpBackend.flush(); | |
42 | -// }); | |
33 | + it("should get articles by profile", (done) => { | |
34 | + let profileId = 1; | |
35 | + $httpBackend.expectGET(`/api/v1/profiles/${profileId}/articles`).respond(200, { articles: [{ name: "article1" }] }); | |
36 | + articleService.getByProfile(<noosfero.Profile>{id: profileId}).then((result: noosfero.RestResult<noosfero.Article[]>) => { | |
37 | + expect(result.data).toEqual([{ name: "article1" }]); | |
38 | + done(); | |
39 | + }); | |
40 | + $httpBackend.flush(); | |
41 | + }); | |
43 | 42 | |
44 | -// it("should get articles by profile with additional filters", (done) => { | |
45 | -// let profileId = 1; | |
46 | -// $httpBackend.expectGET(`/api/v1/profiles/${profileId}/articles?path=test`).respond(200, { articles: [{ name: "article1" }] }); | |
47 | -// articleService.getByProfile<noosfero.ArticlesResult>(profileId, { path: 'test' }).then((result: noosfero.ArticlesResult) => { | |
48 | -// expect(result.articles).toEqual([{ name: "article1" }]); | |
49 | -// done(); | |
50 | -// }); | |
51 | -// $httpBackend.flush(); | |
52 | -// }); | |
43 | + it("should get articles by profile with additional filters", (done) => { | |
44 | + let profileId = 1; | |
45 | + $httpBackend.expectGET(`/api/v1/profiles/${profileId}/articles?path=test`).respond(200, { articles: [{ name: "article1" }] }); | |
46 | + articleService.getByProfile(<noosfero.Profile>{id: profileId}, { path: 'test' }).then((result: noosfero.RestResult<noosfero.Article[]>) => { | |
47 | + expect(result.data).toEqual([{ name: "article1" }]); | |
48 | + done(); | |
49 | + }); | |
50 | + $httpBackend.flush(); | |
51 | + }); | |
53 | 52 | |
54 | -// it("should get article children with additional filters", (done) => { | |
55 | -// let articleId = 1; | |
56 | -// $httpBackend.expectGET(`/api/v1/articles/${articleId}/children?path=test`).respond(200, { articles: [{ name: "article1" }] }); | |
57 | -// articleService.getChildren<noosfero.ArticlesResult>(articleId, { path: 'test' }).then((result: noosfero.ArticlesResult) => { | |
58 | -// expect(result.articles).toEqual([{ name: "article1" }]); | |
59 | -// done(); | |
60 | -// }); | |
61 | -// $httpBackend.flush(); | |
62 | -// }); | |
53 | + it("should get article children with additional filters", (done) => { | |
54 | + let articleId = 1; | |
55 | + $httpBackend.expectGET(`/api/v1/articles/${articleId}/children?path=test`).respond(200, { articles: [{ name: "article1" }] }); | |
56 | + articleService.getChildren(<noosfero.Article>{id: articleId}, { path: 'test' }).then((result: noosfero.RestResult<noosfero.Article[]>) => { | |
57 | + expect(result.data).toEqual([{ name: "article1" }]); | |
58 | + done(); | |
59 | + }); | |
60 | + $httpBackend.flush(); | |
61 | + }); | |
63 | 62 | |
64 | -// it("should create an article in a profile", (done) => { | |
65 | -// let profileId = 1; | |
66 | -// let article: noosfero.Article = <any>{ id: null}; | |
67 | -// $httpBackend.expectPOST(`/api/v1/profiles/${profileId}/articles`, { article: article }).respond(200, {article: { id: 2 }}); | |
68 | -// articleService.create(profileId, article).then((article: noosfero.Article) => { | |
69 | -// expect(article).toEqual({ id: 2 }); | |
70 | -// done(); | |
71 | -// }); | |
72 | -// $httpBackend.flush(); | |
73 | -// }); | |
74 | -// }); | |
63 | + it("should create an article in a profile", (done) => { | |
64 | + let profileId = 1; | |
65 | + let article: noosfero.Article = <any>{ id: null}; | |
66 | + $httpBackend.expectPOST(`/api/v1/profiles/${profileId}/articles`, { article: article }).respond(200, {article: { id: 2 }}); | |
67 | + articleService.createInProfile(<noosfero.Profile>{id: profileId}, article).then((result: noosfero.RestResult<noosfero.Article>) => { | |
68 | + expect(result.data).toEqual({ id: 2 }); | |
69 | + done(); | |
70 | + }); | |
71 | + $httpBackend.flush(); | |
72 | + }); | |
73 | + }); | |
75 | 74 | |
76 | 75 | |
77 | -// }); | |
78 | -// }); | |
76 | + }); | |
77 | +}); | ... | ... |
src/lib/ng-noosfero-api/http/article.service.ts
... | ... | @@ -24,6 +24,8 @@ export class ArticleService extends RestangularService<noosfero.Article> { |
24 | 24 | |
25 | 25 | |
26 | 26 | createInProfile(profile: noosfero.Profile, article: noosfero.Article): ng.IPromise<noosfero.RestResult<noosfero.Article>> { |
27 | + let profileElement = this.profileService.get(<number>profile.id); | |
28 | + (<any>profileElement).id = profile.id; | |
27 | 29 | return this.create(article, profile); |
28 | 30 | } |
29 | 31 | |
... | ... | @@ -47,7 +49,9 @@ export class ArticleService extends RestangularService<noosfero.Article> { |
47 | 49 | } |
48 | 50 | |
49 | 51 | getChildren<T>(article: noosfero.Article, params?: any): ng.IPromise<noosfero.RestResult<noosfero.Article[]>> { |
50 | - return this.listSubElements(article, "children", params); | |
52 | + let articleElement = this.getElement(article.id); | |
53 | + articleElement.id = article.id; | |
54 | + return this.listSubElements(<noosfero.Article>articleElement, "children", params); | |
51 | 55 | } |
52 | 56 | |
53 | 57 | ... | ... |
src/lib/ng-noosfero-api/http/profile.service.spec.ts
src/lib/ng-noosfero-api/http/profile.service.ts
src/lib/ng-noosfero-api/http/restangular_service.spec.ts
... | ... | @@ -7,13 +7,8 @@ interface RootObjectModel extends noosfero.RestModel { |
7 | 7 | |
8 | 8 | } |
9 | 9 | |
10 | - | |
11 | - | |
12 | - | |
13 | 10 | describe("Restangular Service - base Class", () => { |
14 | 11 | |
15 | - | |
16 | - | |
17 | 12 | class ObjectRestService extends RestangularService<ObjectModel> { |
18 | 13 | public getDataKeys() { |
19 | 14 | return { |
... | ... | @@ -212,8 +207,4 @@ describe("Restangular Service - base Class", () => { |
212 | 207 | $httpBackend.flush(); |
213 | 208 | }); |
214 | 209 | |
215 | - | |
216 | - | |
217 | - | |
218 | - | |
219 | 210 | }); |
220 | 211 | \ No newline at end of file | ... | ... |
src/lib/ng-noosfero-api/http/restangular_service.ts
... | ... | @@ -10,6 +10,7 @@ |
10 | 10 | */ |
11 | 11 | export abstract class RestangularService<T extends noosfero.RestModel> { |
12 | 12 | |
13 | + private baseResource: restangular.IElement; | |
13 | 14 | /** |
14 | 15 | * Creates an instance of RestangularService. |
15 | 16 | * |
... | ... | @@ -18,16 +19,17 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
18 | 19 | * @param {ng.ILogService} $log (description) |
19 | 20 | */ |
20 | 21 | constructor(protected restangularService: restangular.IService, protected $q: ng.IQService, protected $log: ng.ILogService) { |
22 | + this.baseResource = restangularService.all(this.getResourcePath()); | |
21 | 23 | // TODO |
22 | - this.restangularService.setResponseInterceptor((data, operation, what, url, response, deferred) => { | |
23 | - let transformedData: any = data; | |
24 | - if (operation === "getList" && url.endsWith("/" + this.getDataKeys().plural)) { | |
25 | - transformedData = data[this.getDataKeys()["plural"]]; | |
26 | - return transformedData; | |
27 | - } else { | |
28 | - return data; | |
29 | - } | |
30 | - }); | |
24 | + // this.restangularService.setResponseInterceptor((data, operation, what, url, response, deferred) => { | |
25 | + // let transformedData: any = data; | |
26 | + // if (operation === "getList" && url.endsWith("/" + this.getDataKeys().plural)) { | |
27 | + // transformedData = data[this.getDataKeys()["plural"]]; | |
28 | + // return transformedData; | |
29 | + // } else { | |
30 | + // return data; | |
31 | + // } | |
32 | + // }); | |
31 | 33 | } |
32 | 34 | |
33 | 35 | protected extractData(response: restangular.IResponse): noosfero.RestResult<T> { |
... | ... | @@ -115,7 +117,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
115 | 117 | if (rootElement) { |
116 | 118 | restRequest = rootElement.customGET(this.getResourcePath(), queryParams, headers); |
117 | 119 | } else { |
118 | - restRequest = this.restangularService.all(this.getResourcePath()).customGET("", queryParams, headers); | |
120 | + restRequest = this.baseResource.customGET("", queryParams, headers); | |
119 | 121 | } |
120 | 122 | |
121 | 123 | |
... | ... | @@ -130,7 +132,8 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
130 | 132 | public listSubElements<C>(obj: T, subElement: string, queryParams?: any, headers?: any): ng.IPromise<noosfero.RestResult<C>> { |
131 | 133 | let deferred = this.$q.defer<noosfero.RestResult<C>>(); |
132 | 134 | let restRequest: ng.IPromise<noosfero.RestResult<T>>; |
133 | - restRequest = obj.all(subElement).get(queryParams, headers); | |
135 | + let objElement = this.getElement(obj.id); | |
136 | + restRequest = objElement.all(subElement).get(queryParams, headers); | |
134 | 137 | restRequest.then(this.getHandleSuccessFunction(deferred)) |
135 | 138 | .catch(this.getHandleErrorFunction(deferred)); |
136 | 139 | return deferred.promise; |
... | ... | @@ -201,7 +204,7 @@ export abstract class RestangularService<T extends noosfero.RestModel> { |
201 | 204 | if (rootElement) { |
202 | 205 | restRequest = rootElement.all(this.getResourcePath()).post(obj, queryParams, headers); |
203 | 206 | } else { |
204 | - restRequest = this.restangularService.all(this.getResourcePath()).post(obj, queryParams, headers); | |
207 | + restRequest = this.baseResource.post(obj, queryParams, headers); | |
205 | 208 | } |
206 | 209 | |
207 | 210 | restRequest.then(this.getHandleSuccessFunction(deferred)) | ... | ... |
src/lib/ng-noosfero-api/interfaces/article.ts
src/lib/ng-noosfero-api/interfaces/profile.ts
src/spec/helpers.ts
... | ... | @@ -2,7 +2,6 @@ |
2 | 2 | import {ngClass, TestComponentBuilder, ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder'; |
3 | 3 | import {providers} from 'ng-forward/cjs/testing/providers'; |
4 | 4 | import {Injectable, Inject, Provider, Input, provide, Component} from 'ng-forward'; |
5 | -import {User, Person} from "./../app/models/interfaces"; | |
6 | 5 | |
7 | 6 | |
8 | 7 | export var ngforward = { |
... | ... | @@ -101,7 +100,7 @@ export var fixtures = { |
101 | 100 | id: 1, |
102 | 101 | login: 'user', |
103 | 102 | email: 'user@company.com', |
104 | - person: <Person>{ | |
103 | + person: <noosfero.Person>{ | |
105 | 104 | id: 1, |
106 | 105 | identifier: 'user' |
107 | 106 | }, | ... | ... |