Skip to content

Commit

Permalink
Adding in holiday support, which requires the Holidays gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
Brad Beattie committed Jun 16, 2009
1 parent 908c361 commit 2d04550
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
8 changes: 5 additions & 3 deletions app/controllers/schedules_controller.rb
Expand Up @@ -103,8 +103,8 @@ def fill
@defaults.delete_if { |user_id, default| !default.weekday_hours.detect { |weekday| weekday != 0 }}
@calendar = Redmine::Helpers::Calendar.new(Date.today, current_language, :week)
end


# Given a version, we want to estimate when it can be completed. To generate
# this date, we need open issues to have time estimates and for assigned
# individuals to have scheduled time.
Expand Down Expand Up @@ -435,7 +435,7 @@ def fill_entries
# Get the defaults for the users we want to fill time for
params[:fill_total].delete_if { |user_id, fill_total| fill_total.to_f == 0 }
defaults = get_defaults(params[:fill_total].collect { |user_id, fill_total| user_id.to_i }).index_by { |default| default.user_id }

# Fill the schedule of each specified user
params[:fill_total].each do |user_id, fill_total|

Expand All @@ -462,6 +462,7 @@ def fill_entries
available_hours -= other_project_hours
available_hours -= project_entry.hours unless project_entry.nil?
available_hours = [available_hours, fill_hours, hours_remaining].min
available_hours = 0 if date_index.holiday?($holiday_locale, :observed)

# Create an entry if we're adding time to this day
if available_hours > 0
Expand Down Expand Up @@ -538,6 +539,7 @@ def get_availabilities
availabilities[day][user.id] -= entries_by_user[user.id][day].collect {|entry| entry.hours }.sum unless entries_by_user[user.id].nil? || entries_by_user[user.id][day].nil?
availabilities[day][user.id] -= closed_entries_by_user[user.id][day].hours unless closed_entries_by_user[user.id].nil? || closed_entries_by_user[user.id][day].nil?
availabilities[day][user.id] = [0, availabilities[day][user.id]].max
availabilities[day][user.id] = 0 if day.holiday?($holiday_locale, :observed)
end
end
availabilities
Expand Down
6 changes: 3 additions & 3 deletions app/views/schedules/_calendar.html.erb
Expand Up @@ -43,7 +43,7 @@
<%= link_to @user, :controller => 'schedules', :action => 'index', :date => @date, :user_id => @user unless @user.nil? %>
</th>
<% (calendar.startdt..calendar.enddt).each do |day| %>
<td class="even<%= ' today' if Date.today == day %>">
<td class="even<%= ' today' if Date.today == day %> <%= ' holiday' if day.holiday?($holiday_locale, :observed) %>">
<ul>
<% if !schedule_entries_by_day.nil? && !schedule_entries_by_day[day].nil? %>
<% schedule_entries_by_day[day].sort.each do |entry| %>
Expand All @@ -65,7 +65,7 @@
<% schedule_entries_by_day = @entries.group_by {|entry| entry.date} %>
<tr>
<% (calendar.startdt..calendar.enddt).each do |day| %>
<td class="even<%= ' today' if Date.today == day %>">
<td class="even<%= ' today' if Date.today == day %> <%= ' holiday' if day.holiday?($holiday_locale, :observed) %>">
<ul>
<% if !schedule_entries_by_day[day].nil? %>
<% schedule_entries_by_day[day].sort.each do |entry| %>
Expand Down Expand Up @@ -97,4 +97,4 @@
<% end %>
</tr>
</tfoot>
</table>
</table>
6 changes: 3 additions & 3 deletions app/views/schedules/_project.html.erb
Expand Up @@ -11,7 +11,7 @@
<tr>
<%= "<th>#{user}</th>" %>
<% (calendar.startdt..calendar.enddt).each do |day| %>
<td class="even<%= ' today' if Date.today == day %>">
<td class="even<%= ' today' if Date.today == day %> <%= ' holiday' if day.holiday?($holiday_locale, :observed) %>">
<%
if date_entries[day.ajd].nil?
entry = ScheduleEntry.new
Expand All @@ -38,11 +38,11 @@
<tr>
<th><%= l(:label_total) %></th>
<% (calendar.startdt..calendar.enddt).each do |day| %>
<th class="even<%= ' today' if Date.today == day %>">
<td class="even<%= ' today' if Date.today == day %> <%= ' holiday' if day.holiday?($holiday_locale, :observed) %>">
<% sum = @entries.collect {|e| e.hours if e.date == day }.compact.sum %>
<%= sum if sum > 0 %>
</th>
<% end %>
</tr>
</tfoot>
</table>
</table>
6 changes: 3 additions & 3 deletions app/views/schedules/_user.html.erb
Expand Up @@ -12,7 +12,7 @@
<tr>
<%= "<th>#{project}</th>" %>
<% (calendar.startdt..calendar.enddt).each do |day| %>
<td class="even<%= ' today' if Date.today == day %>">
<td class="even<%= ' today' if Date.today == day %> <%= ' holiday' if day.holiday?($holiday_locale, :observed) %>">
<%
if date_entries[day.ajd].nil?
entry = ScheduleEntry.new
Expand Down Expand Up @@ -61,12 +61,12 @@
<tr>
<th><%= l(:label_total) %></th>
<% (calendar.startdt..calendar.enddt).each do |day| %>
<th class="even<%= ' today' if Date.today == day %>">
<th class="even<%= ' today' if Date.today == day %> <%= ' holiday' if day.holiday?($holiday_locale, :observed) %>">
<% sum = @entries.collect {|e| e.hours if e.date == day }.compact.sum %>
<% sum += closed_entries[day.ajd].hours unless closed_entries[day.ajd].nil? %>
<%= sum if sum > 0 %>
</th>
<% end %>
</tr>
</tfoot>
</table>
</table>
3 changes: 2 additions & 1 deletion assets/stylesheets/schedules.css
Expand Up @@ -15,4 +15,5 @@ table.schedule_entry_cal li.schedule_entry div { }
span.schedule_available { white-space: nowrap; }
td.hours table.progress { float: right; margin: 1px 0 1px 6px; }
td.hours p.pourcent { font-size: inherit; }
td.underscheduled table.progress td.closed { background: #e0dbba none repeat scroll 0%; }
td.underscheduled table.progress td.closed { background: #e0dbba none repeat scroll 0%; }
table.cal td.holiday { background: #EED; }
3 changes: 3 additions & 0 deletions init.rb
@@ -1,4 +1,7 @@
require 'redmine'
require 'holidays'
require 'holidays/ca' # Edit this to the most appropriate holiday region for you: http://code.dunae.ca/svn/holidays/trunk/data/
$holiday_locale = 'ca_bc' # Set this to the same region (or subregion if appropriate)

require_dependency 'schedule_compatibility'

Expand Down

0 comments on commit 2d04550

Please sign in to comment.