Commit 2a43dc1973bfcd0a9aae47b0f0c1e9e31b4db174
1 parent
f3414673
Exists in
master
and in
8 other branches
Cache request.
Showing
7 changed files
with
126 additions
and
22 deletions
Show diff stats
src/app/index.constants.js
| @@ -6,7 +6,8 @@ | @@ -6,7 +6,8 @@ | ||
| 6 | .module('dialoga') | 6 | .module('dialoga') |
| 7 | .constant('api', { | 7 | .constant('api', { |
| 8 | token: null, | 8 | token: null, |
| 9 | - host: 'http://hom.login.dialoga.gov.br', | 9 | + hostHom: 'http://hom.dialoga.gov.br', |
| 10 | + hostProd: 'http://login.dialoga.gov.br', | ||
| 10 | // host: 'http://www.participa.br', | 11 | // host: 'http://www.participa.br', |
| 11 | articleId: { | 12 | articleId: { |
| 12 | home: 103358 | 13 | home: 103358 |
src/app/index.run.js
| @@ -6,6 +6,7 @@ | @@ -6,6 +6,7 @@ | ||
| 6 | .module('dialoga') | 6 | .module('dialoga') |
| 7 | .run(runAuth) | 7 | .run(runAuth) |
| 8 | .run(runAccessibility) | 8 | .run(runAccessibility) |
| 9 | + .run(runPath) | ||
| 9 | .run(runBlock); | 10 | .run(runBlock); |
| 10 | 11 | ||
| 11 | /** @ngInject */ | 12 | /** @ngInject */ |
| @@ -73,6 +74,14 @@ | @@ -73,6 +74,14 @@ | ||
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | /** @ngInject */ | 76 | /** @ngInject */ |
| 77 | + function runPath($rootScope, api, $log) { | ||
| 78 | + var isProduction = (/^http:\/\/dialoga\.gov\.br\//.test(window.location.href)); | ||
| 79 | + $rootScope.basePath = isProduction ? api.hostProd : api.hostHom; | ||
| 80 | + | ||
| 81 | + $log.debug('runPath end.'); | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + /** @ngInject */ | ||
| 76 | function runBlock($log) { | 85 | function runBlock($log) { |
| 77 | $log.debug('runBlock end.'); | 86 | $log.debug('runBlock end.'); |
| 78 | } | 87 | } |
src/app/partials/article/article.service.js
| @@ -6,34 +6,53 @@ | @@ -6,34 +6,53 @@ | ||
| 6 | .factory('ArticleService', ArticleService); | 6 | .factory('ArticleService', ArticleService); |
| 7 | 7 | ||
| 8 | /** @ngInject */ | 8 | /** @ngInject */ |
| 9 | - function ArticleService($http, $q, api, UtilService, Slug, $log) { | 9 | + function ArticleService($http, $q, $rootScope, UtilService, Slug, $log) { |
| 10 | $log.debug('ArticleService'); | 10 | $log.debug('ArticleService'); |
| 11 | 11 | ||
| 12 | var idArticleHome = '103358'; | 12 | var idArticleHome = '103358'; |
| 13 | var _savedAbstract = null; | 13 | var _savedAbstract = null; |
| 14 | 14 | ||
| 15 | var service = { | 15 | var service = { |
| 16 | - apiArticles: api.host + '/api/v1/articles/', | 16 | + apiArticles: $rootScope.basePath + '/api/v1/articles/', |
| 17 | getHome: getHome, | 17 | getHome: getHome, |
| 18 | getArticleBySlug: getArticleBySlug, | 18 | getArticleBySlug: getArticleBySlug, |
| 19 | setHomeAbstract: setHomeAbstract, | 19 | setHomeAbstract: setHomeAbstract, |
| 20 | getHomeAbstract: getHomeAbstract | 20 | getHomeAbstract: getHomeAbstract |
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | + var CACHE = {}; // cache by article id | ||
| 24 | + | ||
| 23 | return service; | 25 | return service; |
| 24 | 26 | ||
| 25 | - function getHome () { | ||
| 26 | - return getArticleById(idArticleHome); | ||
| 27 | - } | 27 | + function loadArticleById (articleId, cbSuccess, cbError) { |
| 28 | 28 | ||
| 29 | - function getArticleById (articleId) { | ||
| 30 | var url = service.apiArticles + articleId; | 29 | var url = service.apiArticles + articleId; |
| 31 | var params = { | 30 | var params = { |
| 32 | fields: 'id,children,categories,abstract,title,image,url,setting,position', | 31 | fields: 'id,children,categories,abstract,title,image,url,setting,position', |
| 33 | private_token: 'null' | 32 | private_token: 'null' |
| 34 | }; | 33 | }; |
| 35 | 34 | ||
| 36 | - return UtilService.get(url, {params: params}); | 35 | + UtilService.get(url, {params: params}).then(function(data){ |
| 36 | + CACHE[articleId] = data; | ||
| 37 | + cbSuccess(data); | ||
| 38 | + }, function(error){ | ||
| 39 | + cbError(error); | ||
| 40 | + }); | ||
| 41 | + | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + function getArticleById (articleId, cbSuccess, cbError) { | ||
| 45 | + var cachedArticle = CACHE[articleId]; | ||
| 46 | + | ||
| 47 | + if(cachedArticle){ | ||
| 48 | + cbSuccess(cachedArticle); | ||
| 49 | + }else{ | ||
| 50 | + loadArticleById(articleId, cbSuccess, cbError); | ||
| 51 | + } | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + function getHome (cbSuccess, cbError) { | ||
| 55 | + return getArticleById(idArticleHome, cbSuccess, cbError); | ||
| 37 | } | 56 | } |
| 38 | 57 | ||
| 39 | function setHomeAbstract (newAbstract) { | 58 | function setHomeAbstract (newAbstract) { |
| @@ -44,10 +63,10 @@ | @@ -44,10 +63,10 @@ | ||
| 44 | return _savedAbstract; | 63 | return _savedAbstract; |
| 45 | } | 64 | } |
| 46 | 65 | ||
| 47 | - function getArticleBySlug (slug) { | ||
| 48 | - var deferred = $q.defer(); | 66 | + function getArticleBySlug (slug, cbSuccess, cbError) { |
| 67 | + var vm = this; | ||
| 49 | 68 | ||
| 50 | - this.getHome().then(function (data) { | 69 | + vm.getHome(function (data) { |
| 51 | var mainArticle = data.article; | 70 | var mainArticle = data.article; |
| 52 | var programList = mainArticle.children; | 71 | var programList = mainArticle.children; |
| 53 | var result = null; | 72 | var result = null; |
| @@ -66,13 +85,11 @@ | @@ -66,13 +85,11 @@ | ||
| 66 | } | 85 | } |
| 67 | 86 | ||
| 68 | if(result){ | 87 | if(result){ |
| 69 | - deferred.resolve(result); | 88 | + cbSuccess(result); |
| 70 | }else{ | 89 | }else{ |
| 71 | - deferred.reject('None program with slug "' + slug + '"" was found.'); | 90 | + cbError('None program with slug "' + slug + '"" was found.'); |
| 72 | } | 91 | } |
| 73 | - }); | ||
| 74 | - | ||
| 75 | - return deferred.promise; | 92 | + }, cbError); |
| 76 | } | 93 | } |
| 77 | } | 94 | } |
| 78 | })(); | 95 | })(); |
src/app/partials/header/header.html
| @@ -16,4 +16,11 @@ | @@ -16,4 +16,11 @@ | ||
| 16 | <div class="row"> | 16 | <div class="row"> |
| 17 | <app-navbar></app-navbar> | 17 | <app-navbar></app-navbar> |
| 18 | </div> | 18 | </div> |
| 19 | + | ||
| 20 | + <!-- TODO: breadcrumb --> | ||
| 21 | + <!-- <ol class="breadcrumb"> | ||
| 22 | + <li><a href="#">Home</a></li> | ||
| 23 | + <li><a href="#">Library</a></li> | ||
| 24 | + <li class="active">Data</li> | ||
| 25 | + </ol> --> | ||
| 19 | </header> | 26 | </header> |
src/app/partials/inicio/inicio.controller.js
| @@ -32,7 +32,7 @@ | @@ -32,7 +32,7 @@ | ||
| 32 | hideBackground(2000); | 32 | hideBackground(2000); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | - vm.ArticleService.getHome().then(function(data) { | 35 | + vm.ArticleService.getHome(function(data) { |
| 36 | vm.article = data.article; | 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); |
src/app/partials/programas/programa.controller.js
| @@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
| 6 | .controller('ProgramaController', ProgramaController); | 6 | .controller('ProgramaController', ProgramaController); |
| 7 | 7 | ||
| 8 | /** @ngInject */ | 8 | /** @ngInject */ |
| 9 | - function ProgramaController(ArticleService, $state, $log) { | 9 | + function ProgramaController(ArticleService, $state, $rootScope, $log) { |
| 10 | $log.debug('ProgramaController'); | 10 | $log.debug('ProgramaController'); |
| 11 | 11 | ||
| 12 | var vm = this; | 12 | var vm = this; |
| @@ -24,12 +24,42 @@ | @@ -24,12 +24,42 @@ | ||
| 24 | var params = vm.$state.params; | 24 | var params = vm.$state.params; |
| 25 | var slug = params.slug; | 25 | var slug = params.slug; |
| 26 | 26 | ||
| 27 | - vm.ArticleService.getArticleBySlug(slug).then(function(program){ | ||
| 28 | - vm.$log.debug('result progam', program); | ||
| 29 | - },function (error) { | 27 | + vm.program = null; |
| 28 | + | ||
| 29 | + vm.ArticleService.getArticleBySlug(slug, function(program){ | ||
| 30 | + vm.program = program; | ||
| 31 | + | ||
| 32 | + // load proposals | ||
| 33 | + // vm.ArticleService.getRandomProposals(program.id).then(function(proposal){ | ||
| 34 | + // vm.program.proposal = proposal; | ||
| 35 | + // }, function (error){ | ||
| 36 | + // vm.$log.error(error); | ||
| 37 | + // }); | ||
| 38 | + | ||
| 39 | + // load events | ||
| 40 | + // vm.ArticleService.getEvents(program.id).then(function(proposal){ | ||
| 41 | + // vm.program.proposal = proposal; | ||
| 42 | + // }, function (error){ | ||
| 43 | + // vm.$log.error(error); | ||
| 44 | + // }); | ||
| 45 | + | ||
| 46 | + // load body content | ||
| 47 | + // vm.ArticleService.getBodyContent(program.id).then(function(proposal){ | ||
| 48 | + // vm.program.proposal = proposal; | ||
| 49 | + // }, function (error){ | ||
| 50 | + // vm.$log.error(error); | ||
| 51 | + // }); | ||
| 52 | + | ||
| 53 | + }, function (error) { | ||
| 30 | vm.$log.error(error); | 54 | vm.$log.error(error); |
| 31 | vm.$log.info('Rollback to home page.'); | 55 | vm.$log.info('Rollback to home page.'); |
| 32 | vm.$state.go('inicio', {}, {location: true}); | 56 | vm.$state.go('inicio', {}, {location: true}); |
| 33 | }); | 57 | }); |
| 34 | }; | 58 | }; |
| 59 | + | ||
| 60 | + ProgramaController.prototype.goBack = function () { | ||
| 61 | + var vm = this; | ||
| 62 | + | ||
| 63 | + vm.$log.warn('Not implemented yet!'); | ||
| 64 | + }; | ||
| 35 | })(); | 65 | })(); |
src/app/partials/programas/programa.html
| 1 | <div class="container"> | 1 | <div class="container"> |
| 2 | 2 | ||
| 3 | - <h1>Programa</h1> | 3 | + <div class="article-bar"> |
| 4 | + <div class="navbar"> | ||
| 5 | + <div class="navbar-header"> | ||
| 6 | + <button class="btn btn-link" ng-click="programa.goBack()"> | ||
| 7 | + <!-- <span class="glyphicon glyphicon-share-alt" aria-hidden="true"></span> --> | ||
| 8 | + <span class="glyphicon glyphicon-arrow-left" aria-hidden="true"></span> | ||
| 9 | + Voltar | ||
| 10 | + </button> | ||
| 11 | + </div> | ||
| 12 | + <div class="navbar-left"> | ||
| 13 | + <button class="btn btn-link"> | ||
| 14 | + <span class="glyphicon glyphicon-refresh"></span> | ||
| 15 | + <span>{{programa.program.categories[0].name}}</span> | ||
| 16 | + </button> | ||
| 17 | + </div> | ||
| 18 | + <div class="navbar-right"> | ||
| 19 | + <select name="selectCategory" id="selectCategory-{{::programa.program.categories[0].id}}" class="form-control"> | ||
| 20 | + <option value="">-- Selectione um Tema --</option> | ||
| 21 | + </select> | ||
| 22 | + </div> | ||
| 23 | + </div> | ||
| 24 | + </div> | ||
| 4 | 25 | ||
| 26 | + <div ng-if="!programa.program"> | ||
| 27 | + <div class="alert alert-info" role="alert">Carregando informações sobre o progama</div> | ||
| 28 | + </div> | ||
| 29 | + | ||
| 30 | + <div ng-if="programa.program"> | ||
| 31 | + <article> | ||
| 32 | + <header class="program-banner"> | ||
| 33 | + <img class="program-banner--image" ng-src="{{programa.program.image.url}}" alt="Imagem de apresentação do progama."> | ||
| 34 | + <div class="program-banner--strip"> | ||
| 35 | + <h1 class="program-banner--title">{{::programa.program.title}}</h1> | ||
| 36 | + <p class="program-banner--abstract" ng-bind-html="programa.program.abstract"></p> | ||
| 37 | + </div> | ||
| 38 | + | ||
| 39 | + </header> | ||
| 40 | + | ||
| 41 | + </article> | ||
| 42 | + </div> | ||
| 43 | + <div id="content" ng-bind-html="programa.program.body"></div> | ||
| 5 | </div> | 44 | </div> |
| 45 | + |