Commit f3414673957fdbaef8e51f1a2c9aba750d9b6337
1 parent
0606c9a0
Exists in
master
and in
8 other branches
Add program view (with URL friendly)
Showing
8 changed files
with
104 additions
and
7 deletions
Show diff stats
bower.json
src/app/components/programa/programa.directive.js
| ... | ... | @@ -9,17 +9,23 @@ |
| 9 | 9 | function programaBox(api) { |
| 10 | 10 | |
| 11 | 11 | /** @ngInject */ |
| 12 | - function ProgramaController($log) { | |
| 12 | + function ProgramaController($state, Slug, $log) { | |
| 13 | 13 | $log.debug('ProgramaController'); |
| 14 | 14 | |
| 15 | 15 | var vm = this; |
| 16 | + vm.$state = $state; | |
| 17 | + vm.Slug = Slug; | |
| 16 | 18 | vm.$log = $log; |
| 17 | 19 | |
| 18 | 20 | vm.init(); |
| 19 | 21 | } |
| 20 | 22 | |
| 21 | 23 | ProgramaController.prototype.init = function () { |
| 24 | + var vm = this; | |
| 22 | 25 | |
| 26 | + if(!vm.program.slug){ | |
| 27 | + vm.program.slug = vm.Slug.slugify(vm.program.title); | |
| 28 | + } | |
| 23 | 29 | }; |
| 24 | 30 | |
| 25 | 31 | ProgramaController.prototype.getCategory = function () { |
| ... | ... | @@ -52,7 +58,13 @@ |
| 52 | 58 | ProgramaController.prototype.showContent = function () { |
| 53 | 59 | var vm = this; |
| 54 | 60 | |
| 55 | - vm.$log.debug('TODO: showContent()', vm.program); | |
| 61 | + vm.$log.info('showContent'); | |
| 62 | + vm.$state.go('programa', { | |
| 63 | + slug: vm.program.slug, | |
| 64 | + program: vm.program | |
| 65 | + }, { | |
| 66 | + location: true | |
| 67 | + }); | |
| 56 | 68 | }; |
| 57 | 69 | |
| 58 | 70 | var directive = { | ... | ... |
src/app/index.module.js
src/app/index.route.js
| ... | ... | @@ -56,6 +56,18 @@ |
| 56 | 56 | 'footer': { templateUrl: 'app/partials/footer/footer.html' } |
| 57 | 57 | } |
| 58 | 58 | }) |
| 59 | + .state('programa', { | |
| 60 | + url: '/programa/:slug', | |
| 61 | + views: { | |
| 62 | + 'header': { templateUrl: 'app/partials/header/header.html' }, | |
| 63 | + 'main': { | |
| 64 | + templateUrl: 'app/partials/programas/programa.html', | |
| 65 | + controller: 'ProgramaController', | |
| 66 | + controllerAs: 'programa' | |
| 67 | + }, | |
| 68 | + 'footer': { templateUrl: 'app/partials/footer/footer.html' } | |
| 69 | + } | |
| 70 | + }) | |
| 59 | 71 | .state('sobre', { |
| 60 | 72 | url: '/sobre', |
| 61 | 73 | views: { | ... | ... |
src/app/partials/article/article.service.js
| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | .factory('ArticleService', ArticleService); |
| 7 | 7 | |
| 8 | 8 | /** @ngInject */ |
| 9 | - function ArticleService($http, $q, api, UtilService, $log) { | |
| 9 | + function ArticleService($http, $q, api, UtilService, Slug, $log) { | |
| 10 | 10 | $log.debug('ArticleService'); |
| 11 | 11 | |
| 12 | 12 | var idArticleHome = '103358'; |
| ... | ... | @@ -15,6 +15,7 @@ |
| 15 | 15 | var service = { |
| 16 | 16 | apiArticles: api.host + '/api/v1/articles/', |
| 17 | 17 | getHome: getHome, |
| 18 | + getArticleBySlug: getArticleBySlug, | |
| 18 | 19 | setHomeAbstract: setHomeAbstract, |
| 19 | 20 | getHomeAbstract: getHomeAbstract |
| 20 | 21 | }; |
| ... | ... | @@ -42,5 +43,36 @@ |
| 42 | 43 | function getHomeAbstract () { |
| 43 | 44 | return _savedAbstract; |
| 44 | 45 | } |
| 46 | + | |
| 47 | + function getArticleBySlug (slug) { | |
| 48 | + var deferred = $q.defer(); | |
| 49 | + | |
| 50 | + this.getHome().then(function (data) { | |
| 51 | + var mainArticle = data.article; | |
| 52 | + var programList = mainArticle.children; | |
| 53 | + var result = null; | |
| 54 | + | |
| 55 | + for (var i = programList.length - 1; i >= 0; i--) { | |
| 56 | + var program = programList[i]; | |
| 57 | + | |
| 58 | + if(!program.slug){ | |
| 59 | + program.slug = Slug.slugify(program.title); | |
| 60 | + } | |
| 61 | + | |
| 62 | + if(program.slug === slug){ | |
| 63 | + result = program; | |
| 64 | + break; | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + if(result){ | |
| 69 | + deferred.resolve(result); | |
| 70 | + }else{ | |
| 71 | + deferred.reject('None program with slug "' + slug + '"" was found.'); | |
| 72 | + } | |
| 73 | + }); | |
| 74 | + | |
| 75 | + return deferred.promise; | |
| 76 | + } | |
| 45 | 77 | } |
| 46 | 78 | })(); | ... | ... |
src/app/partials/inicio/inicio.controller.js
| ... | ... | @@ -32,8 +32,8 @@ |
| 32 | 32 | hideBackground(2000); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - vm.ArticleService.getHome().then(function(result) { | |
| 36 | - vm.article = result.article; | |
| 35 | + vm.ArticleService.getHome().then(function(data) { | |
| 36 | + vm.article = data.article; | |
| 37 | 37 | }, function(error) { |
| 38 | 38 | vm.$log.error('Error on getHome article.', error); |
| 39 | 39 | }); | ... | ... |
| ... | ... | @@ -0,0 +1,35 @@ |
| 1 | +(function() { | |
| 2 | + 'use strict'; | |
| 3 | + | |
| 4 | + angular | |
| 5 | + .module('dialoga') | |
| 6 | + .controller('ProgramaController', ProgramaController); | |
| 7 | + | |
| 8 | + /** @ngInject */ | |
| 9 | + function ProgramaController(ArticleService, $state, $log) { | |
| 10 | + $log.debug('ProgramaController'); | |
| 11 | + | |
| 12 | + var vm = this; | |
| 13 | + | |
| 14 | + vm.ArticleService = ArticleService; | |
| 15 | + vm.$state = $state; | |
| 16 | + vm.$log = $log; | |
| 17 | + | |
| 18 | + vm.init(); | |
| 19 | + } | |
| 20 | + | |
| 21 | + ProgramaController.prototype.init = function () { | |
| 22 | + var vm = this; | |
| 23 | + | |
| 24 | + var params = vm.$state.params; | |
| 25 | + var slug = params.slug; | |
| 26 | + | |
| 27 | + vm.ArticleService.getArticleBySlug(slug).then(function(program){ | |
| 28 | + vm.$log.debug('result progam', program); | |
| 29 | + },function (error) { | |
| 30 | + vm.$log.error(error); | |
| 31 | + vm.$log.info('Rollback to home page.'); | |
| 32 | + vm.$state.go('inicio', {}, {location: true}); | |
| 33 | + }); | |
| 34 | + }; | |
| 35 | +})(); | ... | ... |