Permalink
Browse files

polish calc; show scoring for n.V.,i.E.

  • Loading branch information...
1 parent 347d3ac commit 29d2d04b08bf68979566557cedeb18031217e650 @geraldb geraldb committed Jun 27, 2012
@@ -34,6 +34,12 @@ def update
score1 = game_hash[:score1].blank? ? nil : game_hash[:score1].to_i
score2 = game_hash[:score2].blank? ? nil : game_hash[:score2].to_i
+ score3 = game_hash[:score3].blank? ? nil : game_hash[:score3].to_i
+ score4 = game_hash[:score4].blank? ? nil : game_hash[:score4].to_i
+ score5 = game_hash[:score5].blank? ? nil : game_hash[:score5].to_i
+ score6 = game_hash[:score6].blank? ? nil : game_hash[:score6].to_i
+
+
if game_hash[:locked].nil?
locked = nil
else
@@ -42,12 +48,20 @@ def update
if((score1.present? && game.score1 != score1) ||
(score2.present? && game.score2 != score2) ||
+ (score3.present? && game.score3 != score3) ||
+ (score4.present? && game.score4 != score4) ||
+ (score5.present? && game.score5 != score5) ||
+ (score6.present? && game.score6 != score6) ||
(locked.nil? == false && game.locked != locked))
- logger.info "*** updating game #{game_id} (score1: #{score1}, score2: #{score2}, locked: #{locked})"
+ logger.info "*** updating game #{game_id} (score1: #{score1}, score2: #{score2}, score3: #{score3}, score4: #{score4}, score5: #{score5}, score6: #{score6}, locked: #{locked})"
game.score1 = score1 if score1.present?
game.score2 = score2 if score2.present?
+ game.score3 = score3 if score3.present?
+ game.score4 = score4 if score4.present?
+ game.score5 = score5 if score5.present?
+ game.score6 = score6 if score6.present?
game.locked = locked if locked.nil? == false # nb: can't use locked.present? because false fails
game.save!
else
@@ -0,0 +1,8 @@
+
+class Setup::BaseController < ApplicationController
+
+ layout 'setup'
+
+ ## todo: add require_admin etc.
+
+end
@@ -0,0 +1,48 @@
+class Setup::BonusRoundsController < Setup::BaseController
+
+ # GET /bonus_rounds
+ def index
+ @rounds = BonusRound.all
+ end
+
+ # GET /bonus_rounds/new
+ def new
+ @round = BonusRound.new
+ end
+
+ # POST /bonus_rounds
+ def create
+ @round = BonusRound.new(params[:bonus_round])
+
+ if @round.save
+ redirect_to bonus_rounds_path(), :notice => 'Runde erfolgreich gespeichert.'
+ else
+ render :action => 'new'
+ end
+ end
+
+ # GET /bonus_rounds/1/edit
+ def edit
+ @round = BonusRound.find(params[:id])
+ end
+
+ # PUT /bonus_rounds/1
+ def update
+ @round = BonusRound.find(params[:id])
+
+ if @round.update_attributes(params[:bonus_round])
+ redirect_to bonus_rounds_path(), :notice => 'Runde erfolgreich gespeichert.'
+ else
+ render :action => 'edit'
+ end
+ end
+
+ # DELETE /bonus_rounds/1
+ def destroy
+ @round = BonusRound.find(params[:id])
+ @round.destroy
+
+ redirect_to bonus_rounds_path()
+ end
+
+end # class BonusRoundsController
@@ -4,6 +4,6 @@ class BonusRound < ActiveRecord::Base
self.table_name = 'bonus_rounds'
has_many :questions, :order => 'pos', :class_name => 'BonusQuestion', :foreign_key => 'round_id'
-
+ belongs_to :pool
end # class BonusRound
View
@@ -129,9 +129,9 @@ def complete?
def score_str
if score5.present? && score6.present? # im Elfmeterschiessen i.E.?
- "#{score5} : #{score6} i.E."
+ "#{score1_str} : #{score2_str} / #{score3} : #{score4} n.V. / #{score5} : #{score6} i.E."
elsif score3.present? && score4.present? # nach Verlaengerung n.V.?
- "#{score3} : #{score4} n.V."
+ "#{score1_str} : #{score2_str} / #{score3} : #{score4} n.V."
else
"#{score1_str} : #{score2_str}"
end
View
@@ -81,10 +81,26 @@ def calc_points
### pts +=1
end
- # ergebnis richtig?
+ # ergebnis richtig?
if game.score1 == score1 && game.score2 == score2
pts += 2
end
+
+ ## check n.V.
+
+ if (game.score3.present? && game.score4.present? &&
+ score3.present? && score4.present? &&
+ game.score3 == score3 && game.score4 == score4)
+ pts +=1
+ end
+
+ ## check i.E.
+
+ if (game.score5.present? && game.score6.present? &&
+ score5.present? && score6.present? &&
+ game.score5 == score3 && game.score6 == score4)
+ pts +=1
+ end
end
pts
end
@@ -237,9 +253,9 @@ def score_str
else
str = ''
if score5.present? && score6.present? # im Elfmeterschiessen i.E.?
- str = "#{score5} : #{score6} i.E."
+ str = "#{score1_str} : #{score2_str} / #{score3} : #{score4} n.V. / #{score5} : #{score6} i.E."
elsif score3.present? && score4.present? # nach Verlaengerung n.V.?
- str = "#{score3} : #{score4} n.V."
+ str = "#{score1_str} : #{score2_str} / #{score3} : #{score4} n.V."
else
str = "#{score1_str} : #{score2_str}"
end
@@ -15,6 +15,18 @@
<%= ff.text_field :score1, :size => 1 %>
:
<%= ff.text_field :score2, :size => 1 %>
+
+ <% if game.knockout? %>
+ /
+ <%= ff.text_field :score3, :size => 1 %>
+ :
+ <%= ff.text_field :score4, :size => 1 %>
+ n.V.
+ <%= ff.text_field :score5, :size => 1 %>
+ :
+ <%= ff.text_field :score6, :size => 1 %>
+ i.E.
+ <% end %>
<% end %><!-- fields_for games -->
</td>
@@ -12,7 +12,7 @@
<!-- left -->
<td>
<span class='logo'><%= link_to '[Logo]', pools_path() %></span>
- <span> - DB Setup - </span>
+ <span> - DB - </span>
&nbsp;&nbsp;&nbsp;
<% if content_for? :breadcrumb %>
<span class='breadcrumb-inline'>
@@ -0,0 +1,62 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <%= render :partial => 'layouts/header' %>
+</head>
+<body>
+
+
+<!-- fix:/todo: use own color scheme for setup section -->
+
+<div class='navbar db'>
+<table width='100%' cellspacing=0>
+ <tr>
+ <!-- left -->
+ <td>
+ <span class='logo'><%= link_to '[Logo]', pools_path() %></span>
+ <span> - Setup - </span>
+ &nbsp;&nbsp;&nbsp;
+ <% if content_for? :breadcrumb %>
+ <span class='breadcrumb-inline'>
+ <%= yield :breadcrumb %>
+ </span>
+ <% end %>
+ </td>
+ <!-- right -->
+ <td style='text-align: right;'>
+ <% if signed_in? %>
+ Willkommen, <%= current_user.name %>!
+
+ &nbsp;
+ <span class='signout'>
+ <%= link_to 'Abmelden', signout_path %>
+ </span>
+ <% else %>
+ <span class='signin'>
+ <%= link_to 'Anmelden', signin_path %>
+ </span>
+ <% end %>
+ </td>
+ </tr>
+</table>
+</div>
+
+
+ <div>
+ <%= link_to 'Bonus Rounds', bonus_rounds_path() %>
+ <!-- todo: add some more links -->
+ </div>
+
+<div class='content' style='padding: 0px 20px 0px 20px;'>
+
+ <%= render :partial => 'layouts/flash', :locals => { :flash => flash } %>
+
+ <%= yield %>
+
+</div>
+
+<%= render :partial => 'layouts/debug' %>
+<%= render :partial => 'layouts/version' %>
+
+</body>
+</html>
@@ -1,4 +1,3 @@
<td class='game-score'>
- <!-- fix/todo: use game.score_str -->
- ( <%= game.score1_str %> : <%= game.score2_str %> )
-</td>
+ ( <%= game.score_str %> )
+</td>
@@ -141,14 +141,25 @@
</table>
-<p>Punkte / Runde:</p>
+
<!-- add scoring/ranking block/data -->
<table>
+ <tr>
+ <td>
+ <td colspan='3'>Runde</td>
+ <td></td>
+ <td colspan='3'>Gesamt</td>
+ </tr>
<% @play.complete_rankings.each do |ranking| %>
<tr>
- <td><%= ranking.round_pts %> => #<%= ranking.round_pos %></td>
- <td><%= ranking.total_pts %> => #<%= ranking.total_pos %> <%= ranking.diff_total_pos_str %></td>
<td>(<%= ranking.round.pos %>) <%= ranking.round.title %></td>
+ <td><%= ranking.round_pts %> Pkte</td>
+ <td>=></td>
+ <td>#<%= ranking.round_pos %></td>
+ <td>/</td>
+ <td><%= ranking.total_pts %> Pkte</td>
+ <td>=></td>
+ <td>#<%= ranking.total_pos %> <%= ranking.diff_total_pos_str %></td>
</tr>
<% end %>
</table>
@@ -42,7 +42,7 @@
<table width='100%' cellspacing=0>
-<% @pool.bonus_rounds.reorder('pos').each do |round| %>
+<% @pool.bonus_rounds.reorder('pos desc').each do |round| %>
<tr>
<td colspan='2' style='background-color: lightgrey;'><%= round.title %></td>
@@ -0,0 +1,35 @@
+<%= form_for(@round) do |f| %>
+ <% if @round.errors.any? %>
+ <div id="error_explanation">
+ <h2><%= pluralize(@round.errors.count, "error") %> prohibited this round from being saved:</h2>
+
+ <ul>
+ <% @round.errors.full_messages.each do |msg| %>
+ <li><%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+ <% end %>
+
+ <table>
+ <tr>
+ <td></td>
+ <td><!-- todo: add pool/event field w/ select box -->
+ <%= @round.pool.full_title %>
+ </td>
+ </tr>
+ <tr>
+ <td><%= f.label :pos, 'Pos#:' %></td>
+ <td><%= f.text_field :pos, size: '3' %></td>
+ </tr>
+ <tr>
+ <td><%= f.label :title, 'Title:' %></td>
+ <td><%= f.text_field :title %></td>
+ </tr>
+ </table>
+
+ <div class="actions">
+ <%= f.submit 'Save', :class => 'btn-primary' %>
+ <%= link_to 'Back', bonus_rounds_path(), :class => 'btn' %>
+ </div>
+<% end %>
@@ -0,0 +1,3 @@
+<h1>Edit Bonus Round</h1>
+
+<%= render 'form' %>
@@ -0,0 +1,21 @@
+<h1><%= BonusRound.count %> Bonus Rounds</h1>
+
+<%= link_to 'New Bonus Round', new_bonus_round_path(), :class => 'btn-primary' %>
+
+<!-- todo: stack by pool -->
+
+<table>
+<% @rounds.each do |round| %>
+ <tr>
+ <td><%= round.pool.full_title %></td>
+ <td>(<%= round.id %>)</td>
+ <td>#<%= round.pos %></td>
+ <td><%= round.title %></td>
+ <td><%= link_to 'Edit', edit_bonus_round_path( round ), :class => 'btn' %></td>
+ </tr>
+<% end %><!-- rounds.each -->
+</table>
+
+<p>
+<%= link_to 'New Bonus Round', new_bonus_round_path(), :class => 'btn-primary' %>
+</p>
@@ -0,0 +1,3 @@
+<h1>New Bonus Round</h1>
+
+<%= render 'form' %>
View
@@ -72,6 +72,13 @@
end
end
+ ##############################
+ ## routes for setup via module (setup not in url -- todo/fix??)
+
+ scope :module => 'setup' do
+ resources :bonus_rounds
+ end
+
#######################
## home route
@@ -9,11 +9,11 @@
poolfix = Pool.find_by_event_id_and_user_id_and_fix!( euro.id, behrooz.id, true )
poolflex = Pool.find_by_event_id_and_user_id_and_fix!( euro.id, behrooz.id, false )
-rfix1 = BonusRound.create!( :pool_id => poolfix.id, :pos => 1, :title => 'Bonuspunkte - Europa- und Vizemeister' )
-rfix2 = BonusRound.create!( :pool_id => poolfix.id, :pos => 2, :title => 'Bonuspunkte - Gruppenplazierung' )
+rfix1 = BonusRound.create!( :pool_id => poolfix.id, :pos => 1, :title => 'Bonuspunkte - Gruppenplazierung' )
+rfix2 = BonusRound.create!( :pool_id => poolfix.id, :pos => 2, :title => 'Bonuspunkte - Europa- und Vizemeister' )
-qfix1 = BonusQuestion.create!( :round_id => rfix1.id, :pos => 1, :title => 'Europameister? Vizemeister?' )
-qfix2 = BonusQuestion.create!( :round_id => rfix2.id, :pos => 1, :title => 'Gruppenerster? Gruppenzweiter? Grupperdritter? Gruppenvierter?' )
+qfix1 = BonusQuestion.create!( :round_id => rfix1.id, :pos => 1, :title => 'Gruppenerster? Gruppenzweiter? Grupperdritter? Gruppenvierter?' )
+qfix2 = BonusQuestion.create!( :round_id => rfix2.id, :pos => 1, :title => 'Europameister? Vizemeister?' )
rflex1 = BonusRound.create!( :pool_id => poolflex.id, :pos => 1, :title => 'Bonuspunkte - Europa- und Vizemeister' )
Oops, something went wrong.

0 comments on commit 29d2d04

Please sign in to comment.