Iker Narvaez

dashboard changes

......@@ -73,7 +73,8 @@ table {
.upcoming {
td {
width: 33%;
width: 25%;
font-size: 12px;
}
}
......@@ -94,9 +95,9 @@ table {
text-align: left;
}
td, th {
width: 50%;
}
// td, th {
// // width: 50%;
// }
}
// Bets
......@@ -182,3 +183,15 @@ input[type="submit"] {
max-width: 70vw;
}
}
.vs-cell {
width: 40px;
}
.text-left { text-align: left; width: 100%; }
td.points {
font-weight: 700;
&.zero { color: red }
&.positive { color: green }
}
......
......@@ -2,15 +2,20 @@ class ApplicationController < HeimdallEngine::ApplicationController
protect_from_forgery with: :exception
def root
leaderboard
load_leaderboard
check_matches
recent_matches
@results = check_results
end
def leaderboard
@leaders = Bet.joins(:user).group('users.name').sum(:points)
.sort_by { |k,v| v }
end
private
def leaderboard
def load_leaderboard
@leaders = Bet.joins(:user).group('users.name').sum(:points)
.sort_by { |k,v| v }.take(5)
end
......@@ -28,7 +33,7 @@ class ApplicationController < HeimdallEngine::ApplicationController
def check_results
return [] unless current_user
current_user.bets.joins(:match).order('matches.date desc')
.where.not(result: nil)
.where.not(points: nil)
.limit(5)
end
end
......
class MyProfileController < CrudController::Base
enable_gatekeeper
private
def object_params
params.require(:user).permit(
:name, :mail, :password, :password_confirmation
)
end
end
h1 Leaderboard
table.leaderboard
tbody
- @leaders.each do |group_name, data|
tr
td colspan=2 = group_name
- data[:leaderboard].each do |user_name, points|
- @leaders.each.with_index do |(user_name, points), i|
tr
td style='width: 50px' = 1 + i
td = user_name
td = points
- if data[:leaderboard].empty?
- if @leaders.empty?
tr
td colspan=2 There are no results yet
.text-left style='margin-top: 10px;'
= link_to 'See everyone', leaderboard_path
......
......@@ -6,7 +6,7 @@ table
td = r.match.local
td VS
td = r.match.visit
td = r.points
td.points class="#{r.points.to_i.zero? ? 'zero' : 'positive'}" = r.points
- if @results.empty?
tr
td colspan=4 There are no finished matches yet.
......
......@@ -5,19 +5,6 @@ table.upcoming
tr
td = l(u.date, format: :short)
td = u.local
td VS
td.vs-cell VS
td = u.visit
h1 Recent matches
table.recent
tbody
- @recent_matches.each do |match|
tr
td = l(match.date, format: :short)
td = match.local
td = match.score_local
td = match.visit
td = match.score_visit
- if @recent_matches.empty?
tr
td colspan=4 There are no finished matches yet.
......
.middle.content
h1 Leaderboard
table.leaderboard
tbody
- @leaders.each.with_index do |(user_name, points), i|
tr
td style='width: 50px' = 1 + i
td = user_name
td = points
- if @leaders.empty?
tr
td colspan=2 There are no results yet
.text-left style='margin-top: 10px;'
= link_to 'Back', root_path
table
thead
th Day
th Home
th Your bet
th Away
th Your bet
th Result
th Home Score
th Away Score
th Points
th style='text-align: left' Day
th style='text-align: left' Home
th style='text-align: left' Your bet
th style='text-align: left' Away
th style='text-align: left' Your bet
th style='text-align: left' Result
th style='text-align: left' Home Score
th style='text-align: left' Away Score
th style='text-align: left' Points
- pool.matches.each do |match|
- bet = current_user.bets.find_or_initialize_by(match_id: match.id)
tr
......@@ -20,5 +20,5 @@ table
td = match.result ? match.result.upcase : 'PENDING'
td = match.score_local
td = match.score_visit
td = bet.try(:points)
td.points class="#{bet.points.to_i.zero? ? 'zero' : 'positive'}" = bet.try(:points)
......
......@@ -2,6 +2,7 @@ Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
HeimdallEngine.load_routes
root 'application#root'
get 'leaderboard', to: 'application#leaderboard', as: :leaderboard
resources :bets, only: [:index] do
collection do
patch :update, as: :put
......