Commit 6738dc3655eb451131e01fa3381722dcd9c2021b

Authored by ABNER SILVA DE OLIVEIRA
1 parent 807f6df6

migrated auth_service, session and auth controller to typescript. renamed articl…

…edirective to articleView. fixed articleView test.
.vscode/settings.json
... ... @@ -4,5 +4,7 @@
4 4 "**/.git": true,
5 5 "**/.DS_Store": true,
6 6 "src/app/*.js": false
7   - }
  7 + },
  8 + "editor.fontSize": 14,
  9 + "typescript.useCodeSnippetsOnMethodSuggest": true
8 10 }
9 11 \ No newline at end of file
... ...
src/app/cms/cms.component.ts
1 1 import {StateConfig, Component, Inject} from 'ng-forward';
2   -
  2 +import {Profile} from "./../models/interfaces";
3 3 @Component({
4 4 selector: 'cms',
5 5 templateUrl: "app/cms/cms.html"
... ... @@ -10,19 +10,19 @@ export class Cms {
10 10 article: any = {};
11 11 profile: any;
12 12  
13   - constructor(private noosfero, private $stateParams, private $httpParamSerializer, private $state, private SweetAlert) {
  13 + constructor(private noosfero: any/* TODO convert noosferoService */, private $stateParams: ng.ui.IStateParamsService, private $httpParamSerializer: any, private $state: ng.ui.IStateService, private SweetAlert: any) {
14 14  
15 15 }
16 16  
17 17 save() {
18   - this.noosfero.currentProfile.then((profile) => {
  18 + this.noosfero.currentProfile.then((profile: Profile) => {
19 19 return this.noosfero.profiles.one(profile.id).customPOST(
20 20 { article: this.article },
21 21 'articles',
22 22 {},
23 23 { 'Content-Type': 'application/json' }
24 24 )
25   - }).then((response) => {
  25 + }).then((response: restangular.IResponse) => {
26 26 this.$state.transitionTo('main.profile.page', { page: response.data.article.path, profile: response.data.article.profile.identifier });
27 27 this.SweetAlert.swal({
28 28 title: "Good job!",
... ...
src/app/components/auth/auth.controller.js
... ... @@ -1,17 +0,0 @@
1   -(function() {
2   - 'use strict';
3   -
4   - angular
5   - .module('noosferoApp')
6   - .controller('AuthController', AuthController);
7   -
8   -
9   - /** @ngInject */
10   - function AuthController(noosfero, $log, $stateParams, AuthService) {
11   - var vm = this;
12   - vm.credentials = {};
13   - vm.login = function() {
14   - AuthService.login(vm.credentials);
15   - }
16   - }
17   -})();
src/app/components/auth/auth_controller.ts 0 → 100644
... ... @@ -0,0 +1,22 @@
  1 +import {Credentials} from "./../../models/interfaces";
  2 +import {AuthService} from "./auth_service";
  3 +
  4 +export class AuthController {
  5 +
  6 + static $inject = ["noosfero", "$log", "$stateParams", "AuthService"];
  7 +
  8 + constructor(
  9 + private noosfero: any,
  10 + private $log: ng.ILogService,
  11 + private $stateParams: any,
  12 + private AuthService: AuthService
  13 + ) {
  14 +
  15 + }
  16 +
  17 + credentials: Credentials;
  18 +
  19 + login() {
  20 + this.AuthService.login(this.credentials);
  21 + }
  22 +}
0 23 \ No newline at end of file
... ...
src/app/components/auth/auth_events.ts
1   -
2   -
3 1 export interface IAuthEvents {
4 2 loginSuccess: string;
5 3 loginFailed: string;
... ...
src/app/components/auth/auth_service.ts
1 1 import {Injectable, Inject} from "ng-forward";
2 2  
3   -import {Credentials} from "./../../models/interfaces";
  3 +import {Credentials, NoosferoRootScope, User, UserResponse} from "./../../models/interfaces";
4 4 import {Session} from "./session";
5   -import {NoosferoRootScope} from "./noosfero_root_scope";
  5 +
6 6 import {AUTH_EVENTS, IAuthEvents} from "./auth_events";
7 7  
8   -@Injectable
9   -@Inject("$q", "$http", "$rootScope", Session, "$log", "AUTH_EVENTS")
  8 +@Injectable()
  9 +@Inject("$q", "$http", "$rootScope", "Session", "$log", "AUTH_EVENTS")
10 10 export class AuthService {
  11 +
11 12 constructor(private $q: ng.IQService,
12 13 private $http: ng.IHttpService,
13 14 private $rootScope: NoosferoRootScope,
14   - private Session: Session,
  15 + private session: Session,
15 16 private $log: ng.ILogService,
16   - private AUTH_EVENTS: IAuthEvents) {
  17 + private auth_events: IAuthEvents) {
17 18  
18 19 }
19 20  
20   - private loginSuccessCallback(response) {
  21 + loginFromCookie() {
  22 + let url: string = '/api/v1/login_from_cookie';
  23 + return this.$http.post(url, null).then(this.loginSuccessCallback.bind(this), this.loginFailedCallback.bind(this));
  24 + }
  25 +
  26 +
  27 + private loginSuccessCallback(response: ng.IHttpPromiseCallbackArg<UserResponse>) {
21 28 this.$log.debug('AuthService.login [SUCCESS] response', response);
22   - let currentUser = this.Session.create(response.data);
  29 + let currentUser: User = this.session.create(response.data);
23 30 this.$rootScope.currentUser = currentUser;
24   - this.$rootScope.$broadcast(this.AUTH_EVENTS.loginSuccess, currentUser);
  31 + this.$rootScope.$broadcast(this.auth_events.loginSuccess, currentUser);
25 32 return currentUser;
26 33 }
27 34  
28 35 login(credentials: Credentials) {
29 36 let url = '/api/v1/login';
30 37 let encodedData = 'login=' + credentials.username + '&password=' + credentials.password;
31   - return this.$http.post(url, encodedData).then(this.loginSuccessCallback, this.loginFailedCallback);
  38 + return this.$http.post(url, encodedData).then(this.loginSuccessCallback.bind(this), this.loginFailedCallback.bind(this));
32 39 }
33 40  
34   - private loginFailedCallback(response) {
  41 + private loginFailedCallback(response: ng.IHttpPromiseCallbackArg<any>): any {
35 42 this.$log.debug('AuthService.login [FAIL] response', response);
36   - this.$rootScope.$broadcast(AUTH_EVENTS.loginFailed);
  43 + this.$rootScope.$broadcast(this.auth_events.loginFailed);
37 44 // return $q.reject(response);
38 45 return null;
39 46 }
40 47  
41 48 public logout() {
42   - this.Session.destroy();
  49 + this.session.destroy();
43 50 this.$rootScope.currentUser = undefined;
44   - this.$rootScope.$broadcast(AUTH_EVENTS.logoutSuccess);
45   - this.$http.jsonp('/account/logout'); //FIXME logout from noosfero to sync login state
  51 + this.$rootScope.$broadcast(this.auth_events.logoutSuccess);
  52 + this.$http.jsonp('/account/logout'); // FIXME logout from noosfero to sync login state
46 53 }
47 54  
48 55 public isAuthenticated() {
49   - return !!this.Session.getCurrentUser();
  56 + return !!this.session.getCurrentUser();
50 57 }
51 58  
52   - public isAuthorized(authorizedRoles) {
  59 + public isAuthorized(authorizedRoles: string | string[]) {
53 60 if (!angular.isArray(authorizedRoles)) {
54   - authorizedRoles = [authorizedRoles];
  61 + authorizedRoles = [<string>authorizedRoles];
55 62 }
56   - return (this.isAuthenticated() && authorizedRoles.indexOf(this.Session.getCurrentUser().userRole) !== -1);
  63 + return (this.isAuthenticated() && authorizedRoles.indexOf(this.session.getCurrentUser().userRole) !== -1);
57 64 }
58 65 }
59 66 \ No newline at end of file
... ...
src/app/components/auth/noosfero_root_scope.ts
... ... @@ -1,5 +0,0 @@
1   -import {User} from "./../../models/interfaces";
2   -
3   -export interface NoosferoRootScope extends ng.IScope {
4   - currentUser: User;
5   -}
6 0 \ No newline at end of file
src/app/components/auth/session.ts
1 1 import {Injectable, Inject} from "ng-forward";
  2 +import {UserResponse, User, INoosferoLocalStorage} from "./../../models/interfaces";
2 3  
3 4 @Injectable()
4 5 @Inject("$localStorage", "$log")
5 6 export class Session {
6   - constructor(private $localStorage, $log) {
  7 +
  8 + constructor(private $localStorage: INoosferoLocalStorage, private $log: ng.ILogService) {
7 9  
8 10 }
9 11  
10   - create = function(data) {
  12 + create(data: UserResponse): User {
11 13 this.$localStorage.currentUser = data.user;
12 14 this.$log.debug('User session created.', this.$localStorage.currentUser);
13 15 return this.$localStorage.currentUser;
14 16 };
15 17  
16   - destroy = function() {
  18 + destroy() {
17 19 delete this.$localStorage.currentUser;
18 20 this.$log.debug('User session destroyed.');
19 21 };
20 22  
21   - getCurrentUser = function() {
  23 + getCurrentUser(): User {
22 24 return this.$localStorage.currentUser;
23 25 };
24 26  
... ...
src/app/components/noosfero-articles/article/article.directive.spec.ts
... ... @@ -1,85 +0,0 @@
1   -import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
2   -import {Input, provide, Component} from 'ng-forward';
3   -
4   -import {ArticleDirective} from './article.directive';
5   -
6   -// Instantiate the Builder, this part is different than ng2.
7   -// In ng2 you inject tcb.
8   -const tcb = new TestComponentBuilder();
9   -
10   -// this htmlTemplate will be re-used between the container components in this spec file
11   -const htmlTemplate: string = '<noosfero-article [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-article>';
12   -
13   -
14   -describe("Article Directive", () => {
15   -
16   -
17   - // the karma preprocessor html2js transform the templates html into js files which put
18   - // the templates to the templateCache into the module templates
19   - // we need to load the module templates here as the template for the
20   - // component NoosferoArtileDirective will be load on our tests
21   - beforeEach(angular.mock.module("templates"));
22   -
23   - it("receives the article and profile as inputs", done => {
24   -
25   - // Creating a container component (ArticleContainerComponent) to include
26   - // the component under test (ArticleDirective)
27   - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleDirective] })
28   - class ArticleContainerComponent {
29   - article = { type: 'anyArticleType' };
30   - profile = { name: 'profile-name' };
31   - constructor() {
32   - }
33   - }
34   -
35   - // uses the TestComponentBuilder instance to initialize the component
36   - tcb.createAsync(ArticleContainerComponent).then((fixture) => {
37   - // and here we can inspect and run the test assertions
38   - let myComponent: ArticleContainerComponent = fixture.componentInstance;
39   -
40   - console.log(myComponent);
41   -
42   - // assure the article object inside the ArticleDirective matches
43   - // the provided through the parent component
44   - expect(myComponent.article.type).toEqual("anyArticleType");
45   - expect(myComponent.profile.name).toEqual("profile-name");
46   -
47   - myComponent.metodoAsync(() => {
48   - done();
49   - });
50   - // done needs to be called (it isn't really needed, as we can read in
51   - // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync)
52   - // because createAsync in ng-forward is not really async, but as the intention
53   - // here is write tests in angular 2 ways, this is recommended
54   - done();
55   - });
56   - });
57   -
58   -
59   - it("renders a directive which matches to the article type", done => {
60   - // NoosferoTinyMceArticle component created to check if it will be used
61   - // when a article with type 'TinyMceArticle' is provided to the noosfero-article (ArticleDirective)
62   - // *** Important *** - the selector is what ng-forward uses to define the name of the directive provider
63   - @Component({ selector: 'noosfero-tiny-mce-article', template: "<h1>TinyMceArticle</h1>" })
64   - class NoosferoTinyMceArticle {
65   - @Input() article: any;
66   - @Input() profile: any;
67   - }
68   -
69   - // Creating a container component (ArticleContainerComponent) to include our NoosferoTinyMceArticle
70   - @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleDirective, NoosferoTinyMceArticle] })
71   - class CustomArticleType {
72   - article = { type: 'TinyMceArticle' };
73   - profile = { name: 'profile-name' };
74   - constructor() {
75   - }
76   - }
77   - tcb.createAsync(CustomArticleType).then(fixture => {
78   - let myComponent: CustomArticleType = fixture.componentInstance;
79   - expect(myComponent.article.type).toEqual("TinyMceArticle");
80   - expect(fixture.debugElement.componentViewChildren[0].text()).toEqual("TinyMceArticle");
81   - done();
82   - });
83   - });
84   -
85   -});
86 0 \ No newline at end of file
src/app/components/noosfero-articles/article/article.directive.ts
... ... @@ -1,43 +0,0 @@
1   -import { bundle, Input, Inject, Component, Directive } from 'ng-forward';
2   -import {NoosferoArticleBlog} from "../blog/blog.component";
3   -
4   -@Component({
5   - selector: 'noosfero-default-article',
6   - templateUrl: 'app/components/noosfero-articles/article/article.html'
7   -})
8   -export class ArticleView {
9   -
10   - @Input() article: any;
11   - @Input() profile: any;
12   -
13   -}
14   -
15   -@Component({
16   - selector: 'noosfero-article',
17   - template: 'not-used',
18   - directives: [ArticleView, NoosferoArticleBlog]
19   -})
20   -@Inject("$element", "$scope", "$injector", "$compile")
21   -export class ArticleDirective {
22   -
23   - @Input() article: any;
24   - @Input() profile: any;
25   - directiveName: string;
26   -
27   - ngOnInit() {
28   - let specificDirective = 'noosfero' + this.article.type;
29   - this.directiveName = "noosfero-default-article";
30   - if (this.$injector.has(specificDirective + 'Directive')) {
31   - this.directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
32   - }
33   - this.$element.replaceWith(this.$compile('<' + this.directiveName + ' [article]="ctrl.article" [profile]="ctrl.profile"></' + this.directiveName + '>')(this.$scope));
34   - }
35   -
36   - constructor(
37   - private $element: any,
38   - private $scope: ng.IScope,
39   - private $injector: ng.auto.IInjectorService,
40   - private $compile: ng.ICompileService) {
41   -
42   - }
43   -}
src/app/components/noosfero-articles/article/article_view.spec.ts 0 → 100644
... ... @@ -0,0 +1,108 @@
  1 +import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
  2 +import {Input, provide, Component} from 'ng-forward';
  3 +
  4 +import {ArticleView, ArticleDefaultView} from './article_view';
  5 +
  6 +// Instantiate the Builder, this part is different than ng2.
  7 +// In ng2 you inject tcb.
  8 +const tcb = new TestComponentBuilder();
  9 +
  10 +// this htmlTemplate will be re-used between the container components in this spec file
  11 +const htmlTemplate: string = '<noosfero-article [article]="ctrl.article" [profile]="ctrl.profile"></noosfero-article>';
  12 +
  13 +
  14 +describe("ArticleView Component", () => {
  15 +
  16 + // the karma preprocessor html2js transform the templates html into js files which put
  17 + // the templates to the templateCache into the module templates
  18 + // we need to load the module templates here as the template for the
  19 + // component Noosfero ArtileView will be load on our tests
  20 + beforeEach(angular.mock.module("templates"));
  21 +
  22 + it("renders the default component when no specific component is found", (done: Function) => {
  23 + // Creating a container component (ArticleContainerComponent) to include
  24 + // the component under test (ArticleView)
  25 + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleView] })
  26 + class ArticleContainerComponent {
  27 + article = { type: 'anyArticleType' };
  28 + profile = { name: 'profile-name' };
  29 + constructor() {
  30 + }
  31 + }
  32 +
  33 + // uses the TestComponentBuilder instance to initialize the component
  34 + tcb.createAsync(ArticleContainerComponent).then((fixture) => {
  35 + // and here we can inspect and run the test assertions
  36 +
  37 + // gets the children component of ArticleContainerComponent
  38 + let articleView: ArticleView = fixture.debugElement.componentViewChildren[0].componentInstance;
  39 +
  40 + // and checks if the article View rendered was the Default Article View
  41 + expect(articleView.constructor.prototype).toEqual(ArticleDefaultView.prototype);
  42 +
  43 + // done needs to be called (it isn't really needed, as we can read in
  44 + // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync)
  45 + // because createAsync in ng-forward is not really async, but as the intention
  46 + // here is write tests in angular 2 ways, this is recommended
  47 + done();
  48 + });
  49 + });
  50 +
  51 + it("receives the article and profile as inputs", (done: Function) => {
  52 +
  53 + // Creating a container component (ArticleContainerComponent) to include
  54 + // the component under test (ArticleView)
  55 + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleView] })
  56 + class ArticleContainerComponent {
  57 + article = { type: 'anyArticleType' };
  58 + profile = { name: 'profile-name' };
  59 + constructor() {
  60 + }
  61 + }
  62 +
  63 + // uses the TestComponentBuilder instance to initialize the component
  64 + tcb.createAsync(ArticleContainerComponent).then((fixture) => {
  65 + // and here we can inspect and run the test assertions
  66 + let articleView: ArticleView = fixture.debugElement.componentViewChildren[0].componentInstance;
  67 +
  68 + // assure the article object inside the ArticleView matches
  69 + // the provided through the parent component
  70 + expect(articleView.article.type).toEqual("anyArticleType");
  71 + expect(articleView.profile.name).toEqual("profile-name");
  72 +
  73 + // done needs to be called (it isn't really needed, as we can read in
  74 + // here (https://github.com/ngUpgraders/ng-forward/blob/master/API.md#createasync)
  75 + // because createAsync in ng-forward is not really async, but as the intention
  76 + // here is write tests in angular 2 ways, this is recommended
  77 + done();
  78 + });
  79 + });
  80 +
  81 +
  82 + it("renders a article view which matches to the article type", done => {
  83 + // NoosferoTinyMceArticle component created to check if it will be used
  84 + // when a article with type 'TinyMceArticle' is provided to the noosfero-article (ArticleView)
  85 + // *** Important *** - the selector is what ng-forward uses to define the name of the directive provider
  86 + @Component({ selector: 'noosfero-tiny-mce-article', template: "<h1>TinyMceArticle</h1>" })
  87 + class TinyMceArticleView {
  88 + @Input() article: any;
  89 + @Input() profile: any;
  90 + }
  91 +
  92 + // Creating a container component (ArticleContainerComponent) to include our NoosferoTinyMceArticle
  93 + @Component({ selector: 'test-container-component', template: htmlTemplate, directives: [ArticleView, TinyMceArticleView] })
  94 + class CustomArticleType {
  95 + article = { type: 'TinyMceArticle' };
  96 + profile = { name: 'profile-name' };
  97 + constructor() {
  98 + }
  99 + }
  100 + tcb.createAsync(CustomArticleType).then(fixture => {
  101 + let myComponent: CustomArticleType = fixture.componentInstance;
  102 + expect(myComponent.article.type).toEqual("TinyMceArticle");
  103 + expect(fixture.debugElement.componentViewChildren[0].text()).toEqual("TinyMceArticle");
  104 + done();
  105 + });
  106 + });
  107 +
  108 +});
0 109 \ No newline at end of file
... ...
src/app/components/noosfero-articles/article/article_view.ts 0 → 100644
... ... @@ -0,0 +1,43 @@
  1 +import { bundle, Input, Inject, Component, Directive } from 'ng-forward';
  2 +import {NoosferoArticleBlog} from "../blog/blog.component";
  3 +
  4 +@Component({
  5 + selector: 'noosfero-default-article',
  6 + templateUrl: 'app/components/noosfero-articles/article/article.html'
  7 +})
  8 +export class ArticleDefaultView {
  9 +
  10 + @Input() article: any;
  11 + @Input() profile: any;
  12 +
  13 +}
  14 +
  15 +@Component({
  16 + selector: 'noosfero-article',
  17 + template: 'not-used',
  18 + directives: [ArticleDefaultView, NoosferoArticleBlog]
  19 +})
  20 +@Inject("$element", "$scope", "$injector", "$compile")
  21 +export class ArticleView {
  22 +
  23 + @Input() article: any;
  24 + @Input() profile: any;
  25 + directiveName: string;
  26 +
  27 + ngOnInit() {
  28 + let specificDirective = 'noosfero' + this.article.type;
  29 + this.directiveName = "noosfero-default-article";
  30 + if (this.$injector.has(specificDirective + 'Directive')) {
  31 + this.directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  32 + }
  33 + this.$element.replaceWith(this.$compile('<' + this.directiveName + ' [article]="ctrl.article" [profile]="ctrl.profile"></' + this.directiveName + '>')(this.$scope));
  34 + }
  35 +
  36 + constructor(
  37 + private $element: any,
  38 + private $scope: ng.IScope,
  39 + private $injector: ng.auto.IInjectorService,
  40 + private $compile: ng.ICompileService) {
  41 +
  42 + }
  43 +}
... ...
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";
3 4  
4 5 @Component({
5 6 selector: "noosfero-blog",
... ... @@ -8,15 +9,15 @@ import {Component, Input, Inject} from &quot;ng-forward&quot;;
8 9 @Inject("noosfero", "$scope")
9 10 export class NoosferoArticleBlog {
10 11  
11   - @Input() article;
12   - @Input() profile;
  12 + @Input() article: Article;
  13 + @Input() profile: Profile;
13 14  
14 15 private posts: any[];
15 16 private perPage: number = 3;
16 17 private currentPage: number;
17 18 private totalPosts: number = 0;
18 19  
19   - constructor(private noosfero: any, private $scope) {
  20 + constructor(private noosfero: any, private $scope: ng.IScope) {
20 21 }
21 22  
22 23 ngOnInit() {
... ... @@ -28,8 +29,8 @@ export class NoosferoArticleBlog {
28 29 content_type: "TinyMceArticle",
29 30 per_page: this.perPage,
30 31 page: this.currentPage
31   - }).then((response) => {
32   - this.totalPosts = response.headers("total");
  32 + }).then((response: restangular.IResponse) => {
  33 + this.totalPosts = <number>(<any>response.headers("total"));
33 34 this.posts = response.data.articles;
34 35 });
35 36 }
... ...
src/app/components/noosfero-boxes/boxes.component.ts
1 1 import { Input, Inject, Component } from 'ng-forward';
2   -
  2 +import {Box} from "./../../models/interfaces";
3 3 @Component({
4 4 selector: "noosfero-boxes",
5 5 templateUrl: "app/components/noosfero-boxes/boxes.html"
6 6 })
7 7 export class Boxes {
8 8  
9   - @Input() boxes: any
10   - @Input() owner: any
  9 + @Input() boxes: any;
  10 + @Input() owner: any;
11 11  
12   - boxesOrder(box) {
13   - if (box.position == 2) return 0;
  12 + boxesOrder(box: Box) {
  13 + if (box.position === 2) return 0;
14 14 return box.position;
15 15 }
16 16 }
... ...
src/app/content-viewer/content-viewer-actions.component.ts
1 1 import {Component, Inject} from "ng-forward";
2 2  
  3 +import {Profile} from "./../models/interfaces";
3 4 @Component({
4 5 selector: "content-viewer-actions",
5 6 templateUrl: "app/content-viewer/navbar-actions.html",
... ... @@ -10,8 +11,8 @@ export class ContentViewerActions {
10 11 article: any;
11 12 profile: any;
12 13  
13   - constructor(noosfero) {
14   - noosfero.currentProfile.then((profile) => {
  14 + constructor(noosfero: any) {
  15 + noosfero.currentProfile.then((profile: Profile) => {
15 16 this.profile = profile;
16 17 });
17 18 }
... ...
src/app/content-viewer/content-viewer.component.ts
1 1 import * as noosfero from "../models/interfaces";
2 2  
3   -import {ArticleDirective, ArticleView} from "../components/noosfero-articles/article/article.directive";
  3 +import {ArticleDefaultView, ArticleView} from "../components/noosfero-articles/article/article_view";
4 4 import {Input, Component, StateConfig, Inject} from "ng-forward";
5 5  
6 6 import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component";
... ... @@ -8,7 +8,7 @@ import {NoosferoArticleBlog} from &quot;./../components/noosfero-articles/blog/blog.c
8 8 @Component({
9 9 selector: "content-viewer",
10 10 templateUrl: "app/content-viewer/page.html",
11   - directives: [NoosferoArticleBlog, ArticleView, ArticleDirective]
  11 + directives: [NoosferoArticleBlog, ArticleView, ArticleDefaultView]
12 12 })
13 13 @Inject("noosfero", "$log", "$stateParams")
14 14 export class ContentViewer {
... ... @@ -24,11 +24,10 @@ export class ContentViewer {
24 24 }
25 25  
26 26 activate() {
27   - console.log("HERE CONTENT VIEWER");
28   - this.noosfero.currentProfile.then((profile) => {
  27 + this.noosfero.currentProfile.then((profile: noosfero.Profile) => {
29 28 this.profile = profile;
30 29 return this.noosfero.profiles.one(this.profile.id).one("articles").get({ path: this.$stateParams["page"] });
31   - }).then((response) => {
  30 + }).then((response: restangular.IResponse) => {
32 31 this.article = response.data.article;
33 32 });
34 33 }
... ...
src/app/index.config.ts
1 1  
2 2 /** @ngInject */
3   -export function noosferoModuleConfig($logProvider, $locationProvider, RestangularProvider, $httpProvider, $provide) {
  3 +export function noosferoModuleConfig($logProvider: ng.ILogProvider, $locationProvider: ng.ILocationProvider, RestangularProvider: restangular.IProvider, $httpProvider: ng.IHttpProvider, $provide: ng.auto.IProvideService) {
4 4 $logProvider.debugEnabled(true);
5 5 $locationProvider.html5Mode({ enabled: true });
6 6 RestangularProvider.setBaseUrl("/api/v1");
7 7 RestangularProvider.setFullResponse(true);
8   - $httpProvider.defaults.headers.post = { "Content-Type": "application/x-www-form-urlencoded; charset=utf-8" };
9 8  
10   - $provide.decorator("$uiViewScroll", function($delegate, $document) {
11   - return function(uiViewElement) {
  9 + (<any>$httpProvider.defaults.headers.post)["Content-Type"] = "application/x-www-form-urlencoded; charset=utf-8";
  10 +
  11 +
  12 + $provide.decorator("$uiViewScroll", function($delegate: any, $document: any) {
  13 + return function(uiViewElement: any) {
12 14 $document.scrollToElementAnimated(uiViewElement);
13 15 };
14 16 });
... ...
src/app/index.module.ts
... ... @@ -2,14 +2,14 @@ export class NoosferoApp {
2 2  
3 3 static appName: string = "noosferoApp";
4 4 static angularModule: any;
5   - //static init(angularModule: any) {
6   - //NoosferoApp.angularModule
  5 + // static init(angularModule: any) {
  6 + // NoosferoApp.angularModule
7 7 // angular.module(NoosferoApp.appName, ["ngAnimate", "ngCookies", "ngStorage", "ngTouch",
8 8 // "ngSanitize", "ngMessages", "ngAria", "restangular",
9 9 // "ui.router", "ui.bootstrap", "toastr",
10 10 // "angularMoment", "angular.filter", "akoenig.deckgrid",
11 11 // "angular-timeline", "duScroll", "oitozero.ngSweetAlert"]);
12   - //}
  12 + // }
13 13  
14 14 static addConfig(configFunc: Function) {
15 15 NoosferoApp.angularModule.config(configFunc);
... ... @@ -23,6 +23,10 @@ export class NoosferoApp {
23 23 NoosferoApp.angularModule.service(serviceName, value);
24 24 }
25 25  
  26 + static addFactory(factoryName: string, value: any) {
  27 + NoosferoApp.angularModule.factory(factoryName, value);
  28 + }
  29 +
26 30 static addController(controllerName: string, value: any) {
27 31 NoosferoApp.angularModule.controller(controllerName, value);
28 32 }
... ...
src/app/index.route.ts
1 1  
2 2  
3 3 /** @ngInject */
4   -export function routeConfig($stateProvider, $urlRouterProvider) {
  4 +export function routeConfig($stateProvider: ng.ui.IStateProvider, $urlRouterProvider: ng.ui.IUrlRouterProvider) {
5 5 $stateProvider
6 6 .state("main.profile.settings", {
7 7 url: "^/myprofile/:profile"
... ...
src/app/index.run.ts
  1 +import {Session} from "./components/auth/session";
1 2  
2 3 /** @ngInject */
3   -export function noosferoAngularRunBlock($log, Restangular, Session) {
4   - Restangular.addFullRequestInterceptor(function(element, operation, route, url, headers) {
  4 +export function noosferoAngularRunBlock($log: ng.ILogService, Restangular: restangular.IService, Session: Session) {
  5 + Restangular.addFullRequestInterceptor((element: any, operation: string, route: string, url: string, headers: string) => {
5 6 if (Session.getCurrentUser()) {
6   - headers["Private-Token"] = Session.getCurrentUser().private_token;
  7 + (<any>headers)["Private-Token"] = Session.getCurrentUser().private_token;
7 8 }
8   - return { headers: headers };
  9 + return <any>{ headers: <any>headers };
9 10 });
10 11 }
11 12  
... ...
src/app/index.ts
... ... @@ -17,6 +17,7 @@ import {Main} from &quot;./main/main.component&quot;;
17 17 import {bootstrap, bundle} from "ng-forward";
18 18  
19 19 import {AUTH_EVENTS} from "./components/auth/auth_events";
  20 +import {AuthController} from "./components/auth/auth_controller";
20 21  
21 22 declare var moment: any;
22 23  
... ... @@ -35,8 +36,11 @@ NoosferoApp.addConstants(&quot;AUTH_EVENTS&quot;, AUTH_EVENTS);
35 36 NoosferoApp.addConfig(noosferoModuleConfig);
36 37 NoosferoApp.run(noosferoAngularRunBlock);
37 38  
38   -require("./components/auth/auth.controller.js");
39   -require("./components/auth/auth.service.js");
  39 +// NoosferoApp.addService("Session", Session);
  40 +// NoosferoApp.addService("AuthService", AuthService);
  41 +NoosferoApp.addController("AuthController", AuthController);
  42 +
  43 +
40 44 require("./components/navbar/navbar.directive.js");
41 45 require("./components/noosfero-activities/activities.component.js");
42 46 require("./components/noosfero-activities/activity/activity.component.js");
... ...
src/app/main/main.component.ts
1 1 import {bundle, Component, StateConfig} from "ng-forward";
2 2 import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component.ts";
3   -import {ArticleDirective} from "../components/noosfero-articles/article/article.directive.ts";
  3 +import {ArticleView} from "../components/noosfero-articles/article/article_view.ts";
4 4 import {Profile} from "../profile/profile.component";
5 5 import {Boxes} from "../components/noosfero-boxes/boxes.component";
6 6 import {Block} from "../components/noosfero-blocks/block.component";
7 7  
  8 +
  9 +import {AuthService} from "./../components/auth/auth_service";
  10 +import {Session} from "./../components/auth/session";
  11 +
8 12 @Component({
9 13 selector: 'main-content',
10 14 templateUrl: "app/main/main.html",
  15 + providers: [AuthService, Session]
11 16 })
12 17 export class MainContent {
13 18  
... ... @@ -15,8 +20,9 @@ export class MainContent {
15 20  
16 21 @Component({
17 22 selector: 'main',
18   - template: 'not-used',
19   - directives: [NoosferoArticleBlog, ArticleDirective, Boxes, Block]
  23 + template: '<div ng-view></div>',
  24 + directives: [NoosferoArticleBlog, ArticleView, Boxes, Block],
  25 + providers: [AuthService, Session]
20 26 })
21 27 @StateConfig([
22 28 {
... ... @@ -24,7 +30,7 @@ export class MainContent {
24 30 component: MainContent,
25 31 name: 'main',
26 32 resolve: {
27   - currentUser: function(AuthService) {
  33 + currentUser: function(AuthService: AuthService) {
28 34 return AuthService.loginFromCookie();
29 35 }
30 36 }
... ...
src/app/models/interfaces.ts
  1 +export interface NoosferoRootScope extends ng.IScope {
  2 + currentUser: User;
  3 +}
  4 +
1 5 export interface Event extends Article {
2 6 id: number;
3 7 }
... ... @@ -8,6 +12,7 @@ export interface Article {
8 12  
9 13 export interface Profile {
10 14 id: number;
  15 + identifier: string;
11 16 }
12 17  
13 18 export interface Person extends Profile {
... ... @@ -32,4 +37,20 @@ export interface User {
32 37 login: string;
33 38 email: string;
34 39 person: Person;
  40 + private_token: string;
  41 + userRole: string;
35 42 }
  43 +
  44 +export interface UserResponse {
  45 + user: User;
  46 +}
  47 +
  48 +
  49 +export interface Box {
  50 + id: number;
  51 + position: number;
  52 +}
  53 +
  54 +export interface INoosferoLocalStorage extends angular.storage.ILocalStorageService {
  55 + currentUser: User;
  56 +}
36 57 \ No newline at end of file
... ...
src/app/profile-info/profile-info.component.ts
1 1 import {StateConfig, Component, Inject} from 'ng-forward';
2 2  
  3 +import {Profile} from "./../models/interfaces";
  4 +
3 5 @Component({
4 6 selector: 'profile',
5 7 templateUrl: "app/profile-info/profile-info.html"
... ... @@ -10,15 +12,15 @@ export class ProfileInfo {
10 12 activities: any
11 13 profile: any
12 14  
13   - constructor(private noosfero) {
  15 + constructor(private noosfero: any) {
14 16 this.activate();
15 17 }
16 18  
17 19 activate() {
18   - this.noosfero.currentProfile.then((profile) => {
  20 + this.noosfero.currentProfile.then((profile: Profile) => {
19 21 this.profile = profile;
20 22 return this.noosfero.profiles.one(this.profile.id).one('activities').get();
21   - }).then((response) => {
  23 + }).then((response: restangular.IResponse) => {
22 24 this.activities = response.data.activities;
23 25 });
24 26 }
... ...
src/app/profile/profile-home.component.ts
1 1 import {StateConfig, Component, Inject} from 'ng-forward';
2 2  
  3 +import {Profile} from "./../models/interfaces";
  4 +
3 5 @Component({
4 6 selector: 'profile-home',
5 7 template: "<div></div>"
... ... @@ -7,13 +9,13 @@ import {StateConfig, Component, Inject} from &#39;ng-forward&#39;;
7 9 @Inject("noosfero", "$log", "$stateParams", "$scope", "$state")
8 10 export class ProfileHome {
9 11  
10   - profile: any;
  12 + profile: Profile;
11 13  
12   - constructor(noosfero, $log, $stateParams, $scope, $state) {
13   - noosfero.currentProfile.then((profile) => {
  14 + constructor(noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService, $scope: ng.IScope, $state: ng.ui.IStateService) {
  15 + noosfero.currentProfile.then((profile: Profile) => {
14 16 this.profile = profile;
15 17 return noosfero.profile(this.profile.id).customGET('home_page', { fields: 'path' });
16   - }).then((response) => {
  18 + }).then((response: restangular.IResponse) => {
17 19 if (response.data.article) {
18 20 $state.transitionTo('main.profile.page', { page: response.data.article.path, profile: this.profile.identifier }, { location: false });
19 21 } else {
... ...
src/app/profile/profile.component.ts
1 1 import {StateConfig, Component, Inject} from 'ng-forward';
2   -import {ProfileInfo} from '../profile-info/profile-info.component'
3   -import {ProfileHome} from '../profile/profile-home.component'
4   -import {Cms} from '../cms/cms.component'
  2 +import {ProfileInfo} from '../profile-info/profile-info.component';
  3 +import {ProfileHome} from '../profile/profile-home.component';
  4 +import {Cms} from '../cms/cms.component';
5 5 import {ContentViewer} from "../content-viewer/content-viewer.component";
6 6  
  7 +import * as noosferoModels from "./../models/interfaces";
  8 +
7 9 @Component({
8 10 selector: 'profile',
9 11 templateUrl: "app/profile/profile.html"
... ... @@ -65,15 +67,15 @@ import {ContentViewer} from &quot;../content-viewer/content-viewer.component&quot;;
65 67 @Inject("noosfero", "$log", "$stateParams")
66 68 export class Profile {
67 69  
68   - boxes: any
69   - profile: any
  70 + boxes: noosferoModels.Box[];
  71 + profile: noosferoModels.Profile;
70 72  
71   - constructor(noosfero, $log, $stateParams) {
72   - noosfero.profiles.one().get({ identifier: $stateParams.profile }).then((response) => {
  73 + constructor(noosfero: any, $log: ng.ILogService, $stateParams: ng.ui.IStateParamsService) {
  74 + noosfero.profiles.one().get({ identifier: $stateParams["profile"] }).then((response: restangular.IResponse) => {
73 75 this.profile = response.data[0];
74 76 noosfero.setCurrentProfile(this.profile);
75 77 return noosfero.boxes(this.profile.id).one().get();
76   - }).then((response) => {
  78 + }).then((response: restangular.IResponse) => {
77 79 this.boxes = response.data.boxes;
78 80 });
79 81 }
... ...
src/lib/ng-noosfero-api/api_descriptor.ts 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +
  2 +
  3 +// TODO - see code generation using swagger resource declaration
  4 +// -> https://github.com/swagger-api/swagger-codegen
... ...
src/lib/ng-noosfero-api/http/http_client.ts
1   -module NgNoosferoAPI {
  1 +namespace NgNoosferoAPI {
2 2 export class NoosferoHttpClient {
3 3 static $inject = ['$http', '$q'];
4 4  
5   - constructor(private $http, private $q) {
  5 + constructor(private $http: ng.IHttpService, private $q: ng.IQService) {
6 6  
7 7 }
8 8 }
9 9  
10 10 NgNoosferoAPI.ngModule.service(NoosferoHttpClient);
11   -}
12   -
  11 +}
13 12 \ No newline at end of file
... ...
src/lib/ng-noosfero-api/http/http_config_provider.ts
1   -module NgNoosferoAPI {
2   -
  1 +namespace NgNoosferoAPI {
3 2  
4 3 // The following class represents the provider
5 4 export class NoosferoHttpServiceConfigProvider implements ng.IServiceProvider {
... ... @@ -12,19 +11,19 @@ module NgNoosferoAPI {
12 11 contentTypeHeader: "application/json",
13 12 textEncoding: "UTF-8"
14 13 };
15   -
16   -
  14 +
  15 +
17 16 // Configuration function
18 17 public setConfig(config: NoosferoHttpServiceConfig) {
19 18 this.config = config;
20 19 }
21   -
  20 +
22 21 // Provider's factory function
23 22 public $get(): NoosferoHttpServiceConfig {
24 23 return this.config;
25 24 }
26 25 }
27   -
  26 +
28 27 ngModule.provider("NoosferoHttpServiceConfig", NoosferoHttpServiceConfigProvider);
29 28  
30 29 }
31 30 \ No newline at end of file
... ...
tsconfig.json
... ... @@ -2,7 +2,7 @@
2 2 "compilerOptions": {
3 3 "module": "commonjs",
4 4 "target": "es5",
5   - "noImplicitAny": false,
  5 + "noImplicitAny": true,
6 6 "sourceMap": true,
7 7 "experimentalDecorators": true
8 8 },
... ...