Skip to content

Commit

Permalink
Passando o gráfico para a view de ranking
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilton Rodrigues committed Nov 22, 2014
1 parent f117985 commit 4c5f261
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/controllers/rankings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class RankingsController < ApplicationController
def index
@themes = order_themes(Theme.all)
@selected_theme_id = find_theme_id_by_params(params)
@qtdOutros = count_other_themes
end

def find_theme_id_by_params(params)
Expand All @@ -17,4 +18,13 @@ def order_themes(themes)
themes = themes.to_a
themes.sort! {|b,a| a.propositions.count <=> b.propositions.count}
end

def count_other_themes
qtdThemes = Theme.count
qtd = 0
for i in 10..qtdThemes

This comment has been minimized.

Copy link
@alvarofernandoms

alvarofernandoms Nov 25, 2014

Member

Veja a issue #120

qtd = qtd + @themes[i].propositions.count
return qtd
end
end
end
21 changes: 19 additions & 2 deletions app/views/rankings/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%= javascript_include_tag "http://www.google.com/jsapi", "chartkick" %>
<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).on( "click", ".theme-chooser", function() {
Expand All @@ -18,8 +20,24 @@
<li class="name">
<h1><a href="#">Ranking Área de Investimento x Parlamentares</a></h1>
</li>
</ul>
</ul>
</nav>
<div>
<%= pie_chart [[@themes[0].description, @themes[0].propositions.count],
[@themes[1].description, @themes[1].propositions.count],
[@themes[2].description, @themes[2].propositions.count],
[@themes[3].description, @themes[3].propositions.count],
[@themes[4].description, @themes[4].propositions.count],
[@themes[5].description, @themes[5].propositions.count],
[@themes[6].description, @themes[6].propositions.count],
[@themes[7].description, @themes[7].propositions.count],
[@themes[8].description, @themes[8].propositions.count],
[@themes[9].description, @themes[9].propositions.count],
["Outros", @qtdOutros]
] %>
</div>
</div>

<div style="width:50%;height:600px;line-height:3em;overflow:scroll;padding:5px;float:left">
<aside>
<ul class="side-nav">
Expand All @@ -44,7 +62,6 @@
</ul>
</div>
</div>
</nav>
<a class="exit-off-canvas"></a>
</div>
</div>
Expand Down

0 comments on commit 4c5f261

Please sign in to comment.