Commit e7877dd68837e4478d83ed6fd708b1ccd3354106

Authored by Michel Felipe
1 parent 37fd3f09

Migrate article directive to typescript using ngforward

@@ -49,7 +49,9 @@ @@ -49,7 +49,9 @@
49 "karma-phantomjs-launcher": "~0.2.1", 49 "karma-phantomjs-launcher": "~0.2.1",
50 "lodash": "~3.10.1", 50 "lodash": "~3.10.1",
51 "main-bower-files": "~2.9.0", 51 "main-bower-files": "~2.9.0",
  52 + "ng-forward": "0.0.1-alpha.12",
52 "phantomjs": "~1.9.18", 53 "phantomjs": "~1.9.18",
  54 + "reflect-metadata": "^0.1.3",
53 "ts-loader": "^0.8.1", 55 "ts-loader": "^0.8.1",
54 "typescript": "^1.8.2", 56 "typescript": "^1.8.2",
55 "typings": "^0.6.8", 57 "typings": "^0.6.8",
src/app/components/noosfero-articles/article/article.directive.js
@@ -1,36 +0,0 @@ @@ -1,36 +0,0 @@
1 -(function() {  
2 - 'use strict';  
3 -  
4 - angular  
5 - .module('noosferoApp')  
6 - .directive('noosferoArticle', noosferoArticle);  
7 -  
8 - /** @ngInject */  
9 - function noosferoArticle($injector, $compile) {  
10 - var directive = {  
11 - restrict: 'E',  
12 - templateUrl: 'app/components/noosfero-articles/article/article.html',  
13 - scope: {  
14 - article: '<',  
15 - profile: '<'  
16 - },  
17 - controller: ArticleController,  
18 - controllerAs: 'vm',  
19 - bindToController: true,  
20 - link: function(scope, element) {  
21 - var specificDirective = 'noosfero'+scope.vm.article.type;  
22 - if($injector.has(specificDirective+'Directive')) {  
23 - var directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();  
24 - element.replaceWith($compile('<'+directiveName+' article="vm.article" profile="vm.profile"></'+directiveName+'>')(scope));  
25 - }  
26 - }  
27 - };  
28 -  
29 - return directive;  
30 -  
31 - /** @ngInject */  
32 - function ArticleController() {  
33 - }  
34 - }  
35 -  
36 -})();  
src/app/components/noosfero-articles/article/article.directive.ts 0 → 100644
@@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
  1 +import { Input, Inject, Component, Directive } from 'ng-forward';
  2 +
  3 +@Component({
  4 + selector: 'noosfero-default-article',
  5 + templateUrl: 'app/components/noosfero-articles/article/article.html',
  6 + providers: ['$injector', '$compile']
  7 +})
  8 +export class ArticleView {
  9 +
  10 +}
  11 +
  12 +/**
  13 +* <noosfero-article></noosfero-article>
  14 +*
  15 +*
  16 +*/
  17 +@Directive({
  18 + selector: 'noosfero-article',
  19 + providers: ['$injector', '$compile'],
  20 +
  21 +})
  22 +@Inject('$element')
  23 +@Inject('$scope')
  24 +export class ArticleDirective {
  25 +
  26 + @Input("article")
  27 + article: any;
  28 +
  29 + @Input("profile")
  30 + profile: any;
  31 +
  32 + constructor($element: any, $scope: ng.IScope, private $injector: ng.auto.IInjectorService, private $compile: ng.ICompileService) {
  33 + console.log('ARTICLE DIRECTIVE');
  34 + var specificDirective = 'noosfero' + this.article.type;
  35 + if ($injector.has(specificDirective + 'Directive')) {
  36 + var directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
  37 + $element.replaceWith($compile('<' + directiveName + ' article="vm.article" profile="vm.profile"></' + directiveName + '>')($scope));
  38 + //$element.html($compile('<' + directiveName + ' article="vm.article" profile="vm.profile"></' + directiveName + '>')(scope))
  39 + } else {
  40 + //TODO
  41 + }
  42 + }
  43 +
  44 +
  45 +}
