Commit e6f9f67de4363bf9d14c6350ec5c6ee29db9b7fa

Authored by ABNER SILVA DE OLIVEIRA
1 parent 7bdf7c86

adding content viewer

src/app/components/noosfero-articles/article/article.directive.ts
@@ -6,7 +6,9 @@ import { bundle, Input, Inject, Component, Directive } from 'ng-forward'; @@ -6,7 +6,9 @@ import { bundle, Input, Inject, Component, Directive } from 'ng-forward';
6 providers: ['$injector', '$compile'] 6 providers: ['$injector', '$compile']
7 }) 7 })
8 export class ArticleView { 8 export class ArticleView {
9 - 9 + constructor() {
  10 + console.log("ARTICLE VIEW");
  11 + }
10 } 12 }
11 13
12 /** 14 /**
@@ -14,24 +16,19 @@ export class ArticleView { @@ -14,24 +16,19 @@ export class ArticleView {
14 * 16 *
15 * 17 *
16 */ 18 */
17 -@Directive({  
18 - selector: 'noosfero-article',  
19 - providers: ['$injector', '$compile'],  
20 19
  20 +@Directive({
  21 + selector: '[noosfero-article]',
  22 + providers: []
21 }) 23 })
22 -@Inject('$element')  
23 -@Inject('$scope') 24 +@Inject("$element")
  25 +@Inject("$scope")
  26 +@Inject("$injector")
  27 +@Inject("$compile")
24 export class ArticleDirective { 28 export class ArticleDirective {
25 29
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) { 30 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; 31 + var specificDirective = 'noosfero' + $scope["vm"].article.type;
35 if ($injector.has(specificDirective + 'Directive')) { 32 if ($injector.has(specificDirective + 'Directive')) {
36 var directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); 33 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)); 34 $element.replaceWith($compile('<' + directiveName + ' article="vm.article" profile="vm.profile"></' + directiveName + '>')($scope));
@@ -42,4 +39,4 @@ export class ArticleDirective { @@ -42,4 +39,4 @@ export class ArticleDirective {
42 } 39 }
43 } 40 }
44 41
45 -bundle('noosferoApp', ArticleDirective).publish(); 42 +//bundle('noosferoApp', ArticleDirective).publish();
src/app/components/noosfero-articles/blog/blog.component.js
@@ -1,36 +0,0 @@ @@ -1,36 +0,0 @@
1 -(function() {  
2 - 'use strict';  
3 -  
4 - angular  
5 - .module('noosferoApp')  
6 - .component('noosferoBlog', {  
7 - restrict: 'E',  
8 - templateUrl: 'app/components/noosfero-articles/blog/blog.html',  
9 - bindings: {  
10 - article: '<',  
11 - profile: '<'  
12 - },  
13 - controller: BlogController  
14 - });  
15 -  
16 - /** @ngInject */  
17 - function BlogController(noosfero) {  
18 - var vm = this;  
19 - vm.posts = [];  
20 - vm.perPage = 3;  
21 - vm.currentPage = 1;  
22 -  
23 - vm.loadPage = function() {  
24 - noosfero.articles.one(vm.article.id).customGET('children', {  
25 - content_type: 'TinyMceArticle',  
26 - per_page: vm.perPage,  
27 - page: vm.currentPage  
28 - }).then(function(response) {  
29 - vm.totalPosts = response.headers('total');  
30 - vm.posts = response.data.articles;  
31 - });  
32 - }  
33 - vm.loadPage();  
34 - }  
35 -  
36 -})();  
src/app/components/noosfero-articles/blog/blog.component.ts 0 → 100644
@@ -0,0 +1,32 @@ @@ -0,0 +1,32 @@
  1 +import {Component, Input} from "ng-forward";
  2 +
  3 +
  4 +@Component({
  5 + selector: "noosfero-blog",
  6 + templateUrl: "app/components/noosfero-articles/blog/blog.html",
  7 + inputs: ["article", "profile"]
  8 +})
  9 +export class NoosferoArticleBlog {
  10 + @Input() article;
  11 + @Input() profile;
  12 +
  13 + private posts: any[];
  14 + private perPage: number;
  15 + private currentPage: number;
  16 + private totalPosts: number = 0;
  17 + constructor(private noosferoService: any) {
  18 + this.loadPage();
  19 + }
  20 +
  21 + loadPage() {
  22 + this.noosferoService.articles.one(this.article.id).customGET("children", {
  23 + content_type: "TinyMceArticle",
  24 + per_page: this.perPage,
  25 + page: this.currentPage
  26 + }).then((response) => {
  27 + this.totalPosts = response.headers("total");
  28 + this.posts = response.data.articles;
  29 + });
  30 + }
  31 +
  32 +}
