lib/Resource.rb in taskjuggler-0.0.4 vs lib/Resource.rb in taskjuggler-0.0.5

- old
+ new

@@ -34,9 +34,166 @@ # ResourceScenario. def method_missing(func, scenarioIdx, *args) @data[scenarioIdx].method(func).call(*args) end + def query_journal(query) + journalMessages(query, true) + end + + def query_dashboard(query) + dashboard(query) + end + + private + + # Create a blog-style list of all alert messages that match the Query. + def journalMessages(query, longVersion) + # 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 = '' + list = @project['journal'].entriesByResource(self, query.start, query.end) + # Sort all entries in buckets by their alert level. + numberOfLevels = project['alertLevels'].length + listByLevel = [] + 0.upto(numberOfLevels - 1) { |i| listByLevel[i] = [] } + list.each do |entry| + listByLevel[entry.alertLevel] << entry + end + (numberOfLevels - 1).downto(0) do |level| + levelList = listByLevel[level] + levelRecord = @project['alertLevels'][level] + alertName = "[[File:icons/flag-#{levelRecord[0]}.png|" + + "alt=[#{levelRecord[1]}]|text-bottom]]" + levelList.each do |entry| + # The TimeSheetRecords associated with this entry. + tsRecord = entry.timeSheetRecord + if entry.property.is_a?(Task) + rText += "== #{alertName} <nowiki>#{entry.property.name}</nowiki> "+ + "(ID: #{entry.property.fullId}) ==\n\n" + if tsRecord + rText += "'''Work:''' #{tsRecord.actualWorkPercent.to_i}% " + if tsRecord.actualWorkPercent != tsRecord.planWorkPercent + rText += "(#{tsRecord.planWorkPercent.to_i}%) " + end + if tsRecord.remaining + rText += "'''Remaining:''' #{tsRecord.actualRemaining}d " + if tsRecord.actualRemaining != tsRecord.planRemaining + rText += "(#{tsRecord.planRemaining}d) " + end + else + rText += "'''End:''' " + + "#{tsRecord.actualEnd.to_s(query.timeFormat)} " + if tsRecord.actualEnd != tsRecord.planEnd + rText += "(#{tsRecord.planEnd.to_s(query.timeFormat)}) " + end + end + rText += "\n\n" + end + elsif !(tsRecord = entry.timeSheetRecord).nil? && + entry.timeSheetRecord.task.is_a?(String) + rText += "== #{alertName} <nowiki>[New Task] #{tsRecord.name} " + + "</nowiki> "+ + "(ID: #{tsRecord.task}) ==\n\n" + if tsRecord + rText += "'''Work:''' #{tsRecord.actualWorkPercent}% " + if tsRecord.remaining + rText += "'''Remaining:''' #{tsRecord.actualRemaining}d " + else + rText += "'''End:''' " + + "#{tsRecord.actualEnd.to_s(query.timeFormat)} " + end + rText += "\n\n" + end + else + rText += "== #{alertName} Personal Notes ==\n\n" + end + unless entry.headline.empty? + rText += "'''<nowiki>#{entry.headline}</nowiki>'''\n\n" + end + if entry.summary + rText += entry.summary.richText.inputText + "\n\n" + end + if longVersion && entry.details + rText += entry.details.richText.inputText + "\n\n" + end + end + end + + # Now convert the RichText markup String into RichTextIntermediate + # format. + handlers = [ + RTFNavigator.new(@project), + RTFQuery.new(@project), + RTFReport.new(@project) + ] + begin + rti = RichText.new(rText, handlers).generateIntermediateFormat + rescue RichTextException => msg + $stderr.puts "Error while processing Rich Text\n" + + "Line #{msg.lineNo}: #{msg.text}\n" + + "#{msg.line}" + 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 + + # Create a dashboard-like list of all task that have a current alert + # status. + def dashboard(query) + scenarioIdx = @project['trackingScenarioIdx'] + taskList = [] + @project.tasks.each do |task| + if task['responsible', scenarioIdx].include?(self) && + !@project['journal'].currentEntries(query.end, task, + 0, query.start).empty? + taskList << task + end + end + + if taskList.empty? + rText = "We have no current status for any task that #{name} " + + "is responsible for." + else + # 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 = '' + + taskList.each do |task| + rText += "== <nowiki>[#{task.query_alert(query)}] Task: " + + "#{task.name}</nowiki> (#{task.fullId}) ==\n\n" + rText += task.query_alertmessage(query).richText.inputText + "\n\n" + end + end + + # Now convert the RichText markup String into RichTextIntermediate + # format. + handlers = [ + RTFNavigator.new(@project), + RTFQuery.new(@project), + RTFReport.new(@project) + ] + begin + rti = RichText.new(rText, handlers).generateIntermediateFormat + rescue RichTextException => msg + $stderr.puts "Error while processing Rich Text\n" + + "Line #{msg.lineNo}: #{msg.text}\n" + + "#{msg.line}" + 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 + end end