Skip to content

Commit

Permalink
Draggable Teams to add to Tournament.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn2.assembla.com/svn/fs/trunk/fpt@13 d4c3aac1-5b85-48de-b3bb-3a454bd87b0a
  • Loading branch information
lmarcucci committed Apr 5, 2008
1 parent 1dd45ef commit 76bae4a
Show file tree
Hide file tree
Showing 31 changed files with 968 additions and 177 deletions.
5 changes: 5 additions & 0 deletions app/controllers/teams_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ def destroy
redirect_to :action => 'index'
end

def sort_teams
@teams = params[:list]
render :partial => 'matches'
end

end
69 changes: 51 additions & 18 deletions app/controllers/tournaments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ def index
def show

#FIXME: this doesnt eager load!!
@tournament = Tournament.find(params[:id],
:include => [:standings, :teams],
:order => "standings.name")
@tournament = Tournament.find(params[:id], :include => [:standings, :teams],
:order => "standings.name")
@standings = @tournament.standings
@teams = @tournament.teams

Expand All @@ -21,17 +20,12 @@ def show
end

def new
if @tournament.save!
redirect_to tournament_path(@tournament)
flash[:notice] = "Everythin ok."
else
flash.now[:notice] = "Save Fubar"
end
@tournament = Tournament.new
end

def create
@tournament = Tournament.new(params[:tournament])
@tournament.team_ids = []
if @tournament.save
flash[:notice] = "Tournament successfully created."
redirect_to tournaments_path
Expand Down Expand Up @@ -66,19 +60,58 @@ def destroy
end

def edit_teams
@teams = Team.find(:all)
@tournament = Tournament.find(params[:id])
@tournament = Tournament.find(params[:id], :include => :teams)
@teams = Team.find(:all, :order => "short_name")
@excluded = @teams - @tournament.teams(:order => "short_name")
@included = @tournament.teams()
end

def add_teams
params[:tournament][:team_ids] ||= []
@tournament = Tournament.find(params[:id])
@tournament.team_ids = params[:tournament][:team_ids]
# def add_teams
# params[:tournament][:team_ids] ||= []
# @tournament = Tournament.find(params[:id])
# @tournament.team_ids = params[:tournament][:team_ids]
# if @tournament.save
# redirect_to tournament_path(@tournament)
# flash[:notice] = "Everythin ok."
# else
# redirect_to tournament_path(@tournament)
# end
# end

def push_team
@tournament = Tournament.find(params[:id], :include => :teams)
@tournament.team_ids = Array.[](@tournament.teams.map {|x| x.id}).flatten
@tournament.team_ids << params[:team]
if @tournament.save
redirect_to tournament_path(@tournament)
flash[:notice] = "Everythin ok."
#@hide = Team.find(params[:team])
@included = @tournament.reload.teams
@excluded = Team.find(:all) - @included

render :partial => 'teams_included'
else
redirect_to tournament_path(@tournament)
#@hide = Team.find(params[:team])
@included = @tournament.teams
@excluded = Team.find(:all) - @included

render :partial => 'teams_included'
end
# THIS WORKS!!
# @tournament = Tournament.find(params[:id])
# @hide = Team.find(params[:team], :order => "short_name" )
# @tournament.teams << @hide
# @included = @tournament.teams(:order => "short_name")
# @excluded = Team.find(:all, :order => "short_name") - @included
#
# render :partial => 'teams_included'
end

def remove_team
@tournament = Tournament.find(params[:id])
@tournament.participations.find_by_team_id(params[:team]).destroy
@included = @tournament.teams
@excluded = Team.find(:all, :order => "short_name") - @included

render :partial => 'excluded_teams'

end
end
16 changes: 16 additions & 0 deletions app/helpers/teams_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,18 @@
module TeamsHelper

def name(team)
if team == nil
"--"
else
team.short_name.capitalize
end
end

def played(match)
if match.played_date == nil
"--"
else
match.played_date.to_formatted_s(:rfc822)
end
end
end
4 changes: 4 additions & 0 deletions app/helpers/tournaments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ def get_tournament_type(tournament)
end
end

def get_team(id)
Team.find(id)
end

end
8 changes: 7 additions & 1 deletion app/models/standing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Standing < ActiveRecord::Base
validates_presence_of :tournament_id
validates_uniqueness_of :scheduled_date


after_create :add_matches

