Permalink
Browse files

add bonus points form and update

  • Loading branch information...
1 parent 8866f5b commit f9d246553b5141335f75afe0acba7b330563e871 @geraldb geraldb committed Jun 21, 2012
View
28 app/controllers/admin/bonus_controller.rb
@@ -1,9 +1,37 @@
class Admin::BonusController < Admin::BaseController
def index
+ @pools = Pool.all
end
def update
+ # mass update of bonus tips
+
+ # check for case w/ no games
+ if params[:tips]
+
+ pp params[:tips]
+
+ params[:tips].each do |tip_id,tip_hash|
+ tip = BonusTip.find( tip_id )
+
+ # only update if has changes (to avoid duplicate/false action item in news feed)
+
+ pts = tip_hash[:pts].blank? ? 0 : tip_hash[:pts].to_i
+
+ if tip.pts != pts
+ logger.info "*** updating bonus tip #{tip_id} (pts: #{pts})"
+
+ tip.pts = pts
+ tip.save!
+ else
+ logger.info "*** skip updating bonus tip #{tip_id} - no changes"
+ end
+ end # each tip
+ flash[:success] = 'Bonuspunkte erfolgreich gespeichert.'
+ end # tips.present?
+
+ redirect_to admin_bonus_path()
end
end # class BonusController
View
1 app/models/bonus_question.rb
@@ -3,5 +3,6 @@ class BonusQuestion < ActiveRecord::Base
self.table_name = 'bonus_questions'
+ has_many :tips, :class_name => 'BonusTip', :foreign_key => 'question_id'
end # class BonusQuestion
View
2 app/models/bonus_round.rb
@@ -2,6 +2,8 @@
class BonusRound < ActiveRecord::Base
self.table_name = 'bonus_rounds'
+
+ has_many :questions, :order => 'pos', :class_name => 'BonusQuestion', :foreign_key => 'round_id'
end # class BonusRound
View
1 app/models/bonus_tip.rb
@@ -3,5 +3,6 @@ class BonusTip < ActiveRecord::Base
self.table_name = 'bonus_tips'
+ belongs_to :user
end # class BonusTip
View
2 app/models/pool.rb
@@ -17,6 +17,8 @@ class Pool < ActiveRecord::Base
belongs_to :user # is owner/admin/manager
+ has_many :bonus_rounds
+
has_many :plays # pools_users join table
## rename to users from players??
View
30 app/views/admin/bonus/index.html.erb
@@ -1,2 +1,30 @@
-<h1> form for bonus updates here </h1>
+
+<% @pools.each do |pool| %>
+<h2><%= pool.full_title %></h2>
+ <% pool.bonus_rounds.each do |round| %>
+ <h3><%= round.title %></h3>
+ <% round.questions.each do |question| %>
+ <h4>Q: <%= question.title %></h4>
+ <%= form_for 'bonus', :url => admin_bonus_update_path(), :html => { :method => 'put' } do |f| %>
+ <table>
+ <% question.tips.each do |tip| %>
+ <tr>
+ <td><%= tip.user.name %></td>
+ <td>
+ <%= fields_for 'tips[]', tip do |ff| %>
+ <%= ff.hidden_field :id %>
+ <%= ff.text_field :pts, :size => 1 %>
+ <% end %><!-- fields_for tips[] -->
+ Punkte
+ </td>
+ </tr>
+ <% end %><!-- each tip -->
+ </table>
+ <p>
+ <%= f.submit "Update '#{question.title}'", :class => 'btn-primary' %>
+ </p>
+ <% end %><!-- form bonus -->
+ <% end %><!-- each question -->
+ <% end %><!-- each round -->
+<% end %><!-- each pool -->

0 comments on commit f9d2465

Please sign in to comment.