Commit dfe7a66da22b374533e93bc6923e2809a9011e99
1 parent
9ed8efe9
Exists in
master
and in
38 other branches
Create blog directive
Showing
5 changed files
with
25 additions
and
9 deletions
Show diff stats
src/app/components/noosfero-articles/article/article.directive.js
| @@ -6,23 +6,30 @@ | @@ -6,23 +6,30 @@ | ||
| 6 | .directive('noosferoArticle', noosferoArticle); | 6 | .directive('noosferoArticle', noosferoArticle); |
| 7 | 7 | ||
| 8 | /** @ngInject */ | 8 | /** @ngInject */ |
| 9 | - function noosferoArticle() { | 9 | + function noosferoArticle($injector, $compile) { |
| 10 | var directive = { | 10 | var directive = { |
| 11 | restrict: 'E', | 11 | restrict: 'E', |
| 12 | templateUrl: 'app/components/noosfero-articles/article/article.html', | 12 | templateUrl: 'app/components/noosfero-articles/article/article.html', |
| 13 | scope: { | 13 | scope: { |
| 14 | article: '=', | 14 | article: '=', |
| 15 | - owner: '=' | 15 | + profile: '=' |
| 16 | }, | 16 | }, |
| 17 | controller: ArticleController, | 17 | controller: ArticleController, |
| 18 | controllerAs: 'vm', | 18 | controllerAs: 'vm', |
| 19 | - bindToController: true | 19 | + bindToController: true, |
| 20 | + link: function(scope, element) { | ||
| 21 | + var specificDirective = 'noosfero'+scope.vm.article.type; | ||
| 22 | + if($injector.has(specificDirective+'Directive')) { | ||
| 23 | + var directiveName = specificDirective.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); | ||
| 24 | + element.replaceWith($compile('<'+directiveName+' article="vm.article" profile="vm.profile"></'+directiveName+'>')(scope)); | ||
| 25 | + } | ||
| 26 | + } | ||
| 20 | }; | 27 | }; |
| 21 | 28 | ||
| 22 | return directive; | 29 | return directive; |
| 23 | 30 | ||
| 24 | /** @ngInject */ | 31 | /** @ngInject */ |
| 25 | - function ArticleController() { | 32 | + function ArticleController($injector, $compile, $scope) { |
| 26 | var vm = this; | 33 | var vm = this; |
| 27 | } | 34 | } |
| 28 | } | 35 | } |
src/app/components/noosfero-articles/blog/blog.directive.js
| @@ -12,7 +12,7 @@ | @@ -12,7 +12,7 @@ | ||
| 12 | templateUrl: 'app/components/noosfero-articles/blog/blog.html', | 12 | templateUrl: 'app/components/noosfero-articles/blog/blog.html', |
| 13 | scope: { | 13 | scope: { |
| 14 | article: '=', | 14 | article: '=', |
| 15 | - owner: '=' | 15 | + profile: '=' |
| 16 | }, | 16 | }, |
| 17 | controller: BlogController, | 17 | controller: BlogController, |
| 18 | controllerAs: 'vm', | 18 | controllerAs: 'vm', |
src/app/components/noosfero-articles/blog/blog.html
| 1 | -{{vm.article.title}} | 1 | +<div class="page-header"> |
| 2 | + <h3 ng-bind="vm.article.title"></h3> | ||
| 3 | +</div> | ||
| 2 | 4 | ||
| 3 | -<pre>{{vm.article}}</pre> | 5 | +<div> |
| 6 | + <div ng-repeat="child in vm.article.children"> | ||
| 7 | + <a ng-href="/{{vm.profile.identifier}}/{{child.path}}"><h4 ng-bind="child.title"></h4></a> | ||
| 8 | + <div ng-bind-html="child.body | limitTo: 500"></div> | ||
| 9 | + </div> | ||
| 10 | +</div> |
src/app/content-viewer/content-viewer.controller.js
| @@ -10,10 +10,12 @@ | @@ -10,10 +10,12 @@ | ||
| 10 | function ContentViewerController(noosfero, $log, $stateParams, $scope) { | 10 | function ContentViewerController(noosfero, $log, $stateParams, $scope) { |
| 11 | var vm = this; | 11 | var vm = this; |
| 12 | vm.article = null; | 12 | vm.article = null; |
| 13 | + vm.profile = null; | ||
| 13 | activate(); | 14 | activate(); |
| 14 | 15 | ||
| 15 | function activate() { | 16 | function activate() { |
| 16 | - noosfero.communities.one($scope.vm.owner.id).one('articles').get({path: $stateParams.page}).then(function(articles) { | 17 | + vm.profile = $scope.vm.owner; |
| 18 | + noosfero.communities.one(vm.profile.id).one('articles').get({path: $stateParams.page}).then(function(articles) { | ||
| 17 | vm.article = articles.article; | 19 | vm.article = articles.article; |
| 18 | }); | 20 | }); |
| 19 | } | 21 | } |
src/app/content-viewer/page.html