lib/taskjuggler/ResourceScenario.rb in taskjuggler-3.3.0 vs lib/taskjuggler/ResourceScenario.rb in taskjuggler-3.4.0

- old
+ new

@@ -49,10 +49,15 @@ # The index of the last booked time Slot. @lastBookedSlot = nil # Same but for each assigned resource. @lastBookedSlots = {} + # First available slot of the resource. + @minslot = nil + # Last available slot of the resource. + @maxslot = nil + # Attributed are only really created when they are accessed the first # time. So make sure some needed attributes really exist so we don't # have to check for existance each time we access them. %w( alloctdeffort chargeset criticalness directreports duties efficiency effort limits managers rate reports shifts @@ -168,10 +173,17 @@ # _sbIdx_. def booked?(sbIdx) @scoreboard[sbIdx].is_a?(Task) end + # Return the Task that this resource is booked for at the time specified + # by _sbIdx_. If not booked to a task, nil is returned. + def bookedTask(sbIdx) + return nil unless (sb = @scoreboard[sbIdx]).is_a?(Task) + sb + end + # Book the slot indicated by the scoreboard index +sbIdx+ for Task +task+. # If +force+ is true, overwrite the existing booking for this slot. The # method returns true if the slot was available. def book(sbIdx, task, force = false) return false if !force && !available?(sbIdx) @@ -675,11 +687,11 @@ end # Count the booked slots between the start and end index. If _task_ is not # nil count only those slots that are assigned to this particular task or # any of its sub tasks. - def getAllocatedSlots(startIdx, endIdx, task) + def getAllocatedSlots(startIdx, endIdx, task = nil) # If there is no scoreboard, we don't have any allocations. return 0 unless @scoreboard startIdx, endIdx = fitIndicies(startIdx, endIdx, task) return 0 if startIdx >= endIdx @@ -726,10 +738,20 @@ # Bit 1 needs to be unset and the leave bits must not be 0. val.is_a?(Fixnum) && (val & 0x2) == 0 && (val & 0x3C) != 0 end end + # Get the first available slot of the resource. + def getMinSlot + @minslot + end + + # Get the last available slot of the resource. + def getMaxSlot + @maxslot + end + private def initScoreboard # Create scoreboard and mark all slots as non-working-time. @scoreboard = Scoreboard.new(@project['start'], @project['end'], @@ -789,9 +811,27 @@ # In merge mode, we only add the shift leaves with higher type # index or unassigned slots. @scoreboard[i] = v & 0x3E end end + end + + # Set minimum and maximum availability + idx = 0 + while idx < @scoreboard.size + if available?(idx) + @minslot = idx + break + end + idx += 1 + end + idx = @scoreboard.size - 1 + while idx >= 0 + if available?(idx) + @maxslot = idx + break + end + idx -= 1 end end def countSlots(startIdx, endIdx) return 0 if startIdx >= endIdx