Showing
9 changed files
with
69 additions
and
37 deletions
| ... | @@ -73,7 +73,8 @@ table { | ... | @@ -73,7 +73,8 @@ table { | 
| 73 | 73 | ||
| 74 | .upcoming { | 74 | .upcoming { | 
| 75 | td { | 75 | td { | 
| 76 | - width: 33%; | 76 | + width: 25%; | 
| 77 | + font-size: 12px; | ||
| 77 | } | 78 | } | 
| 78 | } | 79 | } | 
| 79 | 80 | ||
| ... | @@ -94,9 +95,9 @@ table { | ... | @@ -94,9 +95,9 @@ table { | 
| 94 | text-align: left; | 95 | text-align: left; | 
| 95 | } | 96 | } | 
| 96 | 97 | ||
| 97 | - td, th { | 98 | + // td, th { | 
| 98 | - width: 50%; | 99 | + // // width: 50%; | 
| 99 | - } | 100 | + // } | 
| 100 | } | 101 | } | 
| 101 | 102 | ||
| 102 | // Bets | 103 | // Bets | 
| ... | @@ -182,3 +183,15 @@ input[type="submit"] { | ... | @@ -182,3 +183,15 @@ input[type="submit"] { | 
| 182 | max-width: 70vw; | 183 | max-width: 70vw; | 
| 183 | } | 184 | } | 
| 184 | } | 185 | } | 
| 186 | + | ||
| 187 | +.vs-cell { | ||
| 188 | + width: 40px; | ||
| 189 | +} | ||
| 190 | + | ||
| 191 | +.text-left { text-align: left; width: 100%; } | ||
| 192 | + | ||
| 193 | +td.points { | ||
| 194 | + font-weight: 700; | ||
| 195 | + &.zero { color: red } | ||
| 196 | + &.positive { color: green } | ||
| 197 | +} | ... | ... | 
| ... | @@ -2,15 +2,20 @@ class ApplicationController < HeimdallEngine::ApplicationController | ... | @@ -2,15 +2,20 @@ class ApplicationController < HeimdallEngine::ApplicationController | 
| 2 | protect_from_forgery with: :exception | 2 | protect_from_forgery with: :exception | 
| 3 | 3 | ||
| 4 | def root | 4 | def root | 
| 5 | - leaderboard | 5 | + load_leaderboard | 
| 6 | check_matches | 6 | check_matches | 
| 7 | recent_matches | 7 | recent_matches | 
| 8 | @results = check_results | 8 | @results = check_results | 
| 9 | end | 9 | end | 
| 10 | 10 | ||
| 11 | + def leaderboard | ||
| 12 | + @leaders = Bet.joins(:user).group('users.name').sum(:points) | ||
| 13 | + .sort_by { |k,v| v } | ||
| 14 | + end | ||
| 15 | + | ||
| 11 | private | 16 | private | 
| 12 | 17 | ||
| 13 | - def leaderboard | 18 | + def load_leaderboard | 
| 14 | @leaders = Bet.joins(:user).group('users.name').sum(:points) | 19 | @leaders = Bet.joins(:user).group('users.name').sum(:points) | 
| 15 | .sort_by { |k,v| v }.take(5) | 20 | .sort_by { |k,v| v }.take(5) | 
| 16 | end | 21 | end | 
| ... | @@ -28,7 +33,7 @@ class ApplicationController < HeimdallEngine::ApplicationController | ... | @@ -28,7 +33,7 @@ class ApplicationController < HeimdallEngine::ApplicationController | 
| 28 | def check_results | 33 | def check_results | 
| 29 | return [] unless current_user | 34 | return [] unless current_user | 
| 30 | current_user.bets.joins(:match).order('matches.date desc') | 35 | current_user.bets.joins(:match).order('matches.date desc') | 
| 31 | - .where.not(result: nil) | 36 | + .where.not(points: nil) | 
| 32 | .limit(5) | 37 | .limit(5) | 
| 33 | end | 38 | end | 
| 34 | end | 39 | end | ... | ... | 
app/controllers/my_profile_controller.rb
0 → 100644
| 1 | h1 Leaderboard | 1 | h1 Leaderboard | 
| 2 | table.leaderboard | 2 | table.leaderboard | 
| 3 | tbody | 3 | tbody | 
| 4 | - - @leaders.each do |group_name, data| | 4 | + - @leaders.each.with_index do |(user_name, points), i| | 
| 5 | - tr | ||
| 6 | - td colspan=2 = group_name | ||
| 7 | - - data[:leaderboard].each do |user_name, points| | ||
| 8 | tr | 5 | tr | 
| 6 | + td style='width: 50px' = 1 + i | ||
| 9 | td = user_name | 7 | td = user_name | 
| 10 | td = points | 8 | td = points | 
| 11 | - - if data[:leaderboard].empty? | 9 | + - if @leaders.empty? | 
| 12 | tr | 10 | tr | 
| 13 | td colspan=2 There are no results yet | 11 | td colspan=2 There are no results yet | 
| 12 | +.text-left style='margin-top: 10px;' | ||
| 13 | + = link_to 'See everyone', leaderboard_path | ... | ... | 
| ... | @@ -6,7 +6,7 @@ table | ... | @@ -6,7 +6,7 @@ table | 
| 6 | td = r.match.local | 6 | td = r.match.local | 
| 7 | td VS | 7 | td VS | 
| 8 | td = r.match.visit | 8 | td = r.match.visit | 
| 9 | - td = r.points | 9 | + td.points class="#{r.points.to_i.zero? ? 'zero' : 'positive'}" = r.points | 
| 10 | - if @results.empty? | 10 | - if @results.empty? | 
| 11 | tr | 11 | tr | 
| 12 | td colspan=4 There are no finished matches yet. | 12 | td colspan=4 There are no finished matches yet. | ... | ... | 
| ... | @@ -5,19 +5,6 @@ table.upcoming | ... | @@ -5,19 +5,6 @@ table.upcoming | 
| 5 | tr | 5 | tr | 
| 6 | td = l(u.date, format: :short) | 6 | td = l(u.date, format: :short) | 
| 7 | td = u.local | 7 | td = u.local | 
| 8 | - td VS | 8 | + td.vs-cell VS | 
| 9 | td = u.visit | 9 | td = u.visit | 
| 10 | 10 | ||
| 11 | -h1 Recent matches | ||
| 12 | -table.recent | ||
| 13 | - tbody | ||
| 14 | - - @recent_matches.each do |match| | ||
| 15 | - tr | ||
| 16 | - td = l(match.date, format: :short) | ||
| 17 | - td = match.local | ||
| 18 | - td = match.score_local | ||
| 19 | - td = match.visit | ||
| 20 | - td = match.score_visit | ||
| 21 | - - if @recent_matches.empty? | ||
| 22 | - tr | ||
| 23 | - td colspan=4 There are no finished matches yet. | ... | ... | 
app/views/application/leaderboard.html.slim
0 → 100644
| 1 | +.middle.content | ||
| 2 | + h1 Leaderboard | ||
| 3 | + table.leaderboard | ||
| 4 | + tbody | ||
| 5 | + - @leaders.each.with_index do |(user_name, points), i| | ||
| 6 | + tr | ||
| 7 | + td style='width: 50px' = 1 + i | ||
| 8 | + td = user_name | ||
| 9 | + td = points | ||
| 10 | + - if @leaders.empty? | ||
| 11 | + tr | ||
| 12 | + td colspan=2 There are no results yet | ||
| 13 | + .text-left style='margin-top: 10px;' | ||
| 14 | + = link_to 'Back', root_path | 
| 1 | table | 1 | table | 
| 2 | thead | 2 | thead | 
| 3 | - th Day | 3 | + th style='text-align: left' Day | 
| 4 | - th Home | 4 | + th style='text-align: left' Home | 
| 5 | - th Your bet | 5 | + th style='text-align: left' Your bet | 
| 6 | - th Away | 6 | + th style='text-align: left' Away | 
| 7 | - th Your bet | 7 | + th style='text-align: left' Your bet | 
| 8 | - th Result | 8 | + th style='text-align: left' Result | 
| 9 | - th Home Score | 9 | + th style='text-align: left' Home Score | 
| 10 | - th Away Score | 10 | + th style='text-align: left' Away Score | 
| 11 | - th Points | 11 | + th style='text-align: left' Points | 
| 12 | - pool.matches.each do |match| | 12 | - pool.matches.each do |match| | 
| 13 | - bet = current_user.bets.find_or_initialize_by(match_id: match.id) | 13 | - bet = current_user.bets.find_or_initialize_by(match_id: match.id) | 
| 14 | tr | 14 | tr | 
| ... | @@ -20,5 +20,5 @@ table | ... | @@ -20,5 +20,5 @@ table | 
| 20 | td = match.result ? match.result.upcase : 'PENDING' | 20 | td = match.result ? match.result.upcase : 'PENDING' | 
| 21 | td = match.score_local | 21 | td = match.score_local | 
| 22 | td = match.score_visit | 22 | td = match.score_visit | 
| 23 | - td = bet.try(:points) | 23 | + td.points class="#{bet.points.to_i.zero? ? 'zero' : 'positive'}" = bet.try(:points) | 
| 24 | 24 | ... | ... | 
| ... | @@ -2,6 +2,7 @@ Rails.application.routes.draw do | ... | @@ -2,6 +2,7 @@ Rails.application.routes.draw do | 
| 2 | # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | 2 | # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | 
| 3 | HeimdallEngine.load_routes | 3 | HeimdallEngine.load_routes | 
| 4 | root 'application#root' | 4 | root 'application#root' | 
| 5 | + get 'leaderboard', to: 'application#leaderboard', as: :leaderboard | ||
| 5 | resources :bets, only: [:index] do | 6 | resources :bets, only: [:index] do | 
| 6 | collection do | 7 | collection do | 
| 7 | patch :update, as: :put | 8 | patch :update, as: :put | ... | ... | 
- 
Please register or login to post a comment