From 670ba3606ba55ca1941cab81e59a85e47ddb1b3c Mon Sep 17 00:00:00 2001 From: Leonardo Merlin Date: Sun, 6 Sep 2015 11:25:42 -0300 Subject: [PATCH] Fix service api for 'events' --- src/app/components/article-service/article.service.js | 18 ++++++++++++++++++ src/app/components/dialoga-service/dialoga.service.js | 14 ++++++-------- src/app/index.constants.js | 3 ++- src/app/pages/inicio/inicio.controller.js | 17 ++++++++++------- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/app/components/article-service/article.service.js b/src/app/components/article-service/article.service.js index c27ae10..57f8ebd 100644 --- a/src/app/components/article-service/article.service.js +++ b/src/app/components/article-service/article.service.js @@ -11,6 +11,7 @@ var service = { apiArticles: $rootScope.basePath + '/api/v1/articles/', + apiCommunities: $rootScope.basePath + '/api/v1/communities/', getArticleById: getArticleById, getArticleBySlug: getArticleBySlug, getCategories: getCategories, @@ -19,6 +20,7 @@ getTopicById: getTopicById, getProposals: getProposals, getProposalsByTopicId: getProposalsByTopicId, + getEvents: getEvents, searchTopics: searchTopics, searchProposals: searchProposals }; @@ -125,6 +127,22 @@ } function getRandomProposal (cbSuccess, cbError) {} + + function getEvents (community_id, params, cbSuccess, cbError) { + // Ex.: /api/v1/communities/' + community_id + '/articles?categories_ids[]=' + cat_id + '&content_type=Event'; + + var url = service.apiCommunities + community_id + '/articles'; + var paramsExtended = angular.extend({ + 'fields[]': ['id', 'slug', 'title', 'abstract', 'body', 'categories', 'created_at', 'start_date', 'end_date', 'hits'], + 'content_type':'Event' + }, params); + + UtilService.get(url, {params: paramsExtended}).then(function(data){ + cbSuccess(data); + }).catch(function(error){ + cbError(error); + }); + } function searchTopics (params, cbSuccess, cbError) { // Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Topic&query=cisternas diff --git a/src/app/components/dialoga-service/dialoga.service.js b/src/app/components/dialoga-service/dialoga.service.js index c365391..95ccf15 100644 --- a/src/app/components/dialoga-service/dialoga.service.js +++ b/src/app/components/dialoga-service/dialoga.service.js @@ -148,17 +148,15 @@ }, cbError); } - function getEvents (cbSuccess, cbError) { + function getEvents (params, cbSuccess, cbError) { if( !!CACHE.events ){ cbSuccess(CACHE.events); }else{ - // load main content - getHome(function(){ - if(!CACHE.hasOwnProperty('events')){ - throw { name: 'NotFound', message: '"events" is not defined. "article.categories" was loaded?'}; - } - cbSuccess(CACHE.events); - },cbError); + ArticleService.getEvents(API.communityId, params, function(data){ + CACHE.events = data; + + cbSuccess(data); + }, cbError); } } diff --git a/src/app/index.constants.js b/src/app/index.constants.js index baded95..53e48e0 100644 --- a/src/app/index.constants.js +++ b/src/app/index.constants.js @@ -13,7 +13,8 @@ home: '103358', about: '108073', terms: '107880' - } + }, + communityId: '19195' }) .constant('AUTH_EVENTS', { loginSuccess: 'auth-login-success', diff --git a/src/app/pages/inicio/inicio.controller.js b/src/app/pages/inicio/inicio.controller.js index d0b8bbf..cd8f644 100644 --- a/src/app/pages/inicio/inicio.controller.js +++ b/src/app/pages/inicio/inicio.controller.js @@ -59,14 +59,17 @@ vm.$log.error('Error on getHome.', error); }); + // Load event list + vm.DialogaService.getEvents({}, function(data) { + vm.events = data; + vm.loadingEvents = false; + }, function(error) { + vm.$log.error('Error on getEvents.', error); + vm.loadingEvents = false; + vm.eventsError = true; + }); + function loadAfterHome () { - // Load event list - // vm.DialogaService.getEvents(function(data) { - // vm.events = data; - // vm.loadingEvents = false; - // }, function(error) { - // vm.$log.error('Error on getEvents.', error); - // }); // Load theme list vm.DialogaService.getThemes(function(data) { -- libgit2 0.21.2