Commit fccc77a996436281853a7f817a3cfc20dbeaeb29

Authored by Leonardo Merlin
1 parent dcf142cd

Fixes #138. Load faq questions from CMS

src/app/components/article-service/article.service.js
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 apiSearch: $rootScope.basePath + '/api/v1/search/', 16 apiSearch: $rootScope.basePath + '/api/v1/search/',
17 getArticleById: getArticleById, 17 getArticleById: getArticleById,
18 getArticleBySlug: getArticleBySlug, 18 getArticleBySlug: getArticleBySlug,
  19 + getArtcilesByParentId: getArtcilesByParentId,
19 getCategories: getCategories, 20 getCategories: getCategories,
20 getCategoryBySlug: getCategoryBySlug, 21 getCategoryBySlug: getCategoryBySlug,
21 getTopics: getTopics, 22 getTopics: getTopics,
@@ -57,6 +58,17 @@ @@ -57,6 +58,17 @@
57 throw { name: 'NotImplementedYet', message: 'The service "getArticleBySlug" is not implemented yet.'}; 58 throw { name: 'NotImplementedYet', message: 'The service "getArticleBySlug" is not implemented yet.'};
58 } 59 }
59 60
  61 + function getArtcilesByParentId (parentId, params) {
  62 + // Ex.: /api/v1/articles/103358/children?fields=
  63 +
  64 + var url = service.apiArticles + parentId + '/children';
  65 + var paramsExtended = angular.extend({
  66 + 'fields[]': ['id', 'slug', 'title', 'body']
  67 + }, params);
  68 +
  69 + return UtilService.get(url, {params: paramsExtended});
  70 + }
  71 +
