Commit 83c9d339edc1ed9285230ee3a8c8ca014b4629a7
1 parent
4a6c4a70
Exists in
master
and in
4 other branches
correcao para usar as duas APIs
Showing
3 changed files
with
93 additions
and
54 deletions
Show diff stats
src/app/components/article-service/article.service.js
... | ... | @@ -2,8 +2,8 @@ |
2 | 2 | 'use strict'; |
3 | 3 | |
4 | 4 | angular |
5 | - .module('dialoga') | |
6 | - .factory('ArticleService', ArticleService); | |
5 | + .module('dialoga') | |
6 | + .factory('ArticleService', ArticleService); | |
7 | 7 | |
8 | 8 | /** @ngInject */ |
9 | 9 | function ArticleService($http, $q, $rootScope, API, UtilService, Slug, GUID, $log) { |
... | ... | @@ -23,6 +23,7 @@ |
23 | 23 | getProposals: getProposals, |
24 | 24 | getProposalById: getProposalById, |
25 | 25 | getProposalsByTopicId: getProposalsByTopicId, |
26 | + getProposalsByTopicIdRanked: getProposalsByTopicIdRanked, | |
26 | 27 | getResponseByProposalId: getResponseByProposalId, |
27 | 28 | createProposal: createProposal, |
28 | 29 | voteProposal: voteProposal, |
... | ... | @@ -107,8 +108,7 @@ |
107 | 108 | } |
108 | 109 | |
109 | 110 | function getProposalById (proposalId, params, cbSuccess, cbError) { |
110 | - var url = service.apiProposals + proposalId + '/ranking?per_page=5&page=1'; | |
111 | - console.log(url); | |
111 | + var url = service.apiArticles + proposalId; | |
112 | 112 | |
113 | 113 | var paramsExtended = angular.extend({ |
114 | 114 | // 'fields[]': ['id', 'title', 'abstract', 'children', 'children_count', 'ranking_position', 'hits', 'votes_for', 'votes_against'], |
... | ... | @@ -126,6 +126,25 @@ |
126 | 126 | |
127 | 127 | } |
128 | 128 | |
129 | + function getProposalByIdRanked (proposalId, params, cbSuccess, cbError) { | |
130 | + var url = service.apiProposals + proposalId + '/ranking?per_page=5&page=1'; | |
131 | + console.log(url); | |
132 | + var paramsExtended = angular.extend({ | |
133 | + // 'fields[]': ['id', 'title', 'abstract', 'children', 'children_count', 'ranking_position', 'hits', 'votes_for', 'votes_against'], | |
134 | + // 'per_page':'1', | |
135 | + 'limit':'1', | |
136 | + 'content_type':'ProposalsDiscussionPlugin::Proposal' | |
137 | + }, params); | |
138 | + | |
139 | + UtilService.get(url, {params: paramsExtended}).then(function(data){ | |
140 | + _pipeInjectSlugIntoParentProgramRanked(data); | |
141 | + cbSuccess(data); | |
142 | + }).catch(function(error){ | |
143 | + cbError(error); | |
144 | + }); | |
145 | + | |
146 | + } | |
147 | + | |
129 | 148 | /** |
130 | 149 | * Ex.: /api/v1/articles/[article_id]/children?[params]content_type=ProposalsDiscussionPlugin::Proposal |
131 | 150 | * Ex.: /api/v1/articles/103644/children?limit=20&fields=id,name,slug,abstract,created_by&content_type=ProposalsDiscussionPlugin::Proposal |
... | ... | @@ -136,13 +155,17 @@ |
136 | 155 | * @param {Function} cbError callback for error |
137 | 156 | * @return {Array} [description] |
138 | 157 | */ |
139 | - function getProposalsByTopicId (topicId, params, cbSuccess, cbError) { | |
140 | - getProposalById(topicId /*+ '/children'*/, params, cbSuccess, cbError); | |
158 | + function getProposalsByTopicId (topicId, params, cbSuccess, cbError) { | |
159 | + getProposalById(topicId + '/children', params, cbSuccess, cbError); | |
160 | + } | |
161 | + | |
162 | + function getProposalsByTopicIdRanked (topicId, params, cbSuccess, cbError) { | |
163 | + getProposalByIdRanked(topicId, params, cbSuccess, cbError); | |
141 | 164 | } |
142 | 165 | |
143 | 166 | function getResponseByProposalId (proposalId) { |
144 | 167 | var url = service.apiArticles + proposalId + '/children?content_type=ProposalsDiscussionPlugin::Response&limit=1'; |
145 | - | |
168 | + | |
146 | 169 | // var paramsExtended = {}; |
147 | 170 | |
148 | 171 | return UtilService.get(url); |
... | ... | @@ -233,10 +256,10 @@ |
233 | 256 | function sendContactForm (community_id, data){ |
234 | 257 | var url = service.apiCommunities + community_id + '/contact'; |
235 | 258 | var encodedParams = [ |
236 | - 'contact[name]=' + data.name, | |
237 | - 'contact[email]=' + data.email, | |
238 | - 'contact[subject]=' + data.subject, | |
239 | - 'contact[message]=' + data.message | |
259 | + 'contact[name]=' + data.name, | |
260 | + 'contact[email]=' + data.email, | |
261 | + 'contact[subject]=' + data.subject, | |
262 | + 'contact[message]=' + data.message | |
240 | 263 | ].join('&'); |
241 | 264 | |
242 | 265 | return UtilService.post(url, encodedParams); |
... | ... | @@ -258,33 +281,29 @@ |
258 | 281 | } |
259 | 282 | |
260 | 283 | function searchProposals (params, cbSuccess, cbError) { |
261 | - // Search | |
262 | 284 | // Ex.: /api/v1/search/article?type=ProposalsDiscussionPlugin::Proposal&query=cisternas |
263 | - // Propostal Ranking | |
264 | - // api/v1/proposals_discussion_plugin/103521/ranking?per_page=3&page=1 | |
265 | 285 | var url = service.apiSearch + 'article'; |
266 | - // var url = service.apiProposals; | |
267 | 286 | var paramsExtended = angular.extend({ |
268 | 287 | page: 1, |
269 | - per_page: 3, | |
288 | + per_page: 10, | |
270 | 289 | type: 'ProposalsDiscussionPlugin::Proposal', |
271 | 290 | 'fields[]': [ |
272 | - 'id', | |
273 | - 'abstract', | |
274 | - 'hits', | |
275 | - 'ranking_position', | |
276 | - 'votes_against', | |
277 | - 'votes_count', | |
278 | - 'votes_for', | |
279 | - 'parent', | |
280 | - 'categories', | |
281 | - 'slug', | |
291 | + 'id', | |
292 | + 'abstract', | |
293 | + 'hits', | |
294 | + 'ranking_position', | |
295 | + 'votes_against', | |
296 | + 'votes_count', | |
297 | + 'votes_for', | |
298 | + 'parent', | |
299 | + 'categories', | |
300 | + 'slug', | |
282 | 301 | 'url', // parent.image.url |
283 | 302 | 'image', |
284 | 303 | 'title', |
285 | 304 | 'archived', |
286 | - ] | |
287 | - }, params); | |
305 | + ] | |
306 | + }, params); | |
288 | 307 | |
289 | 308 | UtilService.get(url, {params: paramsExtended}).then(function(data){ |
290 | 309 | _pipeInjectSlugIntoParentProgram(data); |
... | ... | @@ -295,10 +314,10 @@ |
295 | 314 | } |
296 | 315 | |
297 | 316 | function _pipeInjectSlugIntoParentProgram(data){ |
298 | - if(!data.proposals && data.proposals){ | |
299 | - data.proposals = [data.proposals]; | |
317 | + if(!data.articles && data.article){ | |
318 | + data.articles = [data.article]; | |
300 | 319 | } |
301 | - var proposals = data.proposals; | |
320 | + var proposals = data.articles; | |
302 | 321 | for (var i = proposals.length - 1; i >= 0; i--) { |
303 | 322 | var proposal = proposals[i]; |
304 | 323 | if(proposal.parent && !proposal.parent.slug){ |
... | ... | @@ -307,23 +326,37 @@ |
307 | 326 | } |
308 | 327 | } |
309 | 328 | |
310 | - function _pipeRemoveOldEvents(data){ | |
311 | - if(!data.articles && data.article){ | |
312 | - data.articles = [data.article]; | |
313 | - data.article = null; | |
314 | - } | |
329 | +//Refazer esse método. Não faz sentido | |
330 | +function _pipeInjectSlugIntoParentProgramRanked(data){ | |
331 | + if(!data.proposals && data.proposals){ | |
332 | + data.proposals = [data.proposals]; | |
333 | + } | |
334 | + var proposals = data.proposals; | |
335 | + for (var i = proposals.length - 1; i >= 0; i--) { | |
336 | + var proposal = proposals[i]; | |
337 | + if(proposal.parent && !proposal.parent.slug){ | |
338 | + proposal.parent.slug = Slug.slugify(proposal.parent.title); | |
339 | + } | |
340 | + } | |
341 | +} | |
315 | 342 | |
316 | - var now = (new Date()).getTime(); | |
317 | - var eventDate = null; | |
318 | - var events = data.articles; | |
343 | +function _pipeRemoveOldEvents(data){ | |
344 | + if(!data.articles && data.article){ | |
345 | + data.articles = [data.article]; | |
346 | + data.article = null; | |
347 | + } | |
319 | 348 | |
320 | - var results = []; | |
321 | - for (var i = events.length - 1; i >= 0; i--) { | |
322 | - var event = events[i]; | |
349 | + var now = (new Date()).getTime(); | |
350 | + var eventDate = null; | |
351 | + var events = data.articles; | |
323 | 352 | |
324 | - if(event.end_date){ | |
325 | - eventDate = new Date(event.end_date); | |
326 | - } | |
353 | + var results = []; | |
354 | + for (var i = events.length - 1; i >= 0; i--) { | |
355 | + var event = events[i]; | |
356 | + | |
357 | + if(event.end_date){ | |
358 | + eventDate = new Date(event.end_date); | |
359 | + } | |
327 | 360 | |
328 | 361 | // if(eventDate.getTime() < now){ |
329 | 362 | // event.isOld = true; |
... | ... | @@ -336,4 +369,4 @@ |
336 | 369 | data.articles = results; |
337 | 370 | } |
338 | 371 | } |
339 | 372 | -})(); |
373 | +})(); | |
340 | 374 | \ No newline at end of file | ... | ... |
src/app/components/dialoga-service/dialoga.service.js
src/app/pages/programas/programa.controller.js
... | ... | @@ -83,12 +83,18 @@ |
83 | 83 | } |
84 | 84 | |
85 | 85 | vm.loadingTopProposals = true; |
86 | - vm.DialogaService.getProposalsByTopicId(vm.article.id, { | |
86 | + vm.DialogaService.getProposalsByTopicIdRanked(vm.article.id, { | |
87 | 87 | 'limit': 5 |
88 | 88 | }, function(data) { |
89 | 89 | vm.total_proposals = parseInt(vm.article.children_count); |
90 | 90 | // vm.total_proposals = parseInt(vm.article.amount_of_children); // DEPRECATED?! |
91 | - vm.proposals = data.proposals; | |
91 | + if (data.articles) { | |
92 | + vm.proposals = data.articles; | |
93 | + console.log("1"); | |
94 | + } else { | |
95 | + vm.proposals = data.proposals; | |
96 | + console.log("2"); | |
97 | + } | |
92 | 98 | vm.proposalsTopFive = vm.proposals.slice(0, 5); |
93 | 99 | vm.proposalsTopRated = vm.proposals.slice(0, 3); |
94 | 100 | vm.loadingTopProposals = false; |
... | ... | @@ -216,9 +222,9 @@ |
216 | 222 | ProgramaPageController.prototype._handleSuccessOnGetProposal = function(data) { |
217 | 223 | var vm = this; |
218 | 224 | |
219 | - if (data && data.proposals) { | |
220 | - var MAX = data.proposals.length; | |
221 | - vm.randomProposal = data.proposals[Math.floor(Math.random() * MAX)]; | |
225 | + if (data && data.articles) { | |
226 | + var MAX = data.articles.length; | |
227 | + vm.randomProposal = data.articles[Math.floor(Math.random() * MAX)]; | |
222 | 228 | vm.loadingProposalBox = false; |
223 | 229 | vm.$scope.$broadcast('proposal-box:proposal-loaded', { success: true}); |
224 | 230 | } |
... | ... | @@ -252,7 +258,7 @@ |
252 | 258 | vm.voteSkip(); |
253 | 259 | return; |
254 | 260 | } |
255 | - | |
261 | + | |
256 | 262 | vm.DialogaService.voteProposal(proposal_id, { |
257 | 263 | value: value |
258 | 264 | }).then(function(response) { |
... | ... | @@ -378,4 +384,4 @@ |
378 | 384 | } |
379 | 385 | }; |
380 | 386 | |
381 | 387 | -})(); |
388 | +})(); | |
382 | 389 | \ No newline at end of file | ... | ... |