Commit f3414673957fdbaef8e51f1a2c9aba750d9b6337

Authored by Leonardo Merlin
1 parent 0606c9a0

Add program view (with URL friendly)

@@ -11,7 +11,8 @@ @@ -11,7 +11,8 @@
11 "bootstrap-sass-official": "~3.3.4", 11 "bootstrap-sass-official": "~3.3.4",
12 "animate.css": "~3.3.0", 12 "animate.css": "~3.3.0",
13 "angular": "~1.4.0", 13 "angular": "~1.4.0",
14 - "modernizr": "~2.8.3" 14 + "modernizr": "~2.8.3",
  15 + "angular-slugify": "~1.0.1"
15 }, 16 },
16 "devDependencies": { 17 "devDependencies": {
17 "angular-mocks": "~1.4.0" 18 "angular-mocks": "~1.4.0"
src/app/components/programa/programa.directive.js
@@ -9,17 +9,23 @@ @@ -9,17 +9,23 @@
9 function programaBox(api) { 9 function programaBox(api) {
10 10
11 /** @ngInject */ 11 /** @ngInject */
12 - function ProgramaController($log) { 12 + function ProgramaController($state, Slug, $log) {
13 $log.debug('ProgramaController'); 13 $log.debug('ProgramaController');
14 14
15 var vm = this; 15 var vm = this;
  16 + vm.$state = $state;
  17 + vm.Slug = Slug;
16 vm.$log = $log; 18 vm.$log = $log;
17 19
18 vm.init(); 20 vm.init();
19 } 21 }
20 22
21 ProgramaController.prototype.init = function () { 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 ProgramaController.prototype.getCategory = function () { 31 ProgramaController.prototype.getCategory = function () {
@@ -52,7 +58,13 @@ @@ -52,7 +58,13 @@
52 ProgramaController.prototype.showContent = function () { 58 ProgramaController.prototype.showContent = function () {
53 var vm = this; 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 var directive = { 70 var directive = {
src/app/index.module.js
@@ -2,6 +2,6 @@ @@ -2,6 +2,6 @@
2 'use strict'; 2 'use strict';
3 3
4 angular 4 angular
5 - .module('dialoga', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ui.router']); 5 + .module('dialoga', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ui.router', 'slugifier']);
6 6
7 })(); 7 })();
src/app/index.route.js
@@ -56,6 +56,18 @@ @@ -56,6 +56,18 @@
56 'footer': { templateUrl: 'app/partials/footer/footer.html' } 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 .state('sobre', { 71 .state('sobre', {
60 url: '/sobre', 72 url: '/sobre',
61 views: { 73 views: {
src/app/partials/article/article.service.js
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 .factory('ArticleService', ArticleService); 6 .factory('ArticleService', ArticleService);
7 7
8 /** @ngInject */ 8 /** @ngInject */
9 - function ArticleService($http, $q, api, UtilService, $log) { 9 + function ArticleService($http, $q, api, UtilService, Slug, $log) {
10 $log.debug('ArticleService'); 10 $log.debug('ArticleService');
11 11
12 var idArticleHome = '103358'; 12 var idArticleHome = '103358';
@@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
15 var service = { 15 var service = {
16 apiArticles: api.host + '/api/v1/articles/', 16 apiArticles: api.host + '/api/v1/articles/',
17 getHome: getHome, 17 getHome: getHome,
  18 + getArticleBySlug: getArticleBySlug,
18 setHomeAbstract: setHomeAbstract, 19 setHomeAbstract: setHomeAbstract,
19 getHomeAbstract: getHomeAbstract 20 getHomeAbstract: getHomeAbstract
20 }; 21 };
@@ -42,5 +43,36 @@ @@ -42,5 +43,36 @@
42 function getHomeAbstract () { 43 function getHomeAbstract () {
43 return _savedAbstract; 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,8 +32,8 @@
32 hideBackground(2000); 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 }, function(error) { 37 }, function(error) {
38 vm.$log.error('Error on getHome article.', error); 38 vm.$log.error('Error on getHome article.', error);
39 }); 39 });
src/app/partials/programas/programa.controller.js 0 → 100644
@@ -0,0 +1,35 @@ @@ -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 +})();
src/app/partials/programas/programa.html 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +<div class="container">
  2 +
  3 + <h1>Programa</h1>
  4 +
  5 +</div>