Skip to content

Commit

Permalink
Allow rainouts for future games.
Browse files Browse the repository at this point in the history
  • Loading branch information
toomuchpete committed Sep 15, 2024
1 parent 984046a commit 913d8ef
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
16 changes: 10 additions & 6 deletions app/controllers/leagues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -901,14 +901,16 @@ def remove_future_games
end

def rainout_games
@todays_games = @league.games.where(:game_time.gte => Date.today.beginning_of_day, :game_time.lte => Date.today.end_of_day )
@todays_fields = {}
@next_game_date = @league.games.where(:game_time.gte => Time.now).order_by(game_time: 'asc').first.game_time.to_date

@games = @league.games.where(:game_time.gte => @next_game_date.beginning_of_day, :game_time.lte => @next_game_date.end_of_day )
@fields = {}
@field_game_count = {}

@todays_games.each do |g|
@games.each do |g|
fsid = g.field_site._id.to_s

@todays_fields[fsid] ||= g.field_site
@fields[fsid] ||= g.field_site
@field_game_count[fsid] ||= 0

@field_game_count[fsid] += 1
Expand All @@ -924,17 +926,19 @@ def process_rainout
# Create job, queue jobs
jobs = []

rainout_date = Date.parse(params[:rainout_date])

params[:fieldsite_ids].each do |fsid|
fs = FieldSite.find(fsid)
unless fs.present?
redirect_to rainout_games_league_path(@league), flash: {error: "Invalid field site (#{fsid})."}
return
end

GameCancellationWorker.perform_async(@league._id.to_s, fsid, Date.today.beginning_of_day.to_i, Date.today.end_of_day.to_i, current_user._id.to_s, params[:notify])
GameCancellationWorker.perform_async(@league._id.to_s, fsid, rainout_date.beginning_of_day.to_i, rainout_date.end_of_day.to_i, current_user._id.to_s, params[:notify])
end

redirect_to league_path(@league), notice: "We've started processing cancellations for those sites. It may take a few minutes for them all to be sent."
redirect_to league_path(@league), notice: "We've started processing cancellations for those sites for #{rainout_date}. It may take a few minutes for them all to be sent."
end

def missing_spirit_reports
Expand Down
7 changes: 5 additions & 2 deletions app/views/leagues/rainout_games.html.haml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
- content_for :title, @league.name
= render :partial => '/pageheader', :locals => {subtitle: nil, breadcrumbs: {'Leagues' => leagues_path, @league.name => league_path(@league), 'Rainout Games' => nil}}

- if @todays_games.count > 0
%H1 Rainouts for #{@next_game_date.strftime('%A, %B %-d, %Y')}

- if @games.count > 0
=form_tag process_rainout_league_path(@league), class: 'form' do
%input{type: 'hidden', name: "rainout_date", value: @next_game_date}
.row
.span4.offset2
%h3 Fields to Rain Out:
.control-group
.controls
- @todays_fields.each do |id, fs|
- @fields.each do |id, fs|
%label.checkbox
=check_box_tag 'fieldsite_ids[]', id
#{fs.name} (#{@field_game_count[id]} games)
Expand Down
4 changes: 2 additions & 2 deletions app/workers/game_cancellation_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def perform(league_id, fieldsite_id, start_ts, end_ts, cancelling_user_id, notif

new_score_report = {
reporter_id: user._id,
report_time: Time.now,
report_time: 1.minute.ago,
reporter_ip: '0.0.0.4',
rainout: true,
forfeit: false
Expand Down Expand Up @@ -52,7 +52,7 @@ def perform(league_id, fieldsite_id, start_ts, end_ts, cancelling_user_id, notif
end

game_date = Time.at(start_ts).strftime('%a, %b %e')
text_message = "Bad news! Your AFDC games at #{@fieldsite.name} are canceled for today (#{game_date})."
text_message = "Bad news! Your AFDC games at #{@fieldsite.name} are canceled for (#{game_date})."

player_list.each do |user_id, p|
notify_user(p, text_message, start_ts)
Expand Down

0 comments on commit 913d8ef

Please sign in to comment.