Commit bdd92ab95ce62d9cf4ac47ad8a6ee0dfa5bf230b

Authored by Ábner Oliveira
1 parent e7a64b2d
Exists in master and in 1 other branch dev-fixes

refactory of interfaces

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