Commit ef326a93c92b9246df0d002ddec8d6aa9bea8e9c
1 parent
15119bcf
Exists in
master
and in
35 other branches
Refactor article component
Showing
2 changed files
with
6 additions
and
22 deletions
Show diff stats
src/app/components/noosfero-articles/article/article.directive.ts
@@ -2,38 +2,22 @@ import { bundle, Input, Inject, Component, Directive } from 'ng-forward'; | @@ -2,38 +2,22 @@ import { bundle, Input, Inject, Component, Directive } from 'ng-forward'; | ||
2 | import {NoosferoArticleBlog} from "../blog/blog.component"; | 2 | import {NoosferoArticleBlog} from "../blog/blog.component"; |
3 | 3 | ||
4 | @Component({ | 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 | - constructor() { | ||
14 | - | ||
15 | - } | ||
16 | -} | ||
17 | - | ||
18 | -@Component({ | ||
19 | selector: 'noosfero-article', | 5 | selector: 'noosfero-article', |
20 | - template: '<div></div>', | ||
21 | - directives: [ArticleView, NoosferoArticleBlog] | 6 | + templateUrl: 'app/components/noosfero-articles/article/article.html', |
7 | + directives: [NoosferoArticleBlog] | ||
22 | }) | 8 | }) |
23 | @Inject("$element", "$scope", "$injector", "$compile") | 9 | @Inject("$element", "$scope", "$injector", "$compile") |
24 | export class ArticleDirective { | 10 | export class ArticleDirective { |
25 | 11 | ||
26 | @Input() article: any; | 12 | @Input() article: any; |
27 | @Input() profile: any; | 13 | @Input() profile: any; |
28 | - directiveName: string; | ||
29 | 14 | ||
30 | ngOnInit() { | 15 | ngOnInit() { |
31 | let specificDirective = 'noosfero' + this.article.type; | 16 | let specificDirective = 'noosfero' + this.article.type; |
32 | - this.directiveName = "noosfero-default-article"; | ||
33 | if (this.$injector.has(specificDirective + 'Directive')) { | 17 | if (this.$injector.has(specificDirective + 'Directive')) { |
34 | - this.directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | 18 | + let directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); |
19 | + this.$element.replaceWith(this.$compile('<' + directiveName + ' [article]="ctrl.article" [profile]="ctrl.profile"></' + directiveName + '>')(this.$scope)); | ||
35 | } | 20 | } |
36 | - this.$element.replaceWith(this.$compile('<' + this.directiveName + ' [article]="ctrl.article" [profile]="ctrl.profile"></' + this.directiveName + '>')(this.$scope)); | ||
37 | } | 21 | } |
38 | 22 | ||
39 | constructor(private $element: any, private $scope: ng.IScope, private $injector: ng.auto.IInjectorService, private $compile: ng.ICompileService) { | 23 | constructor(private $element: any, private $scope: ng.IScope, private $injector: ng.auto.IInjectorService, private $compile: ng.ICompileService) { |
src/app/content-viewer/content-viewer.component.ts
1 | import * as noosfero from "../models/interfaces"; | 1 | import * as noosfero from "../models/interfaces"; |
2 | 2 | ||
3 | -import {ArticleDirective, ArticleView} from "../components/noosfero-articles/article/article.directive"; | 3 | +import {ArticleDirective} from "../components/noosfero-articles/article/article.directive"; |
4 | import {Input, Component, StateConfig, Inject} from "ng-forward"; | 4 | import {Input, Component, StateConfig, Inject} from "ng-forward"; |
5 | 5 | ||
6 | import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; | 6 | import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.component"; |
@@ -8,7 +8,7 @@ import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.c | @@ -8,7 +8,7 @@ import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.c | ||
8 | @Component({ | 8 | @Component({ |
9 | selector: "content-viewer", | 9 | selector: "content-viewer", |
10 | templateUrl: "app/content-viewer/page.html", | 10 | templateUrl: "app/content-viewer/page.html", |
11 | - directives: [NoosferoArticleBlog, ArticleView, ArticleDirective] | 11 | + directives: [NoosferoArticleBlog, ArticleDirective] |
12 | }) | 12 | }) |
13 | @Inject("noosfero", "$log", "$stateParams") | 13 | @Inject("noosfero", "$log", "$stateParams") |
14 | export class ContentViewer { | 14 | export class ContentViewer { |