src/app/content-viewer/content-viewer.controller.js
@@ -1,25 +0,0 @@ @@ -1,25 +0,0 @@
1 -(function() {  
2 - 'use strict';  
3 -  
4 - angular  
5 - .module('noosferoApp')  
6 - .controller('ContentViewerController', ContentViewerController);  
7 -  
8 -  
9 - /** @ngInject */  
10 - function ContentViewerController(noosfero, $log, $stateParams) {  
11 - var vm = this;  
12 - vm.article = null;  
13 - vm.profile = null;  
14 - activate();  
15 -  
16 - function activate() {  
17 - noosfero.currentProfile.then(function(profile) {  
18 - vm.profile = profile;  
19 - return noosfero.profiles.one(vm.profile.id).one('articles').get({path: $stateParams.page});  
20 - }).then(function(response) {  
21 - vm.article = response.data.article;  
22 - });  
23 - }  
24 - }  
25 -})();  
src/app/content-viewer/content-viewer.controller.ts 0 → 100644
@@ -0,0 +1,18 @@ @@ -0,0 +1,18 @@
  1 +import {ArticleDirective, ArticleView} from "../components/noosfero-articles/article/article.directive";
  2 +
  3 +/** @ngInject */
  4 +export function ContentViewerController(noosfero, $log, $stateParams) {
  5 + var vm = this;
  6 + vm.article = null;
  7 + vm.profile = null;
  8 + activate();
  9 +
  10 + function activate() {
  11 + noosfero.currentProfile.then(function(profile) {
  12 + vm.profile = profile;
  13 + return noosfero.profiles.one(vm.profile.id).one('articles').get({ path: $stateParams.page });
  14 + }).then(function(response) {
  15 + vm.article = response.data.article;
  16 + });
  17 + }
  18 +}
src/app/index.module.ts
@@ -22,6 +22,10 @@ export class NoosferoApp { @@ -22,6 +22,10 @@ export class NoosferoApp {
22 angular.module(NoosferoApp.appName).service(serviceName, value); 22 angular.module(NoosferoApp.appName).service(serviceName, value);
23 } 23 }
24 24
  25 + static addController(controllerName: string, value: any) {
  26 + angular.module(NoosferoApp.appName).controller(controllerName, value);
  27 + }
  28 +