60 function getCategories (articleId, params, cbSuccess, cbError) { 72 function getCategories (articleId, params, cbSuccess, cbError) {
61 // Ex.: /api/v1/articles/103358?fields= 73 // Ex.: /api/v1/articles/103358?fields=
62 74
src/app/components/dialoga-service/dialoga.service.js
@@ -233,17 +233,10 @@ @@ -233,17 +233,10 @@
233 return ArticleService.getResponseByProposalId(proposalId); 233 return ArticleService.getResponseByProposalId(proposalId);
234 } 234 }
235 235
236 - // TODO: implement  
237 - function getQuestions (cbSuccess/*, cbError*/) {  
238 - if( !!CACHE.questions ){  
239 - cbSuccess(CACHE.questions);  
240 - }else{  
241 - // load content  
242 - var questions = [];  
243 -  
244 - CACHE.questions = questions;  
245 - cbSuccess(CACHE.questions);  
246 - } 236 + function getQuestions () {
  237 + var parentId = API.articleId.faq;
  238 + var params = {};
  239 + return ArticleService.getArtcilesByParentId(parentId, params);
247 } 240 }
248 241
249 function searchPrograms (query, cbSuccess, cbError) { 242 function searchPrograms (query, cbSuccess, cbError) {
src/app/index.constants.js
@@ -18,9 +18,10 @@ @@ -18,9 +18,10 @@
18 home: '103358', 18 home: '103358',
19 about: '108073', 19 about: '108073',
20 acessibility: '117319', 20 acessibility: '117319',
21 - terms: '107880' 21 + terms: '107880',
  22 + faq: '117322'
22 }, 23 },
23 - communityId: '19195' 24 + communityId: '19195',
24 }) 25 })
25 .constant('AUTH_EVENTS', { 26 .constant('AUTH_EVENTS', {
26 loginSuccess: 'auth-login-success', 27 loginSuccess: 'auth-login-success',
src/app/pages/duvidas/duvidas.controller.js
@@ -24,23 +24,28 @@ @@ -24,23 +24,28 @@
24 DuvidasPageController.prototype.init = function () { 24 DuvidasPageController.prototype.init = function () {
25 var vm = this; 25 var vm = this;
26 26
27 - vm.questions = [{  
28 - question: 'O que é o Dialoga Brasil?',  
29 - answer: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven`t heard of them accusamus labore sustainable VHS.'  
30 - },{  
31 - question: 'O que ... ?',  
32 - answer: 'Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven`t heard of them accusamus labore sustainable VHS.'  
33 - }  
34 - ];  
35 -  
36 - vm.loading = true; 27 + vm.loadingQuestions = false;
37 vm.error = false; 28 vm.error = false;
38 vm.sendingContactForm = false; 29 vm.sendingContactForm = false;
  30 + vm.questions = [];
39 31
40 }; 32 };
41 33
42 DuvidasPageController.prototype.loadData = function () { 34 DuvidasPageController.prototype.loadData = function () {
43 - // var vm = this; 35 + var vm = this;
  36 +
  37 + vm.loadingQuestions = true;
  38 + vm.DialogaService.getQuestions()
  39 + .then(function(data) {
  40 + // vm.$log.debug('data', data);
  41 + vm.questions = data.articles;
  42 + })
  43 + .catch(function(error){
  44 + vm.$log.error('error', error);
  45 + })
  46 + .finally(function(){
  47 + vm.loadingQuestions = false;
  48 + });
44 }; 49 };
45 50
46 DuvidasPageController.prototype.attachListeners = function () { 51 DuvidasPageController.prototype.attachListeners = function () {
src/app/pages/duvidas/duvidas.html
@@ -13,16 +13,24 @@ @@ -13,16 +13,24 @@
13 <div class="row"> 13 <div class="row">
14 <div class="panel-group" id="accordion-duvidas" role="tablist" aria-multiselectable="false"> 14 <div class="panel-group" id="accordion-duvidas" role="tablist" aria-multiselectable="false">
15 <div class="panel panel-default"> 15 <div class="panel panel-default">
16 - <div class="question-item" ng-repeat="question in pageDuvidas.questions">  
17 - <div id="duvida-{{($index + 1)}}" class="panel-heading" role="tab">  
18 - <div class="panel-title" role="button" data-target="#collapse-{{($index + 1)}}" aria-expanded="($index === 0) ? 'true' : 'false'" aria-controls="collapse-{{($index + 1)}}" data-toggle="collapse" data-parent="#accordion-duvidas">  
19 - <span class="num-duvida">{{($index + 1)}}</span>  
20 - <span class="panel-title">{{question.question}}</span>  
21 - <span class="glyphicon glyphicon-chevron-down icon-white pull-right" aria-hidden="true"></span> 16 + <div ng-if="pageDuvidas.loadingQuestions">
  17 + <div class="alert alert-info" role="alert">Carregando as dúvidas frequentes.</div>
  18 + </div>
  19 + <div ng-if="pageDuvidas.loadingQuestionsError">
  20 + <div class="alert alert-danger" role="alert"><b>Erro!</b> Não foi possível carregar as dúvidas frequêntes.</div>
  21 + </div>
  22 + <div ng-if="!pageDuvidas.loadingQuestions && pageDuvidas.questions">
  23 + <div class="question-item" ng-repeat="question in pageDuvidas.questions">
  24 + <div id="duvida-{{($index + 1)}}" class="panel-heading" role="tab">
  25 + <div class="panel-title" role="button" data-target="#collapse-{{($index + 1)}}" aria-expanded="($index === 0) ? 'true' : 'false'" aria-controls="collapse-{{($index + 1)}}" data-toggle="collapse" data-parent="#accordion-duvidas">
  26 + <span class="num-duvida">{{($index + 1)}}</span>
  27 + <span class="panel-title">{{question.title}}</span>
  28 + <span class="glyphicon glyphicon-chevron-down icon-white pull-right" aria-hidden="true"></span>
  29 + </div>
  30 + </div>
  31 + <div id="collapse-{{($index + 1)}}" class="panel-collapse collapse" ng-class="{ 'in': ($index === 0) }" role="tabpanel" aria-expanded="($index === 0) ? 'true' : 'false'" aria-labelledby="duvida-{{($index + 1)}}">
  32 + <div class="panel-body" ng-bind-html="question.body"></div>
22 </div> 33 </div>
23 - </div>  
24 - <div id="collapse-{{($index + 1)}}" class="panel-collapse collapse" ng-class="{ 'in': ($index === 0) }" role="tabpanel" aria-expanded="($index === 0) ? 'true' : 'false'" aria-labelledby="duvida-{{($index + 1)}}">  
25 - <div class="panel-body" ng-bind-html="question.question"></div>  
26 </div> 34 </div>
27 </div> 35 </div>
28 </div> 36 </div>
src/app/pages/duvidas/duvidas.scss
@@ -16,6 +16,10 @@ @@ -16,6 +16,10 @@
16 16
17 font-size: 18px; 17 font-size: 18px;
18 } 18 }
  19 +
  20 + .panel-group {
  21 + margin-top: 20px;
  22 + }
19 23
20 .panel-default .panel-heading { 24 .panel-default .panel-heading {
21 background-color: #fff; 25 background-color: #fff;