diff --git a/package.json b/package.json index 527e5f0..a83cf3b 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,9 @@ "karma-phantomjs-launcher": "~0.2.1", "lodash": "~3.10.1", "main-bower-files": "~2.9.0", + "ng-forward": "0.0.1-alpha.12", "phantomjs": "~1.9.18", + "reflect-metadata": "^0.1.3", "ts-loader": "^0.8.1", "typescript": "^1.8.2", "typings": "^0.6.8", diff --git a/src/app/components/noosfero-articles/article/article.directive.js b/src/app/components/noosfero-articles/article/article.directive.js deleted file mode 100644 index 99c5dd9..0000000 --- a/src/app/components/noosfero-articles/article/article.directive.js +++ /dev/null @@ -1,36 +0,0 @@ -(function() { - 'use strict'; - - angular - .module('noosferoApp') - .directive('noosferoArticle', noosferoArticle); - - /** @ngInject */ - function noosferoArticle($injector, $compile) { - var directive = { - restrict: 'E', - templateUrl: 'app/components/noosfero-articles/article/article.html', - scope: { - article: '<', - profile: '<' - }, - controller: ArticleController, - controllerAs: 'vm', - bindToController: true, - link: function(scope, element) { - var specificDirective = 'noosfero'+scope.vm.article.type; - if($injector.has(specificDirective+'Directive')) { - var directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); - element.replaceWith($compile('<'+directiveName+' article="vm.article" profile="vm.profile">')(scope)); - } - } - }; - - return directive; - - /** @ngInject */ - function ArticleController() { - } - } - -})(); diff --git a/src/app/components/noosfero-articles/article/article.directive.ts b/src/app/components/noosfero-articles/article/article.directive.ts new file mode 100644 index 0000000..67fed95 --- /dev/null +++ b/src/app/components/noosfero-articles/article/article.directive.ts @@ -0,0 +1,45 @@ +import { Input, Inject, Component, Directive } from 'ng-forward'; + +@Component({ + selector: 'noosfero-default-article', + templateUrl: 'app/components/noosfero-articles/article/article.html', + providers: ['$injector', '$compile'] +}) +export class ArticleView { + +} + +/** +* +* +* +*/ +@Directive({ + selector: 'noosfero-article', + providers: ['$injector', '$compile'], + +}) +@Inject('$element') +@Inject('$scope') +export class ArticleDirective { + + @Input("article") + article: any; + + @Input("profile") + profile: any; + + constructor($element: any, $scope: ng.IScope, private $injector: ng.auto.IInjectorService, private $compile: ng.ICompileService) { + console.log('ARTICLE DIRECTIVE'); + var specificDirective = 'noosfero' + this.article.type; + if ($injector.has(specificDirective + 'Directive')) { + var directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); + $element.replaceWith($compile('<' + directiveName + ' article="vm.article" profile="vm.profile">')($scope)); + //$element.html($compile('<' + directiveName + ' article="vm.article" profile="vm.profile">')(scope)) + } else { + //TODO + } + } + + +} diff --git a/src/app/content-viewer/content-viewer.controller.js b/src/app/content-viewer/content-viewer.controller.js deleted file mode 100644 index a83e37c..0000000 --- a/src/app/content-viewer/content-viewer.controller.js +++ /dev/null @@ -1,25 +0,0 @@ -(function() { - 'use strict'; - - angular - .module('noosferoApp') - .controller('ContentViewerController', ContentViewerController); - - - /** @ngInject */ - function ContentViewerController(noosfero, $log, $stateParams) { - var vm = this; - vm.article = null; - vm.profile = null; - activate(); - - function activate() { - noosfero.currentProfile.then(function(profile) { - vm.profile = profile; - return noosfero.profiles.one(vm.profile.id).one('articles').get({path: $stateParams.page}); - }).then(function(response) { - vm.article = response.data.article; - }); - } - } -})(); diff --git a/src/app/content-viewer/content-viewer.controller.ts b/src/app/content-viewer/content-viewer.controller.ts new file mode 100644 index 0000000..edf1def --- /dev/null +++ b/src/app/content-viewer/content-viewer.controller.ts @@ -0,0 +1,18 @@ +import {ArticleDirective, ArticleView} from "../components/noosfero-articles/article/article.directive"; + +/** @ngInject */ +export function ContentViewerController(noosfero, $log, $stateParams) { + var vm = this; + vm.article = null; + vm.profile = null; + activate(); + + function activate() { + noosfero.currentProfile.then(function(profile) { + vm.profile = profile; + return noosfero.profiles.one(vm.profile.id).one('articles').get({ path: $stateParams.page }); + }).then(function(response) { + vm.article = response.data.article; + }); + } +} diff --git a/src/app/index.module.ts b/src/app/index.module.ts index 0eafcc3..5ee791e 100644 --- a/src/app/index.module.ts +++ b/src/app/index.module.ts @@ -22,6 +22,10 @@ export class NoosferoApp { angular.module(NoosferoApp.appName).service(serviceName, value); } + static addController(controllerName: string, value: any) { + angular.module(NoosferoApp.appName).controller(controllerName, value); + } + static run(runFunction: Function) { angular.module(NoosferoApp.appName).run(runFunction); } diff --git a/src/app/index.route.ts b/src/app/index.route.ts index 88d8df2..cdfc37d 100644 --- a/src/app/index.route.ts +++ b/src/app/index.route.ts @@ -1,79 +1,77 @@ /** @ngInject */ -export function routeConfig($stateProvider, $urlRouterProvider) { +export function routeConfig($stateProvider, $urlRouterProvider) { $stateProvider - .state("main", { - url: "/", - templateUrl: "app/main/main.html", - controller: "MainController", - controllerAs: "vm", - resolve: { - currentUser: function(AuthService) { - return AuthService.loginFromCookie(); - } - } - }) - .state("main.profile.cms", { - url: "^/myprofile/:profile/cms", - views: { - "mainBlockContent": { - templateUrl: "app/cms/cms.html", - controller: "CmsController", - controllerAs: "vm" - } - } - }) - .state("main.profile.settings", { - url: "^/myprofile/:profile" - }) - .state("main.profile", { - url: "^/:profile", - abstract: true, - views: { - "content": { - templateUrl: "app/profile/profile.html", - controller: "ProfileController", - controllerAs: "vm" - } - } - }) - .state("main.profile.home", { - url: "", - views: { - "mainBlockContent": { - controller: "ProfileHomeController", - controllerAs: "vm" - } - } - }) - .state("main.profile.info", { - url: "^/profile/:profile", - views: { - "mainBlockContent": { - templateUrl: "app/profile-info/profile-info.html", - controller: "ProfileInfoController", - controllerAs: "vm" - } - } - }) - .state("main.profile.page", { - url: "/{page:any}", - views: { - "mainBlockContent": { - templateUrl: "app/content-viewer/page.html", - controller: "ContentViewerController", - controllerAs: "vm" - }, - "actions@main": { - templateUrl: "app/content-viewer/navbar-actions.html", - controller: "ContentViewerActionsController", - controllerAs: "vm" - } - } - }); + .state("main", { + url: "/", + templateUrl: "app/main/main.html", + controller: "MainController", + controllerAs: "vm", + resolve: { + currentUser: function(AuthService) { + return AuthService.loginFromCookie(); + } + } + }) + .state("main.profile.cms", { + url: "^/myprofile/:profile/cms", + views: { + "mainBlockContent": { + templateUrl: "app/cms/cms.html", + controller: "CmsController", + controllerAs: "vm" + } + } + }) + .state("main.profile.settings", { + url: "^/myprofile/:profile" + }) + .state("main.profile", { + url: "^/:profile", + abstract: true, + views: { + "content": { + templateUrl: "app/profile/profile.html", + controller: "ProfileController", + controllerAs: "vm" + } + } + }) + .state("main.profile.home", { + url: "", + views: { + "mainBlockContent": { + controller: "ProfileHomeController", + controllerAs: "vm" + } + } + }) + .state("main.profile.info", { + url: "^/profile/:profile", + views: { + "mainBlockContent": { + templateUrl: "app/profile-info/profile-info.html", + controller: "ProfileInfoController", + controllerAs: "vm" + } + } + }) + .state("main.profile.page", { + url: "/{page:any}", + views: { + "mainBlockContent": { + templateUrl: "app/content-viewer/page.html", + controller: "ContentViewerController", + controllerAs: "vm" + }, + "actions@main": { + templateUrl: "app/content-viewer/navbar-actions.html", + controller: "ContentViewerActionsController", + controllerAs: "vm" + } + } + }); $urlRouterProvider.otherwise("/"); - } - - +} diff --git a/src/app/index.ts b/src/app/index.ts index be1bee1..2738e59 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -2,6 +2,7 @@ import {NoosferoApp} from "./index.module"; import {noosferoModuleConfig} from "./index.config"; import {noosferoAngularRunBlock} from "./index.run"; import {routeConfig} from "./index.route"; +import {ContentViewerController} from "./content-viewer/content-viewer.controller"; declare var moment: any; @@ -26,7 +27,7 @@ require("./components/auth/auth.service.js"); require("./components/navbar/navbar.directive.js"); require("./components/noosfero-activities/activities.component.js"); require("./components/noosfero-activities/activity/activity.component.js"); -require("./components/noosfero-articles/article/article.directive.js"); +//require("./components/noosfero-articles/article/article.directive.js"); require("./components/noosfero-articles/blog/blog.component.js"); require("./components/noosfero-blocks/block.directive.js"); require("./components/noosfero-blocks/link-list/link-list.component.js"); @@ -39,9 +40,11 @@ require("./components/noosfero/noosfero-template.filter.js"); require("./components/noosfero/noosfero.service.js"); require("./components/noosfero/profile-image/profile-image.component.js"); require("./content-viewer/content-viewer-actions.controller.js"); -require("./content-viewer/content-viewer.controller.js"); +// require("./content-viewer/content-viewer.controller.js"); require("./profile-info/profile-info.controller.js"); require("./profile/profile-home.controller.js"); require("./profile/profile.controller.js"); +NoosferoApp.addController("ContentViewerController", ContentViewerController); + NoosferoApp.addConfig(routeConfig); diff --git a/tsconfig.json b/tsconfig.json index c09f483..d9f2801 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,7 +3,8 @@ "module": "commonjs", "target": "es5", "noImplicitAny": false, - "sourceMap": false + "sourceMap": false, + "experimentalDecorators": true }, "exclude": [ "node_modules", diff --git a/typings.json b/typings.json index d81a333..68fdf41 100644 --- a/typings.json +++ b/typings.json @@ -4,6 +4,8 @@ "devDependencies": {}, "ambientDependencies": { "angular": "github:DefinitelyTyped/DefinitelyTyped/angularjs/angular.d.ts#1c4a34873c9e70cce86edd0e61c559e43dfa5f75", + "angular-ui-router": "github:DefinitelyTyped/DefinitelyTyped/angular-ui-router/angular-ui-router.d.ts#655f8c1bf3c71b0e1ba415b36309604f79326ac8", + "es6-shim": "github:DefinitelyTyped/DefinitelyTyped/es6-shim/es6-shim.d.ts#4de74cb527395c13ba20b438c3a7a419ad931f1c", "jquery": "github:DefinitelyTyped/DefinitelyTyped/jquery/jquery.d.ts#470954c4f427e0805a2d633636a7c6aa7170def8" } } -- libgit2 0.21.2