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 | 11 | |
12 | 12 | var service = { |
13 | 13 | apiArticles: $rootScope.basePath + '/api/v1/articles/', |
14 | + apiCommunities: $rootScope.basePath + '/api/v1/communities/', | |
14 | 15 | getArticleById: getArticleById, |
15 | 16 | getArticleBySlug: getArticleBySlug, |
16 | 17 | getCategories: getCategories, |
... | ... | @@ -19,6 +20,7 @@ |
19 | 20 | getTopicById: getTopicById, |
20 | 21 | getProposals: getProposals, |
21 | 22 | getProposalsByTopicId: getProposalsByTopicId, |
23 | + getEvents: getEvents, | |
22 | 24 | searchTopics: searchTopics, |
23 | 25 | searchProposals: searchProposals |
24 | 26 | }; |
... | ... | @@ -125,6 +127,22 @@ |
125 | 127 | } |
126 | 128 | |
127 | 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 | 147 | function searchTopics (params, cbSuccess, cbError) { |
130 | 148 | // Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Topic&query=cisternas | ... | ... |
src/app/components/dialoga-service/dialoga.service.js
... | ... | @@ -148,17 +148,15 @@ |
148 | 148 | }, cbError); |
149 | 149 | } |
150 | 150 | |
151 | - function getEvents (cbSuccess, cbError) { | |
151 | + function getEvents (params, cbSuccess, cbError) { | |
152 | 152 | if( !!CACHE.events ){ |
153 | 153 | cbSuccess(CACHE.events); |
154 | 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
src/app/pages/inicio/inicio.controller.js
... | ... | @@ -59,14 +59,17 @@ |
59 | 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 | 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 | 74 | // Load theme list |
72 | 75 | vm.DialogaService.getThemes(function(data) { | ... | ... |