0 \ No newline at end of file 33 \ No newline at end of file
src/app/content-viewer/content-viewer.component.ts 0 → 100644
@@ -0,0 +1,38 @@ @@ -0,0 +1,38 @@
  1 +
  2 +import * as noosfero from "../models/interfaces";
  3 +
  4 +import {ArticleDirective, ArticleView} from "../components/noosfero-articles/article/article.directive";
  5 +import {Input, Component, StateConfig} from "ng-forward";
  6 +
  7 +import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component";
  8 +
  9 +@Component({
  10 + selector: "content-viewer",
  11 + templateUrl: "app/content-viewer/page.html",
  12 + providers: [
  13 + "noosferoService", "$log", "$stateParams"
  14 + ],
  15 + directives: [NoosferoArticleBlog, ArticleView, ArticleDirective]
  16 +})
  17 +export class ContentViewer {
  18 +
  19 + @Input()
  20 + article: noosfero.Article = null;
  21 +
  22 + @Input()
  23 + profile: noosfero.Profile = null;
  24 +
  25 + constructor(private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) {
  26 + this.activate();
  27 + }
  28 +
  29 + activate() {
  30 + console.log("HERE CONTENT VIEWER");
  31 + this.noosfero.currentProfile.then((profile) => {
  32 + this.profile = profile;
  33 + return this.noosfero.profiles.one(this.profile.id).one("articles").get({ path: this.$stateParams["page"] });
  34 + }).then((response) => {
  35 + this.article = response.data.article;
  36 + });
  37 + }
  38 +}
src/app/content-viewer/content-viewer.controller.ts
@@ -1,34 +0,0 @@ @@ -1,34 +0,0 @@
1 -  
2 -import * as noosfero from "../models/interfaces";  
3 -  
4 -import {ArticleDirective, ArticleView} from "../components/noosfero-articles/article/article.directive";  
5 -import {Input, Component, StateConfig} from "ng-forward";  
6 -  
7 -@Component({  
8 - selector: "content-viewer",  
9 - template: "",  
10 - providers: [  
11 - "noosferoService", "$log", "$stateParams"  
12 - ]  
13 -})  
14 -export class ContentViewerController {  
15 -  
16 - @Input()  
17 - article: noosfero.Article = null;  
18 -  
19 - @Input()  
20 - profile: noosfero.Profile = null;  
21 -  
22 - constructor(private noosfero: any, private $log: ng.ILogService, private $stateParams: angular.ui.IStateParamsService) {  
23 - this.activate();  
24 - }  
25 -  
26 - activate() {  
27 - this.noosfero.currentProfile.then(function(profile) {  
28 - this.profile = profile;  
29 - return this.noosfero.profiles.one(this.profile.id).one("articles").get({ path: this.$stateParams.page });  
30 - }).then(function(response) {  
31 - this.article = response.data.article;  
32 - });  
33 - }  
34 -}  
src/app/content-viewer/page.html
1 -<noosfero-article ng-if="vm.article" article="vm.article" profile="vm.profile"></noosfero-article> 1 +console.log("HERE CONTENT VIEWER");
  2 +
  3 +{{vm.article}}
  4 +
  5 +{{vm.profile}}
  6 +<div noosfero-article article="vm.article" profile="vm.profile"></div>
src/app/index.ts
1 -import 'reflect-metadata'; 1 +import "reflect-metadata";
2 import {NoosferoApp} from "./index.module"; 2 import {NoosferoApp} from "./index.module";
3 import {noosferoModuleConfig} from "./index.config"; 3 import {noosferoModuleConfig} from "./index.config";
4 import {noosferoAngularRunBlock} from "./index.run"; 4 import {noosferoAngularRunBlock} from "./index.run";
5 import {routeConfig} from "./index.route"; 5 import {routeConfig} from "./index.route";
6 -import {ContentViewerController} from "./content-viewer/content-viewer.controller"; 6 +
  7 +import {ContentViewer as noosferoContentViewer} from "./content-viewer/content-viewer.component";
  8 +
