From c9010f59ee29ec9a57866f9e361890599ad1a01f Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Sat, 12 Sep 2015 00:17:43 +0200 Subject: [PATCH] add shamepie -- the big slices are really gross! --- Gemfile | 2 ++ Gemfile.lock | 2 ++ app/controllers/concerns/statistics.rb | 7 +++++++ app/views/pages/landing.html.haml | 27 +++++++++++++++----------- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index dd3cfbd..25a0e7f 100644 --- a/Gemfile +++ b/Gemfile @@ -35,6 +35,8 @@ gem 'jquery-datatables-rails' # Use Select2 for selecting users gem 'select2-rails' +# Chartkick for fancy graphs +gem 'chartkick' # Use jquery as the JavaScript library gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 9f81a45..1ad5311 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -70,6 +70,7 @@ GEM capistrano-rbenv (2.0.3) capistrano (~> 3.1) sshkit (~> 1.3) + chartkick (1.3.2) coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -296,6 +297,7 @@ DEPENDENCIES capistrano-passenger capistrano-rails (~> 1.1) capistrano-rbenv + chartkick coffee-rails (~> 4.1.0) coveralls devise diff --git a/app/controllers/concerns/statistics.rb b/app/controllers/concerns/statistics.rb index 166dddb..facec4a 100644 --- a/app/controllers/concerns/statistics.rb +++ b/app/controllers/concerns/statistics.rb @@ -10,6 +10,13 @@ class Statistics < Rails::Application User.where.not(id: User.zeus).where('balance > 0').sum(:balance) end + def shamehash + none_shaming = shameful_users.sum(:balance) + shameful_users.inject({'None-shameful users' => none_shaming}) do |h, u| + h.merge({u.name => u.balance}) + end + end + private def zeus_balance diff --git a/app/views/pages/landing.html.haml b/app/views/pages/landing.html.haml index 12b2f4b..1b5f7d5 100644 --- a/app/views/pages/landing.html.haml +++ b/app/views/pages/landing.html.haml @@ -8,14 +8,19 @@ %h2 Cute Little Statistics %p None here yet. %h2 Wall of Shame -%table.pure-table - %thead - %th Shame on - %th Contribution to Zeus' lack of money - %tbody - - @statistics.shameful_users.each do |user| - %tr - %td.shameful-person= user.name - // Won't divide by zero because there won't be any users with - // a shameful debt if the total debt is zero. - %td.shame-percentage= "#{100 * user.balance / @statistics.total_debt}%" +.pure-g + .pure-u-1-2 + %table.pure-table + %thead + %th Shame on + %th Contribution to Zeus' lack of money + %tbody + - @statistics.shameful_users.each do |user| + %tr + %td.shameful-person= user.name + // Won't divide by zero because there won't be any users with + // a shameful debt if the total debt is zero. + %td.shame-percentage= "#{100 * user.balance / @statistics.total_debt}%" + .pure-u-1-2 + = javascript_include_tag "//www.google.com/jsapi", "chartkick" + = pie_chart @statistics.shamehash