Permalink
Browse files

polish db views

  • Loading branch information...
1 parent b3e9990 commit 9ea868c534d04af51068885257b05563c6440d94 @geraldb geraldb committed Jul 7, 2012
@@ -7,46 +7,9 @@ def index
@events = Event.all
end
- # GET /events/new
- def new
- @event = Event.new
- end
-
- # POST /events
- def create
- @event = Event.new( params[:event] )
-
- if @event.save
- redirect_to events_path(), notice: 'Veranstaltung erfolgreich gespeichert.'
- else
- render action: 'new'
- end
- end
-
- # GET /events/1/edit
- def edit
- @event = Event.find( params[:id] )
- end
-
- # PUT /events/1
- def update
+ # GET /events/1
+ def show
@event = Event.find( params[:id] )
-
- if @event.update_attributes(params[:event])
- redirect_to events_path(), notice: 'Veranstaltung erfolgreich gespeichert.'
- else
- render action: 'edit'
- end
end
- # POST /events/1/add_team_to
- def add_team_to # rename to add_team or similar?
- event = Event.find( params[:id] )
- team = Team.find( params[:team_id] )
-
- event.teams << team
-
- redirect_to events_path(), :notice => 'Team erfolgreich hinzugefügt.'
- end
-
end # class EventsController
@@ -5,44 +5,9 @@ def index
@teams = Team.all
end
- # GET /teams/new
- def new
- @team = Team.new
- end
-
- # POST /teams
- def create
- @team = Team.new(params[:team])
-
- if @team.save
- redirect_to teams_path(), notice: 'Team erfolgreich gespeichert.'
- else
- render action: 'new'
- end
- end
-
- # GET /teams/1/edit
- def edit
+ # GET /teams/1
+ def show
@team = Team.find(params[:id])
end
- # PUT /teams/1
- def update
- @team = Team.find(params[:id])
-
- if @team.update_attributes(params[:team])
- redirect_to teams_path(), notice: 'Team erfolgreich gespeichert.'
- else
- render action: 'edit'
- end
- end
-
- # DELETE /teams/1
- def destroy
- @team = Team.find(params[:id])
- @team.destroy
-
- redirect_to teams_path()
- end
-
end # class TeamsController
View
@@ -19,6 +19,14 @@
class Team < ActiveRecord::Base
+ has_many :home_games, :class_name => 'Game', :foreign_key => 'team1_id'
+ has_many :away_games, :class_name => 'Game', :foreign_key => 'team2_id'
+
+ ### fix - how to do it with has_many macro? possible??
+ def games
+ Game.where( 'team1_id = ? or team2_id = ?', id, id ).order( 'play_at' ).all
+ end
+
def calc?
calc == true
end
@@ -1,37 +0,0 @@
-<%= form_for(@event) do |f| %>
-
-<table>
- <tr>
- <td><%= f.label :title, 'Titel' %></td>
- <td><%= f.text_field :title %></td>
- </tr>
-
- <tr>
- <td><%= f.label :key, 'Key' %></td>
- <td><%= f.text_field :key %></td>
- </tr>
-
- <tr>
- <td><%= f.label :start_at, 'Start (Datum)' %></td>
- <td><%= f.text_field :start_at %></td>
- </tr>
-
- <tr>
- <td><%= f.label :team3, '3. Platz Flag' %></td>
- <td>
- <%= f.radio_button :team3, 'true' %><%= f.label :team3_true, 'Ja' %>
- <%= f.radio_button :team3, 'false' %><%= f.label :team3_false, 'Nein' %>
- </td>
- </tr>
-
-
-
-
-</table>
-
-<div class="actions">
- <%= f.submit 'Speichern', :class => 'btn-primary' %>
- <%= link_to 'Zurück', events_path(), :class => 'btn' %>
- </div>
-
-<% end %><!-- form_for event -->
@@ -1,29 +0,0 @@
-<h1>Veranstaltung Bearbeiten</h1>
-
-<%= render 'form' %>
-
-<h3>Teams</h3>
-
-<%= form_for :event, :url => add_team_to_event_path(@event) do |f| %>
-
- <!-- todo/fix: remove teams already added to event -->
- <%= select_tag 'team_id', options_from_collection_for_select( Team.where( :calc => false ).all, :id, :title) %>
- <%= f.submit 'Hinzufügen', :class => 'btn-primary' %>
-
-<% end %><!-- form_for event_team -->
-
-<table>
- <% @event.teams.each do |team| %>
- <tr>
- <td>(<%= team.id %>)</td>
- <td>
- <% if team.img.present? %>
- <%= image_tag( team.img ) %>
- <% end %>
- </td>
- <td><%= team.title %></td>
- </tr>
- <% end %><!-- teams.each -->
-</table>
-
-<!-- todo/fix: add loeschen button -->
@@ -1,24 +1,12 @@
<h1><%= Event.count %> Veranstaltungen</h1>
-<%= link_to 'Neue Veranstaltung', new_event_path(), :class => 'btn-primary' %>
-
<table>
<% @events.each do |event| %>
- <tr style='background-color: black; color: white; font-weight: bold; font-size: 120%;'>
- <td>(<%= event.id %>)</td>
- <td colspan='2'><%= event.title %> (<%= event.key %>)</td>
- <td><%= link_to 'Bearbeiten', edit_event_path(event), :class => 'btn' %></td>
- </tr>
- <% event.teams.each do |team| %>
- <tr>
- <td>(<%= team.id %>)</td>
- <td>
- <%= image_tag( team.img ) if team.img.present? %>
+ <tr>
+ <td colspan='2'><%= link_to event.title, db_event_path( event ) %>
</td>
- <td><%= team.title %> (<%= team.key %>)</td>
- </tr>
- <% end %><!-- teams.each -->
+ </tr>
<% end %><!-- events.each -->
</table>
-<%= link_to 'Neue Veranstaltung', new_event_path(), :class => 'btn-primary' %>
+
@@ -1,3 +0,0 @@
-<h1>Neue Veranstaltung</h1>
-
-<%= render 'form' %>
@@ -0,0 +1,64 @@
+
+<h3><%= @event.title %></h3>
+
+
+<p>
+<!-- todo: add anchors for intra page links -->
+<% @event.rounds.each_with_index do |round,i| %>
+ <% if i > 0 %>
+ &bull;
+ <% end %>
+ <%= round.title %>
+<% end %>
+</p>
+
+
+<!-- todo: use different css class e.g. db?? -->
+<table class='play' cellspacing=0>
+
+<% @event.rounds.each do |round| %>
+<tr class='game-round'>
+ <td colspan='6' class='game-round-title'>
+ <%= round.title %>
+ <%= "/ #{round.title2}" if round.title2.present? %>
+ </td>
+</tr>
+
+
+
+ <% round.games.each do |game| %>
+ <tr>
+
+<td class='game-date'>
+ <%= game.play_at_str %>
+</td>
+
+<td class='game-team1'>
+ <span class='<%= game.team1_style_class %>'>
+ <%= link_to game.team1.title, db_team_path( game.team1 ) %>
+ </span>
+ <%= "(#{game.team1.title2})" if game.team1.title2.present? %>
+</td>
+<td>
+ <%= image_tag( game.team1.img ) if game.team1.img.present? %>
+</td>
+
+<td class='game-score'>
+ ( <%= game.score_str %> )
+</td>
+
+<td>
+ <%= image_tag( game.team2.img ) if game.team2.img.present? %>
+</td>
+<td class='game-team2'>
+ <span class='<%= game.team2_style_class %>'>
+ <%= link_to game.team2.title, db_team_path( game.team2 ) %>
+ </span>
+ <%= "(#{game.team2.title2})" if game.team2.title2.present? %>
+</td>
+
+ </tr>
+ <% end %> <!-- games -->
+<% end %> <!-- rounds -->
+
+</table>
@@ -20,7 +20,7 @@
<%= game.play_at.strftime('%H:%M') %>
</td>
<td style='text-align: right;'>
- <%= game.team1.title %>
+ <%= link_to game.team1.title, db_team_path( game.team1 ) %>
<%= "(#{game.team1.title2})" if game.team1.title2.present? %>
</td>
<td>
@@ -32,11 +32,11 @@
<%= image_tag( game.team2.img ) if game.team2.img.present? %>
</td>
<td>
- <%= game.team2.title %>
+ <%= link_to game.team2.title, db_team_path( game.team2 ) %>
<%= "(#{game.team2.title2})" if game.team2.title2.present? %>
</td>
<td>
- (<%= game.round.event.title %> / <%= game.round.title %>)
+ (<%= link_to game.round.event.title, db_event_path( game.round.event ) %> / <%= game.round.title %>)
</td>
</tr>
@@ -1,42 +0,0 @@
-
-<%= form_for(@team) do |f| %>
- <% if @team.errors.any? %>
- <div id="error_explanation">
- <h2><%= pluralize(@team.errors.count, "error") %> prohibited this team from being saved:</h2>
-
- <ul>
- <% @team.errors.full_messages.each do |msg| %>
- <li><%= msg %></li>
- <% end %>
- </ul>
- </div>
- <% end %>
-
- <table>
- <tr>
- <td><%= f.label :title, 'Titel' %></td>
- <td><%= f.text_field :title %></td>
- </tr>
- <tr>
- <td><%= f.label :img, 'Bild' %></td>
- <td><%= f.text_field :img %></td>
- </tr>
- <tr>
- <td><%= f.label :key, 'Key' %></td>
- <td><%= f.text_field :key %></td>
- </tr>
-
- <tr>
- <td><%= f.label :calc, 'Calc Flag' %></td>
- <td>
- <%= f.radio_button :calc, 'true' %><%= f.label :calc_true, 'Ja' %>
- <%= f.radio_button :calc, 'false' %><%= f.label :calc_false, 'Nein' %>
- </td>
- </tr>
- </table>
-
- <div class="actions">
- <%= f.submit 'Speichern', :class => 'btn-primary' %>
- <%= link_to 'Zurück', teams_path(), :class => 'btn' %>
- </div>
-<% end %>
@@ -1,3 +0,0 @@
-<h1>Team Bearbeiten</h1>
-
-<%= render 'form' %>
@@ -1,19 +1,17 @@
<h1><%= Team.count %> Teams</h1>
-<%= link_to 'Neues Team', new_team_path(), :class => 'btn-primary' %>
-
<table>
<% @teams.each do |team| %>
<tr>
- <td>(<%= team.id %>)</td>
<td>
<%= image_tag( team.img ) if team.img.present? %>
</td>
- <td><%= team.title %> (<%= team.key %>)</td>
- <td><%= link_to 'Bearbeiten', edit_team_path( team.id ), :class => 'btn' %></td>
+ <td>
+ <%= link_to team.title, db_team_path( team ) %>
+ </td>
+ <td>
+ <%= "(#{team.title2})" if team.title2.present? %>
+ </td>
</tr>
<% end %><!-- teams.each -->
</table>
-
-
-<%= link_to 'Neues Team', new_team_path(), :class => 'btn-primary' %>
@@ -1,3 +0,0 @@
-<h1>Neues Team</h1>
-
-<%= render 'form' %>
Oops, something went wrong.

0 comments on commit 9ea868c

Please sign in to comment.