From fccc77a996436281853a7f817a3cfc20dbeaeb29 Mon Sep 17 00:00:00 2001 From: Leonardo Merlin Date: Tue, 12 Jan 2016 09:56:38 -0200 Subject: [PATCH] Fixes #138. Load faq questions from CMS --- src/app/components/article-service/article.service.js | 12 ++++++++++++ src/app/components/dialoga-service/dialoga.service.js | 15 ++++----------- src/app/index.constants.js | 5 +++-- src/app/pages/duvidas/duvidas.controller.js | 27 ++++++++++++++++----------- src/app/pages/duvidas/duvidas.html | 26 +++++++++++++++++--------- src/app/pages/duvidas/duvidas.scss | 4 ++++ 6 files changed, 56 insertions(+), 33 deletions(-) diff --git a/src/app/components/article-service/article.service.js b/src/app/components/article-service/article.service.js index a256c86..a395767 100644 --- a/src/app/components/article-service/article.service.js +++ b/src/app/components/article-service/article.service.js @@ -16,6 +16,7 @@ apiSearch: $rootScope.basePath + '/api/v1/search/', getArticleById: getArticleById, getArticleBySlug: getArticleBySlug, + getArtcilesByParentId: getArtcilesByParentId, getCategories: getCategories, getCategoryBySlug: getCategoryBySlug, getTopics: getTopics, @@ -57,6 +58,17 @@ throw { name: 'NotImplementedYet', message: 'The service "getArticleBySlug" is not implemented yet.'}; } + function getArtcilesByParentId (parentId, params) { + // Ex.: /api/v1/articles/103358/children?fields= + + var url = service.apiArticles + parentId + '/children'; + var paramsExtended = angular.extend({ + 'fields[]': ['id', 'slug', 'title', 'body'] + }, params); + + return UtilService.get(url, {params: paramsExtended}); + } + function getCategories (articleId, params, cbSuccess, cbError) { // Ex.: /api/v1/articles/103358?fields= diff --git a/src/app/components/dialoga-service/dialoga.service.js b/src/app/components/dialoga-service/dialoga.service.js index e9977f1..2880090 100644 --- a/src/app/components/dialoga-service/dialoga.service.js +++ b/src/app/components/dialoga-service/dialoga.service.js @@ -233,17 +233,10 @@ return ArticleService.getResponseByProposalId(proposalId); } - // TODO: implement - function getQuestions (cbSuccess/*, cbError*/) { - if( !!CACHE.questions ){ - cbSuccess(CACHE.questions); - }else{ - // load content - var questions = []; - - CACHE.questions = questions; - cbSuccess(CACHE.questions); - } + function getQuestions () { + var parentId = API.articleId.faq; + var params = {}; + return ArticleService.getArtcilesByParentId(parentId, params); } function searchPrograms (query, cbSuccess, cbError) { diff --git a/src/app/index.constants.js b/src/app/index.constants.js index 835bd19..4ebdc34 100644 --- a/src/app/index.constants.js +++ b/src/app/index.constants.js @@ -18,9 +18,10 @@ home: '103358', about: '108073', acessibility: '117319', - terms: '107880' + terms: '107880', + faq: '117322' }, - communityId: '19195' + communityId: '19195', }) .constant('AUTH_EVENTS', { loginSuccess: 'auth-login-success', diff --git a/src/app/pages/duvidas/duvidas.controller.js b/src/app/pages/duvidas/duvidas.controller.js index 0a67633..18bac22 100644 --- a/src/app/pages/duvidas/duvidas.controller.js +++ b/src/app/pages/duvidas/duvidas.controller.js @@ -24,23 +24,28 @@ DuvidasPageController.prototype.init = function () { var vm = this; - vm.questions = [{ - question: 'O que é o Dialoga Brasil?', - 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.' - },{ - question: 'O que ... ?', - 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.' - } - ]; - - vm.loading = true; + vm.loadingQuestions = false; vm.error = false; vm.sendingContactForm = false; + vm.questions = []; }; DuvidasPageController.prototype.loadData = function () { - // var vm = this; + var vm = this; + + vm.loadingQuestions = true; + vm.DialogaService.getQuestions() + .then(function(data) { + // vm.$log.debug('data', data); + vm.questions = data.articles; + }) + .catch(function(error){ + vm.$log.error('error', error); + }) + .finally(function(){ + vm.loadingQuestions = false; + }); }; DuvidasPageController.prototype.attachListeners = function () { diff --git a/src/app/pages/duvidas/duvidas.html b/src/app/pages/duvidas/duvidas.html index dff51c9..74abe16 100644 --- a/src/app/pages/duvidas/duvidas.html +++ b/src/app/pages/duvidas/duvidas.html @@ -13,16 +13,24 @@
-
-