Skip to content

Commit

Permalink
Updated to display full dashboard info and spruce up dashboard more
Browse files Browse the repository at this point in the history
  • Loading branch information
stevetuckner@stewdle.com committed Aug 11, 2011
1 parent 38f5767 commit b0919a1
Show file tree
Hide file tree
Showing 10 changed files with 163 additions and 71 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class UsersController < InheritedResources::Base
def dashboard
@user = current_user
@schedule = @user.league.schedules.first
@recent_games_played = Game.where('actual_start_datetime is not NULL')
@recent_games_played = Game.where('actual_start_datetime is not NULL').order('actual_start_datetime DESC').limit(10)
@recent_comments = []
end

Expand Down
11 changes: 11 additions & 0 deletions app/models/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ class Game < ActiveRecord::Base

after_save :update_standings

class << self
def unplayed
where("actual_start_datetime is NULL").order("expected_start_date ASC")
end

def recent
where("actual_start_datetime is NOT NULL").order("actual_start_datetime DESC").limit(10)
end
end

def opponent(user)
raise "more than two players for this game" unless game_roles.size == 2
opponents = game_roles.inject([]) {|sum,gr| gr.user != user ? (sum + [gr]) : sum }

if opponents.size == 0 then
raise "user both players in the game"
elsif opponents.size == 1
Expand Down
8 changes: 0 additions & 8 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ class User < ActiveRecord::Base
has_many :games, :through => :game_roles
belongs_to :league

def unplayed_games
[]
end

def recent_games
[]
end

def record
schedule_result = self.league.schedules.first.schedule_results.where(:user_id => self).first
if (schedule_result)
Expand Down
38 changes: 23 additions & 15 deletions app/views/games/_user_table.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,37 @@
%tr
%th
Round
%th
Expected Start Date
%th
Actual Start Date
- if unplayed_games
%th
Expected Start Date
- if finished_games
%th
Actual Start Date
%th
Opponent
%th
Opponent Color
- if verbose
%th
Opponent Color
%th
Result
%th
Record
%th
Rating
- if verbose
%th
Record
%th
Rating
%tbody
- games.each do |game|
%tr
- opponent = game.opponent(@user)
%td= game.round
%td= game.expected_start_date
%td= game.actual_start_datetime
- if unplayed_games
%td= game.expected_start_date
- if finished_games
%td= game.actual_start_datetime
%td= link_to opponent.name, user_path(opponent.user)
%td= game.actual_start_datetime ? opponent.role : ""
- if verbose
%td= game.actual_start_datetime ? opponent.role : ""
%td= game.actual_start_datetime ? link_to(game.result_for_user(@user), game_path(game)) : link_to("unplayed", edit_game_path(game))
%td= opponent.record
%td= formatted_rating(opponent.rating)
- if verbose
%td= opponent.record
%td= formatted_rating(opponent.rating)
67 changes: 36 additions & 31 deletions app/views/users/dashboard.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,56 @@
%h1
Dashboard
%section.user
%h2
= @user.name
%section.user-info
%h2
Your Status
%h3
Current Status
%div
.big-title
.med-title
Record
.big-value
.med-value
= @user.record
%div
.med-title
Rating
.med-value
= formatted_rating(@user.rating)

%section.user-game-highlight
- unless @user.unplayed_games.empty?
- unless @user.games.unplayed.empty?
%section.user-games
%h2
Unplayed Games
%h3
Next Opponent
- opponent = @user.unplayed_games.first.opponent(@user)
.med-title
Opponent
.med-value
= opponent.name
.small-title
Opponent's Record
.small-value
= opponent.record
.small-title
Opponent's Rating
.small-value
= opponent.rating

%section.user-games
- if @user.unplayed_games.size > 1
%section.user-game-highlight
- next_game = @user.games.unplayed.first
- opponent = next_game.opponent(@user)
%h3
After That
= render :partial => "games/user_table", :locals => {:games => @user.unplayed_games[1..-1]}
= link_to("Next Opponent", game_path(next_game))
.med-title
Opponent
.med-value
= link_to(opponent.name, user_path(opponent.user))
.medsmall-title
Opponent's Record
.medsmall-value
= opponent.record
.medsmall-title
Opponent's Rating
.medsmall-value
= formatted_rating(opponent.rating)
.clear