def self.find_with_tournament_matches_teams(id)
self.find(id, :include => [ :tournament, :matches,
Expand Down Expand Up @@ -37,4 +37,10 @@ def scheduled_date_too_late?
true
end

def add_matches
10.times do
self.matches.create
end
end

end
18 changes: 7 additions & 11 deletions app/models/tournament.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,16 @@ def add_standings
end

def fulfill_teams
# if has_teams?
Participation.destroy_all(:tournament_id == self.id)
self.team_ids.each do |t|
Participation.create(:team_id => t, :tournament_id => self.id)
end
# end
Participation.destroy_all(:tournament_id == self.id)
self.team_ids.each do |t|
Participation.create(:team_id => t, :tournament_id => self.id)
end
end

def too_many_teams?
# if has_teams?
if self.team_ids.size > 20
self.errors.add :teams, "cant pass 20."
end
# end
if self.team_ids.size > 20
self.errors.add :teams, "cant pass 20."
end
end

def has_teams?
Expand Down
69 changes: 16 additions & 53 deletions app/views/layouts/futstat.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,25 @@

<html>
<head>
<title>Futbol Stats</title>
<style type="text/css" media="screen">
body {
font-family: verdana;
background-color: #30787e;
padding: 30px;
}
#content {
padding: 15px;
background-color: #7dc56c;
border: 2px solid black;
}
.fieldWithErrors {
padding: 2px;
background-color: red;
}
#errorExplanation {
width: 400px;
border: 2px solid red;
padding: 7px;
padding-bottom: 12px;
margin-bottom: 20px;
background-color: #f0f0f0 ;
}
#errorExplanation h2 {
visibility: hidden;
font-size: 10px;
padding: 5px;
margin: -15px;
}
#errorExplanation p {
color: red;
font-size: 12px;
margin-bottom: 0;
padding: 5px;
}
#errorExplanation ul li {
font-size: 12px;
list-style: square;
}
#notice {
margin: 5px;
padding: 5px 5px 5px 15px;
background-color: #48cccd;
border: 1px solid black;
font-size: 10px;
width: 400px;
}
</style>
<title>
Futbol Stats
</title>
<%= stylesheet_link_tag 'fpt' %>
<%= javascript_include_tag :defaults %>
</head>
<body>
<div id="content">
<h1 style="margin: 0px;"><%= link_to "Futstat", root_path %></h1>
<%= link_to 'Teams', teams_path %>
<%= link_to 'Tournaments', tournaments_path %>
<%= yield :layout %>
<div id="title">
<h1>
<%= link_to "FutStat.", root_path, :style => "color:black;" %>
</h1>
</div>
<div id="yield">
<%= yield :layout %>
</div>
<div id="footer" class="footer">
Footer vieja!
</div>
</div>
</body>
</html>
46 changes: 33 additions & 13 deletions app/views/standings/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,38 @@
</h4>

<% if @standing.matches.empty? %>
<p>
<div class="msg">
Click
<%= link_to "here", edit_tournament_standing_path(@standing.tournament,
@standing) %> to edit this standing's matches.
</p>
<% else %>
<% for match in @standing.matches %>
<p>
<%= match.home_team.short_name %>
<%= match.home_team_score %> vs <%= match.away_team_score %>
<%= match.away_team.short_name %>
(<%= match.played_date.to_formatted_s(:rfc822) %>)
</p>
<% end %>
<%= link_to "here", edit_tournament_standing_path(@standing.tournament, @standing) %>
to edit this standing's matches.
</div>
<% else %>
<ul style="list-style-type:none;padding-left:0px">
<li>
<div style="float:left;width:130px;">Jugado</div>
<div style="float:left;width:150px;">Local</div>
<div style="float:left;width:60px;">Goles</div>
<div style="float:left;width:60px;">Goles</div>
<div style="float:left;width:150px;">Visitante</div>
</li><br />
<% for match in @standing.matches %>
<li>
<div style="float:left;width:130px;"><%= played(match) %></div>
<div style="float:left;width:150px;"><%= name(match.home_team) %></div>
<div style="float:left;width:60px;"><%= match.home_team_score %></div>
<div style="float:left;width:60px;"><%= match.away_team_score %></div>
<div style="float:left;width:150px;"><%= name(match.away_team) %></div>
</li><br />
<% end %>
</ul>
<% end %>
<ul id="list">
<% for team in @tournament.teams -%>
<li id="team_<%= team.id %>"><%= team.short_name %> </li>
<% end %>
</ul>
<div id="matches">
</div>
<%= sortable_element 'list',
:update => 'matches',
:url => sort_teams_team_path %>
13 changes: 13 additions & 0 deletions app/views/teams/_matches.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h3>Matches </h3>
<ul style="list-style-type:none;padding-left:0px">
<li>
<div style="float:left;width:130px;">Jugado</div>
<div style="float:left;width:150px;">Local</div>
<div style="float:left;width:60px;">Goles</div>
<div style="float:left;width:60px;">Goles</div>
<div style="float:left;width:150px;">Visitante</div>
</li><br />
<li>
<%= @teams %>
</li><br />
</ul>
11 changes: 8 additions & 3 deletions app/views/tournaments/_add_teams.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<h3>Teams:</h3>

<% i=1 %>
<% for team in @teams %>
<p>
<div style="min-width:150px;float:left;">
<%= check_box_tag "tournament[team_ids][]",
team.id,
@tournament.teams.include?(team) %>
<%= team.short_name.titleize %>
</p>
</div>
<% if i.modulo(4) == 0 %>
<br />
<% end %>
<% i = i+1 %>
<% end %>

<br /><br />
<%= submit_tag "Just Do It", :class => 'submit' %><br />
5 changes: 5 additions & 0 deletions app/views/tournaments/_excluded_teams.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h3>excluded teams</h3>
<% for team in @excluded %>
<div id="team_<%= team.id %>" class="excluded_teams"><%= team.short_name.capitalize %></div>
<%= draggable_element "team_#{team.id}", :revert => true, :success => "Element.hide" %>
<% end %>
6 changes: 6 additions & 0 deletions app/views/tournaments/_teams_included.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h3>included teams</h3>
<% for team in @included %>
<div id="team_<%= team.id %>" class="competitors"><%= team.short_name.capitalize %></div>
<%= draggable_element "team_#{team.id}", :revert => true, :success => "Element.hide" %>
<% end %>
<%= "Drop teams here." if @included.empty? %>
4 changes: 2 additions & 2 deletions app/views/tournaments/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3>edit tournament</h3>
<h3>edit tournament <%= link_to "(show)", tournament_path(@tournament) %></h3>

<%= error_messages_for 'tournament' %>

Expand All @@ -17,4 +17,4 @@

<br />

<%= link_to 'tournaments', tournaments_path %> <%= link_to 'edit teams', edit_teams_tournament_path(@tournament) %>
<%= link_to 'edit teams', edit_teams_tournament_path(@tournament) %>
Loading

0 comments on commit 76bae4a

Please sign in to comment.