Permalink
Browse files

Adding in holiday support, which requires the Holidays gem.

  • Loading branch information...
1 parent 908c361 commit 2d045504e940098a80c77328ee78dfe5f1bddbb5 Brad Beattie committed Jun 16, 2009
@@ -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.
@@ -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|
@@ -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
@@ -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
@@ -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| %>
@@ -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| %>
@@ -97,4 +97,4 @@
<% end %>
</tr>
</tfoot>
-</table>
+</table>
@@ -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
@@ -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>
@@ -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
@@ -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>
@@ -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; }
View
@@ -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'

0 comments on commit 2d04550

Please sign in to comment.