class TaskJuggler::Journal
A Journal
is a list of JournalEntry
objects. It provides methods to add JournalEntry
objects and retrieve specific entries or other processed information.
Public Class Methods
Create a new Journal
object.
# File lib/taskjuggler/Journal.rb, line 350 def initialize # This list holds all entries. @entries = JournalEntryList.new # This hash holds a list of entries for each property. @propertyToEntries = {} end
Public Instance Methods
Add a new JournalEntry
to the Journal
.
# File lib/taskjuggler/Journal.rb, line 358 def addEntry(entry) return if @entries.include?(entry) @entries << entry return if entry.property.nil? # When we store the property into the @propertyToEntries hash, we need # to make sure that we store the PropertyTreeNode object and not a # PTNProxy object. unless @propertyToEntries.include?(entry.property.ptn) @propertyToEntries[entry.property.ptn] = JournalEntryList.new end @propertyToEntries[entry.property.ptn] << entry end
Return the list of JournalEntry
objects that are dated at or before date, are for property or any of its childs, have at least level alert and are after minDate. We only return those entries with the highest overall alert level.
# File lib/taskjuggler/Journal.rb, line 597 def alertEntries(date, property, minLevel, minDate, query) maxLevel = 0 entries = [] # Gather all the current (as of the specified _date_) JournalEntry # objects for the property and than find the highest level. currentEntriesR(date, property, minLevel, minDate, query).each do |e| if maxLevel < e.alertLevel maxLevel = e.alertLevel entries = [ e ] elsif maxLevel == e.alertLevel entries << e end end entries end
Determine the alert level for the given property at the given date. If the property does not have any JournalEntry
objects or they are out of date compared to the child properties, the level is computed based on the highest level of the children. Only take the entries that are not filtered by query.hideJournalEntry into account.
# File lib/taskjuggler/Journal.rb, line 583 def alertLevel(date, property, query) maxLevel = 0 # Gather all the current (as of the specified _date_) JournalEntry # objects for the property and than find the highest level. currentEntriesR(date, property, 0, nil, query).each do |e| maxLevel = e.alertLevel if maxLevel < e.alertLevel end maxLevel end
This function returns a list of entries that have all the exact same date and are the last entries before the deadline date. Only messages with at least the required alert level minLevel are returned. Messages with alert level minLevel or higher must be newer than minDate.
# File lib/taskjuggler/Journal.rb, line 617 def currentEntries(date, property, minLevel, minDate, logExp) pEntries = getEntries(property) ? getEntries(property).last(date) : JournalEntryList.new # Remove entries below the minium alert level or before the timeout # date. pEntries.delete_if do |e| e.headline.empty? || e.alertLevel < minLevel || (e.alertLevel >= minLevel && minDate && e.date < minDate) end unless pEntries.empty? # Check parents for a more important or more up-to-date message. p = property.parent while p do ppEntries = getEntries(p) ? getEntries(p).last(date) : JournalEntryList.new # A parent has a more up-to-date message. if !ppEntries.empty? && ppEntries.first.date >= pEntries.first.date return JournalEntryList.new end p = p.parent end end # Remove all entries that are filtered by logExp. if logExp pEntries.delete_if { |e| hidden(e, logExp) } end pEntries end
This function recursively traverses a tree of PropertyTreeNode
objects from bottom to top. It returns the last entries before date for each property unless there is a property in the sub-tree specified by the root property with more up-to-date entries. The result is a JournalEntryList
.
# File lib/taskjuggler/Journal.rb, line 656 def currentEntriesR(date, property, minLevel, minDate, query) DataCache.instance.cached(self, :currentEntriesR, date, property, minLevel, minDate, query) do # See if this property has any current JournalEntry objects. pEntries = getEntries(property) ? getEntries(property).last(date) : JournalEntryList.new # Remove entries below the minium alert level or before the timeout # date. pEntries.delete_if do |e| e.headline.empty? || e.alertLevel < minLevel || (e.alertLevel == minLevel && minDate && e.date < minDate) end # Determine the highest alert level of the pEntries. maxPAlertLevel = 0 pEntries.each do |e| maxPAlertLevel = e.alertLevel if e.alertLevel > maxPAlertLevel end cEntries = JournalEntryList.new latestDate = nil maxAlertLevel = 0 # If we have an entry from this property, we only care about child # entries that are from a later date. minDate = pEntries.first.date + 1 unless pEntries.empty? # Now gather all current entries of the child properties and find the # date that is closest to and right before the given _date_. property.kids.each do |p| currentEntriesR(date, p, minLevel, minDate, query).each do |e| # Find the date of the most recent entry. latestDate = e.date if latestDate.nil? || e.date > latestDate # Find the highest alert level. maxAlertLevel = e.alertLevel if e.alertLevel > maxAlertLevel cEntries << e unless cEntries.include?(e) end end # Only Task properties have dependencies. if (query.journalMode == :status_dep || query.journalMode == :alerts_dep) && property.is_a?(Task) # Now gather all current entries of the dependency properties and find # the date that is closest to and right before the given _date_. property['startpreds', query.scenarioIdx].each do |p, onEnd| # We only follow end->start dependencies. next unless onEnd currentEntriesR(date, p, minLevel, minDate, query).each do |e| # Find the date of the most recent entry. latestDate = e.date if latestDate.nil? || e.date > latestDate # Find the highest alert level. maxAlertLevel = e.alertLevel if e.alertLevel > maxAlertLevel cEntries << e unless cEntries.include?(e) end end end if !pEntries.empty? && (maxPAlertLevel > maxAlertLevel || latestDate.nil? || pEntries.first.date >= latestDate) # If no child property has a more current JournalEntry or one with a # higher alert level than this property and this property has # JournalEntry objects, than those are taken. entries = pEntries else # Otherwise we take the entries from the kids. entries = cEntries end # Remove all entries that are filtered by query.hideJournalEntry. if query.hideJournalEntry entries.delete_if { |e| hidden(e, query.hideJournalEntry) } end # Otherwise return the list provided by the childen. entries end end
Delete all entries of the Journal
for which the block yields true.
# File lib/taskjuggler/Journal.rb, line 378 def delete_if @entries.delete_if do |e| res = yield(e) @propertyToEntries[e.property.ptn].delete(e) if res res end end
# File lib/taskjuggler/Journal.rb, line 562 def entries(startDate = nil, endDate = nil, logExp = nil, property = nil, alertLevel = nil) list = JournalEntryList.new @entries.each do |entry| if (startDate.nil? || startDate <= entry.date) && (endDate.nil? || endDate >= entry.date) && (property.nil? || property.ptn == entry.property || entry.property.isChildOf?(property.ptn)) && (alertLevel.nil? || alertLevel == entry.alertLevel) && !hidden(entry, logExp) list << entry end end list end
Return a list of all JournalEntry
objects for the given resource that are dated between startDate and endDate, are not hidden by their flags matching logExp, are for Task
task and have at least the alert level _alertLevel. If an optional parameter is nil, it always matches the entry.
# File lib/taskjuggler/Journal.rb, line 507 def entriesByResource(resource, startDate = nil, endDate = nil, logExp = nil, task = nil, alertLevel = nil) list = JournalEntryList.new @entries.each do |entry| if entry.author == resource.ptn && (startDate.nil? || entry.date > startDate) && (endDate.nil? || entry.date <= endDate) && (task.nil? || entry.property == task.ptn) && (alertLevel.nil? || entry.alertLevel >= alertLevel) && !entry.headline.empty? && !hidden(entry, logExp) list << entry end end list end
Return a list of all JournalEntry
objects for the given task that are dated between startDate and endDate (end date not included), are not hidden by their flags matching logExp are from Author resource and have at least the alert level _alertLevel. If an optional parameter is nil, it always matches the entry.
# File lib/taskjuggler/Journal.rb, line 528 def entriesByTask(task, startDate = nil, endDate = nil, logExp = nil, resource = nil, alertLevel = nil) list = JournalEntryList.new @entries.each do |entry| if entry.property == task.ptn && (startDate.nil? || entry.date >= startDate) && (endDate.nil? || entry.date < endDate) && (resource.nil? || entry.author == resource) && (alertLevel.nil? || entry.alertLevel >= alertLevel) && !entry.headline.empty? && !hidden(entry, logExp) list << entry end end list end
Return a list of all JournalEntry
objects for the given task or any of its sub tasks that are dated between startDate and endDate, are not hidden by their flags matching logExp, are from Author resource and have at least the alert level _alertLevel. If an optional parameter is nil, it always matches the entry.
# File lib/taskjuggler/Journal.rb, line 549 def entriesByTaskR(task, startDate = nil, endDate = nil, logExp = nil, resource = nil, alertLevel = nil) list = entriesByTask(task, startDate, endDate, logExp, resource, alertLevel) task.kids.each do |t| list += entriesByTaskR(t, startDate, endDate, logExp, resource, alertLevel) end list end
# File lib/taskjuggler/Journal.rb, line 373 def getEntries(property) @propertyToEntries[property.ptn] end
# File lib/taskjuggler/Journal.rb, line 388 def to_rti(query) entries = JournalEntryList.new case query.journalMode when :journal # This is the regular journal. It contains all journal entries that # are dated in the query interval. If a property is given, only # entries of this property are included. if query.property if query.property.is_a?(Task) entries = entriesByTask(query.property, query.start, query.end, query.hideJournalEntry) elsif query.property.is_a?(Resource) entries = entriesByResource(query.property, query.start, query.end, query.hideJournalEntry) end else entries = self.entries(query.start, query.end, query.hideJournalEntry) end when :journal_sub # This mode also contains all journal entries that are dated in the # query interval. A property must be given and only entries of this # property and all its children are included. if query.property.is_a?(Task) entries = entriesByTaskR(query.property, query.start, query.end, query.hideJournalEntry) end when :status_up # In this mode only the last entries before the query end date for # each task are included. An entry is not included if any of the # parent tasks has a more recent entry that is still before the query # end date. if query.property if query.property.is_a?(Task) entries += currentEntries(query.end, query.property, 0, query.start, query.hideJournalEntry) end else query.project.tasks.each do |task| # We only care about top-level tasks. next if task.parent entries += currentEntries(query.end, task, 0, query.start, query.hideJournalEntry) # Eliminate duplicates due to entries from adopted tasks entries.uniq! end end when :status_down, :status_dep # In this mode only the last entries before the query end date for # each task (incl. sub tasks) are included. if query.property if query.property.is_a?(Task) entries += currentEntriesR(query.end, query.property, 0, query.start, query) end else query.project.tasks.each do |task| # We only care about top-level tasks. next if task.parent entries += currentEntriesR(query.end, task, 0, query.start, query) # Eliminate duplicates due to entries from adopted tasks entries.uniq! end end when :alerts_down, :alerts_dep # In this mode only the last entries before the query end date for # each task (incl. sub tasks) and only the ones with the highest alert # level are included. if query.property if query.property.is_a?(Task) entries += alertEntries(query.end, query.property, 1, query.start, query) end else query.project.tasks.each do |task| # We only care about top-level tasks. next if task.parent entries += alertEntries(query.end, task, 1, query.start, query) # Eliminate duplicates due to entries from adopted tasks entries.uniq! end end else raise "Unknown jourmal mode: #{query.journalMode}" end # Sort entries according to the user specified sorting criteria. entries.setSorting(query.sortJournalEntries) entries.sort! # The components of the message are either UTF-8 text or RichText. For # the RichText components, we use the originally provided markup since # we compose the result as RichText markup first. rText = '' entries.each do |entry| rText += entry.to_rText(query) end # Now convert the RichText markup String into RichTextIntermediate # format. unless (rti = RichText.new(rText, RTFHandlers.create(query.project)). generateIntermediateFormat) warning('ptn_journal', "Syntax error in journal: #{rText}") return nil end # No section numbers, please! rti.sectionNumbers = false # We use a special class to allow CSS formating. rti.cssClass = 'tj_journal' query.rti = rti end