Commit 80989ce243635ef93e69ab686c62b5aab85066dc
1 parent
d83be70e
Exists in
master
and in
2 other branches
Update: add top 3 proposals ranking
Showing
3 changed files
with
75 additions
and
2 deletions
Show diff stats
index.html
| @@ -328,7 +328,22 @@ | @@ -328,7 +328,22 @@ | ||
| 328 | </p> | 328 | </p> |
| 329 | </div> | 329 | </div> |
| 330 | 330 | ||
| 331 | - <div class="freeze--top-proposals"></div> | 331 | + <div class="freeze--top-proposals" style="display: none;"> |
| 332 | + | ||
| 333 | + <table> | ||
| 334 | + <thead> | ||
| 335 | + <tr class="header"> | ||
| 336 | + <th class="position">Posição <a href="#/artigo/108047" class="question-link"><span class="fa fa-question"></span></a></th> | ||
| 337 | + <th class="abstract-text" data-toggle="true">Propostas</th> | ||
| 338 | + <th class="views" data-hide="phone">Exibições</th> | ||
| 339 | + <th class="votes-for" data-hide="phone"><span class="sr-only">A favor</span><span class="fa fa-check"></span></th> | ||
| 340 | + <th class="votes-against" data-hide="phone"><span class="sr-only">Contra</span><span class="fa fa-times"></span></th> | ||
| 341 | + </tr> | ||
| 342 | + </thead> | ||
| 343 | + <tbody></tbody> | ||
| 344 | + </table> | ||
| 345 | + | ||
| 346 | + </div> | ||
| 332 | 347 | ||
| 333 | <div class="results-container hide col-sm-12"></div> | 348 | <div class="results-container hide col-sm-12"></div> |
| 334 | </div> | 349 | </div> |
js/main.js
| @@ -22,7 +22,8 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -22,7 +22,8 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
| 22 | 22 | ||
| 23 | var lastHash = window.location.hash; | 23 | var lastHash = window.location.hash; |
| 24 | 24 | ||
| 25 | - var isProduction = /^http:\/\/dialoga\.gov\.br\//.test(window.location.href); | 25 | + // var isProduction = /^http:\/\/dialoga\.gov\.br\//.test(window.location.href); |
| 26 | + var isProduction = true; | ||
| 26 | var host = isProduction ? 'http://login.dialoga.gov.br' : 'http://hom.login.dialoga.gov.br'; | 27 | var host = isProduction ? 'http://login.dialoga.gov.br' : 'http://hom.login.dialoga.gov.br'; |
| 27 | var serpro_captcha_clienteId = 'fdbcdc7a0b754ee7ae9d865fda740f17'; | 28 | var serpro_captcha_clienteId = 'fdbcdc7a0b754ee7ae9d865fda740f17'; |
| 28 | var dialoga_community = 19195; | 29 | var dialoga_community = 19195; |
| @@ -241,6 +242,60 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -241,6 +242,60 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
| 241 | $('.support-proposal .alert').show(); | 242 | $('.support-proposal .alert').show(); |
| 242 | }); | 243 | }); |
| 243 | }, | 244 | }, |
| 245 | + loadTopProposals: function (topic_id) { | ||
| 246 | + | ||
| 247 | + // TODO: start loading | ||
| 248 | + | ||
| 249 | + var url = host + '/api/v1/proposals_discussion_plugin/' + topic_id + '/ranking?per_page=3&page=1'; | ||
| 250 | + $.getJSON(url).done(function( data, stats, xhr ) { | ||
| 251 | + | ||
| 252 | + // TODO: stop loading | ||
| 253 | + | ||
| 254 | + if ( !data || !data.proposals ) { | ||
| 255 | + console.error('Proposals not found.'); | ||
| 256 | + return; | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + var $containerWrapper = $('#proposal-item-' + topic_id); | ||
| 260 | + var $containerTopProposals = $containerWrapper.find('.freeze--top-proposals'); | ||
| 261 | + var $tbody = $containerTopProposals.find('tbody'); | ||
| 262 | + | ||
| 263 | + if ( $containerTopProposals.css('display') === 'block' ) { | ||
| 264 | + console.log('Top ranking already loaded.'); | ||
| 265 | + return; | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + var TEMPLATE_TR = '' + | ||
| 269 | + '<tr>' + | ||
| 270 | + '<td>{{position}}°</td>' + | ||
| 271 | + '<td>{{abstract}}</td>' + | ||
| 272 | + '<td>{{hits}}</td>' + | ||
| 273 | + '<td>{{votes_for}}</td>' + | ||
| 274 | + '<td>{{votes_against}}</td>' + | ||
| 275 | + '</tr>'; | ||
| 276 | + | ||
| 277 | + var proposals = data.proposals; | ||
| 278 | + var proposal = null; | ||
| 279 | + var proposal_tpl = null; | ||
| 280 | + | ||
| 281 | + for (var i = proposals.length - 1; i >= 0; i--) { | ||
| 282 | + proposal = proposals[i]; | ||
| 283 | + proposal_tpl = '' + TEMPLATE_TR; | ||
| 284 | + proposal_tpl = replace(proposal_tpl, '{{position}}', proposal.position); | ||
| 285 | + proposal_tpl = replace(proposal_tpl, '{{abstract}}', proposal.abstract); | ||
| 286 | + proposal_tpl = replace(proposal_tpl, '{{hits}}', proposal.hits); | ||
| 287 | + proposal_tpl = replace(proposal_tpl, '{{votes_for}}', proposal.votes_for); | ||
| 288 | + proposal_tpl = replace(proposal_tpl, '{{votes_against}}', proposal.votes_against); | ||
| 289 | + | ||
| 290 | + $tbody.prepend($(proposal_tpl)); | ||
| 291 | + } | ||
| 292 | + | ||
| 293 | + $containerTopProposals.css('display', 'block'); | ||
| 294 | + | ||
| 295 | + console.log('data', data); | ||
| 296 | + | ||
| 297 | + }); | ||
| 298 | + }, | ||
| 244 | loadRanking: function($resultsContainer, topic_id, page) { | 299 | loadRanking: function($resultsContainer, topic_id, page) { |
| 245 | $resultsContainer.find('.loading').show(); | 300 | $resultsContainer.find('.loading').show(); |
| 246 | $resultsContainer.find('.results-content').hide(); | 301 | $resultsContainer.find('.results-content').hide(); |
| @@ -483,6 +538,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | @@ -483,6 +538,7 @@ define(['jquery', 'handlebars', 'fastclick', 'proposal_app', 'handlebars_helpers | ||
| 483 | 538 | ||
| 484 | var topic_id = proposal_id.split('-').pop(); | 539 | var topic_id = proposal_id.split('-').pop(); |
| 485 | this.loadRandomProposal(topic_id); | 540 | this.loadRandomProposal(topic_id); |
| 541 | + this.loadTopProposals(topic_id); | ||
| 486 | Main.display_events(category_id, active_category); | 542 | Main.display_events(category_id, active_category); |
| 487 | }, | 543 | }, |
| 488 | display_proposal_detail: function(proposal_id){ | 544 | display_proposal_detail: function(proposal_id){ |
sass/style.sass
| @@ -1279,6 +1279,8 @@ td | @@ -1279,6 +1279,8 @@ td | ||
| 1279 | .freeze--theme-message | 1279 | .freeze--theme-message |
| 1280 | font-weight: bold | 1280 | font-weight: bold |
| 1281 | margin: 10px 0 | 1281 | margin: 10px 0 |
| 1282 | +.freeze--top-proposals | ||
| 1283 | + margin: 10px 0 | ||
| 1282 | 1284 | ||
| 1283 | // ------------------------------------ | 1285 | // ------------------------------------ |
| 1284 | // 7 - Modificadores | 1286 | // 7 - Modificadores |