diff --git a/src/app/components/noosfero-articles/article/article.directive.ts b/src/app/components/noosfero-articles/article/article.directive.ts index 4c8f498..2f07c19 100644 --- a/src/app/components/noosfero-articles/article/article.directive.ts +++ b/src/app/components/noosfero-articles/article/article.directive.ts @@ -6,7 +6,9 @@ import { bundle, Input, Inject, Component, Directive } from 'ng-forward'; providers: ['$injector', '$compile'] }) export class ArticleView { - + constructor() { + console.log("ARTICLE VIEW"); + } } /** @@ -14,24 +16,19 @@ export class ArticleView { * * */ -@Directive({ - selector: 'noosfero-article', - providers: ['$injector', '$compile'], +@Directive({ + selector: '[noosfero-article]', + providers: [] }) -@Inject('$element') -@Inject('$scope') +@Inject("$element") +@Inject("$scope") +@Inject("$injector") +@Inject("$compile") 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; + 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)); @@ -42,4 +39,4 @@ export class ArticleDirective { } } -bundle('noosferoApp', ArticleDirective).publish(); +//bundle('noosferoApp', ArticleDirective).publish(); diff --git a/src/app/components/noosfero-articles/blog/blog.component.js b/src/app/components/noosfero-articles/blog/blog.component.js deleted file mode 100644 index c5db9d5..0000000 --- a/src/app/components/noosfero-articles/blog/blog.component.js +++ /dev/null @@ -1,36 +0,0 @@ -(function() { - 'use strict'; - - angular - .module('noosferoApp') - .component('noosferoBlog', { - restrict: 'E', - templateUrl: 'app/components/noosfero-articles/blog/blog.html', - bindings: { - article: '<', - profile: '<' - }, - controller: BlogController - }); - - /** @ngInject */ - function BlogController(noosfero) { - var vm = this; - vm.posts = []; - vm.perPage = 3; - vm.currentPage = 1; - - vm.loadPage = function() { - noosfero.articles.one(vm.article.id).customGET('children', { - content_type: 'TinyMceArticle', - per_page: vm.perPage, - page: vm.currentPage - }).then(function(response) { - vm.totalPosts = response.headers('total'); - vm.posts = response.data.articles; - }); - } - vm.loadPage(); - } - -})(); diff --git a/src/app/components/noosfero-articles/blog/blog.component.ts b/src/app/components/noosfero-articles/blog/blog.component.ts new file mode 100644 index 0000000..51bfa35 --- /dev/null +++ b/src/app/components/noosfero-articles/blog/blog.component.ts @@ -0,0 +1,32 @@ +import {Component, Input} from "ng-forward"; + + +@Component({ + selector: "noosfero-blog", + templateUrl: "app/components/noosfero-articles/blog/blog.html", + inputs: ["article", "profile"] +}) +export class NoosferoArticleBlog { + @Input() article; + @Input() profile; + + private posts: any[]; + private perPage: number; + private currentPage: number; + private totalPosts: number = 0; + constructor(private noosferoService: any) { + this.loadPage(); + } + + loadPage() { + this.noosferoService.articles.one(this.article.id).customGET("children", { + content_type: "TinyMceArticle", + per_page: this.perPage, + page: this.currentPage + }).then((response) => { + this.totalPosts = response.headers("total"); + this.posts = response.data.articles; + }); + } + +} \ No newline at end of file diff --git a/src/app/content-viewer/content-viewer.component.ts b/src/app/content-viewer/content-viewer.component.ts new file mode 100644 index 0000000..5a2361a --- /dev/null +++ b/src/app/content-viewer/content-viewer.component.ts @@ -0,0 +1,38 @@ + +import * as noosfero from "../models/interfaces"; + +import {ArticleDirective, ArticleView} from "../components/noosfero-articles/article/article.directive"; +import {Input, Component, StateConfig} from "ng-forward"; + +import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; + +@Component({ + selector: "content-viewer", + templateUrl: "app/content-viewer/page.html", + providers: [ + "noosferoService", "$log", "$stateParams" + ], + directives: [NoosferoArticleBlog, ArticleView, ArticleDirective] +}) +export class ContentViewer { + + @Input() + article: noosfero.Article = null; + + @Input() + profile: noosfero.Profile = null; + + constructor(private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) { + this.activate(); + } + + activate() { + console.log("HERE CONTENT VIEWER"); + this.noosfero.currentProfile.then((profile) => { + this.profile = profile; + return this.noosfero.profiles.one(this.profile.id).one("articles").get({ path: this.$stateParams["page"] }); + }).then((response) => { + this.article = response.data.article; + }); + } +} diff --git a/src/app/content-viewer/content-viewer.controller.ts b/src/app/content-viewer/content-viewer.controller.ts deleted file mode 100644 index 0c59546..0000000 --- a/src/app/content-viewer/content-viewer.controller.ts +++ /dev/null @@ -1,34 +0,0 @@ - -import * as noosfero from "../models/interfaces"; - -import {ArticleDirective, ArticleView} from "../components/noosfero-articles/article/article.directive"; -import {Input, Component, StateConfig} from "ng-forward"; - -@Component({ - selector: "content-viewer", - template: "", - providers: [ - "noosferoService", "$log", "$stateParams" - ] -}) -export class ContentViewerController { - - @Input() - article: noosfero.Article = null; - - @Input() - profile: noosfero.Profile = null; - - constructor(private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) { - this.activate(); - } - - activate() { - this.noosfero.currentProfile.then(function(profile) { - this.profile = profile; - return this.noosfero.profiles.one(this.profile.id).one("articles").get({ path: this.$stateParams.page }); - }).then(function(response) { - this.article = response.data.article; - }); - } -} diff --git a/src/app/content-viewer/page.html b/src/app/content-viewer/page.html index d51a781..10ae4f7 100644 --- a/src/app/content-viewer/page.html +++ b/src/app/content-viewer/page.html @@ -1 +1,6 @@ - +console.log("HERE CONTENT VIEWER"); + +{{vm.article}} + +{{vm.profile}} +
diff --git a/src/app/index.ts b/src/app/index.ts index d209427..168740c 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -1,11 +1,13 @@ -import 'reflect-metadata'; +import "reflect-metadata"; 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"; + +import {ContentViewer as noosferoContentViewer} from "./content-viewer/content-viewer.component"; + import {Main} from "./main/main.component"; -import {bootstrap, bundle} from 'ng-forward'; +import {bootstrap, bundle} from "ng-forward"; declare var moment: any; @@ -40,7 +42,10 @@ 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/blog/blog.component.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"); require("./components/noosfero-blocks/main-block/main-block.component.js"); @@ -57,6 +62,6 @@ require("./profile-info/profile-info.controller.js"); require("./profile/profile-home.controller.js"); require("./profile/profile.controller.js"); -// NoosferoApp.addController("ContentViewerController", ContentViewerController); +NoosferoApp.addController("ContentViewerController", noosferoContentViewer); NoosferoApp.addConfig(routeConfig); diff --git a/src/app/main/main.component.ts b/src/app/main/main.component.ts index 47a5cb6..29ce780 100644 --- a/src/app/main/main.component.ts +++ b/src/app/main/main.component.ts @@ -1,4 +1,7 @@ import {bundle, Component, StateConfig} from 'ng-forward'; +import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component.ts"; + +import {ArticleDirective} from "../components/noosfero-articles/article/article.directive.ts"; @Component({ selector: 'main-content', @@ -10,7 +13,8 @@ export class MainContent { @Component({ selector: 'main', - template: '
' + template: '
', + directives: [NoosferoArticleBlog, ArticleDirective] }) @StateConfig([ { diff --git a/src/app/models/interfaces.ts b/src/app/models/interfaces.ts index f64c58f..e850fa1 100644 --- a/src/app/models/interfaces.ts +++ b/src/app/models/interfaces.ts @@ -1,23 +1,23 @@ export interface Event extends Article { - + id: number; } export interface Article { - + id: number; } export interface Profile { - + id: number; } export interface Person extends Profile { - + id: number; } export interface TynyMceArticle extends Article { - + id: number; } export interface Blog extends Article { - + id: number; } -- libgit2 0.21.2