lib/ResourceScenario.rb in taskjuggler-0.0.8 vs lib/ResourceScenario.rb in taskjuggler-0.0.9
- old
+ new
@@ -1,11 +1,12 @@
#!/usr/bin/env ruby -w
# encoding: UTF-8
#
# = ResourceScenario.rb -- The TaskJuggler III Project Management Software
#
-# Copyright (c) 2006, 2007, 2008, 2009, 2010 by Chris Schlaeger <cs@kde.org>
+# Copyright (c) 2006, 2007, 2008, 2009, 2010, 2011
+# by Chris Schlaeger <chris@linux.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
@@ -131,11 +132,11 @@
end
end
end
def postScheduleCheck
- if a('fail') || a('warn')
+ if !a('fail').empty? || !a('warn').empty?
queryAttrs = { 'project' => @project,
'scenarioIdx' => @scenarioIdx,
'property' => @property,
'scopeProperty' => nil,
'start' => @project['start'],
@@ -143,23 +144,28 @@
'loadUnit' => :days,
'numberFormat' => @project['numberFormat'],
'timeFormat' => @project['timeFormat'],
'currencyFormat' => @project['currencyFormat'] }
query = Query.new(queryAttrs)
- if a('fail') && a('fail').eval(query)
- error('resource_fail_check',
- "User defined check failed for resource #{@property.fullId} \n" +
- "Condition: #{a('fail').to_s}\n" +
- "Result: #{a('fail').to_s(query)}")
- end
- if a('warn') && a('warn').eval(query)
- warning('resource_warn_check',
- "User defined warning triggered for resource " +
+ a('fail').each do |expr|
+ if expr.eval(query)
+ error('resource_fail_check',
+ "User defined check failed for resource " +
"#{@property.fullId} \n" +
- "Condition: #{a('warn').to_s}\n" +
- "Result: #{a('warn').to_s(query)}")
+ "Condition: #{expr.to_s}\n" +
+ "Result: #{expr.to_s(query)}")
+ end
end
+ a('warn').each do |expr|
+ if expr.eval(query)
+ warning('resource_warn_check',
+ "User defined warning triggered for resource " +
+ "#{@property.fullId} \n" +
+ "Condition: #{expr.to_s}\n" +
+ "Result: #{expr.to_s(query)}")
+ end
+ end
end
end
# Returns true if the resource is available at the time specified by
# _sbIdx_.
@@ -477,11 +483,13 @@
return allocatedSub(startIdx, endIdx, task)
end
# Iterate over the scoreboard and turn its content into a set of Bookings.
- def getBookings
+ # _iv_ can be an Interval to limit the bookings within the provided
+ # period.
+ def getBookings(iv = nil)
return {} if @property.container? || @scoreboard.nil? ||
@firstBookedSlot.nil? || @lastBookedSlot.nil?
bookings = {}
lastTask = nil
@@ -493,10 +501,19 @@
endIdx = @lastBookedSlot + 1
# In case the index markers are still uninitialized, we have no bookings.
return {} if startIdx.nil? || endIdx.nil?
+ # If the user provided an Interval, we only return bookings within this
+ # Interval.
+ if iv
+ ivStartIdx = @project.dateToIdx(iv.start)
+ ivEndIdx = @project.dateToIdx(iv.end)
+ startIdx = ivStartIdx if ivStartIdx > startIdx
+ endIdx = ivEndIdx if ivEndIdx < endIdx
+ end
+
startIdx.upto(endIdx) do |idx|
task = @scoreboard[idx]
# Now we watch for task changes.
if task != lastTask || (lastTask == nil && task.is_a?(Task)) ||
(task.is_a?(Task) && idx == endIdx)
@@ -525,9 +542,13 @@
# Return a list of scoreboard intervals that are at least _minDuration_ long
# and contain only off-duty and vacation slots. The result is an Array of
# [ start, end ] TjTime values.
def collectTimeOffIntervals(iv, minDuration)
+ # Time-off intervals are only useful for leaf resources. Group resources
+ # would just default to the global working hours.
+ return [] unless @property.leaf?
+
initScoreboard if @scoreboard.nil?
@scoreboard.collectIntervals(iv, minDuration) do |val|
val.is_a?(Fixnum) && (val & 0x3E) != 0
end