Commit 5e222a2257b82bf2d6e366d92d911f86c1f339fc
1 parent
2e424f97
Exists in
master
and in
35 other branches
Migrate block component to ngforward
Showing
5 changed files
with
23 additions
and
27 deletions
Show diff stats
... | ... | @@ -0,0 +1,20 @@ |
1 | +import { Input, Inject, Component } from 'ng-forward'; | |
2 | + | |
3 | +@Component({ | |
4 | + selector: 'noosfero-block', | |
5 | + template: '<div></div>' | |
6 | +}) | |
7 | +@Inject("$element", "$scope", "$injector", "$compile") | |
8 | +export class Block { | |
9 | + | |
10 | + @Input() block: any; | |
11 | + @Input() owner: any; | |
12 | + | |
13 | + ngOnInit() { | |
14 | + let blockName = this.block.type.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | |
15 | + this.$element.replaceWith(this.$compile('<noosfero-' + blockName + ' block="ctrl.block" owner="ctrl.owner"></noosfero-' + blockName + '>')(this.$scope)); | |
16 | + } | |
17 | + | |
18 | + constructor(private $element: any, private $scope: ng.IScope, private $injector: ng.auto.IInjectorService, private $compile: ng.ICompileService) { | |
19 | + } | |
20 | +} | ... | ... |
src/app/components/noosfero-blocks/block.directive.js
... | ... | @@ -1,24 +0,0 @@ |
1 | -(function() { | |
2 | - 'use strict'; | |
3 | - | |
4 | - angular | |
5 | - .module('noosferoApp') | |
6 | - .directive('noosferoBlock', noosferoBlock); | |
7 | - | |
8 | - /** @ngInject */ | |
9 | - function noosferoBlock($compile) { | |
10 | - var directive = { | |
11 | - restrict: 'E', | |
12 | - scope: { | |
13 | - block: '<', | |
14 | - owner: '<' | |
15 | - }, | |
16 | - link: function(scope, element) { | |
17 | - var blockName = scope.block.type.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | |
18 | - element.replaceWith($compile('<noosfero-'+blockName+' block="block" owner="owner"></noosfero-'+blockName+'>')(scope)); | |
19 | - } | |
20 | - }; | |
21 | - return directive; | |
22 | - } | |
23 | - | |
24 | -})(); |
src/app/components/noosfero-boxes/box.html
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | <h3 class="panel-title">{{block.title}}</h3> |
5 | 5 | </div> |
6 | 6 | <div class="panel-body"> |
7 | - <noosfero-block block="block" owner="ctrl.owner"></noosfero-block> | |
7 | + <noosfero-block [block]="block" [owner]="ctrl.owner"></noosfero-block> | |
8 | 8 | </div> |
9 | 9 | </div> |
10 | 10 | </div> | ... | ... |
src/app/index.ts
... | ... | @@ -43,7 +43,6 @@ require("./components/auth/auth.service.js"); |
43 | 43 | require("./components/navbar/navbar.directive.js"); |
44 | 44 | require("./components/noosfero-activities/activities.component.js"); |
45 | 45 | require("./components/noosfero-activities/activity/activity.component.js"); |
46 | -require("./components/noosfero-blocks/block.directive.js"); | |
47 | 46 | require("./components/noosfero-blocks/link-list/link-list.component.js"); |
48 | 47 | require("./components/noosfero-blocks/main-block/main-block.component.js"); |
49 | 48 | require("./components/noosfero-blocks/members-block/members-block.component.js"); | ... | ... |
src/app/main/main.component.ts
... | ... | @@ -3,6 +3,7 @@ import {NoosferoArticleBlog} from "./../components/noosfero-articles/blog/blog.c |
3 | 3 | import {ArticleDirective} from "../components/noosfero-articles/article/article.directive.ts"; |
4 | 4 | import {Profile} from "../profile/profile.component"; |
5 | 5 | import {Boxes} from "../components/noosfero-boxes/boxes.component"; |
6 | +import {Block} from "../components/noosfero-blocks/block.component"; | |
6 | 7 | |
7 | 8 | @Component({ |
8 | 9 | selector: 'main-content', |
... | ... | @@ -15,7 +16,7 @@ export class MainContent { |
15 | 16 | @Component({ |
16 | 17 | selector: 'main', |
17 | 18 | template: '<div ng-view></div>', |
18 | - directives: [NoosferoArticleBlog, ArticleDirective, Boxes] | |
19 | + directives: [NoosferoArticleBlog, ArticleDirective, Boxes, Block] | |
19 | 20 | }) |
20 | 21 | @StateConfig([ |
21 | 22 | { | ... | ... |