Commit 670ba3606ba55ca1941cab81e59a85e47ddb1b3c
1 parent
27fccff6
Exists in
master
and in
8 other branches
Fix service api for 'events'
Showing
4 changed files
with
36 additions
and
16 deletions
Show diff stats
src/app/components/article-service/article.service.js
@@ -11,6 +11,7 @@ | @@ -11,6 +11,7 @@ | ||
11 | 11 | ||
12 | var service = { | 12 | var service = { |
13 | apiArticles: $rootScope.basePath + '/api/v1/articles/', | 13 | apiArticles: $rootScope.basePath + '/api/v1/articles/', |
14 | + apiCommunities: $rootScope.basePath + '/api/v1/communities/', | ||
14 | getArticleById: getArticleById, | 15 | getArticleById: getArticleById, |
15 | getArticleBySlug: getArticleBySlug, | 16 | getArticleBySlug: getArticleBySlug, |
16 | getCategories: getCategories, | 17 | getCategories: getCategories, |
@@ -19,6 +20,7 @@ | @@ -19,6 +20,7 @@ | ||
19 | getTopicById: getTopicById, | 20 | getTopicById: getTopicById, |
20 | getProposals: getProposals, | 21 | getProposals: getProposals, |
21 | getProposalsByTopicId: getProposalsByTopicId, | 22 | getProposalsByTopicId: getProposalsByTopicId, |
23 | + getEvents: getEvents, | ||
22 | searchTopics: searchTopics, | 24 | searchTopics: searchTopics, |
23 | searchProposals: searchProposals | 25 | searchProposals: searchProposals |
24 | }; | 26 | }; |
@@ -125,6 +127,22 @@ | @@ -125,6 +127,22 @@ | ||
125 | } | 127 | } |
126 | 128 | ||
127 | function getRandomProposal (cbSuccess, cbError) {} | 129 | function getRandomProposal (cbSuccess, cbError) {} |
130 | + | ||
131 | + function getEvents (community_id, params, cbSuccess, cbError) { | ||
132 | + // Ex.: /api/v1/communities/' + community_id + '/articles?categories_ids[]=' + cat_id + '&content_type=Event'; | ||
133 | + | ||
134 | + var url = service.apiCommunities + community_id + '/articles'; | ||
135 | + var paramsExtended = angular.extend({ | ||
136 | + 'fields[]': ['id', 'slug', 'title', 'abstract', 'body', 'categories', 'created_at', 'start_date', 'end_date', 'hits'], | ||
137 | + 'content_type':'Event' | ||
138 | + }, params); | ||
139 | + | ||
140 | + UtilService.get(url, {params: paramsExtended}).then(function(data){ | ||
141 | + cbSuccess(data); | ||
142 | + }).catch(function(error){ | ||
143 | + cbError(error); | ||
144 | + }); | ||
145 | + } | ||
128 | 146 | ||
129 | function searchTopics (params, cbSuccess, cbError) { | 147 | function searchTopics (params, cbSuccess, cbError) { |
130 | // Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Topic&query=cisternas | 148 | // Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Topic&query=cisternas |
src/app/components/dialoga-service/dialoga.service.js
@@ -148,17 +148,15 @@ | @@ -148,17 +148,15 @@ | ||
148 | }, cbError); | 148 | }, cbError); |
149 | } | 149 | } |
150 | 150 | ||
151 | - function getEvents (cbSuccess, cbError) { | 151 | + function getEvents (params, cbSuccess, cbError) { |
152 | if( !!CACHE.events ){ | 152 | if( !!CACHE.events ){ |
153 | cbSuccess(CACHE.events); | 153 | cbSuccess(CACHE.events); |
154 | }else{ | 154 | }else{ |
155 | - // load main content | ||
156 | - getHome(function(){ | ||
157 | - if(!CACHE.hasOwnProperty('events')){ | ||
158 | - throw { name: 'NotFound', message: '"events" is not defined. "article.categories" was loaded?'}; | ||
159 | - } | ||
160 | - cbSuccess(CACHE.events); | ||
161 | - },cbError); | 155 | + ArticleService.getEvents(API.communityId, params, function(data){ |
156 | + CACHE.events = data; | ||
157 | + | ||
158 | + cbSuccess(data); | ||
159 | + }, cbError); | ||
162 | } | 160 | } |
163 | } | 161 | } |
164 | 162 |
src/app/index.constants.js
@@ -13,7 +13,8 @@ | @@ -13,7 +13,8 @@ | ||
13 | home: '103358', | 13 | home: '103358', |
14 | about: '108073', | 14 | about: '108073', |
15 | terms: '107880' | 15 | terms: '107880' |
16 | - } | 16 | + }, |
17 | + communityId: '19195' | ||
17 | }) | 18 | }) |
18 | .constant('AUTH_EVENTS', { | 19 | .constant('AUTH_EVENTS', { |
19 | loginSuccess: 'auth-login-success', | 20 | loginSuccess: 'auth-login-success', |
src/app/pages/inicio/inicio.controller.js
@@ -59,14 +59,17 @@ | @@ -59,14 +59,17 @@ | ||
59 | vm.$log.error('Error on getHome.', error); | 59 | vm.$log.error('Error on getHome.', error); |
60 | }); | 60 | }); |
61 | 61 | ||
62 | + // Load event list | ||
63 | + vm.DialogaService.getEvents({}, function(data) { | ||
64 | + vm.events = data; | ||
65 | + vm.loadingEvents = false; | ||
66 | + }, function(error) { | ||
67 | + vm.$log.error('Error on getEvents.', error); | ||
68 | + vm.loadingEvents = false; | ||
69 | + vm.eventsError = true; | ||
70 | + }); | ||
71 | + | ||
62 | function loadAfterHome () { | 72 | function loadAfterHome () { |
63 | - // Load event list | ||
64 | - // vm.DialogaService.getEvents(function(data) { | ||
65 | - // vm.events = data; | ||
66 | - // vm.loadingEvents = false; | ||
67 | - // }, function(error) { | ||
68 | - // vm.$log.error('Error on getEvents.', error); | ||
69 | - // }); | ||
70 | 73 | ||
71 | // Load theme list | 74 | // Load theme list |
72 | vm.DialogaService.getThemes(function(data) { | 75 | vm.DialogaService.getThemes(function(data) { |