25 static run(runFunction: Function) { 29 static run(runFunction: Function) {
26 angular.module(NoosferoApp.appName).run(runFunction); 30 angular.module(NoosferoApp.appName).run(runFunction);
27 } 31 }
src/app/index.route.ts
1 1
2 2
3 /** @ngInject */ 3 /** @ngInject */
4 -export function routeConfig($stateProvider, $urlRouterProvider) { 4 +export function routeConfig($stateProvider, $urlRouterProvider) {
5 $stateProvider 5 $stateProvider
6 - .state("main", {  
7 - url: "/",  
8 - templateUrl: "app/main/main.html",  
9 - controller: "MainController",  
10 - controllerAs: "vm",  
11 - resolve: {  
12 - currentUser: function(AuthService) {  
13 - return AuthService.loginFromCookie();  
14 - }  
15 - }  
16 - })  
17 - .state("main.profile.cms", {  
18 - url: "^/myprofile/:profile/cms",  
19 - views: {  
20 - "mainBlockContent": {  
21 - templateUrl: "app/cms/cms.html",  
22 - controller: "CmsController",  
23 - controllerAs: "vm"  
24 - }  
25 - }  
26 - })  
27 - .state("main.profile.settings", {  
28 - url: "^/myprofile/:profile"  
29 - })  
30 - .state("main.profile", {  
31 - url: "^/:profile",  
32 - abstract: true,  
33 - views: {  
34 - "content": {  
35 - templateUrl: "app/profile/profile.html",  
36 - controller: "ProfileController",  
37 - controllerAs: "vm"  
38 - }  
39 - }  
40 - })  
41 - .state("main.profile.home", {  
42 - url: "",  
43 - views: {  
44 - "mainBlockContent": {  
45 - controller: "ProfileHomeController",  
46 - controllerAs: "vm"  
47 - }  
48 - }  
49 - })  
50 - .state("main.profile.info", {  
51 - url: "^/profile/:profile",  
52 - views: {  
53 - "mainBlockContent": {  
54 - templateUrl: "app/profile-info/profile-info.html",  
55 - controller: "ProfileInfoController",  
56 - controllerAs: "vm"  
57 - }  
58 - }  
59 - })  
60 - .state("main.profile.page", {  
61 - url: "/{page:any}",  
62 - views: {  
63 - "mainBlockContent": {  
64 - templateUrl: "app/content-viewer/page.html",  
65 - controller: "ContentViewerController",  
66 - controllerAs: "vm"  
67 - },  
68 - "actions@main": {  
69 - templateUrl: "app/content-viewer/navbar-actions.html",  
70 - controller: "ContentViewerActionsController",  
71 - controllerAs: "vm"  
72 - }  
73 - }  
74 - }); 6 + .state("main", {
  7 + url: "/",
  8 + templateUrl: "app/main/main.html",
  9 + controller: "MainController",
  10 + controllerAs: "vm",
  11 + resolve: {
  12 + currentUser: function(AuthService) {
  13 + return AuthService.loginFromCookie();
  14 + }
  15 + }
  16 + })
  17 + .state("main.profile.cms", {
  18 + url: "^/myprofile/:profile/cms",
  19 + views: {
  20 + "mainBlockContent": {
  21 + templateUrl: "app/cms/cms.html",
  22 + controller: "CmsController",
  23 + controllerAs: "vm"
  24 + }
  25 + }
  26 + })
  27 + .state("main.profile.settings", {
  28 + url: "^/myprofile/:profile"
  29 + })
  30 + .state("main.profile", {
  31 + url: "^/:profile",
  32 + abstract: true,
  33 + views: {
  34 + "content": {
  35 + templateUrl: "app/profile/profile.html",
  36 + controller: "ProfileController",
  37 + controllerAs: "vm"
  38 + }
  39 + }
  40 + })
  41 + .state("main.profile.home", {
  42 + url: "",
  43 + views: {
  44 + "mainBlockContent": {
  45 + controller: "ProfileHomeController",
  46 + controllerAs: "vm"
  47 + }
  48 + }
  49 + })
  50 + .state("main.profile.info", {
  51 + url: "^/profile/:profile",
  52 + views: {
  53 + "mainBlockContent": {
  54 + templateUrl: "app/profile-info/profile-info.html",
  55 + controller: "ProfileInfoController",
  56 + controllerAs: "vm"
  57 + }
  58 + }
  59 + })
  60 + .state("main.profile.page", {
  61 + url: "/{page:any}",
  62 + views: {
  63 + "mainBlockContent": {
  64 + templateUrl: "app/content-viewer/page.html",
  65 + controller: "ContentViewerController",
  66 + controllerAs: "vm"
  67 + },
  68 + "actions@main": {
  69 + templateUrl: "app/content-viewer/navbar-actions.html",
  70 + controller: "ContentViewerActionsController",
  71 + controllerAs: "vm"
  72 + }
  73 + }
  74 + });
75 75
76 $urlRouterProvider.otherwise("/"); 76 $urlRouterProvider.otherwise("/");
77 - }  
78 -  
79 - 77 +}
src/app/index.ts
@@ -2,6 +2,7 @@ import {NoosferoApp} from &quot;./index.module&quot;; @@ -2,6 +2,7 @@ import {NoosferoApp} from &quot;./index.module&quot;;
2 import {noosferoModuleConfig} from "./index.config"; 2 import {noosferoModuleConfig} from "./index.config";
3 import {noosferoAngularRunBlock} from "./index.run"; 3 import {noosferoAngularRunBlock} from "./index.run";
4 import {routeConfig} from "./index.route"; 4 import {routeConfig} from "./index.route";
  5 +import {ContentViewerController} from "./content-viewer/content-viewer.controller";