%section.user-games
- unless @user.recent_games.empty?
%h3
Recent Games
= render :partial => "games/user_table", :locals => {:games => @user.recent_games}
- if @user.games.unplayed.size > 1
%section.user-games
%h3
After That
= render :partial => "games/user_table", :locals => {:games => @user.games.unplayed[1..-1], :unplayed_games => true, :finished_games => false, :verbose => false}

- unless @user.games.recent.empty?
%section.user-games
%h2
Finished Games
= render :partial => "games/user_table", :locals => {:games => @user.games.recent, :unplayed_games => false, :finished_games => true, :verbose => false}
%section{:style => "clear:left;"}

%section.league
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
%section.user-games
%h2
Games
= render :partial => "games/user_table", :locals => {:games => @user.games.order(:round)}
= render :partial => "games/user_table", :locals => {:games => @user.games.order(:round), :unplayed_games => true, :finished_games => true, :verbose => true}
.clear

2 changes: 2 additions & 0 deletions public/stylesheets/sass/partials/_base.sass
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ $passive_color: #8a8989
$link_color: #FFF
$link_hover_color: #888
$section_color: #0AE
$highlighted_section_color: #440000
$highlighted_section_header_color: #220000

$table_header_background_color: #220000
$table_even_row_background_color: #330000
Expand Down
15 changes: 14 additions & 1 deletion public/stylesheets/sass/partials/_layout.sass
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ header
.inner-container
margin: 10px
background-color: $inner_container_background_color
+box-shadow(5px 5px 5px, black)
+box-shadow(2px 5px 5px, black)
#border-top: 1px solid #444444
#border-left: 1px solid #444444

Expand All @@ -87,6 +87,19 @@ header
background-color: $article_background_color
section
background-color: $section_background_color
&.user-info
background-color: $highlighted_section_color
padding: 5px
margin-bottom: 10px
h3
background-color: $highlighted_section_header_color
&.user-game-highlight
padding: 5px
background-color: $highlighted_section_color
margin-bottom: 10px
h3
background-color: $highlighted_section_header_color
padding: 5px
footer
//background: transparent url(../images/footer_bg.gif) repeat-x
//height: 95px
Expand Down
34 changes: 29 additions & 5 deletions public/stylesheets/sass/partials/_styles.sass
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,22 @@ section.league
float: left

section.user-info
width: 180px
width: 360px
@media screen and (max-width: 320px)
width: 280px
margin-left: 5px
margin-right: 5px
float: left
margin-bottom: 10px

section.user-game-highlight
width: 360px
@media screen and (max-width: 320px)
width: 280px
margin-left: 5px
margin-right: 5px
float: left
margin-bottom: 10px

section.user-games
float: left
Expand Down Expand Up @@ -278,33 +288,47 @@ caption
float: left
width: 25%

.medsmall-title
font-size: 1.2em
line-height: 1.2em
//margin-bottom: 1.5em
float: left
width: 55%

.medsmall-value
font-size: 1.2em
line-height: 1.2em
//margin-bottom: 1.5em
float: left
width: 35%

.med-title
font-size: 1.5em
line-height: 1.0em
//margin-bottom: 1.5em
float: left
width: 50%
width: 55%

.med-value
font-size: 1.3em
line-height: 1.5em
//margin-bottom: 1.5em
float: left
width: 40%
width: 35%

.big-title
font-size: 1.8em
line-height: 2.0em
margin-bottom: 0.5em
float: left
width: 50%
width: 55%

.big-value
font-size: 1.8em
line-height: 2.0em
margin-bottom: 0.5em
float: left
width: 40%
width: 35%

.edit-link-span
font-size: 0.5em
Expand Down
Loading

0 comments on commit b0919a1

Please sign in to comment.