7 import {Main} from "./main/main.component"; 9 import {Main} from "./main/main.component";
8 -import {bootstrap, bundle} from 'ng-forward'; 10 +import {bootstrap, bundle} from "ng-forward";
9 11
10 declare var moment: any; 12 declare var moment: any;
11 13
@@ -40,7 +42,10 @@ require(&quot;./components/auth/auth.service.js&quot;); @@ -40,7 +42,10 @@ require(&quot;./components/auth/auth.service.js&quot;);
40 require("./components/navbar/navbar.directive.js"); 42 require("./components/navbar/navbar.directive.js");
41 require("./components/noosfero-activities/activities.component.js"); 43 require("./components/noosfero-activities/activities.component.js");
42 require("./components/noosfero-activities/activity/activity.component.js"); 44 require("./components/noosfero-activities/activity/activity.component.js");
43 -require("./components/noosfero-articles/blog/blog.component.js"); 45 +
  46 +// require("./components/noosfero-articles/blog/blog.component.js");
  47 +
  48 +
44 require("./components/noosfero-blocks/block.directive.js"); 49 require("./components/noosfero-blocks/block.directive.js");
45 require("./components/noosfero-blocks/link-list/link-list.component.js"); 50 require("./components/noosfero-blocks/link-list/link-list.component.js");
46 require("./components/noosfero-blocks/main-block/main-block.component.js"); 51 require("./components/noosfero-blocks/main-block/main-block.component.js");
@@ -57,6 +62,6 @@ require(&quot;./profile-info/profile-info.controller.js&quot;); @@ -57,6 +62,6 @@ require(&quot;./profile-info/profile-info.controller.js&quot;);
57 require("./profile/profile-home.controller.js"); 62 require("./profile/profile-home.controller.js");
58 require("./profile/profile.controller.js"); 63 require("./profile/profile.controller.js");
59 64
60 -// NoosferoApp.addController("ContentViewerController", ContentViewerController); 65 +NoosferoApp.addController("ContentViewerController", noosferoContentViewer);
61 66
62 NoosferoApp.addConfig(routeConfig); 67 NoosferoApp.addConfig(routeConfig);
src/app/main/main.component.ts
1 import {bundle, Component, StateConfig} from 'ng-forward'; 1 import {bundle, Component, StateConfig} from 'ng-forward';
  2 +import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component.ts";
  3 +
  4 +import {ArticleDirective} from "../components/noosfero-articles/article/article.directive.ts";
2 5
3 @Component({ 6 @Component({
4 selector: 'main-content', 7 selector: 'main-content',
@@ -10,7 +13,8 @@ export class MainContent { @@ -10,7 +13,8 @@ export class MainContent {
10 13
11 @Component({ 14 @Component({
12 selector: 'main', 15 selector: 'main',
13 - template: '<div ng-view></div>' 16 + template: '<div ng-view></div>',
  17 + directives: [NoosferoArticleBlog, ArticleDirective]
14 }) 18 })
15 @StateConfig([ 19 @StateConfig([
16 { 20 {
src/app/models/interfaces.ts
1 export interface Event extends Article { 1 export interface Event extends Article {
2 - 2 + id: number;
3 } 3 }
4 4
5 export interface Article { 5 export interface Article {
6 - 6 + id: number;
7 } 7 }
8 8
9 export interface Profile { 9 export interface Profile {
10 - 10 + id: number;
11 } 11 }
12 12
13 export interface Person extends Profile { 13 export interface Person extends Profile {
14 - 14 + id: number;
15 } 15 }
16 16
17 export interface TynyMceArticle extends Article { 17 export interface TynyMceArticle extends Article {
18 - 18 + id: number;
19 } 19 }
20 20
21 export interface Blog extends Article { 21 export interface Blog extends Article {
22 - 22 + id: number;
23 } 23 }