5 6
6 declare var moment: any; 7 declare var moment: any;
7 8
@@ -26,7 +27,7 @@ require(&quot;./components/auth/auth.service.js&quot;); @@ -26,7 +27,7 @@ require(&quot;./components/auth/auth.service.js&quot;);
26 require("./components/navbar/navbar.directive.js"); 27 require("./components/navbar/navbar.directive.js");
27 require("./components/noosfero-activities/activities.component.js"); 28 require("./components/noosfero-activities/activities.component.js");
28 require("./components/noosfero-activities/activity/activity.component.js"); 29 require("./components/noosfero-activities/activity/activity.component.js");
29 -require("./components/noosfero-articles/article/article.directive.js"); 30 +//require("./components/noosfero-articles/article/article.directive.js");
30 require("./components/noosfero-articles/blog/blog.component.js"); 31 require("./components/noosfero-articles/blog/blog.component.js");
31 require("./components/noosfero-blocks/block.directive.js"); 32 require("./components/noosfero-blocks/block.directive.js");
32 require("./components/noosfero-blocks/link-list/link-list.component.js"); 33 require("./components/noosfero-blocks/link-list/link-list.component.js");
@@ -39,9 +40,11 @@ require(&quot;./components/noosfero/noosfero-template.filter.js&quot;); @@ -39,9 +40,11 @@ require(&quot;./components/noosfero/noosfero-template.filter.js&quot;);
39 require("./components/noosfero/noosfero.service.js"); 40 require("./components/noosfero/noosfero.service.js");
40 require("./components/noosfero/profile-image/profile-image.component.js"); 41 require("./components/noosfero/profile-image/profile-image.component.js");
41 require("./content-viewer/content-viewer-actions.controller.js"); 42 require("./content-viewer/content-viewer-actions.controller.js");
42 -require("./content-viewer/content-viewer.controller.js"); 43 +// require("./content-viewer/content-viewer.controller.js");
43 require("./profile-info/profile-info.controller.js"); 44 require("./profile-info/profile-info.controller.js");
44 require("./profile/profile-home.controller.js"); 45 require("./profile/profile-home.controller.js");
45 require("./profile/profile.controller.js"); 46 require("./profile/profile.controller.js");
46 47
  48 +NoosferoApp.addController("ContentViewerController", ContentViewerController);
  49 +
47 NoosferoApp.addConfig(routeConfig); 50 NoosferoApp.addConfig(routeConfig);
@@ -3,7 +3,8 @@ @@ -3,7 +3,8 @@
3 "module": "commonjs", 3 "module": "commonjs",
4 "target": "es5", 4 "target": "es5",
5 "noImplicitAny": false, 5 "noImplicitAny": false,
6 - "sourceMap": false 6 + "sourceMap": false,
  7 + "experimentalDecorators": true
7 }, 8 },
8 "exclude": [ 9 "exclude": [
9 "node_modules", 10 "node_modules",
@@ -4,6 +4,8 @@ @@ -4,6 +4,8 @@
4 "devDependencies": {}, 4 "devDependencies": {},
5 "ambientDependencies": { 5 "ambientDependencies": {
6 "angular": "github:DefinitelyTyped/DefinitelyTyped/angularjs/angular.d.ts#1c4a34873c9e70cce86edd0e61c559e43dfa5f75", 6 "angular": "github:DefinitelyTyped/DefinitelyTyped/angularjs/angular.d.ts#1c4a34873c9e70cce86edd0e61c559e43dfa5f75",
  7 + "angular-ui-router": "github:DefinitelyTyped/DefinitelyTyped/angular-ui-router/angular-ui-router.d.ts#655f8c1bf3c71b0e1ba415b36309604f79326ac8",
  8 + "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c",
7 "jquery": "github:DefinitelyTyped/DefinitelyTyped/jquery/jquery.d.ts#470954c4f427e0805a2d633636a7c6aa7170def8" 9 "jquery": "github:DefinitelyTyped/DefinitelyTyped/jquery/jquery.d.ts#470954c4f427e0805a2d633636a7c6aa7170def8"
8 } 10 }
9 } 11 }